Browse Source

工单 货主批量完结

loustwo 4 năm trước cách đây
mục cha
commit
6fb13006da

+ 24 - 1
app/Http/Controllers/WorkOrderController.php

@@ -158,9 +158,32 @@ class WorkOrderController extends Controller
         }
         try {
             $this->service->ownerEndWorkOrderDetail($detail);
-            return ['success'=>true,'message' => '参数异常'];
+            return ['success'=>true];
         } catch (\Exception $e) {
             return ['success' => false,'message' => '工单完结异常'];
         }
     }
+
+    /**
+     * 货主批量完结工单
+     * @param Request $request
+     * @return array
+     */
+    public function ownerBatchEndWorkOrderApi(Request $request): array
+    {
+        if (Gate::denies('订单管理-工单处理-货主编辑'))
+            return ['success' => false, 'message' => '没有对应权限'];
+        $detail_ids = $request->input('detail_ids',[]);
+        if (count($detail_ids) == 0) return ['success' => false,'message' => '参数异常'];
+
+        $details = WorkOrderDetail::query()->find($detail_ids);
+        if (count($details) == 0 ) return ['success' => false,'message' => '参数异常'];
+        try {
+            $this->service->ownerBatchEndWorkOrderDetails($details);
+            return ['success' => true];
+        } catch (\Exception $e) {
+            return ['success' => false, 'message' => '工单完结异常,请刷新后重试'];
+        }
+    }
+
 }

+ 10 - 0
app/Services/WorkOrderService.php

@@ -117,6 +117,16 @@ class WorkOrderService
         $this->detailService->endDetail($detail);                       // 标记为处理过
     }
 
+    /**
+     * 商家批量完结工单
+     * @param $details
+     */
+    public function ownerBatchEndWorkOrderDetails($details){
+        foreach ($details as $detail){
+            $this->ownerEndWorkOrderDetail($detail);
+        }
+    }
+
     /**
      * @param WorkOrder $workOrder
      * @param WorkOrderDetail $detail

+ 42 - 1
resources/views/order/workOrder/index.blade.php

@@ -40,6 +40,12 @@
                         </button>
                     @endcan
 
+                    @can('订单管理-工单处理-货主编辑')
+                        <button type="button"
+                                class="ml-1 btn btn-outline-dark btn-sm"
+                                @click="batchEndWorkOrder">批量完结
+                        </button>
+                    @endcan
                 </div>
                 <div>
                     <table class="table table-sm table-striped table-hover table-bordered td-min-width-80 " id="table">
@@ -2880,7 +2886,42 @@
                             window.tempTip.cancelWaitingTip();
                             this.errorTempTip(err)
                         });
-
+                    },
+                    batchEndWorkOrder(){
+                        if (checkData.length === 0){
+                            this.errorTempTip("请勾选需要完结的工单");
+                            return ;
+                        }
+                        let count = this.workOrders.filter(e=>checkData.includes(`${e.id}`))
+                            .filter(e=>e.status !== '待货主完结').length;
+                        if (count>0){
+                            this.errorTempTip("勾选工单中有不符合完结条件的工单");
+                            return ;
+                        }
+                        let detail_ids = this.workOrders.filter(e=>{
+                            return checkData.includes(`${e.id}`);
+                        }).map(e=>{
+                            return e.pending_detail ? e.pending_detail.id : null;
+                        }).filter(e=>e);
+                        let url = "{{route('workOrder.owner.batchEndApi')}}";
+                        let data = {detail_ids:detail_ids};
+                        this.waitingTempTip('处理中');
+                        window.axios.post(url,data).then(res=>{
+                            window.tempTip.cancelWaitingTip();
+                            if(res.data.success){
+                                checkData.forEach(e=>{
+                                    let index = this.workOrders.findIndex(workOrder=>`${workOrder.id}` === `${e}`);
+                                    if (index >= 0){
+                                        this.$delete(this.workOrders,index);
+                                    }
+                                });
+                            } else {
+                                this.errorTempTip(res.data.message);
+                            }
+                        }).catch(err=>{
+                            window.tempTip.cancelWaitingTip();
+                            this.errorTempTip(err);
+                        });
                     }
                 },
             })

+ 1 - 0
routes/apiLocal.php

@@ -290,6 +290,7 @@ Route::group(['prefix' => 'print'],function (){
 
 Route::prefix('workOrder')->group(function(){
     Route::post('end','WorkOrderController@ownerEndWorkOrderApi')->name('workOrder.owner.endApi');                      // 承运商完结工单
+    Route::post('batchEnd','WorkOrderController@ownerBatchEndWorkOrderApi')->name('workOrder.owner.batchEndApi');      // 承运商处理标记
     Route::post('logisticTag','WorkOrderController@logisticHandlerTagApi')->name('workOrder.logistic.handlerTagApi');      // 承运商处理标记
     Route::prefix('intercept')->group(function(){           // 拦截
         Route::post('store','WorkOrderInterceptController@storeApi')->name('workOrder.intercept.storeApi');                                     // 拦截订单创建