|
|
@@ -39,12 +39,14 @@ class DeliveryAppointmentController extends Controller
|
|
|
*/
|
|
|
public function getCapacity()
|
|
|
{
|
|
|
+ $model = request("model");
|
|
|
+ $errors = $this->appointmentValidator($model)->errors();
|
|
|
+ if (count($errors)>0)$this->success(["errors"=>$errors]);
|
|
|
/** @var \stdClass $warehouse */
|
|
|
$warehouse = Warehouse::query()->find(request("warehouse_id"));
|
|
|
- $tonne = request("tonne");
|
|
|
- $cubicMeter = request("cubic_meter");
|
|
|
+ $tonne = $model["tonne"];
|
|
|
+ $cubicMeter = $model["cubic_meter"];
|
|
|
$amount = request("detail_amount");
|
|
|
- if (!$warehouse || (!$tonne && !$cubicMeter))$this->error("非法参数");
|
|
|
$need = app("DeliveryAppointmentService")->calculateCapacity($tonne,$cubicMeter,$amount,$warehouse->reduced_production_capacity_coefficient);//所需产能
|
|
|
$start = Carbon::tomorrow();
|
|
|
$end = Carbon::today()->addDays(7);
|
|
|
@@ -83,32 +85,7 @@ class DeliveryAppointmentController extends Controller
|
|
|
$model = request("model");
|
|
|
$selectDate = request("selectDate");
|
|
|
$details = request("details");
|
|
|
- $errors = Validator::make($model,[
|
|
|
- "owner_id" => ["required","integer"],
|
|
|
- "warehouse_id" => ["required","integer"],
|
|
|
- "tonne" => ["required_without:cubic_meter","numeric"],
|
|
|
- "cubic_meter" => ["required_without:tonne","numeric"],
|
|
|
- "box_amount" => ["nullable","integer"],
|
|
|
- "cars.*.license_plate_number" => ["required","size:7"],
|
|
|
- "cars.*.car_id" => ["nullable","integer"],
|
|
|
- "cars.*.driver_phone" => ["nullable"],
|
|
|
- "cars.*.driver_name" => ["nullable"],
|
|
|
- ],[
|
|
|
- 'required'=>':attribute 不应为空',
|
|
|
- 'integer'=>':attribute 应为数值',
|
|
|
- 'required_without'=>':attribute 不应为空',
|
|
|
- 'numeric'=>':attribute 必须为数字',
|
|
|
- 'size'=>':attribute 非法',
|
|
|
- ],[
|
|
|
- 'owner_id'=>'货主',
|
|
|
- 'warehouse_id'=>'仓库',
|
|
|
- 'tonne'=>'吨',
|
|
|
- 'cubic_meter'=>'立方',
|
|
|
- 'cars.*.license_plate_number'=>'车牌号',
|
|
|
- 'cars.*.car_id'=>'车型',
|
|
|
- 'cars.*.driver_phone'=>'司机电话',
|
|
|
- 'cars.*.driver_name'=>'司机姓名',
|
|
|
- ])->errors();
|
|
|
+ $errors = $this->appointmentValidator($model)->errors();
|
|
|
if (count($errors)>0)$this->success(["errors"=>$errors]);
|
|
|
$errors = Validator::make($selectDate,[
|
|
|
"date" => ["required","date","after:today"],
|
|
|
@@ -132,7 +109,7 @@ class DeliveryAppointmentController extends Controller
|
|
|
if ($result){
|
|
|
$total = $warehouse->production_capacity*DeliveryAppointment::HOUR[$selectDate["time"]];
|
|
|
$available = $total-$result->capacity;
|
|
|
- if ($available < $need)$this->success(["isFail"=>false]);
|
|
|
+ if ($available < $need)$this->success(["isFail"=>true]);
|
|
|
}
|
|
|
/** @var \stdClass $appointment */
|
|
|
$appointment = DeliveryAppointment::query()->create([
|
|
|
@@ -173,6 +150,36 @@ class DeliveryAppointmentController extends Controller
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ private function appointmentValidator(array $model)
|
|
|
+ {
|
|
|
+ return Validator::make($model,[
|
|
|
+ "owner_id" => ["required","integer"],
|
|
|
+ "warehouse_id" => ["required","integer"],
|
|
|
+ "tonne" => ["required_without:cubic_meter","numeric"],
|
|
|
+ "cubic_meter" => ["required_without:tonne","numeric"],
|
|
|
+ "box_amount" => ["nullable","integer"],
|
|
|
+ "cars.*.license_plate_number" => ["required","size:7"],
|
|
|
+ "cars.*.car_id" => ["nullable","integer"],
|
|
|
+ "cars.*.driver_phone" => ["nullable"],
|
|
|
+ "cars.*.driver_name" => ["nullable"],
|
|
|
+ ],[
|
|
|
+ 'required'=>':attribute 不应为空',
|
|
|
+ 'integer'=>':attribute 应为数值',
|
|
|
+ 'required_without'=>':attribute 不应为空',
|
|
|
+ 'numeric'=>':attribute 必须为数字',
|
|
|
+ 'size'=>':attribute 非法',
|
|
|
+ ],[
|
|
|
+ 'owner_id'=>'货主',
|
|
|
+ 'warehouse_id'=>'仓库',
|
|
|
+ 'tonne'=>'吨',
|
|
|
+ 'cubic_meter'=>'立方',
|
|
|
+ 'cars.*.license_plate_number'=>'车牌号',
|
|
|
+ 'cars.*.car_id'=>'车型',
|
|
|
+ 'cars.*.driver_phone'=>'司机电话',
|
|
|
+ 'cars.*.driver_name'=>'司机姓名',
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据key取id 鉴权数据
|
|
|
*/
|
|
|
@@ -186,6 +193,6 @@ class DeliveryAppointmentController extends Controller
|
|
|
/** @var \stdClass $appointment */
|
|
|
$appointment = DeliveryAppointment::query()->with("cars")->find($id);
|
|
|
if (!$appointment || $appointment->user_id != Auth::id())return view("exception.404");
|
|
|
- return $appointment->cars;
|
|
|
+ return view("store.deliveryAppointment.success",compact("appointment"));
|
|
|
}
|
|
|
}
|