Bladeren bron

客户预约新需求改动

Zhouzhendong 5 jaren geleden
bovenliggende
commit
18000f850f

+ 48 - 15
app/Http/Controllers/DeliveryAppointmentController.php

@@ -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();
+    }
 }

+ 1 - 1
app/Services/DeliveryAppointmentService.php

@@ -155,7 +155,7 @@ class DeliveryAppointmentService
         /** @var DeliveryAppointment|\stdClass $delivery */
         $delivery = DeliveryAppointment::query()->withCount(["cars"=>function($query){
             /** @var Builder $query */
-            $query->whereNull("delivery_time");
+            $query->whereNull("delivery_time")->where("status","!=",2);
         }])->find($id);
         if ($delivery->cars_count == 0)$delivery->update(["status"=>2]);
     }

+ 5 - 0
database/migrations/2021_04_02_134141_change_appointment_cars_add_status_column.php

@@ -16,6 +16,10 @@ class ChangeAppointmentCarsAddStatusColumn extends Migration
         Schema::table('delivery_appointment_cars', function (Blueprint $table) {
             $table->tinyInteger("status")->default(0)->comment("状态");
         });
+        \App\Authority::query()->firstOrCreate([
+            "name" => "入库管理-客户预约-预约管理-卸货完成",
+            "alias_name" => "入库管理-客户预约-预约管理-卸货完成",
+        ]);
     }
 
     /**
@@ -28,5 +32,6 @@ class ChangeAppointmentCarsAddStatusColumn extends Migration
         Schema::table('delivery_appointment_cars', function (Blueprint $table) {
             $table->dropColumn("status");
         });
+        \App\Authority::query()->where("name","入库管理-客户预约-预约管理-卸货完成")->delete();
     }
 }

+ 0 - 3
laravel-echo-server.lock

@@ -1,3 +0,0 @@
-{
-	"process": 18588
-}

+ 67 - 31
resources/views/store/deliveryAppointment/exhibition.blade.php

@@ -21,6 +21,9 @@
         .h-5{
             height: 5%;
         }
+        .h-9{
+            height: 9%;
+        }
         .text-line{
             line-height: 1;
             font-size: 1.5em;
@@ -86,22 +89,24 @@
             <div class="h-5"></div>
             <div class="h-5 h6">
                 <div class="font-weight-bold row">
-                    <div class="col-2"><span class="fa fa-diamond text-info"></span>&nbsp;当前时段预约车辆:</div>
+                    <div class="col-2"><span class="fa fa-diamond text-info"></span>&nbsp;当预约车辆:</div>
                     <div class="col-8 m-0">
                         <div class="progress">
-                            <div class="progress-bar bg-success progress-bar-striped" :style="{width:(count>0 ? (success/count)*100 : 100)+'%'}">@{{ success }}/@{{ count }}</div>
+                            <div class="progress-bar bg-info progress-bar-striped" :style="{width:(count.total>0 ? (count.work/count.total)*100 : 0)+'%'}">作业中:@{{ count.work }}</div>
+                            <div class="progress-bar bg-secondary progress-bar-striped" :style="{width:(count.total>0 ? (count.notReached/count.total)*100 : 0)+'%'}">待送达:@{{ count.notReached }}</div>
+                            <div class="progress-bar bg-success progress-bar-striped" :style="{width:(count.total>0 ? (count.success/count.total)*100 : 100)+'%'}">已完成:@{{ count.success }}</div>
                         </div>
                     </div>
                 </div>
                 <hr class="font-weight-bold">
             </div>
             <div class="w-100 h-90">
-                <div class="row h-10 mt-0" v-for="(data,i) in list" :class="data.is_delivery ? 'text-success' : 'text-primary'" {{--v-if="i<5"--}}>
+                <div class="row h-9 mt-1" v-for="(data,i) in list" :class="data.status==1 ? 'text-primary' : (data.status==2 ? 'text-success' : 'text-dark')" {{--v-if="i<5"--}}>
                     <div class="col-3 text-line">@{{ data.license_plate_number }}</div>
                     <div class="col-2 text-line">@{{ data.driver_name }}</div>
                     <div class="col-3 text-line">@{{ data.driver_phone }}</div>
                     <div class="col-2 text-line">
-                        <span v-if="data.is_delivery">已送达</span>
+                        <span class="badge badge-pill badge-primary" {{--v-if="data.is_delivery"--}} v-if="data.status == 1">{{--已送达--}}作业中</span>
                     </div>
                 </div>
             </div>
@@ -156,13 +161,18 @@
             key:"",
             baseUrl:"{{url('store/deliveryAppointment/delivery?k=')}}",
             QrCode : null,
-            count : 0,
+            count : {
+                total : 0,
+                success : 0,
+                notReached : 0,
+                work : 0,
+            },
             success : 0,
         },
         mounted(){
             $("#container").removeClass("d-none");
             this._initData();
-            this._broadcast();
+            //this._broadcast();
             /*this._getKey();
             setTimeout(()=>{
                 //刷新密匙
@@ -175,38 +185,62 @@
         methods:{
             _broadcast(){
                 initEcho();
-                window.Echo.channel('{{config('database.redis.options.prefix')}}delivery').listen('.car',(res)=>{
+                window.Echo.channel('{{config('database.redis.options.prefix')}}delivery').listen('.car',(res)=>{this._sortData(res.delivery)})
+            },
+            _sortData(res){
+                if (this.list.every((data,i)=>{
+                    if (data.id === res.id){
+                        //this.$set(this.list[i],"is_delivery",true);
+                        data.status = res.status;
+                        this.list.splice(i,1);
+                        if (data.status=='1'){
+                            if (this.list.every((car,j)=>{
+                                if (car.status!=data.status){
+                                    this.list.splice(j,0,data);
+                                    return false;
+                                }
+                                return true;
+                            }))this.list.push(data);
+                        }else this.list.push(data);
+                        return false;
+                    }
+                    return true;
+                })){
                     if (this.list.length>=10) this.list = this.list.splice(0,9);
-                    res = res.delivery;
-                    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({
+                    let obj = {
+                        "id"                    : res.id,
                         "license_plate_number"  : res.license_plate_number,
                         "driver_name"           : res.driver_name,
                         "driver_phone"          : res.driver_phone,
-                        "is_delivery"           : true,
-                    });
-                    setTimeout(()=>{
-                        this.list.some((data,i)=>{
-                            if (data.license_plate_number === res.license_plate_number) {
-                                this.$set(this.list[i],"is_delivery",false);
-                                return true;
+                        "status"                : res.status,
+                        /*"is_delivery"           : true,*/
+                    };
+                    if (res.status=='1'){
+                        if (this.list.every((car,j)=>{
+                            if (car.status!=res.status){
+                                this.list.splice(j,0,obj);
+                                return false;
                             }
-                        });
-                    },1800000);
-                    this.success++;
-                })
+                            return true;
+                        }))this.list.push(obj);
+                    }else this.list.push(obj);
+                }
+                /*setTimeout(()=>{
+                    this.list.some((data,i)=>{
+                        if (data.license_plate_number === res.license_plate_number) {
+                            this.$set(this.list[i],"is_delivery",false);
+                            return true;
+                        }
+                    });
+                },1800000);*/
+                this.success++;
             },
             //初始化数据
             _initData(){
                 let url = "{{url('store/deliveryAppointment/getExhibitionList')}}";
                 window.tempTip.postBasicRequest(url,{},res=>{
                     if (res.list){
-                        let data = res.list;
+                        /*let data = res.list;
                         data.forEach((item,i)=>{
                             if (item.diff){
                                 data[i].is_delivery = true;
@@ -219,10 +253,12 @@
                                     });
                                 },item.diff);
                             }
-                        });
-                        this.list = data;
-                        this.count = res.count;
-                        this.success = res.success;
+                        });*/
+                        this.list = res.list;
+                        this.count.notReached = res.notReached;
+                        this.count.success = res.success;
+                        this.count.work = res.work;
+                        this.count.total = res.notReached+res.success+res.work;
                     }
                     //判断下次刷新数据的时间
                     let refreshVal = res.refresh ? res.refresh : this._getDiffDate();

+ 23 - 66
resources/views/store/deliveryAppointment/list.blade.php

@@ -38,9 +38,10 @@
                     <div class="row">
                         <div class="col-2">预约号</div>
                         <div class="col-2">车牌号</div>
-                        <div class="col-3">车型</div>
-                        <div class="col-2">司机姓名</div>
+                        <div class="col-2">车型</div>
+                        <div class="col-1">司机姓名</div>
                         <div class="col-3">司机电话</div>
+                        <div class="col-2"></div>
                     </div>
                 </th>
                 <th>吨</th>
@@ -88,20 +89,22 @@
                 </td>
                 <td>
                     <div v-if="info.cars.length>0">
-                        <div class="row">
+                        <div class="row" style="width: 500px">
                             <div class="col-2 font-weight-bold">@{{ info.cars[0].appointment_number }}</div>
                             <div class="col-2 text-secondary">@{{ info.cars[0].license_plate_number }}</div>
-                            <div class="col-3 text-secondary">@{{ info.cars[0].car ? info.cars[0].car.name : '' }}</div>
-                            <div class="col-2 text-secondary">@{{ info.cars[0].driver_name }}</div>
+                            <div class="col-2 text-secondary">@{{ info.cars[0].car ? info.cars[0].car.name : '' }}</div>
+                            <div class="col-1 text-secondary">@{{ info.cars[0].driver_name }}</div>
                             <div class="col-3 text-secondary">@{{ info.cars[0].driver_phone }}</div>
+                            <div class="col-2">@can("入库管理-客户预约-预约管理-卸货完成")<button class="btn btn-sm btn-outline-success" @click="unloading(i,0)" v-if="info.cars[0].status==1">卸货完成</button>@endcan</div>
                         </div>
                         <div class="up" :id="'item-'+info.id" v-show="info.cars.length>1">
-                            <div class="row" v-for="(car,i) in info.cars" v-if="i!==0">
+                            <div class="row" v-for="(car,j) in info.cars" v-if="j!==0">
                                 <div class="col-2 font-weight-bold">@{{ car.appointment_number }}</div>
                                 <div class="col-2 text-secondary">@{{ car.license_plate_number }}</div>
-                                <div class="col-3 text-secondary">@{{ car.car ? car.car.name : '' }}</div>
-                                <div class="col-2 text-secondary">@{{ car.driver_name }}</div>
+                                <div class="col-2 text-secondary">@{{ car.car ? car.car.name : '' }}</div>
+                                <div class="col-1 text-secondary">@{{ car.driver_name }}</div>
                                 <div class="col-3 text-secondary">@{{ car.driver_phone }}</div>
+                                <div class="col-2">@can("入库管理-客户预约-预约管理-卸货完成")<button class="btn btn-sm btn-outline-success" @click="unloading(i,j)" v-if="car.status==1">卸货完成</button>@endcan</div>
                             </div>
                         </div>
                         <div class="text-center m-auto small cursor-pointer" v-if="info.cars.length>1" @click="upAll(info.id)">
@@ -236,6 +239,18 @@
                     else $(dom).slideDown();
                     this.$set(this.upListDetail,id,!this.upListDetail[id]);
                 },
+                unloading(i,j){
+                    window.tempTip.confirm("确定已经完成卸货?",()=>{
+                        window.tempTip.postBasicRequest("{{url('store/deliveryAppointment/unloading')}}",{id:this.list[i].cars[j].id},res=>{
+                            this.list[i].cars[j].status = 2;
+                            if (this.list[i].cars.every(car=>{
+                                if (car.status!=2)return false;
+                                return true
+                            }))this.list[i].status = 2;
+                            return "成功确认";
+                        })
+                    })
+                },
                 cancel(id,index){
                     window.tempTip.confirm("确定要取消该次预约吗?此操作不可逆,请谨慎选择",()=>{
                         window.tempTip.postBasicRequest("{{url('store/deliveryAppointment/cancel')}}",{id:id},res=>{
@@ -267,62 +282,4 @@
             },
         });
     </script>
-    <script type="text/javascript">
-        var tTD; //用来存储当前更改宽度的Table Cell,避免快速移动鼠标的问题
-        var table = document.getElementById("table");
-        var down = false;
-        for (i = 0; i < table.rows[0].cells.length; i++) {
-            table.rows[0].cells[i].onmousedown = function () {
-                //记录单元格
-                tTD = this;
-                if (event.offsetX > tTD.offsetWidth - 10) {
-                    down = true;
-                    tTD.oldX = event.x;
-                    tTD.oldWidth = tTD.offsetWidth;
-                }
-                //记录Table宽度
-                table = tTD; while (table.tagName != 'TABLE') table = table.parentElement;
-                tTD.tableWidth = table.offsetWidth;
-            };
-            table.rows[0].cells[i].onmousemove = function () {
-                //更改鼠标样式
-                if (event.offsetX > this.offsetWidth - 10)
-                    this.style.cursor = 'col-resize';
-                else
-                    this.style.cursor = 'default';
-                //取出暂存的Table Cell
-                if (tTD == undefined) tTD = this;
-            }
-        }
-        document.onmouseup = function () {
-            if (down) {
-                //结束宽度调整
-                if (tTD == undefined) tTD = this;
-                down = false;
-                tTD.style.cursor = 'default';
-            }
-        };
-        document.onmousemove = function () {
-            if (down) {
-                //调整宽度
-                if (down) {
-                    tTD.style.cursor = 'default';
-                    if (tTD.oldWidth + (event.x - tTD.oldX) > 0)
-                        tTD.width = tTD.oldWidth + (event.x - tTD.oldX);
-                    //调整列宽
-                    tTD.style.width = tTD.width;
-                    tTD.style.cursor = 'col-resize';
-                    //调整该列中的每个Cell
-                    table = tTD;
-                    while (table.tagName != 'TABLE') table = table.parentElement;
-                    for (i = 0; i < table.rows.length; i++) {
-                        table.rows[i].cells[tTD.cellIndex].width = tTD.width;
-                    }
-                    //调整整个表
-                    table.width = tTD.tableWidth + (tTD.offsetWidth - tTD.oldWidth);
-                    table.style.width = table.width;
-                }
-            }
-        };
-    </script>
 @stop

+ 1 - 0
routes/web.php

@@ -451,6 +451,7 @@ Route::group(['prefix'=>'store'],function(){
         Route::get('successMsg','DeliveryAppointmentController@successMsg');
         Route::post('delivery','DeliveryAppointmentController@checkAppointment');
         Route::post('cancel','DeliveryAppointmentController@cancel');
+        Route::post('unloading','DeliveryAppointmentController@unloading');
         Route::any('export','DeliveryAppointmentController@export');
         Route::post('getExhibitionList','DeliveryAppointmentController@getExhibitionList');
         Route::post('getKey','DeliveryAppointmentController@getKey');