afa 6 달 전
부모
커밋
035398aa10
1개의 변경된 파일30개의 추가작업 그리고 19개의 파일을 삭제
  1. 30 19
      application/api/controller/Index.php

+ 30 - 19
application/api/controller/Index.php

@@ -4,9 +4,9 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 use app\common\model\ProductOrder;
-use think\console\Output;
-use think\Exception;
-use app\common\model\Region;
+use fast\Asset;
+use app\common\model\LedgerTeacChangeModel;
+use app\common\model\LedgerWalletModel;
 use app\common\model\UserPledge;
 use fast\Random;
 
@@ -22,33 +22,44 @@ class Index extends Api
     private $data;
     
     //测试脚本
-    public function task(UserPledge $userPledge, ProductOrder $productOrder) {
+    public function task(UserPledge $userPledge, ProductOrder $productOrder, LedgerWalletModel $ledgerWalletModel) {
       
             //$rows = UserPledge::where('status', '=', 1)->select();
             $list   = $userPledge::alias('a')
                 ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
-                ->where('a.status', '=', 1)
+                ->where('a.status', '>', 0)
                 ->field('a.*,b.day_num')
                 ->select();
             $i = 0;
             $time= time();
-            foreach ($list as $rows) {
-
-                $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; //累计收益
-                $rows->total_self= bcadd($total, $rows->total_self, 6);
-            
+            $day   = 86400;
+            foreach ($list as $item) {
+               
+                if($item->status == 2) {
+                    //解除收益
+                    $total = $item->total_self;
+                }else{
+                    //未接触收益
+                    $reta  = bcdiv($item->day_num, $day, 6); //天数
+                    $inter = ($item->last_time == 0) ? $time - $item->create_time: $time - $item->last_time; //最后收取时间
+                    $total_inco = bcmul($reta, $inter, 6) * $item->num; //累计收益
+                    $item->last_time = $time; //收取时间
+                    $item->total_self= bcadd($total_inco, $item->total_self, 2); //累计收益
+                    $total = $total_inco; //累计收益
+                }
+           
+                
+                //更新用户资产
+                $ledgerWalletModel->changeWalletAccount($item->user_id, Asset::TEAC, $total, LedgerTeacChangeModel::Pledge, 0);  
+
                 //修改详情订单状态
-                $detail = json_decode($rows['details'], true);
+                $detail = json_decode($item['details'], true);
                 $productOrder::where('status', 6)->whereIn('id', array_column($detail, 'id'))->setField('status', ProductOrder::Paid);
-            
+
                 //更新存储订单状态
-                $rows->last_time = $time;
-                $rows->status = 2;
-                $rows->save();
+                $item->last_time = $time;
+                $item->status = 0; //关闭
+                $item->save();
                 $i++;
             }