driverStatusModel ->where('cycle_id',$this->cycleId) ->where('site_id',$this->request->input('site_id')) ->where('driver_id',$this->adminInfo->id) ->first(); if (empty($info)) throw new ErrException('今日无该点位的送餐数据'); if ($info->status == DriverCode::DESTINATION) throw new ErrException('该点位已送达,无需上报异常信息'); $todaySiteIds = $this->driverStatusModel ->where('cycle_id',$this->cycleId) ->where('driver_id',$this->adminInfo->id) ->whereIn('status',[DriverCode::DEPARTURES,DriverCode::EXCEPTIONS]) ->pluck('site_id') ->toArray(); if (empty($todaySiteIds)) throw new ErrException('数据错误-1'); $insertData = []; foreach ($todaySiteIds as $siteId) { $insertData[] = [ 'cycle_id' => $this->cycleId, 'site_id' => $siteId, 'driver_id' => $this->adminInfo->id, 'exceptions_msg' => $this->request->input('exceptions_msg'), 'image_id' => $this->request->input('image_id'), 'create_time' => date('Y-m-d H:i:s') ]; } if (empty($insertData)) throw new ErrException('数据错误-2'); Db::transaction(function () use ($todaySiteIds,$insertData) { $this->driverExceptionModel->insert($insertData); $this->driverStatusModel->update([ 'status' => DriverCode::EXCEPTIONS, ]); }); return $this->return->success(); } }