Zhouzhendong пре 5 година
родитељ
комит
afc42ae4dd

+ 3 - 3
app/Http/Controllers/PriceModelController.php

@@ -1102,7 +1102,7 @@ class PriceModelController extends Controller
         $this->gate("客户管理-项目-录入");
         $params = request()->input();
         $params["logistic_id"] = $params["logistics"];
-        $errors = $this->expressValidator($params,request("id"))->errors();
+        $errors = $this->expressValidator($params,request("id"))->errors()->toArray();
         $exist = [];
         foreach ($params["items"] as $index => $item){
             if (isset($exist[$item["province_id"]]))$errors["items.".$index.".province_id"] = ["已存在"];
@@ -1165,7 +1165,7 @@ class PriceModelController extends Controller
         $params = request()->input();
         $params["owner_id"] = [$params["owner_id"]];
         $params["logistic_id"] = $params["logistics"];
-        $errors = $this->logisticValidator($params,request("id"))->errors();
+        $errors = $this->logisticValidator($params,request("id"))->errors()->toArray();
         $exist = [];
         foreach ($params["items"] as $index => $item){
             $key = $item["unit_id"]."-".$item["range"]."-".$item["province_id"]."-".$item["city_id"];
@@ -1237,7 +1237,7 @@ class PriceModelController extends Controller
     public function apiStoreDirectLogistic()
     {
         $this->gate("客户管理-项目-录入");
-        $errors = $this->directLogisticValidator(request()->input(),request("id"))->errors();
+        $errors = $this->directLogisticValidator(request()->input(),request("id"))->errors()->toArray();
         $exist = [];
         foreach (request("items") as $index=>$item){
             if (isset($exist[$item['car_type_id']]))$errors["items.".$index.".car_type_id"] = ["已存在"];

+ 3 - 4
app/Http/Controllers/TestController.php

@@ -214,10 +214,9 @@ sql;
 
     public function zzd1()
     {
-        DB::transaction(function (){
-            ValueStore::query()->where("name","wave_detail_last_sync_date")->lockForUpdate()->first();
-        });
-        return microtime(true);
+        $a = [1,2];
+        $b = [2];
+        dd(array_diff($b,$a));
     }
 
     public function mergeCarrier()

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

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 
 
+use App\Components\AsyncResponse;
 use App\Services\CarTypeService;
 use App\Services\CityService;
 use App\Services\LogisticService;
@@ -27,6 +28,7 @@ use Exception;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Http\Request;
+use Illuminate\Http\UploadedFile;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Gate;
@@ -37,6 +39,8 @@ use Ramsey\Uuid\Uuid;
 
 class WaybillController extends Controller
 {
+    use AsyncResponse;
+
     public function __construct()
     {
         app()->singleton('waybillService',WaybillService::class);
@@ -521,6 +525,58 @@ class WaybillController extends Controller
         return ['success'=>false,'error'=>"图片保存失败!"];
     }
 
+    //批量上传图片
+    public function batchUploadImages()
+    {
+        $this->gate("运输管理-图片上传");
+        $images = request("images");
+        $errors = [];
+        $number = [];
+        $mapping = [];
+        $type = ["jpg","png","gif","jfif","pjpeg","jpeg","webp"];
+        foreach ($images as $index => $image){
+            $suffix = $image->getClientOriginalExtension();
+            $name = $image->getClientOriginalName();
+            if (array_search(strtolower($suffix),$type) === false){
+                $errors[] = "“".$name."”格式错误";
+                unset($images[$index]);
+                continue;
+            }
+            $num = rtrim($name,".".$suffix);
+            $number[] = $num;
+            $mapping[$num] = $index;
+        }
+        $waybills = Waybill::query()->select("id","wms_bill_number")->doesntHave("uploadFile")->whereIn('wms_bill_number',$number)->get();
+        foreach (array_diff($number,array_column($waybills->toArray(),"wms_bill_number")) as $diff){
+            $errors[] = "“".$diff."”不存在运单或已存在照片";
+            unset($images[$mapping[$diff]]);
+        }
+        $insert = [];
+        foreach ($waybills as $waybill){
+            $image = $images[$mapping[$waybill->wms_bill_number]];
+            $fileName = date('ymd').'-'.Uuid::uuid1();
+            $suffix = $image->getClientOriginalExtension();
+            $thumbnailName=storage_path('app/public/files/'.$fileName.'-thumbnail.'.$suffix);
+            $commonName=storage_path('app/public/files/'.$fileName.'-common.'.$suffix);
+            $bulkyName=storage_path('app/public/files/'.$fileName.'-bulky.'.$suffix);
+            move_uploaded_file ($image->getRealPath() ,$bulkyName);
+            $img=Image::make($bulkyName);
+            if ($img->height() > $img->width())
+                $img->heighten(250)->save($commonName);
+            else $img->widen(250)->save($commonName);
+            $img->heighten(28)->save($thumbnailName);
+            $insert[] = [
+                "table_name"=>"waybills",
+                "table_id"=>$waybill->id,
+                "url"=>'/files/'.$fileName,
+                "type"=>strtolower($suffix),
+            ];
+        }
+        if ($insert)UploadFile::query()->insert($insert);
+        $waybills->load("uploadFile");
+        $this->success(["errors"=>$errors,"data"=>$waybills]);
+    }
+
     //删除照片
     public function deleteImg(Request $request){
         if(!Gate::allows('运输管理-图片删除')){ return '没有权限';  }

+ 1 - 1
app/Services/FeatureService.php

@@ -233,7 +233,7 @@ Class FeatureService
                     $str = $this->multiMatching($packages,$logic,$describe,$columnMapping[$column] ?? '');
                     continue;
                 }
-                $value = isset($columnMapping[$column]) ? $matchObject[$columnMapping[$column]] : '';
+                $value = isset($columnMapping[$column]) ? ($matchObject[$columnMapping[$column]] ?? '') : '';
                 switch ($logic) {
                     case "包含":
                         $str = mb_strpos($value,$describe) === false ? 'false' : 'true';

+ 2 - 2
app/Services/OwnerPriceOperationService.php

@@ -105,7 +105,7 @@ Class OwnerPriceOperationService
 
         $rules = OwnerPriceOperation::query()->with(["items"=>function($query){
             /** @var Builder $query */
-            $query->orderByRaw("CASE strategy  WHEN '起步' THEN 1 WHEN '默认' THEN 2 WHEN '特征' THEN 3 END DESC,priority DESC");
+            $query->orderByRaw("CASE strategy  WHEN '起步' THEN 1 WHEN '默认' THEN 2 WHEN '特征' THEN 3 END DESC,priority");
         }])->where("operation_type",$type)->whereHas("ownerPriceOperationOwners",function ($query)use($owner_id){
                 /** @var Builder $query */
                 $query->where("id",$owner_id);
@@ -171,7 +171,7 @@ Class OwnerPriceOperationService
                 if ($money>0)return $money;
             };
         }
-        return -7;
+        return $money ?? -7;
     }
     private function changeUnit($amount,$owner_id,$sku)
     {

+ 5 - 0
resources/sass/text.scss

@@ -122,4 +122,9 @@
     height:3px;
     border:none;
     border-top:3px solid #007bff;
+}
+//文本强制换行
+.text-wrap{
+    white-space: normal;
+    word-break:break-all
 }

+ 1 - 0
resources/views/customer/project/create.blade.php

@@ -752,6 +752,7 @@
                     window.tempTip.postBasicRequest(url,params,res=>{
                         if (res && res.errors){
                             this.errors = res.errors;
+                            window.tempTip.show("检查您的子项详情列表是否完整");
                             return;
                         }
                         this.model.logistic.items.forEach((item,i)=>{

+ 48 - 0
resources/views/waybill/_batchUploadImg.blade.php

@@ -0,0 +1,48 @@
+<div class="modal fade" tabindex="-1" role="dialog" id="batchUploadImg">
+    <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable">
+        <div class="modal-content">
+            <div class="modal-header">
+                <div class="pull-left ml-2 small text-primary">
+                    选择文件时使用SHIFT键或CTRL键可多选
+                </div>
+                <button type="button" class="close" data-dismiss="modal">&times;</button>
+            </div>
+            <div class="modal-body">
+                <label hidden><input type="file" @change="uploadFiles($event)" multiple="multiple" id="uploadImg" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg"></label>
+                <div class="container-fluid">
+                    <div class="text-center small row mb-1" v-if="batchUploadError.length>0">
+                        <div class="col-3 text-danger">部分上传失败:</div>
+                        <div class="col-8">
+                            <b v-for="err in batchUploadError">@{{ err }}<br></b>
+                        </div>
+                    </div>
+                    <div class="row">
+                        <div class="col-8 text-center offset-2 border border-2 rounded" style="min-height: 100px;cursor: pointer"
+                        @click="selectedFile()" v-if="images.length<1">
+                            <div class="h1 text-secondary mt-3">
+                                <span class="fa fa-plus"></span>
+                            </div>
+                        </div>
+                        <div class="col-3 border border-2 rounded" v-for="(img,i) in images">
+                            <div class="w-100 h4 m-1" style="height: 10%;">
+                                <span class="text-danger font-weight-bold pull-right" style="cursor: pointer;" @click="delTempImg(i)"> &times;</span>
+                            </div>
+                            <div class="w-100 m-0 text-center" style="height: 60%">
+                                <img class="img-fluid" :src="img.src" alt="img.name">
+                            </div>
+                            <div class="w-100 text-center small" style="height: 25%;margin-top: 5%">
+                                <span class="text-wrap">@{{ img.name }}(<span class="text-info">@{{ img.size | size }}</span>)</span>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button class="btn btn-info text-white mr-1" @click="selectedFile()" v-if="images.length>1">
+                    <span class="fa fa-image"></span>
+                    继续添加</button>
+                <button class="btn btn-success" @click="batchUploadImages()">开始上传</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 82 - 14
resources/views/waybill/index.blade.php

@@ -8,6 +8,9 @@
     </div>
     <div class="container-fluid" style="min-width: 1500px;">
         <div class="d-none" id="list">
+
+            @include("waybill._batchUploadImg")
+
             <div class="container-fluid nav3">
                 <div class="card menu-third" >
                     <ul class="nav nav-pills">
@@ -37,6 +40,7 @@
                     <a class="dropdown-item" @click="waybillExport(true)" href="javascript:">导出所有页</a>
                 </div>
             </span>
+            <button class="btn btn-sm btn-outline-info" data-target="#batchUploadImg" data-toggle="modal">批量上传图片</button>
             <div>
                 @if(Session::has('successTip'))
                     <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
@@ -338,6 +342,8 @@
                 paginate : 50,
                 page : Number('{{$waybills->currentPage()}}'),
                 count : Number('{{$waybills->count()}}'),
+                images:[],
+                batchUploadError:[],
             },
             watch:{
                 checkData:{
@@ -497,10 +503,6 @@
                         tempTip.show('审核失败,网络连接错误!'+err);
                     });
                 },
-                {{--waybillUpdate(id){--}}
-                {{--    location.href="{{url('waybill/waybillEdit')}}/"+id;--}}
-                {{--},--}}
-                // 软删除
                 waybillDestroy(id,waybill_number,index){
                     if(!confirm('确定要删除运单号为:“'+waybill_number+'”的运单吗?')){return};
                     let url = '{{url('waybill')}}/'+id;
@@ -550,9 +552,6 @@
                         tempTip.show('审核驳回失败,网络连接错误!'+err);
                     });
                 },
-                {{--job(id){--}}
-                {{--    location.href="{{url('waybill')}}/"+id+"/edit";--}}
-                {{--},--}}
                 waybillEndAudit(id,waybill_number){
                     if(!confirm('确定要通过“'+waybill_number+'”的终审吗?')){return};
                     let _this=this;
@@ -665,7 +664,7 @@
                         "<img src=\""+url+'-common.'+suffix+"\" style='position: relative;left:-50px;' >" +
                         "</a>" +
                         "</div>"+
-                            @can('运输管理-图片删除')"<button type='button' class='btn btn-sm btn-danger' onclick='vueList.btnDeleteImg(this)' value='"+id+"' style='position: relative;float: right;margin-right: 51px;margin-top: -30px;' >删除</button>" +@endcan
+                            @can('运输管理-图片删除')"<button type='button' class='btn btn-sm btn-danger' onclick='vue.btnDeleteImg(this)' value='"+id+"' style='position: relative;float: right;margin-right: 51px;margin-top: -30px;' >删除</button>" +@endcan
                             "</div>"+
                         "</div>");
                 },
@@ -787,10 +786,6 @@
                         }
                     })
                 },
