| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 | 
							- <?php
 
- namespace app\index\controller;
 
- use think\Controller;
 
- use think\Db;
 
- use app\common\model\Wallet;
 
- 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;
 
-         }
 
-         //最后买东西是11天前了,intro_num在这里使用,减少查到的数据量
 
-         $tendays_ago = $this->hualuo_tendays_ago();
 
-         $list = Db::name('user')->where('last_paytime','lt',$tendays_ago)->where('intro_num','gt',0)->select();
 
-         if(!empty($list)){
 
-             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();
 
-                 }
 
-                 //我的推荐人数变0
 
-                 $rs2 = Db::name('user')->where('id',$user['id'])->update(['intro_num',0]);
 
-                 if($rs2 === 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;
 
-     }
 
-     //订单支付回调之后的任务,每分钟运行
 
-     public function auto_order_paid(){
 
-         $map = [
 
-             'status' => 1,
 
-             'have_paid' => ['gt',0],
 
-             'paidtasktime' => 0,
 
-         ];
 
-         $order_list = Db::name('unishop_order')->where($map)->limit(10)->select();
 
-         if(empty($order_list)){
 
-             echo '没有数据';
 
-             exit;
 
-         }
 
-         Db::startTrans();
 
-         $walletmodel = new Wallet();
 
-         foreach($order_list as $key => $order){
 
-             //直推代理商获益
 
-             $intro_uid = Db::name('user')->where('id',$order['user_id'])->value('intro_uid');
 
-             if($intro_uid){
 
-                 $bili = config('site.orderpaid_zhitui_bili') ?: 5;
 
-                 $score = bcdiv(bcmul($order['total_price'],$bili,2),100,2);
 
-                 if($score > 0){
 
-                     $rs_wallet = $walletmodel->lockChangeAccountRemain($intro_uid,'score',$score,3,'直推代理奖励','unishop_order',$order['id']);
 
-                     if($rs_wallet['status'] === false){
 
-                         echo $rs_wallet['msg'];
 
-                         Db::rollback();
 
-                         exit;
 
-                     }
 
-                 }
 
-             }
 
-             $score = 0;
 
-             //上上级
 
-             $top_uid = Db::name('user')->where('id',$intro_uid)->value('intro_uid');
 
-             if($top_uid){
 
-                 $bili = config('site.orderpaid_jiantui_bili') ?: 1;
 
-                 $score = bcdiv(bcmul($order['total_price'],$bili,2),100,2);
 
-                 if($score > 0){
 
-                     $rs_wallet = $walletmodel->lockChangeAccountRemain($top_uid,'score',$score,4,'间推代理奖励','unishop_order',$order['id']);
 
-                     if($rs_wallet['status'] === false){
 
-                         echo $rs_wallet['msg'];
 
-                         Db::rollback();
 
-                         exit;
 
-                     }
 
-                 }
 
-             }
 
-             //订单完成
 
-             $rs_order = Db::name('unishop_order')->where('id',$order['id'])->update(['paidtasktime'=>time()]);
 
-             if($rs_order === false){
 
-                 echo '更新失败';
 
-                 Db::rollback();
 
-                 exit;
 
-             }
 
-             //循环结束
 
-         }
 
-         Db::commit();
 
-         echo '成功';
 
-     }
 
- }
 
 
  |