Explorar el Código

客户管理-权限限制

Zhouzhendong hace 5 años
padre
commit
6796d2a471

+ 44 - 28
app/Http/Controllers/CustomerController.php

@@ -227,7 +227,7 @@ class CustomerController extends Controller
     public function projectArea(Request $request)
     {
         if(!Gate::allows('客户管理-项目-面积')){ return redirect('denied');  }
-        $areas = app('OwnerAreaReportService')->paginate($request->input(),["owner"=>function($query){$query->with(["customer","ownerStoragePriceModels.unit"]);}]);
+        $areas = app('OwnerAreaReportService')->paginate($request->input(),["owner"=>function($query){$query->with(["customer","ownerStoragePriceModels.unit"]);},"userOwnerGroup"]);
         $ownerGroups = app('UserOwnerGroupService')->getSelection();
         $customers = app('CustomerService')->getSelection();
         $owners = app('OwnerService')->getIntersectPermitting();
@@ -235,27 +235,34 @@ class CustomerController extends Controller
         return response()->view('customer.project.area',compact("areas","ownerGroups","customers","owners","params"));
     }
 
-    public function updateArea(Request $request)
+    public function updateArea()
     {
-        if(!Gate::allows('客户管理-项目-面积-编辑')){ return ["success"=>false,'data'=>"无权操作!"];  }
-        if (!($request->id ?? false) || !($request->area ?? false)) return ["success"=>false,'data'=>"传递错误!"];
-
-        if (!request("accounting_area")){
-            $values = $request->area ?? null;
-            if (!$values)return ["success"=>true,"data"=>$values];
-            foreach ($values as $column=>$value){
-                if ($value && (!is_numeric($value) || $value<0))return ["success"=>false,'data'=>$column."非数字或小于0!"];
-            }
-            $accounting_area = ((int)$values["area_on_tray"]*2.5) + ((int)$values["area_on_half_tray"]*1.8) + ((int)$values["area_on_flat"]*1.3);
-            $values["accounting_area"] = $accounting_area;
-        }else $values = ["accounting_area"=>request("accounting_area")];
-
-        $row = app('OwnerAreaReportService')->update(["id"=>$request->id],$values);
-        if ($row==1){
-            LogService::log(__METHOD__,"客户管理-修改面积",json_encode($request->input()));
-            return ["success"=>true,"data"=>$values];
-        }
-        return ["success"=>false,"data"=>"影响了".$row."条数据!"];
+        $this->gate("客户管理-项目-面积-编辑");
+        if (!request("id")) $this->error("非法参数");
+
+        $obj = [
+            "user_owner_group_id" => request("ownerGroupId"),
+            "area_on_tray" => request("areaOnTray"),
+            "area_on_half_tray" => request("areaOnHalfTray"),
+            "area_on_flat" => request("areaOnFlat"),
+            "accounting_area" => ((int)request("areaOnTray")*2.5) +
+                ((int)request("areaOnHalfTray")*1.8) + ((int)request("areaOnFlat")*1.3),
+        ];
+        app('OwnerAreaReportService')->update(["id"=>request("id")],$obj);
+        $this->success($obj);
+    }
+
+    //面积报表审核
+    public function areaReportAudit()
+    {
+        $this->gate("客户管理-项目-用仓盘点-审核");
+        $id = request("id");
+        if(!$id)$this->error("非法参数");
+        $area = OwnerAreaReport::query()->find($id);
+        /** @var \stdClass $area */
+        if (!$area || $area->status!='编辑中')$this->error("记录已被操作");
+        $area->update(["status"=>"已审核"]);
+        $this->success();
     }
 
     public function projectAreaExport(Request $request)
@@ -395,16 +402,25 @@ class CustomerController extends Controller
         return ["success"=>true,"data"=>$date];
     }
 
