1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Console\Commands;
- use App\Events\FinishAccount;
- use App\Models\Amount;
- use App\Models\OrderW;
- use App\Models\OrderFinishFailsW;
- use App\Handlers\SignHandler;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- class OrderFinishFails extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'order_finish_fails';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '定时查询完结失败订单';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- Log::info('开始查询完结失败订单');
- $orders=OrderW::where('is_pay',1)->where('status',3)->where('is_finish',0)->where('apply_cancel',0)->where('is_refund',0)->get();
- foreach($orders as $key=>$val){
- $finish=OrderFinishFailsW::where('status',0)->where('order_no',$val->order_no)->first();
- if(empty($finish)){
- OrderFinishFailsW::create([
- 'order_no'=>$val->order_no,
- 'store_id'=>$val->store_id,
- 'status'=>0,
- 'code'=>null,
- 'message'=>null,
- ]);
- }
- }
- Log::info('开始处理完结失败订单');
- $order_nos=OrderFinishFailsW::where('status',0)->pluck('order_no');
- foreach($order_nos as $key=>$val){
- $or=OrderW::where('order_no',$val)->where('is_pay',1)->where('status',3)->where('is_finish',0)
- ->where('apply_cancel',0)->where('is_refund',0)->where('pay_type',3)->where('express_state','3')->first();
- if($or && $or->pay_type == 3){
- Log::info('开始处理完结失败订单123');
- $or->is_finish = 1;
- $or->finish_no = $or->order_no;
- $or->save();
- OrderFinishFailsW::where('order_no',$val)->update(['message'=>'定时收货','status'=>1]);
- }else{
- event(new FinishAccount($val));
- }
- }
- }
- }
|