ReceivedGoods.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Events\FinishAccount;
  4. use App\Handlers\ExpressHandler;
  5. use App\Models\Order;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Log;
  8. class ReceivedGoods extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'received_goods';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '定时收货';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. Log::info('定时收货任务在运行 ing');
  39. $date=date("Y-m-d H:i:s",strtotime('-15 days'));
  40. Log::info($date);
  41. // $date=date("Y-m-d H:i:s",strtotime('-1 days'));//测试期间设为一天
  42. // $date=date("Y-m-d H:i:s",strtotime('-1 hours'));
  43. $orders=Order::with('address')
  44. ->where('status',2)->where('express_state','3')
  45. ->where('express_receive_time','<',$date)->get();
  46. foreach($orders as $key=>$val){
  47. Log::info($val->order_no.':订单系统自动收货');
  48. Order::where('id',$val->id)->update(['status'=>3,'order_status'=>1]);
  49. event(new FinishAccount($val->order_no));
  50. }
  51. }
  52. }