|
@@ -20,6 +20,12 @@ use Illuminate\Support\Facades\Validator;
|
|
|
class DeliveryAppointmentController extends Controller
|
|
class DeliveryAppointmentController extends Controller
|
|
|
{
|
|
{
|
|
|
use AsyncResponse;
|
|
use AsyncResponse;
|
|
|
|
|
+
|
|
|
|
|
+ public function list()
|
|
|
|
|
+ {
|
|
|
|
|
+ $owners = app("UserService")->getPermittingOwnerIds(Auth::id());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function appointment()
|
|
public function appointment()
|
|
|
{
|
|
{
|
|
|
$owners = app("OwnerService")->getIntersectPermitting();
|
|
$owners = app("OwnerService")->getIntersectPermitting();
|
|
@@ -43,9 +49,9 @@ class DeliveryAppointmentController extends Controller
|
|
|
$errors = $this->appointmentValidator($model)->errors();
|
|
$errors = $this->appointmentValidator($model)->errors();
|
|
|
if (count($errors)>0)$this->success(["errors"=>$errors]);
|
|
if (count($errors)>0)$this->success(["errors"=>$errors]);
|
|
|
/** @var \stdClass $warehouse */
|
|
/** @var \stdClass $warehouse */
|
|
|
- $warehouse = Warehouse::query()->find(request("warehouse_id"));
|
|
|
|
|
- $tonne = $model["tonne"];
|
|
|
|
|
- $cubicMeter = $model["cubic_meter"];
|
|
|
|
|
|
|
+ $warehouse = Warehouse::query()->find($model["warehouse_id"]);
|
|
|
|
|
+ $tonne = $model["tonne"] ?? 0;
|
|
|
|
|
+ $cubicMeter = $model["cubic_meter"] ?? 0;
|
|
|
$amount = request("detail_amount");
|
|
$amount = request("detail_amount");
|
|
|
$need = app("DeliveryAppointmentService")->calculateCapacity($tonne,$cubicMeter,$amount,$warehouse->reduced_production_capacity_coefficient);//所需产能
|
|
$need = app("DeliveryAppointmentService")->calculateCapacity($tonne,$cubicMeter,$amount,$warehouse->reduced_production_capacity_coefficient);//所需产能
|
|
|
$start = Carbon::tomorrow();
|
|
$start = Carbon::tomorrow();
|
|
@@ -83,7 +89,7 @@ class DeliveryAppointmentController extends Controller
|
|
|
public function submitAppointment()
|
|
public function submitAppointment()
|
|
|
{
|
|
{
|
|
|
$model = request("model");
|
|
$model = request("model");
|
|
|
- $selectDate = request("selectDate");
|
|
|
|
|
|
|
+ $selectDate = request("date");
|
|
|
$details = request("details");
|
|
$details = request("details");
|
|
|
$errors = $this->appointmentValidator($model)->errors();
|
|
$errors = $this->appointmentValidator($model)->errors();
|
|
|
if (count($errors)>0)$this->success(["errors"=>$errors]);
|
|
if (count($errors)>0)$this->success(["errors"=>$errors]);
|
|
@@ -93,7 +99,7 @@ class DeliveryAppointmentController extends Controller
|
|
|
])->errors();
|
|
])->errors();
|
|
|
if (count($errors)>0)$this->error("未选定预约日期");
|
|
if (count($errors)>0)$this->error("未选定预约日期");
|
|
|
|
|
|
|
|
- DB::transaction(function ()use($model,$selectDate,$details){
|
|
|
|
|
|
|
+ DB::transaction(function ()use($model,$selectDate,$details,&$appointment){
|
|
|
$result = DeliveryAppointment::query()->selectRaw("appointment_date,date_period,SUM(capacity) AS capacity")
|
|
$result = DeliveryAppointment::query()->selectRaw("appointment_date,date_period,SUM(capacity) AS capacity")
|
|
|
->where("appointment_date",$selectDate["date"])
|
|
->where("appointment_date",$selectDate["date"])
|
|
|
->where("date_period",$selectDate["time"])
|
|
->where("date_period",$selectDate["time"])
|
|
@@ -104,7 +110,7 @@ class DeliveryAppointmentController extends Controller
|
|
|
/** @var \stdClass $warehouse */
|
|
/** @var \stdClass $warehouse */
|
|
|
$warehouse = Warehouse::query()->find($model["warehouse_id"]);
|
|
$warehouse = Warehouse::query()->find($model["warehouse_id"]);
|
|
|
$need = app("DeliveryAppointmentService")->
|
|
$need = app("DeliveryAppointmentService")->
|
|
|
- calculateCapacity($model["tonne"],$model["cubic_meter"],count($details),
|
|
|
|
|
|
|
+ calculateCapacity($model["tonne"] ?? 0,$model["cubic_meter"] ?? 0,count($details),
|
|
|
$warehouse->reduced_production_capacity_coefficient);
|
|
$warehouse->reduced_production_capacity_coefficient);
|
|
|
if ($result){
|
|
if ($result){
|
|
|
$total = $warehouse->production_capacity*DeliveryAppointment::HOUR[$selectDate["time"]];
|
|
$total = $warehouse->production_capacity*DeliveryAppointment::HOUR[$selectDate["time"]];
|
|
@@ -115,12 +121,12 @@ class DeliveryAppointmentController extends Controller
|
|
|
$appointment = DeliveryAppointment::query()->create([
|
|
$appointment = DeliveryAppointment::query()->create([
|
|
|
"user_id" => Auth::id(),
|
|
"user_id" => Auth::id(),
|
|
|
"owner_id" => $model["owner_id"],
|
|
"owner_id" => $model["owner_id"],
|
|
|
- "procurement_number" => $model["procurement_number"],
|
|
|
|
|
- "asn_number" => $model["asn_number"],
|
|
|
|
|
|
|
+ "procurement_number" => $model["procurement_number"] ?? null,
|
|
|
|
|
+ "asn_number" => $model["asn_number"] ?? null,
|
|
|
"warehouse_id" => $model["warehouse_id"],
|
|
"warehouse_id" => $model["warehouse_id"],
|
|
|
- "tonne" => $model["tonne"],
|
|
|
|
|
- "cubic_meter" => $model["cubic_meter"],
|
|
|
|
|
- "box_amount" => $model["box_amount"],
|
|
|
|
|
|
|
+ "tonne" => $model["tonne"] ?? 0,
|
|
|
|
|
+ "cubic_meter" => $model["cubic_meter"] ?? 0,
|
|
|
|
|
+ "box_amount" => $model["box_amount"] ?? 0,
|
|
|
"capacity" => $need,
|
|
"capacity" => $need,
|
|
|
"appointment_date" => $selectDate["date"],
|
|
"appointment_date" => $selectDate["date"],
|
|
|
"date_period" => $selectDate["time"],
|
|
"date_period" => $selectDate["time"],
|
|
@@ -144,10 +150,10 @@ class DeliveryAppointmentController extends Controller
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
DeliveryAppointmentCar::query()->insert($insert);
|
|
DeliveryAppointmentCar::query()->insert($insert);
|
|
|
- //md5加密在密文第五位后插入
|
|
|
|
|
- $md5 = substr_replace(md5(date("m-d")),$appointment->id,5,0);
|
|
|
|
|
- $this->success(["key"=>$md5]);
|
|
|
|
|
});
|
|
});
|
|
|
|
|
+ //md5加密在密文第五位后插入
|
|
|
|
|
+ $md5 = substr_replace(md5(date("m-d")),$appointment->id,5,0);
|
|
|
|
|
+ $this->success(["key"=>$md5]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private function appointmentValidator(array $model)
|
|
private function appointmentValidator(array $model)
|
|
@@ -188,8 +194,9 @@ class DeliveryAppointmentController extends Controller
|
|
|
$key = request("k");
|
|
$key = request("k");
|
|
|
$len = strlen($key);
|
|
$len = strlen($key);
|
|
|
$id = substr($key,5,$len-32);
|
|
$id = substr($key,5,$len-32);
|
|
|
- $md5 = substr($id,0,5).substr($id,5+$len-32);
|
|
|
|
|
|
|
+ $md5 = substr($key,0,5).substr($key,5+$len-32);
|
|
|
if ($md5!==md5(date("m-d")))return view("exception.404");
|
|
if ($md5!==md5(date("m-d")))return view("exception.404");
|
|
|
|
|
+
|
|
|
/** @var \stdClass $appointment */
|
|
/** @var \stdClass $appointment */
|
|
|
$appointment = DeliveryAppointment::query()->with("cars")->find($id);
|
|
$appointment = DeliveryAppointment::query()->with("cars")->find($id);
|
|
|
if (!$appointment || $appointment->user_id != Auth::id())return view("exception.404");
|
|
if (!$appointment || $appointment->user_id != Auth::id())return view("exception.404");
|