UserSign.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Console\Commands\Temp;
  3. use Log;
  4. use Illuminate\Console\Command;
  5. use DB;
  6. class UserSign extends Command
  7. {
  8. /**
  9. * 执行命令 php artisan tmep:user_sign
  10. *
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'tmep:user_sign';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '书币大于500最近签到';
  22. /**
  23. * Execute the console command.
  24. *
  25. * @return mixed
  26. */
  27. public function handle()
  28. {
  29. /**
  30. * CREATE TABLE `temp_user_sign` (
  31. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  32. `uid` int(11) DEFAULT NULL,
  33. `distribution_channel_id` int(11) DEFAULT NULL,
  34. `balance` decimal(11,2) DEFAULT NULL,
  35. `latest_sign_time` datetime DEFAULT NULL,
  36. PRIMARY KEY (`id`)
  37. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  38. *
  39. *
  40. */
  41. print_r("======书币大于500最近签到生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  42. Log::info("======书币大于500最近签到生成 【任务执行开始】=====".date("y-m-d H:i:s"."\n"));
  43. $_start = new \DateTime('2017-12-12');
  44. $_end = new \DateTime('2018-02-18');
  45. foreach (new \DatePeriod($_start, new \DateInterval('P1D'), $_end) as $d)
  46. {
  47. $date = $d->format('Y-m-d');
  48. $start = $date;
  49. $end = date('Y-m-d', strtotime($date) + 86400);
  50. $offset = 0;
  51. $limit = 1000;
  52. $data = [];
  53. while (true) {
  54. print_r("select id,distribution_channel_id,balance from users where balance > 500 limit $offset,$limit" . "\n");
  55. $users = DB::select("select id,distribution_channel_id,balance from users where balance > 500 limit $offset,$limit");
  56. print_r("users_count:".count($users));
  57. if (count($users) == 0) break;
  58. foreach ($users as $user) {
  59. $sign = DB::table('user_sign')->where('uid',$user->id)->orderBy('id','desc')->first();
  60. $data[] = [
  61. 'uid'=>$user->id,
  62. 'distribution_channel_id'=>$user->distribution_channel_id,
  63. 'balance'=>$user->balance,
  64. 'latest_sign_time'=>$sign ? $sign->created_at : null
  65. ];
  66. }
  67. $offset = $offset + $limit;
  68. DB::table('temp_user_sign')->insert($data);
  69. $data = [];
  70. }
  71. Log::info("======书币大于500最近签到生成 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  72. print_r("======书币大于500最近签到生成 【任务执行结束】=====" . date("y-m-d H:i:s" . "\n"));
  73. }
  74. }
  75. }