|
|
@@ -64,12 +64,12 @@ class DeliveryAppointmentController extends Controller
|
|
|
$cubicMeter = $model["cubic_meter"] ?? 0;
|
|
|
$amount = request("detail_amount");
|
|
|
$need = app("DeliveryAppointmentService")->calculateCapacity($tonne,$cubicMeter,$amount,$warehouse->reduced_production_capacity_coefficient);//所需产能
|
|
|
- $start = Carbon::tomorrow();
|
|
|
- $end = Carbon::today()->addDays(7);
|
|
|
+ $start = Carbon::today();
|
|
|
+ $end = Carbon::today()->addDays(6);
|
|
|
$map = [];
|
|
|
DeliveryAppointment::query()->selectRaw("appointment_date,date_period,SUM(capacity) AS capacity")
|
|
|
->whereBetween("appointment_date",[$start->toDateString(),$end->toDateString()])
|
|
|
- ->where("status",0)
|
|
|
+ ->whereIn("status",[0,2])
|
|
|
->where("warehouse_id",$warehouse->id)
|
|
|
->groupBy(["appointment_date","date_period"])->get()
|
|
|
->each(function ($appointment)use(&$map){
|
|
|
@@ -81,14 +81,30 @@ class DeliveryAppointmentController extends Controller
|
|
|
/** @var $date Carbon */
|
|
|
$date = $date->format("Y-m-d");
|
|
|
$periods = [];
|
|
|
- foreach (DeliveryAppointment::PERIOD as $key=>$period){
|
|
|
- $total = $capacity*DeliveryAppointment::HOUR[$key];//仓库该时段产能总量
|
|
|
- $used = $map[$date."-".$key] ?? 0; //已使用产能
|
|
|
- $available = $total-$used; //可用产能
|
|
|
- $period = explode("-",$period);
|
|
|
- $period = $period[0].":00 - ".$period[1].":00";
|
|
|
- if ($available < $need)$periods[] = ["time"=>$period,"index"=>$key,"isAvailable"=>false];
|
|
|
- else $periods[] = ["time"=>$period,"index"=>$key,"isAvailable"=>true];
|
|
|
+ if ($date==date("Y-m-d")){
|
|
|
+ $hour = date("H");
|
|
|
+ foreach (DeliveryAppointment::PERIOD as $key=>$period){
|
|
|
+ $period = explode("-",$period);
|
|
|
+ $periodArr = ["time"=>$period[0].":00 - ".$period[1].":00","index"=>$key,"isAvailable"=>false];
|
|
|
+ if ($hour<$period[1]-1){
|
|
|
+ $total = $capacity*DeliveryAppointment::HOUR[$key];//仓库该时段产能总量
|
|
|
+ $used = $map[$date."-".$key] ?? 0; //已使用产能
|
|
|
+ $available = $total-$used; //可用产能
|
|
|
+ if ($available > $need)$periodArr["isAvailable"] = true;
|
|
|
+ }
|
|
|
+ $periods[] = $periodArr;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ foreach (DeliveryAppointment::PERIOD as $key=>$period){
|
|
|
+ $period = explode("-",$period);
|
|
|
+ $period = $period[0].":00 - ".$period[1].":00";
|
|
|
+ $periodArr = ["time"=>$period,"index"=>$key,"isAvailable"=>false];
|
|
|
+ $total = $capacity*DeliveryAppointment::HOUR[$key];//仓库该时段产能总量
|
|
|
+ $used = $map[$date."-".$key] ?? 0; //已使用产能
|
|
|
+ $available = $total-$used; //可用产能
|
|
|
+ if ($available > $need)$periodArr["isAvailable"] = true;
|
|
|
+ $periods[] = $periodArr;
|
|
|
+ }
|
|
|
}
|
|
|
$list[] = ["date"=>$date,"period"=>$periods];
|
|
|
}
|
|
|
@@ -290,13 +306,44 @@ class DeliveryAppointmentController extends Controller
|
|
|
return app(ExportService::class)->json($row,$list,"预约记录");
|
|
|
}
|
|
|
|
|
|
+ private function carList($period,$date,$warehouse)
|
|
|
+ {
|
|
|
+ $list = [];
|
|
|
+ DeliveryAppointmentCar::query()->with(["deliveryAppointment"=>function($query){
|
|
|
+ /** @var Builder $query */
|
|
|
+ $query->withCount("cars");
|
|
|
+ }])->whereHas("deliveryAppointment",function ($query)use($period,$warehouse,$date){
|
|
|
+ /** @var Builder $query */
|
|
|
+ $query->where("appointment_date",$date)
|
|
|
+ ->where("warehouse_id",$warehouse)->whereIn("status",[0,2]);
|
|
|
+ })->where(function ($query)use($period){
|
|
|
+ /** @var Builder $query */
|
|
|
+ $query->where("status",1)->orWhereHas("deliveryAppointment",function (Builder $query)use($period){
|
|
|
+ $query->where("date_period",">=",$period);
|
|
|
+ });
|
|
|
+ })->orderByRaw("(CASE WHEN status=0 THEN 2 WHEN status=2 THEN 3 END),IF(ISNULL(delivery_time),1,0),delivery_time")
|
|
|
+ ->limit(10)->get()->each(function ($car)use(&$list){
|
|
|
+ //$diff = $car->delivery_time ? (strtotime($car->delivery_time)+1799)-time() : 0;
|
|
|
+ $count = $car->deliveryAppointment->cars_count ?? 0;
|
|
|
+ $list[] = [
|
|
|
+ "id" => $car->id,
|
|
|
+ "license_plate_number" => $car->license_plate_number,
|
|
|
+ "driver_name" => $car->driver_name,
|
|
|
+ "driver_phone" => $car->driver_phone,
|
|
|
+ "status" => $car->status,
|
|
|
+ "cubic_meter" => isset($car->deliveryAppointment->cubic_meter) && $car->deliveryAppointment->cubic_meter>0 ? ($count>1 ? $car->deliveryAppointment->cubic_meter."/".$count : $car->deliveryAppointment->cubic_meter) : "",
|
|
|
+ "tonne" => isset($car->deliveryAppointment->tonne) && $car->deliveryAppointment->tonne>0 ? ($count>1 ? $car->deliveryAppointment->tonne."/".$count : $car->deliveryAppointment->tonne) : "",
|
|
|
+ //"diff" => $diff>0 ? $diff*1000 : 0,
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ return $list;
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取展览数据
|
|
|
*/
|
|
|
public function getExhibitionList()
|
|
|
{
|
|
|
$this->gate("入库管理-入库预约-入库区终端");
|
|
|
- $list = [];
|
|
|
$hour = date("H");
|
|
|
$warehouse = request("warehouse");
|
|
|
$index = null;
|
|
|
@@ -309,30 +356,7 @@ class DeliveryAppointmentController extends Controller
|
|
|
}
|
|
|
}
|
|
|
if ($index===null)$this->success();
|
|
|
- DeliveryAppointmentCar::query()->whereHas("deliveryAppointment",function ($query)use($index,$warehouse){
|
|
|
- /** @var Builder $query */
|
|
|
- $query->withCount("cars")->where("appointment_date",date("Y-m-d"))
|
|
|
- ->where("warehouse_id",$warehouse)->whereIn("status",[0,2]);
|
|
|
- })->where(function ($query)use($index){
|
|
|
- /** @var Builder $query */
|
|
|
- $query->where("status",1)->orWhereHas("deliveryAppointment",function (Builder $query)use($index){
|
|
|
- $query->where("date_period",">=",$index);
|
|
|
- });
|
|
|
- })->orderByRaw("(CASE WHEN status=0 THEN 2 WHEN status=2 THEN 3 END),IF(ISNULL(delivery_time),1,0),delivery_time")
|
|
|
- ->limit(10)->get()->each(function ($car)use(&$list){
|
|
|
- //$diff = $car->delivery_time ? (strtotime($car->delivery_time)+1799)-time() : 0;
|
|
|
- $count = $car->deliveryAppointment->cars_count ?? 0;
|
|
|
- $list[] = [
|
|
|
- "id" => $car->id,
|
|
|
- "license_plate_number" => $car->license_plate_number,
|
|
|
- "driver_name" => $car->driver_name,
|
|
|
- "driver_phone" => $car->driver_phone,
|
|
|
- "status" => $car->status,
|
|
|
- "cubic_meter" => isset($car->deliveryAppointment->cubic_meter) ? ($count>1 ? $car->deliveryAppointment->cubic_meter."/".$count : $car->deliveryAppointment->cubic_meter) : "",
|
|
|
- "tonne" => isset($car->deliveryAppointment->tonne) ? ($count>1 ? $car->deliveryAppointment->tonne."/".$count : $car->deliveryAppointment->tonne) : "",
|
|
|
- //"diff" => $diff>0 ? $diff*1000 : 0,
|
|
|
- ];
|
|
|
- });
|
|
|
+ $list = $this->carList($index,date("Y-m-d"),$warehouse);
|
|
|
$counts = DeliveryAppointmentCar::query()->whereHas("deliveryAppointment",function (Builder $query)use($index,$warehouse){
|
|
|
$query->where("appointment_date",date("Y-m-d"))
|
|
|
->where("warehouse_id",$warehouse)->whereIn("status",[0,2]);
|
|
|
@@ -353,7 +377,7 @@ class DeliveryAppointmentController extends Controller
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- $result = ["list"=>$list,"success"=>$success,"work"=>$work,"notReached"=>$notReached];
|
|
|
+ $result = ["list"=>$list,"success"=>$success,"work"=>$work,"notReached"=>$notReached,"nextDay"=>$this->carList(0,date("Y-m-d",strtotime("+1 day")),$warehouse)];
|
|
|
$nextTime = DeliveryAppointment::PERIOD[$index+1] ?? null;
|
|
|
if ($nextTime){
|
|
|
$nextTime = explode("-",$nextTime)[0];
|