afa 6 months ago
parent
commit
2decfb67da

+ 3 - 2
application/api/controller/Pledge.php

@@ -152,11 +152,12 @@ class Pledge extends Api
       public function remove(PledgeLogic $pledgeLogic)
       {
             $pledge_id  = $this->request->post('pledge_id', 0, 'intval');
-            if(empty($pledge_id)) $this->error(__("参数有误,无可用产品"));
+            $product_id  = $this->request->post('product_id/s', '');
+            if(empty($pledge_id) || empty($product_id)) $this->error(__("参数有误,无可用产品"));
             Db::startTrans();
             try {
                   // 质抵押订单 
-                  $res = $pledgeLogic::setPledgeRemove($pledge_id,  $this->auth->id);
+                  $res = $pledgeLogic::setPledgeRemove($pledge_id, $product_id, $this->auth->id);
                   
                   // 提交事务
                   Db::commit();

+ 18 - 5
application/api/logic/PledgeLogic.php

@@ -60,7 +60,7 @@ class PledgeLogic
 
         //扣除支付金额
         $action = ($pay_type == Asset::TEAC)? LedgerTeacChangeModel::PledgeFee: LedgerTokenChangeModel::Pledge; //类型
-        (new LedgerWalletModel())->changeWalletAccount($user_id, $pay_type, $price, $action, 0);
+        (new LedgerWalletModel())->changeWalletAccount($user_id, $pay_type, -$price, $action, 0);
   
         //修改状态
         return $model->whereIn('id', array_column($product, 'id'))->setField('status', $model::Freeze);
@@ -98,7 +98,7 @@ class PledgeLogic
     }
 
     //解除质抵押订单
-    public static function setPledgeRemove(int $pledge_id, int $user_id)
+    public static function setPledgeRemove(int $pledge_id, string $product_id, int $user_id)
     {
         $model  = Loader::model('UserPledge');
         $time  = time();
@@ -111,18 +111,31 @@ class PledgeLogic
                 ->field('a.*,b.day_num')
                 ->find();
         if(empty($rows))  throw new Exception('暂无质押订单');
+        $productAll = explode(',', $rows->product_id);
+        $productId  = explode(',', $product_id);
+        $count      = count(array_intersect($productAll, $productId));
+        if(count($productId) != $count) throw new Exception('参数有误');
+        $diff = array_diff($productAll, $productId);
+        $num = $rows->num;
+        if(empty($diff)) {
+            $rows->status  = $model::Remove;
+        }else{
+            $rows->product_id = implode(',', $diff);
+            $rows->num        = count($diff);
+            $num = $count;
+        }
         $day   = 86400;
         $total = 0; //当前累计收益
         $reta  = bcdiv($rows->day_num, $day, 6); //天数
         $inter = ($rows->last_time == 0) ? $time - $rows->create_time: $time - $rows->last_time; //最后收取时间
-        $total = bcmul($reta, $inter, 6) * $rows->num; //累计收益
+        $total = bcmul($reta, $inter, 6) * $num; //累计收益
         $rows->total_self= bcadd($total, $rows->total_self, 6);
 
         //修改状态
         $detail =json_decode($rows->details, true);
         Loader::model('ProductOrder')::where('user_id', $user_id)->whereIn('id', array_column($detail, 'id'))->setField('status', ProductOrder::Paid);
 
-        $rows->status    = $model::Remove;
+        //更新领取状态
         $rows->last_time = $time;
         return  $rows->save();   
     }
@@ -171,7 +184,7 @@ class PledgeLogic
     {   
         //扣除支付金额
         $action = ($pay_type == Asset::TEAC)? LedgerTeacChangeModel::PledgeFee: LedgerTokenChangeModel::Pledge; //类型
-        (new LedgerWalletModel())->changeWalletAccount($user_id, $pay_type, $pledge[$pay_type], $action, 0);
+        (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();

+ 1 - 1
public/assets/js/backend/ledger/ledger_teac_change.js

@@ -41,7 +41,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 '4': '求购出售',
                                 '5': '取消出售',
                                 '6': 'Teac兑换',
-                                '30': '团队平级奖励',
+                                '7': '存储服务费',
                                 '99': '系统调整',
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },

+ 2 - 1
public/assets/js/backend/ledger/ledger_token_change.js

@@ -52,7 +52,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 16: '求购购买',
                                 17: '求购出售',
                                 18: '求购取消',
-                            
+                                19: '生态节点奖励',
+                                20: '存储服务费',
                             }, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
                         },
                     ]