Zhouzhendong 5 роки тому
батько
коміт
f5e348d4d1

+ 1 - 1
app/DeliveryAppointment.php

@@ -26,7 +26,7 @@ class DeliveryAppointment extends Model
         "date_period",
         "status",
     ];
-    //时段 映射date_period字段
+    //时段 映射date_period字段 必须有序 否则展示数据错乱
     const PERIOD=[
         0 => "9-11",
         1 => "13-17",

+ 20 - 4
app/Http/Controllers/DeliveryAppointmentController.php

@@ -293,8 +293,17 @@ class DeliveryAppointmentController extends Controller
     {
         $this->gate("入库管理-客户预约-预约管理");
         $list = [];
-        DeliveryAppointmentCar::query()->whereNotNull("delivery_time")->whereHas("deliveryAppointment",function (Builder $query){
-            $query->where("appointment_date",date("Y-m-d"));
+        $hour = date("H");
+        $index = null;
+        foreach (DeliveryAppointment::PERIOD as $key=>$period){
+            $arr = explode("-",$period);
+            if (count($arr)!=2)continue;
+            if ($hour<$arr[1])$index = $key;
+        }
+        if ($index===null)$this->success([]);
+        DeliveryAppointmentCar::query()->whereNotNull("delivery_time")->whereHas("deliveryAppointment",function (Builder $query)use($index){
+            $query->where("appointment_date",date("Y-m-d"))->whereIn("status",[0,2])
+                ->where("date_period",">=",$index);
         })->orderByDesc("id")->limit(10)->get()->each(function ($car)use(&$list){
             $diff = (strtotime($car->delivery_time)+1799)-time();
             $list[] = [
@@ -304,7 +313,14 @@ class DeliveryAppointmentController extends Controller
                 "diff" => $diff>0 ? $diff*1000 : 0,
             ];
         });
-        $this->success($list);
+        $result = ["list"=>$list];
+        $nextTime = DeliveryAppointment::PERIOD[$index+1] ?? null;
+        if ($nextTime){
+            $nextTime = explode("-",$nextTime)[0];
+            $timestamp = strtotime(date("Y-m-d")." ".$nextTime.":00:00");
+            $result["refresh"] = (($timestamp-time())*1000) ?? 1000;
+        }
+        $this->success($result);
     }
 
     public function getKey()
@@ -371,7 +387,7 @@ html;
         $car = DeliveryAppointmentCar::query()->whereNull("delivery_time")
             ->where("appointment_number",$number)->whereHas("deliveryAppointment",function (Builder $query)use($period){
                 $query->where("appointment_date",date("Y-m-d"))
-                ->where("date_period",$period);
+                ->where("date_period",$period)->where("status",0);
             })->first();
         if (!$car)return ["status"=>417];
         $car->update(["delivery_time"=>date("Y-m-d H:i:s")]);

+ 5 - 5
app/Http/Controllers/TestController.php

@@ -157,11 +157,11 @@ class TestController extends Controller
     }
     public function tt1()
     {
-        $delivery = DeliveryAppointment::query()->withCount(["cars"=>function($query){
-            /** @var Builder $query */
-            $query->whereNull("delivery_time");
-        }])->find(1);
-        dd($delivery);
+        $nextTime = DeliveryAppointment::PERIOD[1];
+        $nextTime = explode("-",$nextTime)[1];
+        $timestamp = strtotime(date("Y-m-d")." ".$nextTime.":00:00");
+        $result["refresh"] = ($timestamp-time())*1000;
+        dd($result);
         return view("store.deliveryAppointment.delivery",["k"=>"15661461456"]);
     }
     public function zzd(){

+ 1 - 1
app/Services/DeliveryAppointmentService.php

@@ -52,7 +52,7 @@ class DeliveryAppointmentService
             ($cubicMeter*config("appointment.production_capacity.cubic_meter")));
         $coefficient = config("appointment.production_capacity.coefficient");
         if ($amount && ($need/$amount < $coefficient)){
-            $need *= 1-(($coefficient-($need/$amount))*($rpcc/100));
+            $need *= 1+(($coefficient-($need/$amount))*($rpcc/100));
         }
         return $need;
     }

+ 25 - 7
resources/views/store/deliveryAppointment/exhibition.blade.php

@@ -80,7 +80,7 @@
     </style>
 </head>
 <body onload="initLoad()" class="h-100">
-    <div class="container-fluid h-100" id="container">
+    <div class="container-fluid h-100 d-none" id="container">
         <div class="offset-1 h1 font-weight-bold h-100">
             <div class="h-5"></div>
             <div class="w-100 h-40">
@@ -146,6 +146,7 @@
             QrCode : null,
         },
         mounted(){
+            $("#container").removeClass("d-none");
             this._initData();
             this._getKey();
             this._broadcast();
@@ -163,7 +164,13 @@
                 window.Echo.channel('{{config('database.redis.options.prefix')}}delivery').listen('.car',(res)=>{
                     if (this.list.length>=10) this.list = this.list.splice(0,9);
                     res = res.delivery;
-                    this.list.unshift({
+                    if (this.list.every((data,i)=>{
+                        if (data.license_plate_number === res.license_plate_number){
+                            this.$set(this.list[i],"is_delivery",true);
+                            return false;
+                        }
+                        return true;
+                    }))this.list.unshift({
                         "license_plate_number"  : res.license_plate_number,
                         "driver_name"           : res.driver_name,
                         "driver_phone"          : res.driver_phone,
@@ -183,17 +190,28 @@
             _initData(){
                 let url = "{{url('store/deliveryAppointment/getExhibitionList')}}";
                 window.tempTip.postBasicRequest(url,{},res=>{
-                    if (res){
-                        res.forEach((item,i)=>{
+                    if (res.list){
+                        let data = res.list;
+                        data.forEach((item,i)=>{
                             if (item.diff){
-                                res[i].is_delivery = true;
+                                data[i].is_delivery = true;
                                 setTimeout(()=>{
-                                    this.list[i].is_delivery = false;
+                                    this.list.some((data,i)=>{
+                                        if (data.license_plate_number === item.license_plate_number) {
+                                            this.$set(this.list[i],"is_delivery",false);
+                                            return true;
+                                        }
+                                    });
                                 },item.diff);
                             }
                         });
-                        this.list = res;
+                        this.list = data;
                     }
+                    //判断下次刷新数据的时间
+                    let refreshVal = res.refresh ? res.refresh : this._getDiffDate();
+                    setTimeout(()=>{
+                        this._initData();
+                    },refreshVal);
                 });
             },
             //获取密匙

+ 1 - 1
resources/views/store/deliveryAppointment/success.blade.php

@@ -29,7 +29,7 @@
                     <span class="badge badge-pill badge-info">{{$car->appointment_number}}</span>
                 </span><br>
                 <span class="mt-1">预约时间:{{$appointment->appointment_date}}&nbsp;&nbsp;{{$appointment->period}}</span>
-                <span class="ml-4 mt-1">司机:{{$appointment->driver_name ?? '未知'}}</span>
+                <span class="ml-4 mt-1">司机:{{$car->driver_name ?? '未知'}}</span>
             </div>
             @endforeach
             <div class="mt-5">