afa 7 miesięcy temu
rodzic
commit
dd82d0b0b6

+ 25 - 5
application/api/controller/Pledge.php

@@ -87,11 +87,9 @@ class Pledge extends Api
         Db::startTrans();
         try {
           
-            // 质抵押订单 $this->auth->id
-            $pledgeLogic::setPledgeOrder($pledge, $order_no, 1275);
+            // 质抵押订单 
+            $pledgeLogic::setPledgeOrder($pledge, $order_no, $this->auth->id);
 
-            // $synthesis->num += $num;
-            // $synthesis->save();
             // 提交事务
             Db::commit();
         } catch (Exception $e) {
@@ -105,7 +103,29 @@ class Pledge extends Api
 
     
 
-   
+ 
+      /*
+      * 我的茶矿
+      */
+      public function teamine(ProductPledges $productPledges, PledgeLogic $pledgeLogic)
+      {
+           
+            Db::startTrans();
+            try {
+            
+                  // 质抵押订单 
+                  $res = $pledgeLogic::getPledgeOrderList(1275);
+
+
+                 // 提交事务
+                  Db::commit();
+            } catch (Exception $e) {
+                  // 回滚事务
+                  Db::rollback();
+                  $this->error($e->getMessage(), null, $e->getCode());
+            }
+            $this->success('ok', $res);
+      }
 
 
    

+ 19 - 2
application/common/logic/PledgeLogic.php

@@ -48,9 +48,26 @@ class PledgeLogic
    
         //修改状态
         return $model->whereIn('order_no', $order_no)->setField('status', $model::Freeze);
-
-
     }
 
+    //获取质抵押订单列表
+    //(60*60*24)*(当前时间-最后一次收取时间)
+    public static function getPledgeOrderList(int $user_id)
+    {
+        $model  = Loader::model('UserPledge');
+        $list   = $model::where('user_id', $user_id)->where('status', $model::Ongoing)->select();
+        if(empty($list))  throw new Exception('暂无质押订单');
+        $day   = 86400;
+        $total = 0; //当前累计收益
+        $growth= 0; //增长累计收益
+        $time  = time();
+        foreach ($list as $item) {
+           $reta  = bcdiv($item->day_num, $day, 2); //天数
+           $inter = ($item->last_time == 0) ? $time - $item->create_time: $time - $item->last_time; //最后收取时间
+           $total += bcmul($reta, $inter, 2) * $item->num; //累计收益
+           $growth += $reta* $item->num;
+        }
+        return ['total' => $total, 'growth' => $growth, 'list' => $list];   
+    }
 
 }

+ 4 - 0
application/common/model/UserPledge.php

@@ -29,6 +29,10 @@ class UserPledge extends Model
         'update_time_text'
     ];
 
+    //状态: 存储中 0解除
+    const Remove = 0;
+    const Ongoing= 1;
+
 
     public static function setPledgeData($user_id, $pledge_id, $product_id, $day_num, $num)
     {