Kaynağa Gözat

运输管理部分BUG修复
全局导入方法抽离优化

Zhouzhendong 5 yıl önce
ebeveyn
işleme
0c3a0f4fe5

+ 15 - 0
app/Components/AsyncResponse.php

@@ -3,6 +3,7 @@
 namespace App\Components;
 
 use Illuminate\Support\Facades\Gate;
+use Maatwebsite\Excel\Facades\Excel;
 
 trait AsyncResponse{
 
@@ -27,4 +28,18 @@ trait AsyncResponse{
         echo json_encode($result);
         exit();
     }
+
+    public function importExcel(object $class)
+    {
+        ini_set('max_execution_time',2500);
+        ini_set('memory_limit','1526M');
+        $file = request()->file();
+        if (!$file)$this->error("文件不存在");
+        $file = reset($file);
+        $fileSuffix=strtolower($file->getClientOriginalExtension());
+        $types = ["xlsx",'xls','csv'];
+        if (!in_array($fileSuffix,$types)) $this->error("不支持该文件类型");
+        $fileSuffix = ucwords($fileSuffix);
+        Excel::import($class,$file->path(),null,$fileSuffix);
+    }
 }

+ 9 - 0
app/Http/Controllers/DeliveryAppointmentController.php

@@ -2,11 +2,20 @@
 
 namespace App\Http\Controllers;
 
+use App\Components\AsyncResponse;
+use App\Imports\AppointmentDetail;
+
 class DeliveryAppointmentController extends Controller
 {
+    use AsyncResponse;
     public function appointment()
     {
         $owners = app("OwnerService")->getIntersectPermitting();
         return view("store.checkingReceive.appointment",compact("owners"));
     }
+
+    public function import()
+    {
+        $this->importExcel(new AppointmentDetail());
+    }
 }

+ 0 - 1
app/Http/Controllers/WaybillController.php

@@ -635,7 +635,6 @@ class WaybillController extends Controller
                 $waybill->source_bill,
                 $waybill->wms_bill_number,
                 $waybill->waybill_number,
-                $waybill->waybill_number,
                 $waybill->charge,
                 $waybill->other_charge,
                 $waybill->other_charge_remark,

+ 58 - 0
app/Imports/AppointmentDetail.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace App\Imports;
+
+use App\Components\AsyncResponse;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Validator;
+use Maatwebsite\Excel\Concerns\ToCollection;
+use Maatwebsite\Excel\Concerns\WithHeadingRow;
+use Maatwebsite\Excel\Concerns\WithMultipleSheets;
+use Maatwebsite\Excel\Imports\HeadingRowFormatter;
+
+HeadingRowFormatter::default('none');
+class AppointmentDetail implements ToCollection,WithMultipleSheets,WithHeadingRow
+{
+    use AsyncResponse;
+    protected $row = ["条码","商品名称","数量"];
+    public function sheets(): array
+    {
+        return [
+            0 => $this,
+        ];
+    }
+
+    /**
+    * @param Collection $collection
+    */
+    public function collection(Collection $collection)
+    {
+        $header = $collection->first();
+        foreach ($this->row as $row)if (!isset($header[$row]))$this->error("表头不存在“".$row."”");
+        $errors = Validator::make($collection->toArray(),[
+            "*.条码" => ["required_without_all:*.商品名称,*.数量"],
+            "*.商品名称" => ["required_without:*.条码"],
+            "*.数量" => ["required_without:*.条码","integer","min:1"],
+        ],[
+            'required_without_all'=>':attribute 条码与商品名称,数量至少存在一组',
+            'required_without'=>':attribute 条码与商品名称,数量至少存在一组',
+            'integer'=>':attribute 必须为数字',
+            'min'=>':attribute 非法',
+        ],[
+            "*.条码" => "条码",
+            "*.商品名称" => "商品名称",
+            "*.数量" => "数量",
+        ])->errors();
+        if (count($errors)>0){
+            $temp = [];
+            foreach ($errors->toArray() as $key=>$arr){
+                $key = explode(".",$key,2)[0];
+                unset($collection[$key]);
+                $key = $key+2;
+                if (array_key_exists($key,$temp))$temp[$key] = array_merge($temp[$key],$arr);
+            }
+            $errors = $temp;
+        }
+        dd(json_encode($collection,JSON_UNESCAPED_UNICODE));
+    }
+}

