|
|
@@ -57,12 +57,20 @@ class ReceivingTaskController extends Controller
|
|
|
}
|
|
|
$appointment_number = $request->input('appointment_number',null);
|
|
|
|
|
|
- $delivery_appointment_car = DeliveryAppointmentCar::query()->where('appointment_number',$appointment_number)->first();
|
|
|
+ $delivery_appointment_car = DeliveryAppointmentCar::query()->with('deliveryAppointment')->where('appointment_number',$appointment_number)->first();
|
|
|
|
|
|
- if (!$delivery_appointment_car) return ['success' => false,'errors' =>['appointment_number' => ['对应预约号未找到']]];
|
|
|
-
|
|
|
- if (ReceivingTask::query()->where('delivery_appointment_car_id',$delivery_appointment_car->id)->exists())
|
|
|
+ if (!$delivery_appointment_car){
|
|
|
+ return ['success' => false,'errors' =>['appointment_number' => ['对应预约号未找到']]];
|
|
|
+ }
|
|
|
+ if (!$delivery_appointment_car->deliveryAppointment){
|
|
|
+ return [['success' => false,'errors' =>['appointment_number' => ['对应预约号未找到']]]];
|
|
|
+ }
|
|
|
+ if (!$delivery_appointment_car->deliveryAppointment->owner_id != $request->input('owner_id')){
|
|
|
+ return [['success' => false,'errors' =>['appointment_number' => ['预约号与货主未对应']]]];
|
|
|
+ }
|
|
|
+ if (ReceivingTask::query()->where('delivery_appointment_car_id',$delivery_appointment_car->id)->exists()){
|
|
|
return ['success' => false, 'errors' =>['appointment_number' => ['预约号已有对应的任务']]];
|
|
|
+ }
|
|
|
try {
|
|
|
$receiving_task = $this->service->createReceivingTask($delivery_appointment_car, $request->all());
|
|
|
if (!$receiving_task->id) return ['success' => false, 'message' => '生成入库单任务失败,请重新尝试'];
|