-    public function billConfirm(Request $request)
+    public function billConfirm()
     {
-        if(!Gate::allows('结算管理-账单确认-完结')){ return ["success"=>false,'data'=>"无权操作!"];  }
-        if (!($request->id ?? false))return["success"=>false,"data"=>"非法参数"];
-        app('OwnerBillReportService')->update(["id"=>$request->id],["confirmed"=>"是"]);
-        LogService::log(__METHOD__,"客户管理-确认账单",json_encode($request->input()));
-        $bill =  app('OwnerBillReportService')->first(["id"=>$request->id,"confirmed"=>"是"]);
+        $this->gate("结算管理-账单确认-完结");
+        if (!request("id"))$this->error("非法参数");
+
+        /** @var OwnerBillReport $bill */
+        $bill =  app('OwnerBillReportService')->first(["id"=>request("id"),"confirmed"=>"否"]);
+
+        if (!$bill)$this->error("账单状态变更,禁止操作");
+        /** @var \stdClass $bill */
+        $area = OwnerAreaReport::query()->where("owner_id",$bill->owner_id)
+            ->where("counting_month","like",$bill->counting_month."%")->first();
+        if (!$area || $area->status!='编辑中')$this->error("对应面积报表状态异常");
+        $bill->update(["confirmed"=>"是"]);
+
+        LogService::log(__METHOD__,"客户管理-确认账单",json_encode(request()->input()));
         app('OwnerAreaReportService')->lockArea(null, $bill->owner_id, $bill->counting_month);
         LogService::log(__METHOD__,"客户管理-锁定账单的所有面积",json_encode($bill,JSON_UNESCAPED_UNICODE));
-        return ["success"=>true];
+        $this->success();
     }
 
     private function validator(array $params){

+ 31 - 0
database/migrations/2021_03_05_105547_add_authority_to_area_report.php

@@ -0,0 +1,31 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddAuthorityToAreaReport extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        \App\Authority::query()->firstOrCreate(["name"=>"客户管理-项目-用仓盘点-审核"],[
+            "name"=>"客户管理-项目-用仓盘点-审核",
+            "alias_name"=>"客户管理-项目-用仓盘点-审核",
+        ]);
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        \App\Authority::query()->where("name","客户管理-项目-用仓盘点-审核")->delete();
+    }
+}

+ 35 - 0
resources/views/customer/project/_editArea.blade.php

@@ -0,0 +1,35 @@
+<div class="modal fade" tabindex="-1" role="dialog" id="editArea">
+    <div class="modal-dialog modal-lg modal-dialog-centered">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal">&times;</button>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <label class="col-2 offset-1" for="ownerGroup">项目小组</label>
+                    <select id="ownerGroup" class="form-control col-6" v-model="area.ownerGroupId">
+                        <option v-for="group in ownerGroups" :value="group.name">@{{ group.value }}</option>
+                    </select>
+                </div>
+                <div class="row mt-3">
+                    <label class="col-2 offset-1" for="areaOnTray">货物整托</label>
+                    <input id="areaOnTray" :readonly="area.unitName=='m²' ? false : true"
+                           type="number" min="0" class="form-control col-6" v-model="area.areaOnTray">
+                </div>
+                <div class="row mt-3">
+                    <label class="col-2 offset-1" for="areaOnHalfTray">货物半托</label>
+                    <input id="areaOnHalfTray" :readonly="area.unitName=='m²' ? false : true"
+                           type="number" min="0" class="form-control col-6" v-model="area.areaOnHalfTray">
+                </div>
+                <div class="row mt-3">
+                    <label class="col-2 offset-1" for="areaOnFlat">平面区</label>
+                    <input id="areaOnFlat" :readonly="area.unitName=='m²' ? false : true"
+                           type="number" min="0" class="form-control col-6" v-model="area.areaOnFlat">
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-success" @click="submitArea()">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 49 - 75
resources/views/customer/project/area.blade.php

@@ -1,13 +1,13 @@
 @extends('layouts.app')
 @section('title')
