FixRealReg.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Console\Commands\Temp;
  3. use Log;
  4. use Illuminate\Console\Command;
  5. use DB;
  6. class FixRealReg extends Command
  7. {
  8. /**
  9. * 执行命令 php artisan temp:fix_read_reg
  10. *
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'temp:fix_read_reg';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '修复实际注册用户数';
  22. /**
  23. * Execute the console command.
  24. *
  25. * @return mixed
  26. */
  27. public function handle()
  28. {
  29. print_r("======修复实际注册用户数 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  30. Log::info("======修复实际注册用户数 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  31. $_start = new \DateTime('2017-12-12');
  32. $_end = new \DateTime('2017-12-24');
  33. foreach (new \DatePeriod($_start, new \DateInterval('P1D'), $_end) as $d)
  34. {
  35. $date = $d->format('Y-m-d');
  36. $start = $date;
  37. $end_time = date('Y-m-d', strtotime($date) + 86400);
  38. $real_reg_data_res = DB::select("select distribution_channel_id,count(1) num from users u where created_at >='{$date}' and created_at <'{$end_time}' and not exists (select id from users where openid = u.openid and created_at < '{$date}' limit 1) group by distribution_channel_id");
  39. dump($real_reg_data_res);
  40. foreach ($real_reg_data_res as $item)
  41. {
  42. DB::table('order_day_stats')->where('date',$date)->where('distribution_channel_id',$item->distribution_channel_id)->update(['real_register_user_num'=>(int)$item->num]);
  43. }
  44. Log::info("======修复实际注册用户数 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  45. print_r("======修复实际注册用户数 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  46. }
  47. }
  48. }