afa 6 月之前
父节点
当前提交
1dcf07e449
共有 2 个文件被更改,包括 10 次插入12 次删除
  1. 2 2
      application/api/controller/Pledge.php
  2. 8 10
      application/api/logic/PledgeLogic.php

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

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

+ 8 - 10
application/api/logic/PledgeLogic.php

@@ -98,7 +98,7 @@ class PledgeLogic
     }
 
     //解除质抵押订单
-    public static function setPledgeRemove(int $pledge_id, string $product_id, int $user_id)
+    public static function setPledgeRemove(int $pledge_id, string $order_id, int $user_id)
     {
         $model  = Loader::model('UserPledge');
         $time  = time();
@@ -111,19 +111,18 @@ 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);
+        //修改状态
+        $orderId  = explode(',', $order_id);
+        $detail   = array_column(json_decode($rows->details, true), 'id');
+        $diff     = array_diff($detail, $orderId);
         $num = $rows->num;
         if(empty($diff)) {
             $rows->status  = $model::Remove;
         }else{
-            $rows->product_id = implode(',', $diff);
             $rows->num        = count($diff);
-            $num = $count;
+            $num = count($orderId);
         }
+
         $day   = 86400;
         $total = 0; //当前累计收益
         $reta  = bcdiv($rows->day_num, $day, 6); //天数
@@ -132,8 +131,7 @@ class PledgeLogic
         $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);
+        Loader::model('ProductOrder')::where('user_id', $user_id)->whereIn('id', $orderId)->setField('status', ProductOrder::Paid);
 
         //更新领取状态
         $rows->last_time = $time;