| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 | <?phpnamespace 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)->where('intro_num','gt',0)->select(); //最后买东西是11天前了        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;    }}
 |