afa 6 달 전
부모
커밋
4acbe580d8
4개의 변경된 파일43개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 1
      application/admin/command/Task.php
  2. 39 15
      application/api/controller/Index.php
  3. 1 0
      application/api/controller/Pledge.php
  4. 2 1
      application/api/logic/PledgeLogic.php

+ 1 - 1
application/admin/command/Task.php

@@ -69,7 +69,7 @@ class Task extends Command
       public function execute(Input $input, Output $output){
 
             //
-            $rows = UserPledge::where('status', '>', 0)->select();
+            $rows = UserPledge::where('status', '=', 1)->select();
             $model = new ProductOrder();
             foreach ($rows as $row) {
 

+ 39 - 15
application/api/controller/Index.php

@@ -3,8 +3,11 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
-use app\common\library\EthSign;
-use app\common\library\Token;
+use app\common\model\ProductOrder;
+use think\console\Output;
+use think\Exception;
+use app\common\model\Region;
+use app\common\model\UserPledge;
 use fast\Random;
 
 /**
@@ -17,22 +20,43 @@ class Index extends Api
 
     private $loaded = false;
     private $data;
- 
-    public function index() {
-       if(!$this->loaded) {
-        
-            $this->loadData();
-        }
-
-        $this->success('请求成功', $this->data);
+    
+    //测试脚本
+    public function task(UserPledge $userPledge, ProductOrder $productOrder) {
+      
+            //$rows = UserPledge::where('status', '=', 1)->select();
+            $list   = $userPledge::alias('a')
+                ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
+                ->where('a.status', '=', 1)
+                ->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);
+            
+                //修改详情订单状态
+                $detail = json_decode($rows['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();
+                $i++;
+            }
+
+        $this->success('ok:'. $i);
     }
  
 
-    private function loadData(){
-        // 耗时的数据加载操作
-        $this->data =/* ... */
-        $this->loaded =true;
-    }
+  
 
 
 

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

@@ -137,6 +137,7 @@ class Pledge extends Api
             try {
                   // 质抵押订单
                   $res = $pledgeLogic::getPledgeCollect($this->auth->id);
+               
                   //请求限制      
                   cache('collect_'.$this->auth->id, time(), 300);
                  // 提交事务

+ 2 - 1
application/api/logic/PledgeLogic.php

@@ -66,17 +66,18 @@ class PledgeLogic
     public static function getPledgeOrderList(int $user_id)//: array
     {
         $model  = Loader::model('UserPledge');
+        $time  = time();
         $list   = $model::alias('a')
             ->join('product_pledge b', 'a.pledge_id = b.id', 'left')
             ->where('a.user_id', $user_id)
             ->where('a.status', '>', $model::Close)
+            ->where('a.end_time', '>',  $time)
             ->field('a.*,b.title,b.type_id,b.day_num,b.token,b.teac,b.is_renew')
             ->select();
         if(empty($list)) throw new Exception('暂无质押订单');
         $day   = 86400;
         $total = 0; //当前累计收益
         $growth= 0; //增长累计收益
-        $time  = time();
         $result = [];
         foreach ($list as $item) {
             if($item->status == $model::Remove) {