Prechádzať zdrojové kódy

自动滑落计划任务

lizhen_gitee 1 rok pred
rodič
commit
079eb0266f

+ 1 - 0
addons/unishop/controller/Order.php

@@ -752,6 +752,7 @@ class Order extends Base
      */
     public function refund()
     {
+        $this->error('申请成功,客服人员会主动联系您');
         $order_id = $this->request->post('order_id');
         $order_id = Hashids::decodeHex($order_id);
         $orderModel = new \addons\unishop\model\Order();

+ 44 - 3
application/api/controller/Demo.php

@@ -15,9 +15,9 @@ class Demo extends Api
     //如果接口已经设置无需登录,那也就无需鉴权了
     //
     // 无需登录的接口,*表示全部
-    protected $noNeedLogin = ['test', 'test4'];
+    protected $noNeedLogin = ['*'];
     // 无需鉴权的接口,*表示全部
-    protected $noNeedRight = ['test2'];
+    protected $noNeedRight = ['*'];
 
     /**
      * 测试方法
@@ -70,7 +70,7 @@ class Demo extends Api
         $this->success('返回成功', ['action' => 'test3']);
     }
 
-    //支付回调后的逻辑,或者计划任务的逻辑
+    //订单算奖金。计划任务的逻辑
     public function test4(){
         $order_id = 488359520289034240;
 
@@ -80,6 +80,47 @@ class Demo extends Api
             $shouyi = bcmul($product['number'],$product['pifa_shouyi'],0);
 
         }
+
+
+        $user_id = 1;
+        //我的下级数量
+        Db::name('user')->where('intro_uid',$user_id)->count();
+
+        //我的上级id
+        $my_intro_uid = Db::name('user')->where('id',$user_id)->value('intro_uid');
+
+        //我的上上级id
+        $two_intro_uid =Db::name('user')->where('id',$my_intro_uid)->value('intro_uid') ?: 0;
+
+        //结算订单后,用户活跃时间更新
+        Db::name('user_wallet')->where('user_id',$user_id)->update(['active_time'=>time()]);
+    }
+
+
+
+    //结算要按10天算
+    public function jiesuan_tendays_ago(){
+
+        $nowtime = time();
+        $today   = strtotime(date('Y-m-d',$nowtime));
+
+        $toweek  = date('w',$nowtime);
+
+
+        $enum = [
+            1 => 11,
+            2 => 12,
+            3 => 12,
+            4 => 12, //
+            5 => 12, //
+            6 => 11, //
+            0 => 11, //
+        ];
+
+        $rs = $today - ($enum[$toweek] * 86400);
+        dump(date('Y-m-d',$rs));
+
+        return $rs;
     }
 
 }

+ 67 - 0
application/index/controller/Plantask.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace app\index\controller;
+use think\Controller;
+use think\Db;
+
+class Plantask extends Controller
+{
+    public function index()
+    {
+        exit;
+    }
+
+    //10天不买的用户,第10天结算完,第11天自动滑落,上下级自动衔接
+    //该用户的所有下级,的推荐人,改成此人的上级。
+    public function auto_hualuo(){
+        $nowtime = time();
+        $toweek  = date('w',$nowtime);
+        if($toweek == 1){
+            //周日不结算(自动到下周一),所以,周一不滑落
+            exit;
+        }
+
+        $tendays_ago = $this->hualuo_tendays_ago();
+        $list = Db::name('user')->where('last_paytime','lt',$tendays_ago)->select(); //最后买东西是11天前了
+
+        Db::startTrans();
+        foreach($list as $key => $user){
+            //我的下级,的推荐人,改成我的上级。也就是跳过了我
+            $rs = Db::name('user')->where('intro_uid',$user['id'])->update(['intro_uid',$user['intro_uid']]);
+            if($rs === false){
+                Db::rollback();
+            }
+        }
+        Db::commit();
+    }
+
+    //滑落要按11天算
+    private function hualuo_tendays_ago(){
+        $nowtime = time();
+
+        /*if(input('date','')){
+            $nowtime = strtotime(input('date',''));
+        }*/
+
+        $today   = strtotime(date('Y-m-d',$nowtime));
+
+        $toweek  = date('w',$nowtime);
+
+
+        $enum = [
+            1 => 12,//这一天没人滑落
+            2 => 12,
+            3 => 12,
+            4 => 12,
+            5 => 11,
+            6 => 11,
+            0 => 11,
+        ];
+
+        $rs = $today - ($enum[$toweek] * 86400);
+//        dump(date('Y-m-d',$rs));
+
+        return $rs;
+    }
+
+}