-
-
-
-
                 // 运费修改
                 waybillFeeCheck:function (e) {
                     let target = $(e.target);
@@ -961,7 +956,73 @@
                         tempTip.setDuration(3000);
                         tempTip.show('刷新计重失败,网络连接错误!'+err);
                     });
-                }
+                },
+                //选择文件
+                selectedFile(){
+                    $("#uploadImg").click();
+                },
+                //上传文件
+                uploadFiles(event){
+                    let images = event.target.files;
+                    for(let i=0;i<images.length;i++){
+                        images[i]['src'] = window.URL.createObjectURL(images[i]);
+                        this.images.push(images[i]);
+                    }
+                },
+                //删除图片
+                delTempImg(index){
+                    this.$delete(this.images,index);
+                },
+                //上传图片
+                batchUploadImages(){
+                    if (this.images.length<1){
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show("未选择图片");
+                        return;
+                    }
+                    let formData = new FormData();
+                    this.images.forEach(image=>{
+                        formData.append("images[]",image);
+                    });
+                    window.tempTip.setIndex(1099);
+                    window.tempTip.setDuration(9999);
+                    window.tempTip.waitingTip("上传中,请稍等......");
+                    window.axios.post('{{url('waybill/batchUploadImages')}}',formData,{
+                        'Content-Type':'multipart/form-data'
+                    }).then(res=>{
+                        if (res.data.success){
+                            let result = res.data.data.data;
+                            let errors = res.data.data.errors;
+                            if (errors.length>0)this.batchUploadError =  errors;
+                            console.log(result);
+                            result.forEach(r=>{
+                                this.waybills.some(waybill=> {
+                                    if (waybill.id==r.id){
+                                        waybill.url=r.upload_file.url;
+                                        waybill.suffix=r.upload_file.type;
+                                        setTimeout(()=> {
+                                            this.imgs.push(document.getElementById('img_'+waybill.id));
+                                            this.lazy();
+                                        },1);
+                                        return true;
+                                    }
+                                });
+                            });
+                            this.$forceUpdate();
+                            window.tempTip.cancelWaitingTip();
+                            window.tempTip.setDuration(2000);
+                            window.tempTip.showSuccess("上传成功!");
+                            return;
+                        }
+                        window.tempTip.cancelWaitingTip();
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show(res.data.data);
+                    }).catch(err=>{
+                        window.tempTip.cancelWaitingTip();
+                        window.tempTip.setDuration(3000);
+                        window.tempTip.show('网络错误:'+err);
+                    });
+                },
             },
             filters:{
                 km:function(value){
@@ -979,12 +1040,19 @@
                     value=value.replace(/(\.[1-9])0$/,'$1');
                     return value;
                 },
+                size:function (val) {
+                    if (!val)return '';
+                    val = Number(parseInt(val/1024));
+                    if (val >= 1024){
+                        return  parseInt(val/1024)+"MB";
+                    }
+                    return val+"KB";
+                }
             }
         });
         // modal 隐藏时修改 input 为空
         $("#exampleModal").on('hide.bs.modal',function(e){
             $('#remark').val('');
         });
-
     </script>
 @endsection

+ 1 - 0
routes/web.php

@@ -248,6 +248,7 @@ Route::group(['prefix'=>'waybill'],function(){
     Route::any('waybillEndAudit','WaybillController@waybillEndAudit');
     Route::any('export','WaybillController@export');
     Route::any('waybillUpdate/{id}','WaybillController@waybillUpdate');
+    Route::post('batchUploadImages','WaybillController@batchUploadImages');
 
     Route::resource('waybillFinancialSnapshot','WaybillFinancialSnapshotsController');
     Route::resource('waybillFinancialExcepted','WaybillFinancialExceptedController');