1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Bike;
- use App\Models\WorkOrder;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\Log;
- class UpdateWatchWorkOrdersCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'update:watch_worker_orders';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '更新watch工单';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- //1.查找所有大于36小时未骑行的车辆
- $timeOut = Carbon::now()->subHours(36);
- $bikes = Bike::query()
- ->where('is_link',Bike::LINK_ONLINE) //在线
- ->where('is_trouble',Bike::TROUBLE_NO) //无故障
- ->where('put_status',Bike::PUT_STATUS_YES) //已投放
- ->where('is_riding',Bike::RIDING_NO) //没人骑车
- ->where('last_use_bike_end_time','<',$timeOut)
- ->get();
- if(empty($bikes)) return ;
- // 2.插入工单
- foreach ($bikes as $v){
- $data = [
- 'work_no' => WorkOrder::makeWorkNo(),
- 'type' => WorkOrder::TYPE_WATCH,
- 'type_name' => WorkOrder::$typeMaps[WorkOrder::TYPE_WATCH],
- 'bike_no' => $v->bike_no,
- 'bike_id' => $v->id,
- 'source' => WorkOrder::SOURCE_SYSTEM,
- 'planned' => WorkOrder::PLANNED_STATUS_MEET,
- 'area_id' => $v->put_area_id,
- ];
- $verify =[
- 'bike_id' => $v->id,
- 'type' => WorkOrder::TYPE_WATCH,
- 'status' => WorkOrder::STATUS_NO,
- ];
- try{
- WorkOrder::firstOrCreate($verify,$data);
- }catch(\Exception $e){
- Log::error($e->getMessage());
- }
- }
- }
- }
|