|
|
@@ -13,6 +13,7 @@ use App\Warehouse;
|
|
|
use Carbon\Carbon;
|
|
|
use Carbon\CarbonPeriod;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
+use Illuminate\Database\Eloquent\Model;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
@@ -306,27 +307,45 @@ class DeliveryAppointmentController extends Controller
|
|
|
}
|
|
|
}
|
|
|
if ($index===null)$this->success([]);
|
|
|
- $query = DeliveryAppointmentCar::query()->whereHas("deliveryAppointment",function (Builder $query)use($index){
|
|
|
- $query->where("appointment_date",date("Y-m-d"))->whereIn("status",[0,2])
|
|
|
- ->where("date_period",">=",$index);
|
|
|
- });
|
|
|
- $query->orderByDesc("id")->limit(10)->get()->each(function ($car)use(&$list){
|
|
|
- $diff = $car->delivery_time ? (strtotime($car->delivery_time)+1799)-time() : 0;
|
|
|
+ DeliveryAppointmentCar::query()->whereHas("deliveryAppointment",function (Builder $query)use($index){
|
|
|
+ $query->where("appointment_date",date("Y-m-d"))->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;
|
|
|
$list[] = [
|
|
|
+ "id" => $car->id,
|
|
|
"license_plate_number" => $car->license_plate_number,
|
|
|
"driver_name" => $car->driver_name,
|
|
|
"driver_phone" => $car->driver_phone,
|
|
|
- "diff" => $diff>0 ? $diff*1000 : 0,
|
|
|
+ "status" => $car->status,
|
|
|
+ //"diff" => $diff>0 ? $diff*1000 : 0,
|
|
|
];
|
|
|
});
|
|
|
- $counts = $query->selectRaw("(CASE WHEN delivery_time IS NOT NULL THEN 1 ELSE 2 END) AS time, COUNT(1) AS c")->groupByRaw("time")->get();
|
|
|
- $count = 0;
|
|
|
+ $counts = DeliveryAppointmentCar::query()->whereHas("deliveryAppointment",function (Builder $query)use($index){
|
|
|
+ $query->where("appointment_date",date("Y-m-d"))->whereIn("status",[0,2]);
|
|
|
+ })->selectRaw("status, COUNT(1) AS c")->groupByRaw("status")->get();
|
|
|
$success = 0;
|
|
|
+ $work = 0;
|
|
|
+ $notReached = 0;
|
|
|
if ($counts)foreach ($counts as $c){
|
|
|
- if ($c->time==1)$success = $c->c;
|
|
|
- $count += $c->c;
|
|
|
+ switch ($c->status){
|
|
|
+ case 0:
|
|
|
+ $notReached = $c->c;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ $work = $c->c;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ $success = $c->c;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- $result = ["list"=>$list,"count"=>$count,"success"=>$success];
|
|
|
+ $result = ["list"=>$list,"success"=>$success,"work"=>$work,"notReached"=>$notReached];
|
|
|
$nextTime = DeliveryAppointment::PERIOD[$index+1] ?? null;
|
|
|
if ($nextTime){
|
|
|
$nextTime = explode("-",$nextTime)[0];
|
|
|
@@ -398,16 +417,15 @@ html;
|
|
|
if (!$number)return ["status"=>417];
|
|
|
$period = app("DeliveryAppointmentService")->getPeriod();
|
|
|
if ($period===false)return ["status"=>416]; //非法时段扫码
|
|
|
- $car = DeliveryAppointmentCar::query()->whereNull("delivery_time")
|
|
|
+ $car = DeliveryAppointmentCar::query()->whereNull("delivery_time")->where("status",0)
|
|
|
->where("appointment_number",$number)->whereHas("deliveryAppointment",function (Builder $query)use($period){
|
|
|
$query->where("appointment_date",date("Y-m-d"))
|
|
|
->where("date_period",$period)->where("status",0);
|
|
|
})->first();
|
|
|
if (!$car)return ["status"=>417];
|
|
|
- $car->update(["delivery_time"=>date("Y-m-d H:i:s")]);
|
|
|
+ $car->update(["delivery_time"=>date("Y-m-d H:i:s"),"status"=>1]);
|
|
|
/** @var DeliveryAppointmentCar $car */
|
|
|
event(new DeliveryAppointmentEvent($car));
|
|
|
- app("DeliveryAppointmentService")->checkFull($car->delivery_appointment_id);
|
|
|
return ["status"=>200,"k"=>$car->delivery_appointment_id];
|
|
|
}
|
|
|
|
|
|
@@ -421,4 +439,19 @@ html;
|
|
|
}])->find(request("k"));
|
|
|
return view("store.deliveryAppointment.deliverySuccess",["cars"=>$appointment->cars]);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 卸货完成
|
|
|
+ */
|
|
|
+ public function unloading()
|
|
|
+ {
|
|
|
+ if (!request("id"))$this->error("非法参数");
|
|
|
+ /** @var DeliveryAppointmentCar|\stdClass $car */
|
|
|
+ $car = DeliveryAppointmentCar::query()->find(request("id"));
|
|
|
+ if (!$car || !$car->deliveryAppointment)$this->error("单据不存在");
|
|
|
+ $car->update(["status"=>2]);
|
|
|
+ app("DeliveryAppointmentService")->checkFull($car->delivery_appointment_id);
|
|
|
+ event(new DeliveryAppointmentEvent($car));
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
}
|