service = app(ReceivingTaskService::class); $this->ownerService = app(OwnerService::class); } public function index() { $wareHouse = Warehouse::query()->get(); $owners = $this->ownerService->getQuery()->select("id","code","name")->get(); return view("store.receivingTasks.create",compact('wareHouse','owners')); } public function create() { } public function storeApi(ReceivingTaskRequest $request): array { $delivery_appointment_number = $request->input('delivery_appointment_number',null); $delivery_appointment = DeliveryAppointment::query()->where('procurement_number',$delivery_appointment_number)->first(); if (!$delivery_appointment) return ['success' => false, 'message' => '预约号未找到']; if (ReceivingTask::query()->where('delivery_appointment_id',$delivery_appointment->id)->exists()) return ['success' => false, 'message' => '预约号已有对应的任务']; try { $receiving_task = $this->service->createReceivingTask($delivery_appointment, $request->all()); $receiving_task->loadMissing("deliveryAppointment"); return ['success' => true, 'data' => $receiving_task]; } catch (\Exception $e) { return ['success' => false, 'message' => '生成入库单任务失败,请重新尝试']; } } }