-    面积报表-客户管理
+    用仓盘点-客户管理
 @endsection
 @section('content')
     @component('customer.project.menu')@endcomponent
     <div class="container-fluid d-none" id="container">
 
         @include("customer._selectedOwner")
-
+        @include("customer.project._editArea")
         <div id="form_div"></div>
         <div>
             <button type="button" class="btn btn-outline-dark btn-sm dropdown-toggle tooltipTarget" :class="[checkData.length>0?'btn-dark text-light':'']"
@@ -33,43 +33,24 @@
                     </td>
                     <td>@{{ i+1 }}</td>
                     <td>
-                        <span v-if="area.status=='已完成'" class="text-success">@{{ area.status }}</span>
-                        <span v-if="area.status!='已完成' && editIndex!=i"><button class="btn btn-sm btn-outline-info" @click="edit(area,i)">编辑</button></span>
-                        <span v-if="editIndex==i">
-                            <button class="btn btn-sm btn-success" @click="submitArea()">确定</button>
-                            <button class="btn btn-sm btn-danger" @click="editIndex='-1'">取消</button>
+                        <span v-if="area.status=='编辑中'">
+                            <button class="btn btn-sm btn-outline-info" @click="edit(area,i)">编辑</button>
+                            <button class="btn btn-sm btn-outline-success" v-if="area.accountingArea" @click="audit(i)">审核</button>
                         </span>
+                        <span v-if="area.status=='已完成'" class="text-success font-weight-bold">@{{ area.status }}</span>
+                        <span v-if="area.status=='已审核'" class="text-primary font-weight-bold">@{{ area.status }}</span>
                     </td>
-                    <td>
-                        <label><select @change="thisArea.user_owner_group_id = $event.target.value" :disabled="editIndex==i ? false : true"
-                                       :value="area.ownerGroupId" class="form-control form-control-sm">
-                            <option v-for="ownerGroup in ownerGroups" :value="ownerGroup.name">@{{ ownerGroup.value }}</option>
-                        </select></label>
-                    </td>
+                    <td>@{{ area.userOwnerGroupName }}</td>
                     <td>@{{ area.customerName }}</td>
                     <td>@{{ area.ownerName }}</td>
                     <td>@{{ area.countingMonth }}</td>
                     <td>@{{ area.updatedAt }}</td>
                     <td>@{{ area.ownerStoragePriceModel }}</td>
                     <td>@{{ area.unitName }}</td>
-                    <td>
-                        <label><input :readonly="editIndex==i && (area.unitName=='m²' || area.unitName=='㎡') ? false : true" @change="thisArea.area_on_tray = $event.target.value"
-                                      type="number" min="0" class="form-control form-control-sm" :value="area.areaOnTray"></label>
-                    </td>
-                    <td>
-                        <label><input :readonly="editIndex==i && (area.unitName=='m²' || area.unitName=='㎡') ? false : true" @change="thisArea.area_on_half_tray = $event.target.value"
-                                      type="number" min="0" class="form-control form-control-sm" :value=area.areaOnHalfTray></label>
-                    </td>
-                    <td>
-                        <label><input :readonly="editIndex==i && (area.unitName=='m²' || area.unitName=='㎡') ? false : true" @change="thisArea.area_on_flat = $event.target.value"
-                                      type="number" min="0" class="form-control form-control-sm" :value="area.areaOnFlat"></label>
-                    </td>
-                    <td>
-                        <label class="form-inline"><input :readonly="editIndex==i && (area.unitName!='m²' || area.unitName!='㎡') ? false : true" @change="thisArea.accounting_area = $event.target.value"
-                                      type="number" min="0" class="form-control form-control-sm" :value="area.accountingArea">
-                            <label> / @{{ area.unitName }}</label>
-                        </label>
-                    </td>
+                    <td>@{{ area.areaOnTray }}</td>
+                    <td>@{{ area.areaOnHalfTray }}</td>
+                    <td>@{{ area.areaOnFlat }}</td>
+                    <td>@{{ area.accountingArea }}</td>
                 </tr>
             </table>
             {{$areas->appends($params)->links()}}
