afa 6 сар өмнө
parent
commit
dc53d87adf

+ 27 - 1
application/api/controller/Pledge.php

@@ -11,7 +11,7 @@ use Exception;
 use app\common\model\UserModel;
 use think\Db;
 use app\api\logic\PledgeLogic;
-
+use app\common\model\UserPledge;
 
 //质押抵扣
 class Pledge extends Api
@@ -169,5 +169,31 @@ class Pledge extends Api
       }
    
       //存储续费
+      public function setRenew(UserPledge $userPledge, PledgeLogic $pledgeLogic, LedgerWalletModel $ledgerWalletModel)
+      {
+            $pledge_id  = $this->request->post('pledge_id', 0, 'intval');
+            $pay_type   = $this->request->post('pay_type/d', 1);//支付方式 1 茶宝 2 Teac
+            if(empty($pledge_id) || in_array($pay_type, [1,2]) == false) $this->error(__("参数有误,无可用产品"));
+            //记录
+            $pledge = $userPledge::alias('a')->where('a.id', $pledge_id)->join('product_pledge p', 'p.id = a.pledge_id')->field('a.*,p.token,p.teac,p.type_id,p.is_renew,p.status as p_status')->find();
+            if (empty($pledge)) $this->error(__("质抵活动不存在"));
+            if ($pledge->status != $userPledge::Ongoing || empty($pledge->is_renew) || empty($pledge->p_status))$this->error(__("质抵活动已结束"));
+            //余额判断
+            $user = $ledgerWalletModel::getWallet($this->auth->id);
+            if($user[$this->pay[$pay_type]] < $pledge[$this->pay[$pay_type]]) $this->error(__("余额不足"));
+            
+            Db::startTrans();
+            try {
+                  // 质抵押订单 
+                  $pledgeLogic::setPledgeOrderRenew($pledge, $this->auth->id, $this->pay[$pay_type]);
+                  // 提交事务
+                  Db::commit();
+            } catch (Exception $e) {
+                  // 回滚事务
+                  Db::rollback();
+                  $this->error($e->getMessage(), null, $e->getCode());
+            }
+            $this->success('ok');
+      }
  
 }

+ 11 - 0
application/api/logic/PledgeLogic.php

@@ -166,5 +166,16 @@ class PledgeLogic
         return Loader::model('LedgerWalletModel')->changeWalletAccount($user_id, Asset::TEAC, $total, LedgerTeacChangeModel::Pledge, 0);  
     }
 
+    //存储订单续费
+    public static function setPledgeOrderRenew(object $pledge, int $user_id, string $pay_type)
+    {   
+        //扣除支付金额
+        $action = ($pay_type == Asset::TEAC)? LedgerTeacChangeModel::PledgeFee: LedgerTokenChangeModel::Pledge; //类型
+        (new LedgerWalletModel())->changeWalletAccount($user_id, $pay_type, $pledge[$pay_type], $action, 0);
+  
+        $pledge->end_time = $pledge->end_time + config('pledge_end_time');
+        return $pledge->save();
+
+    }
 
 }

+ 9 - 5
application/api/logic/WelfareLoginc.php

@@ -5,6 +5,7 @@ namespace app\api\logic;
 
 use app\common\model\ProductArea;
 use fast\Asset;
+use app\common\model\LedgerTokenChangeModel;
 use app\common\model\LedgerFrozenChangeModel;
 use app\common\model\ProductLists;
 use app\common\model\ProductOrder;
@@ -44,9 +45,6 @@ class WelfareLoginc
     向持有A茶超过10套的用户,空投持有 数量X20%套B茶,数量取整
     */
-    /** $mod 0指定数量 1比
-     * 获取用户Rwa数量
-     */
     public static function getUserRwaProductNum(int $productId, int $rwa_num, $mod, $num): int
     {   
         //读取当前持有RWa数据
@@ -173,10 +171,16 @@ class WelfareLoginc
             }
         }
 
-        //发放层级奖励
+        //发放上级推广奖励
+        $ecologyCount = UserModel::where('parent_id', $parentId)->where('is_ecology', 1)->count() + 1;
+        $mod = bcmod($ecologyCount, 3);
+        $parent_chabao = $ecology['parent_chabao'][$mod];
+        if($mod == 0) Loader::model('ProductOrder')::setCreateOrder(0, ['product_id'=> $ecology['parent_product_id'], 'area_id'=>0, 'price'=>0], ProductOrder::Airdrop, $parentId, 0, 0, 0, 0);
+        //发放上级茶宝奖励
+        Loader::model('LedgerWalletModel')->changeWalletAccount($parentId, Asset::TOKEN, $parent_chabao, LedgerTokenChangeModel::Ecology, 0);
         
 
-        //发放标记茶宝
+        //发放自己标记茶宝
         Loader::model('LedgerWalletModel')->changeWalletAccount($uid, Asset::FROZEN, $ecology['frozen'], LedgerFrozenChangeModel::Ecology, 0);
         //修改生态节点标识
         $user->is_ecology  = 1;

+ 6 - 4
application/common/model/LedgerTokenChangeModel.php

@@ -30,7 +30,8 @@ class LedgerTokenChangeModel extends Model
      const Buying            = 16; //求购购买
      const BuySellg          = 17; //求购出售
      const BuyCancel         = 18; //求购取消
-     const Pledge            = 19; //存储服务费
+     const Ecology           = 19; //生态节点奖励
+     const Pledge            = 20; //存储服务费
 
      /*
       * 支付状态
@@ -52,8 +53,8 @@ class LedgerTokenChangeModel extends Model
          self::Community         => '社区津贴',
          self::Service           => '服务津贴',
          self::Together          => '共创津贴',
-         self::Pledge            => '存储服务费',
-       
+         self::Ecology           => '生态节点奖励',
+         self::Pledge            => '存储服务费'
      ];
 
            
@@ -77,8 +78,9 @@ class LedgerTokenChangeModel extends Model
             self::Together => __('共创津贴'),
             self::Super => __('茶宝标记激活'),
             self::Buying => __('求购购买'),
-            self::BuySellg => __('求购出售'),
+            self::BuySellg => __('求购出售'),   
             self::BuyCancel => __('求购取消'),
+            self::Ecology => __('生态节点奖励'),
             self::Pledge => __('存储服务费'),
            ];
     }

+ 3 - 1
application/config.php

@@ -375,7 +375,9 @@ return [
             3 => ['product_id'=>40, 'num'=>8],   //4.RWACHA·破茧化蝶 8套(id 40)
             4 => ['product_id'=>52, 'num'=>1]   //4.TeaC·生态发展,空投卡 1 张(id 52)
         ],
-        'frozen' => '999', //发放标记茶宝 999个
+        'frozen'            => '999', //发放标记茶宝 999个
+        'parent_product_id' => 26,    //上级空投指定产品
+        'parent_chabao'     => [0=>699.3, 1=>99.9, 2=>199.8], //上级奖励茶宝
     ],
     //超级福利奖励
     'super_welfare' => [