| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | <?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)->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;    }}
 |