@@ -90,6 +71,7 @@
                     {
                         id : "{{$area->id}}",
                         ownerGroupId : "{{$area->user_owner_group_id}}",
+                        userOwnerGroupName : "{{$area->userOwnerGroup->name ?? ''}}",
                         ownerName : "{{$area->owner ? $area->owner->name : ''}}",
                         customerName : "{{$area->owner ? ($area->owner->customer ? $area->owner->customer->name : '') : ''}}",
                         countingMonth : "{{$area->counting_month}}",
@@ -100,16 +82,10 @@
                         status : "{{$area->status}}",
                         updatedAt : "{{$area->updated_at}}",
                         ownerStoragePriceModel:"{{ $area->ownerStoragePriceModel ? $area->ownerStoragePriceModel->using_type : '' }}",
-                        unitName:"{{ $area->ownerStoragePriceModel ? ($area->ownerStoragePriceModel->unit ? $area->ownerStoragePriceModel->unit->name : '') : '' }}",
+                        unitName:"{{ $area->ownerStoragePriceModel->unit->name ?? '' }}",
                     },
                     @endforeach
                 ],
-                thisArea : {
-                    user_owner_group_id : "",
-                    area_on_tray : "",
-                    area_on_half_tray : "",
-                    area_on_flat : "",
-                },
                 ownerGroups : [
                     @foreach($ownerGroups as $ownerGroup)
                     {name:"{{$ownerGroup->id}}",value:"{{$ownerGroup->name}}"},
@@ -125,11 +101,12 @@
                     {name:"{{$owner->id}}",value:"{{$owner->name}}"},
                     @endforeach
                 ],
-                status : [{name:"编辑中",value:"编辑中"},{name:"已完成",value:"已完成"}],
+                status : [{name:"编辑中",value:"编辑中"},{name:"已审核",value:"已审核"},{name:"已完成",value:"已完成"}],
                 checkData : [],
-                editIndex : "-1",
                 sum : Number("{{ $areas->total() }}"),
                 errors:[],
+                area:{},
+                index:"",
             },
             watch:{
                 checkData:{
@@ -169,7 +146,7 @@
                         dom:$('#cloneCheckAll').removeClass('d-none'), neglect: true},
                     {name:'index',value: '序号', neglect: true},
                     {name:'status',value: '状态'},
-                    {name:'ownerGroupId',value: '项目组', neglect : true},
+                    {name:'userOwnerGroupName',value: '项目组'},
                     {name:'customerName',value: '客户'},
                     {name:'ownerName',value: '子项目'},
                     {name:'countingMonth',value: '结算月'},
@@ -215,42 +192,29 @@
                     }
                 },
                 edit(area,index){
-                    this.editIndex = index;
-                    this.thisArea.user_owner_group_id = area.ownerGroupId;
-                    this.thisArea.area_on_tray = area.areaOnTray;
-                    this.thisArea.area_on_half_tray = area.areaOnHalfTray;
-                    this.thisArea.area_on_flat = area.areaOnFlat;
-                    this.thisArea.accounting_area = area.accountingArea;
+                    $("#editArea").modal("show");
+                    this.area = Object.assign({},area);
+                    this.index = index;
                 },
                 submitArea(){
-                    window.tempTip.confirm("确认要提交该面积的更新吗?",()=>{
-                        axios.post("{{url('customer/project/updateArea')}}",{
-                            id:this.areas[this.editIndex].id,area:this.thisArea
-                        }).then(res=>{
-                            if (res.data.success){
-                                this.areas[this.editIndex].ownerGroupId = res.data.data["user_owner_group_id"];
-                                this.areas[this.editIndex].areaOnTray = res.data.data["area_on_tray"];
-                                this.areas[this.editIndex].areaOnHalfTray = res.data.data["area_on_half_tray"];
-                                this.areas[this.editIndex].areaOnFlat = res.data.data["area_on_flat"];
-                                this.areas[this.editIndex].accountingArea = res.data.data["accounting_area"];
-                                this.editIndex = '-1';
-                                this.thisArea = {
-                                    user_owner_group_id : "",
-                                    area_on_tray : "",
-                                    area_on_half_tray : "",
-                                    area_on_flat : "",
-                                };
-                                window.tempTip.setDuration(2000);
-                                window.tempTip.showSuccess("修改成功");
-                                return;
-                            }
-                            window.tempTip.setDuration(3000);
-                            window.tempTip.show(res.data.data);
-                        }).catch(err=>{
-                            window.tempTip.setDuration(3000);
-                            window.tempTip.show("网络错误:"+err);
-                        })
-                    });
+                    let url = "{{url('customer/project/updateArea')}}";
+                    window.tempTip.postBasicRequest(url,this.area,res=>{
+                        if (this.areas[this.index].ownerGroupId !== res.user_owner_group_id){
+                            this.areas[this.index].ownerGroupId = res.user_owner_group_id;
+                            this.ownerGroups.some(group=>{
+                                if(group.name === res.user_owner_group_id){
+                                    this.areas[this.index].userOwnerGroupName = group.value;
+                                    return true;
+                                }
+                            });
+                        }
+                        this.areas[this.index].areaOnTray = res.area_on_tray;
+                        this.areas[this.index].areaOnHalfTray = res.area_on_half_tray;
+                        this.areas[this.index].areaOnFlat = res.area_on_flat;
+                        this.areas[this.index].accountingArea = res.accounting_area;
+                        $("#editArea").modal("hide");
+                        return "修改成功";
+                    },true);
                 },
                 createReport(isAll = false){
                     let dom = $("#owners");
@@ -280,6 +244,16 @@
                         return "已生成报表";
                     },true)
                 },