+ 2 - 2
app/Services/WaybillService.php

@@ -150,7 +150,7 @@ class WaybillService
             $request->offsetSet('dispatch_remark', str_replace(["\n","\r"], ' ', $request->dispatch_remark));
         }
         if (!$request->destination) $request->offsetSet('destination', $waybill->destination);
-        if ($request->destination_city_id && $waybill->destination_city_id != $request->destination_city_id) {
+        /*if ($request->destination_city_id && $waybill->destination_city_id != $request->destination_city_id) {
             $city = app(CityService::class)->find($request->destination_city_id);
             if ($city && $city->province_name && (mb_strpos($request->destination, $city->name) === false || mb_strpos($request->destination, $city->province_name) === false)) {
                 if (mb_strpos($request->destination, $city->name) === false && mb_strpos($request->destination, $city->province_name) === false) {
@@ -171,7 +171,7 @@ class WaybillService
                 }
             }
         }
-        sign:
+        sign:*/
         $waybill->fill($request->input());
         $waybill->update();
         return $waybill;

+ 17 - 5
resources/views/store/checkingReceive/appointment.blade.php

@@ -43,6 +43,12 @@
                             </div>
                         </div>
                     </div>
+                    <div class="row mt-4 ml-1">
+                        <label class="col-2" for="ownerId">货主</label>
+                        <select id="ownerId" v-model="model.owner_id" class="col-6 form-control">
+                            <option v-for="owner in owners" :value="owner.id">@{{ owner.name }}</option>
+                        </select>
+                    </div>
                     <div class="row mt-4 ml-1">
                         <label class="col-2" for="procurementNumber">采购单号</label>
                         <input class="col-6 form-control" type="text" id="procurementNumber" v-model="model.procurement_number">
@@ -64,7 +70,9 @@
                     <div class="row mt-2 ml-1">
                         <label class="col-2" for="isUpload">是否上传明细单</label>
                         <input content="col-3" id="isUpload" type="checkbox" class="switch" v-model="model.is_upload">
-                        <button v-if="model.is_upload" type="button" class="col-2 offset-1 btn btn-info text-white" @click="openFile()">
+                        <button data-toggle="tooltip" id="openFile" type="button" class="col-2 offset-1 btn btn-info text-white"
+                                title="表头必须包含:商品名称 数量 条码"
+                                v-show="model.is_upload" @click="openFile()">
                             <span class="fa fa-cloud-upload"></span> 选择文件</button>
                         <span v-if="model.is_upload" class="text-secondary mt-1">&nbsp;@{{ fileName }}</span>
                         <label hidden><input type="file" id="file" accept=".csv, .xlsx, .xls" @change="selectedFile($event)"></label>
@@ -87,15 +95,19 @@
                 model:{
                     cars:[{number:"",id:"",name:"",phone:""}],
                 },
-                owners:JSON.parse("{{$owners->toJson() ?? '{}'}}"),
+                owners:@json($owners),
                 fileName:""
             },
             mounted(){
-
+                if (this.owners.length === 1)this.model.owner_id = this.owners[0].id;
+                $('#openFile').tooltip();
             },
             methods:{
                 openFile(){
-                    $('#file').click();
+                    if (!this.model.owner_id){
+                        window.tempTip.setDuration(2000);
+                        window.tempTip.show("必须先选定货主");
+                    }else $('#file').click();
                 },
                 selectedFile(e){
                     let file=e.target.files[0];
@@ -107,7 +119,7 @@
                     }
                     let formData = new FormData();
                     formData.append("file",file);
-                    window.axios.post('{{url('maintenance/priceModel/logistic/import')}}',formData,{
+                    window.axios.post('{{url('store/checkingReceive/appointment/import')}}',formData,{
                         'Content-Type':'multipart/form-data'
                     }).then(res=>{
                         window.tempTip.setDuration(3000);

+ 3 - 0
routes/web.php

@@ -407,6 +407,9 @@ Route::group(['prefix'=>'store'],function(){
         Route::get('mission','StoreCheckingReceiveController@mission');
         Route::post('destroyItem','StoreCheckingReceiveController@destroyItem');
         Route::get('appointment','DeliveryAppointmentController@appointment');
+        Route::group(['prefix'=>'appointment'],function(){
+            Route::post('import','DeliveryAppointmentController@import');
+        });
     });
 });