Plantask.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use think\Db;
  5. class Plantask extends Controller
  6. {
  7. public function index()
  8. {
  9. exit;
  10. }
  11. //10天不买的用户,第10天结算完,第11天自动滑落,上下级自动衔接
  12. //该用户的所有下级,的推荐人,改成此人的上级。
  13. public function auto_hualuo(){
  14. $nowtime = time();
  15. $toweek = date('w',$nowtime);
  16. if($toweek == 1){
  17. //周日不结算(自动到下周一),所以,周一不滑落
  18. exit;
  19. }
  20. $tendays_ago = $this->hualuo_tendays_ago();
  21. $list = Db::name('user')->where('last_paytime','lt',$tendays_ago)->select(); //最后买东西是11天前了
  22. Db::startTrans();
  23. foreach($list as $key => $user){
  24. //我的下级,的推荐人,改成我的上级。也就是跳过了我
  25. $rs = Db::name('user')->where('intro_uid',$user['id'])->update(['intro_uid',$user['intro_uid']]);
  26. if($rs === false){
  27. Db::rollback();
  28. }
  29. }
  30. Db::commit();
  31. }
  32. //滑落要按11天算
  33. private function hualuo_tendays_ago(){
  34. $nowtime = time();
  35. /*if(input('date','')){
  36. $nowtime = strtotime(input('date',''));
  37. }*/
  38. $today = strtotime(date('Y-m-d',$nowtime));
  39. $toweek = date('w',$nowtime);
  40. $enum = [
  41. 1 => 12,//这一天没人滑落
  42. 2 => 12,
  43. 3 => 12,
  44. 4 => 12,
  45. 5 => 11,
  46. 6 => 11,
  47. 0 => 11,
  48. ];
  49. $rs = $today - ($enum[$toweek] * 86400);
  50. // dump(date('Y-m-d',$rs));
  51. return $rs;
  52. }
  53. }