+                audit(index){
+                    window.tempTip.confirm("确定要通过该盘点记录的审核吗?",()=>{
+                        let area = this.areas[index];
+                        let url = '{{url('customer/project/areaReportAudit')}}';
+                        window.tempTip.postBasicRequest(url,{id:area.id},()=>{
+                            this.areas[index].status = "已审核";
+                            return "审核通过";
+                        });
+                    })
+                },
             },
         });
     </script>

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

@@ -202,6 +202,7 @@
                 let type = "{{$type ?? ''}}";
                 if (type){
                     this.base = "three";
+                    this.type = "";
                     setTimeout(()=>{
                         this.switchType(type);
                         if (!this.isLoad && this.ownerTemp.id)this._loadPriceModel();//计费模型未被加载且项目ID存在时

+ 6 - 6
resources/views/customer/project/index.blade.php

@@ -1,5 +1,5 @@
 @extends('layouts.app')
-@section('title')项目查询-客户管理@endsection
+@section('title')项目列表-客户管理@endsection
 
 @section('content')
     @component('customer.project.menu')@endcomponent
@@ -12,27 +12,27 @@
                         <div class="container-fluid" v-if="priceModel[thisClickIndex]">
                             <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerStoragePriceModels']">
                                 <label class="text-dark font-weight-bold col-3"><span v-if="i==0">仓储:</span></label>
-                                <a target="_blank" :href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=storage'" class="text-decoration-none">@{{ model.counting_type }}-@{{ model.using_type }}</a>
+                                <a target="_blank" @can("计费模型-仓储-录入"):href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=storage'" @endcan class="text-decoration-none">@{{ model.counting_type }}-@{{ model.using_type }}</a>
                             </div>
                             <hr class="m-1" v-if="priceModel[thisClickIndex]['ownerPriceOperations'].length>0">
                             <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceOperations']">
                                 <label class="text-dark font-weight-bold col-3"><span v-if="i==0">作业:</span></label>
-                                <a target="_blank" :href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=operation'" class="text-decoration-none">@{{ model.name }}</a>
+                                <a target="_blank" @can("计费模型-作业-录入"):href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=operation'" @endcan class="text-decoration-none">@{{ model.name }}</a>
                             </div>
                             <hr class="m-1" v-if="priceModel[thisClickIndex]['ownerPriceExpresses'].length>0">
                             <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceExpresses']">
                                 <label class="text-dark font-weight-bold col-3"><span v-if="i==0">快递:</span></label>
-                                <a target="_blank" :href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=express'" class="text-decoration-none">@{{ model.name }}</a>
+                                <a target="_blank" @can("计费模型-快递-录入"):href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=express'" @endcan class="text-decoration-none">@{{ model.name }}</a>
                             </div>
                             <hr class="m-1" v-if="priceModel[thisClickIndex]['ownerPriceLogistics'].length>0">
                             <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceLogistics']">
                                 <label class="text-dark font-weight-bold col-3"><span v-if="i==0">物流:</span></label>
-                                <a target="_blank" :href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=logistic'" class="text-decoration-none">@{{ model.name }}</a>
+                                <a target="_blank" @can("计费模型-物流-录入"):href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=logistic'" @endcan class="text-decoration-none">@{{ model.name }}</a>
                             </div>
                             <hr class="m-1" v-if="priceModel[thisClickIndex]['ownerPriceDirectLogistics'].length>0">
                             <div class="row" v-for="(model,i) in priceModel[thisClickIndex]['ownerPriceDirectLogistics']">
                                 <label class="text-dark font-weight-bold col-3"><span v-if="i==0">直发车:</span></label>
-                                <a target="_blank" :href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=directLogistic'" class="text-decoration-none">@{{ model.name }}</a>
+                                <a target="_blank" @can("计费模型-直发-录入"):href="'{{url('customer/project')}}/'+thisClickIndex+'/edit?type=directLogistic'" @endcan class="text-decoration-none">@{{ model.name }}</a>
                             </div>
                         </div>
                     </div>

+ 10 - 10
resources/views/customer/project/part/_three.blade.php

@@ -332,23 +332,23 @@
                 <button type="button" class="btn mr-1" :class="type == 'directLogistic' ? 'btn-primary text-white' : 'btn-outline-primary'" @click="switchType('directLogistic')">直发</button>
             </div>
             <div class="card-body">
-                <div v-if="type == 'storage'">
+                @can("计费模型-仓储-录入")<div v-if="type == 'storage'">
                     @include("customer.project.part._storage")
-                </div>
-                <div v-show="type == 'operation'">
+                </div>@endcan
+                @can("计费模型-作业-录入")<div v-show="type == 'operation'">
                     @include("customer.project.part._operation")
                     @include("customer.project.part._addFeature")
-                </div>
-                <div v-show="type == 'express'">
+                </div>@endcan
+                @can("计费模型-快递-录入")<div v-show="type == 'express'">
                     @include("customer.project.part._express")
-                </div>
-                <div v-show="type == 'logistic'">
+                </div>@endcan
+                @can("计费模型-物流-录入")<div v-show="type == 'logistic'">
                     @include("customer.project.part._logistic")
                     @include("customer.project.part._logisticDetail")
-                </div>
-                <div v-show="type == 'directLogistic'">
+                </div>@endcan
+                @can("计费模型-直发-录入")<div v-show="type == 'directLogistic'">
                     @include("customer.project.part._directLogistic")
-                </div>
+                </div>@endcan
                 @include("customer.project.part._introducePriceModel")
                 <div class="row mt-3" v-if="base=='three'">
                     <div class="col-2"></div>

+ 1 - 0
routes/web.php

@@ -681,6 +681,7 @@ Route::group(['prefix'=>'customer'],function(){
         Route::post('getOwnerPriceModel','CustomerController@getOwnerPriceModel');
         Route::post('updateArea','CustomerController@updateArea');
         Route::post('verify','CustomerController@verifyProject');
+        Route::post('areaReportAudit','CustomerController@areaReportAudit');
 
         //获取现有计费模型
         Route::post('getPriceModel','PriceModelController@getPriceModel');