sendOrderTime.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Console\Commands\Temp;
  3. use Log;
  4. use Illuminate\Console\Command;
  5. use DB;
  6. class sendOrderTime extends Command
  7. {
  8. /**
  9. * 执行命令 php artisan temp:cal_send_order_time
  10. *
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'temp:cal_send_order_time';
  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. $this->genSendOrdertime('mysql');
  30. }
  31. public function genSendOrdertime($connecton = ''){
  32. $channel_user_ids = DB::connection($connecton)->table('channel_users')
  33. ->get()
  34. ->pluck('id')
  35. ->toArray();
  36. $distribution_channel_ids = DB::connection($connecton)->table('distribution_channels')
  37. ->whereIn('channel_user_id',$channel_user_ids)
  38. ->get()
  39. ->pluck('id')
  40. ->toArray()
  41. ;
  42. dump(implode(',',$distribution_channel_ids));
  43. $max_id = DB::connection($connecton)->table('send_order_first_order_times')->max('send_order_id');
  44. if(!$max_id) $max_id=0;
  45. $sql = "SELECT * FROM (select orders.created_at otime,send_orders.id send_order_id from send_orders
  46. left join users on send_orders.id = users.send_order_id
  47. left join orders on orders.uid = users.id
  48. where send_orders.distribution_channel_id in(".implode(',',$distribution_channel_ids).")
  49. and orders.status='PAID'
  50. and send_orders.id >{$max_id}
  51. ORDER BY orders.id asc) send_orders GROUP BY send_order_id";
  52. $send_orders = DB::connection($connecton)->select($sql);
  53. dump(count($send_orders));
  54. foreach (array_chunk($send_orders, 500) as $send_order_set){
  55. //通过强关进行状态更新
  56. $insert = array();
  57. foreach ($send_order_set as $send_order){
  58. $insert[]= [
  59. 'send_order_id'=>$send_order->send_order_id,
  60. 'first_order_time'=>$send_order->otime,
  61. ];
  62. }
  63. DB::connection($connecton)->table('send_order_first_order_times')->insert($insert);
  64. }
  65. }
  66. }