OrderFinishFails.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Events\FinishAccount;
  4. use App\Models\Amount;
  5. use App\Models\OrderW;
  6. use App\Models\OrderFinishFailsW;
  7. use App\Handlers\SignHandler;
  8. use Illuminate\Console\Command;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Log;
  11. class OrderFinishFails extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'order_finish_fails';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = '定时查询完结失败订单';
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34. /**
  35. * Execute the console command.
  36. *
  37. * @return mixed
  38. */
  39. public function handle()
  40. {
  41. Log::info('开始查询完结失败订单');
  42. $orders=OrderW::where('is_pay',1)->where('status',3)->where('is_finish',0)->where('apply_cancel',0)->where('is_refund',0)->get();
  43. foreach($orders as $key=>$val){
  44. $finish=OrderFinishFailsW::where('status',0)->where('order_no',$val->order_no)->first();
  45. if(empty($finish)){
  46. OrderFinishFailsW::create([
  47. 'order_no'=>$val->order_no,
  48. 'store_id'=>$val->store_id,
  49. 'status'=>0,
  50. 'code'=>null,
  51. 'message'=>null,
  52. ]);
  53. }
  54. }
  55. Log::info('开始处理完结失败订单');
  56. $order_nos=OrderFinishFailsW::where('status',0)->pluck('order_no');
  57. foreach($order_nos as $key=>$val){
  58. $or=OrderW::where('order_no',$val)->where('is_pay',1)->where('status',3)->where('is_finish',0)
  59. ->where('apply_cancel',0)->where('is_refund',0)->where('pay_type',3)->where('express_state','3')->first();
  60. if($or && $or->pay_type == 3){
  61. Log::info('开始处理完结失败订单123');
  62. $or->is_finish = 1;
  63. $or->finish_no = $or->order_no;
  64. $or->save();
  65. OrderFinishFailsW::where('order_no',$val)->update(['message'=>'定时收货','status'=>1]);
  66. }else{
  67. event(new FinishAccount($val));
  68. }
  69. }
  70. }
  71. }