orderRepair.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Order;
  4. use Illuminate\Console\Command;
  5. class orderRepair extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'order:repair';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '添加预约时间';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. $count = Order::whereIn('product_type',[3,4,5])->count();
  36. $page = ceil($count /1000);
  37. for ($i=1;$i<=$page;$i++){
  38. $list = Order::leftjoin('order_patients','order_patients.order_id','=','orders.id')
  39. ->select(['orders.id','order_patients.appoint_start_time','order_patients.appoint_end_time'])
  40. ->where('orders.appoint_start_time','=', 0)
  41. ->whereIn('product_type',[3,4,5])->limit(($i-1)*1000,$i*1000)->get()->toArray();
  42. foreach ($list as $info){
  43. $data = ['appoint_date'=>strtotime('today'),'appoint_start_time'=>$info['appoint_start_time'],'appoint_end_time'=>$info['appoint_end_time']];
  44. Order::where('id',$info['id'])->update($data);
  45. unset($data);
  46. }
  47. echo '第'.$i.'页'.PHP_EOL;
  48. unset($list);
  49. }
  50. dd('end');
  51. }
  52. }