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 '成功'; } }