12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?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 AutoRepairWorkOrderCommand extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'auto_repair:work_order';
- /**
- * 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()
- {
- // 离线工单
- $workOrder = WorkOrder::query()
- ->where('type',WorkOrder::TYPE_OFFLINE)
- ->where('status',WorkOrder::STATUS_NO)
- ->get();
- if(count($workOrder) == 0) return ;
- foreach ($workOrder as $v){
- $bike_no = $v->bike_no;
- $bike = Bike::query()->where('bike_no',$bike_no)->first();
- if($bike->is_link == Bike::LOCK_YES){
- $this->overWorkOrder($v->id);
- }
- }
- }
- /**
- * 完结工单
- * @param $workOrderId int 工单id
- * */
- private function overWorkOrder($workOrderId){
- try{
- $work_order = WorkOrder::find($workOrderId);
- $work_order->planned = WorkOrder::PLANNED_STATUS_OVER;
- $work_order->status = WorkOrder::STATUS_OK;
- $work_order->fix_start_time = Carbon::now();
- $work_order->worker_id = 0;
- $work_order->work_over_id = 0;
- $work_order->fix_end_time = Carbon::now();
- $work_order->save();
- }catch (\Exception $e){
- Log::error($e->getMessage());
- }
- }
- }
|