Просмотр исходного кода

Merge branch 'zzd' of ssh://was.baoshi56.com:10022/var/git/bswas

LD 5 лет назад
Родитель
Сommit
91bf6ab474

+ 5 - 0
app/Customer.php

@@ -29,4 +29,9 @@ class Customer extends Model
     {   //子项目
         return $this->hasMany(Owner::class,"customer_id","id");
     }
+
+    public function tags()
+    {   //标签
+        return $this->belongsToMany(CustomerTag::class,"customer_tag_customer");
+    }
 }

+ 12 - 0
app/CustomerTag.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomerTag extends Model
+{
+    protected $fillable=[
+        "name","explanation"
+    ];
+}

+ 10 - 0
app/Http/Controllers/CustomerBaseController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Owner;
 use App\Services\LogService;
 use Illuminate\Http\Request;
 use Illuminate\Http\Response;
@@ -131,4 +132,13 @@ class CustomerBaseController extends Controller
             'name'=>'客户名称',
         ]);
     }
+
+    public function relatedOwner(Request $request)
+    {
+        $ids = $request->input("ids") ?? [];
+        $id = $request->input("customer_id");
+        $row = Owner::query()->whereIn("id",$ids)->update(["customer_id"=>$id]);
+        if ($row==count($ids))return ["success"=>true];
+        return ["success"=>false,"data"=>"修改错误,影响了“".$row."”个项目"];
+    }
 }

+ 4 - 0
app/Http/Controllers/CustomerLogStatusController.php

@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
 use App\CustomerLogStatus;
 use App\Services\LogService;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Validator;
 
 
@@ -17,6 +18,7 @@ class CustomerLogStatusController extends Controller
 
     public function index()
     {
+        if(!Gate::allows('客户-客户状态-查询')){ return redirect(url('denied'));  }
         $customerLogStatuses = CustomerLogStatus::query()->paginate();
         return view('customer.customerLogStatus.index', compact('customerLogStatuses'));
     }
@@ -28,6 +30,7 @@ class CustomerLogStatusController extends Controller
 
     public function save(Request $request)
     {
+        if(!Gate::allows('客户-客户状态-录入') || !Gate::allows('客户-客户状态-编辑')){ return ["success"=>false,"data"=>"无权操作"];  }
         $errors = $this->validator($request->input(),$request->input("id"))->errors();
         if (count($errors) > 0)return ["success"=>true,"data"=>["errors"=>$errors]];
         if ($request->input("id")){
@@ -57,6 +60,7 @@ class CustomerLogStatusController extends Controller
 
     public function destroy(Request $request)
     {
+        if(!Gate::allows('客户-客户状态-删除')){ return ["success"=>false,"data"=>"无权操作"];  }
         $id = $request->input("id");
         if (!$id) return ["success"=>false,"data"=>"非法参数!"];
         app("CustomerLogStatusService")->destroy($request->input("id"));

+ 60 - 0
app/Http/Controllers/CustomerTagController.php

@@ -0,0 +1,60 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\CustomerTag;
+use App\Services\LogService;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Gate;
+use Illuminate\Support\Facades\Validator;
+
+class CustomerTagController extends Controller
+{
+    public function index()
+    {
+        $tags = CustomerTag::query()->orderByDesc("id")->get();
+        return view("customer.customer.tag.index",compact("tags"));
+    }
+
+    public function save(Request $request)
+    {
+        if(!Gate::allows('客户-客户标签-编辑')){ return ["success"=>false,"data"=>"无权操作!"]; }
+        $errors = $this->validator($request->input(),$request->input("id"))->errors();
+        if (count($errors) > 0)return ["success"=>true,"data"=>["errors"=>$errors]];
+        if ($request->input("id")){
+            CustomerTag::query()->where("id",$request->input("id"))->update([
+                "name"=>$request->input("name"),
+                "explanation"=>$request->input("explanation")
+            ]);
+            LogService::log(__METHOD__,"录入客户标签",json_encode($request->input(),JSON_UNESCAPED_UNICODE));
+            return ["success"=>true];
+        }
+        $model = CustomerTag::query()->create([
+            "name"=>$request->input("name"),
+            "explanation"=>$request->input("explanation")
+        ]);
+        LogService::log(__METHOD__,"录入客户标签",$model->toJson());
+        return ["success"=>true,"data"=>$model];
+    }
+
+    public function destroy($id)
+    {
+        if(!Gate::allows('客户-客户标签-删除')){ return ["success"=>false,"data"=>"无权操作!"];  }
+        CustomerTag::destroy($id);
+        LogService::log(__METHOD__,"删除客户标签",$id);
+        return ["success"=>true];
+    }
+
+    private function validator($params, $id)
+    {
+        return Validator::make($params,[
+            "name" => ['max:50','required',$id?"unique:customer_tags,name,$id":'unique:customer_tags,name']
+        ],[
+            'required'=>':attribute 为必填项',
+            'max'=>':attribute 最大为50个字符',
+            'unique'=>':attribute 已存在',
+        ],[
+            "name" => "标签名"
+        ]);
+    }
+}

+ 1 - 1
app/Imports/UpdatePickZone.php

@@ -81,7 +81,7 @@ class UpdatePickZone implements ToCollection,WithHeadingRow
                 $errors[] = "第“" . ($index + 2) . "”行未知订单商品";
                 continue;
             }
-            $sql = "select BAS_ZONE.DESCR,INV_LOT_LOC_ID.LOCATIONID,INV_LOT_LOC_ID.LOTNUM,BAS_LOCATION.PICKZONE,(INV_LOT_LOC_ID.QTY-INV_LOT_LOC_ID.QTYALLOCATED) AS qty from INV_LOT_ATT LEFT JOIN
+            $sql = "select BAS_ZONE.DESCR,INV_LOT_LOC_ID.LOCATIONID,INV_LOT_LOC_ID.LOTNUM,BAS_LOCATION.PICKZONE,(INV_LOT_LOC_ID.QTY-INV_LOT_LOC_ID.QTYALLOCATED-QTYONHOLD-QTYRPOUT-QTYMVOUT) AS qty from INV_LOT_ATT LEFT JOIN
                         INV_LOT_LOC_ID ON INV_LOT_ATT.LOTNUM = INV_LOT_LOC_ID.LOTNUM LEFT JOIN BAS_LOCATION ON INV_LOT_LOC_ID.LOCATIONID = BAS_LOCATION.LOCATIONID
                     LEFT JOIN BAS_ZONE ON BAS_LOCATION.PICKZONE = BAS_ZONE.ZONE 
                     where INV_LOT_ATT.LOTNUM in (select LOTNUM from INV_LOT_LOC_ID where CUSTOMERID = ? AND SKU = ? GROUP BY LOTNUM)";

+ 1 - 1
app/Services/OwnerAreaReportService.php

@@ -45,7 +45,7 @@ Class OwnerAreaReportService
      *
      * @param array $params
      * @param array $values
-     * @return int
+     * @return bool
      */
     public function update(array $params, array $values):bool
     {

+ 14 - 5
database/migrations/2020_12_15_095959_add_customer_phone_address.php

@@ -7,11 +7,11 @@ use Illuminate\Support\Facades\Schema;
 class AddCustomerPhoneAddress extends Migration
 {
     protected $authorities = [
-        "客户管理-客户-客户状态",
-        "客户管理-客户-客户状态-查询",
-        "客户管理-客户-客户状态-录入",
-        "客户管理-客户-客户状态-编辑",
-        "客户管理-客户-客户状态-删除",
+        "客户-客户状态",
+        "客户-客户状态-查询",
+        "客户-客户状态-录入",
+        "客户-客户状态-编辑",
+        "客户-客户状态-删除",
     ];
     /**
      * Run the migrations.
@@ -26,6 +26,12 @@ class AddCustomerPhoneAddress extends Migration
             $table->string('phone')->nullable()->comment('联系电话');
             $table->string('remark')->nullable()->comment('公司备注');
         });
+        foreach ($this->authorities as $authority){
+            \App\Authority::query()->firstOrCreate([
+                "name"        =>  $authority,
+                "alias_name"  =>  $authority,
+            ]);
+        }
     }
 
     /**
@@ -41,5 +47,8 @@ class AddCustomerPhoneAddress extends Migration
             $table->dropColumn('phone');
             $table->dropColumn('remark');
         });
+        foreach ($this->authorities as $authority){
+            \App\Authority::query()->where("name",$authority)->where("alias_name",$authority)->delete();
+        }
     }
 }

+ 33 - 0
database/migrations/2020_12_22_143253_create_customer_tags_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCustomerTagsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('customer_tags', function (Blueprint $table) {
+            $table->id();
+            $table->string("name",50)->comment("标签名");
+            $table->string("explanation")->nullable()->comment("说明");
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('customer_tags');
+    }
+}

+ 47 - 0
database/migrations/2020_12_22_143641_create_customer_tag_customer_table.php

@@ -0,0 +1,47 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCustomerTagCustomerTable extends Migration
+{
+    protected $authorities = [
+        "客户-客户标签",
+        "客户-客户标签-查询",
+        "客户-客户标签-录入",
+        "客户-客户标签-编辑",
+        "客户-客户标签-删除",
+    ];
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('customer_tag_customer', function (Blueprint $table) {
+            $table->bigInteger("customer_id");
+            $table->bigInteger("customer_tag_id");
+        });
+        foreach ($this->authorities as $authority){
+            \App\Authority::query()->firstOrCreate([
+                "name"        =>  $authority,
+                "alias_name"  =>  $authority,
+            ]);
+        }
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('customer_tag_customer');
+        foreach ($this->authorities as $authority){
+            \App\Authority::query()->where("name",$authority)->where("alias_name",$authority)->delete();
+        }
+    }
+}

+ 31 - 7
resources/views/customer/customer/index.blade.php

@@ -345,16 +345,40 @@
                     let id = this.customers[this.index]['id'];
                     if (val.length>0){
                         let error = "";
+                        let storage = [];
                         this.owners.forEach(owner=>{
-                            val.forEach(v=>{
-                                if (v===owner.id&&(owner.customer_id && owner.customer_id!==id)){
-                                    error += owner.name+",";
-                                }
-                            });
+
+                            if (owner.customer_id){
+                                val.forEach((v,i)=>{
+                                    if (v===owner.id&&(owner.customer_id!=id)){
+                                        error += owner.name+",";
+                                        storage.push(i);
+                                    }
+                                });
+                            }
                         });
-                        if (error)error += "已绑定其他客户";
+                        if (error){
+                            window.tempTip.setIndex(1099);
+                            window.tempTip.confirm(error+"已绑定其他客户,是否取消选中",()=>{
+                                storage.forEach(s=>{
+                                    val.splice(s,1);
+                                });
+                                $("#ownerSelectpicker").selectpicker('val',val);
+                            });
+                            return;
+                        }
                     }
-                    console.log(error);
+                    let url = "{{url('customer/customer/relatedOwner')}}";
+                    let params = {ids:val,customer_id:id};
+                    window.tempTip.postBasicRequest(url,params,(res)=>{
+                        let names = [];
+                        this.owners.forEach(owner=>{
+                            if (val.indexOf(owner.id) !== -1)names.push(owner.name);
+                        });
+                        this.ownerNames[id] = names;
+                        this.$forceUpdate();
+                        return "关联成功";
+                    },true);
                 }
             },
             filters:{

+ 6 - 1
resources/views/customer/customer/menu.blade.php

@@ -9,9 +9,14 @@
             <li class="nav-item">
                 <a class="nav-link" href="{{url('customer/customer/create')}}" :class="{active:isActive('create',3)}">录入</a>
             </li> @endcan
+            @can('客户-客户状态')
             <li class="nav-item">
                 <a class="nav-link" href="{{url('customer/customer/customerLogStatus')}}" :class="{active:isActive('customerLogStatus',3)}">客户状态</a>
-            </li>
+            </li>@endcan
+            @can('客户-客户标签')
+            <li class="nav-item">
+                <a class="nav-link" href="{{url('customer/customer/customerTag')}}" :class="{active:isActive('customerTag',3)}">客户状态</a>
+            </li>@endcan
             {{$slot}}
         </ul>
     </div>

+ 28 - 0
resources/views/customer/customer/tag/_edit.blade.php

@@ -0,0 +1,28 @@
+<div class="modal fade" tabindex="-1" role="dialog" id="modal">
+    <div class="modal-dialog modal-lg modal-dialog-centered modal-dialog-scrollable">
+        <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="name">名称</label>
+                    <input class="col-7 form-control form-control-sm" :class="errors.name ? 'is-invalid' : ''" id="name" type="text" v-model="status.name">
+                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.name">
+                        <strong>@{{ errors.name[0] }}</strong>
+                    </span>
+                </div>
+                <div class="row mt-2">
+                    <label class="col-2 offset-1" for="description">说明</label>
+                    <textarea class="col-7 form-control form-control-sm" :class="errors.description ? 'is-invalid' : ''" id="description" type="text" v-model="status.description"></textarea>
+                    <span class="invalid-feedback mt-0 offset-3" role="alert" v-if="errors.description">
+                        <strong>@{{ errors.description[0] }}</strong>
+                    </span>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-success" @click="submitCustomerLogStatus()">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 73 - 0
resources/views/customer/customer/tag/index.blade.php

@@ -0,0 +1,73 @@
+@extends('layouts.app')
+@section('title')客户-客户标签@endsection
+
+@section('content')
+    <div id="nav2">
+        @component('customer.menu')@endcomponent
+        @component('customer.customer.menu')@endcomponent
+    </div>
+    <div class="container-fluid" id="container">
+        @include("customer.customer.tag._edit")
+        <div class="row pull-right">
+            @can("客户-客户标签-录入")<button class="btn btn-outline-info mb-1 mr-3" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>@endcan
+        </div>
+        <table class="table table-striped table-hover">
+            <tr>
+                <th>序号</th>
+                <th>标签名</th>
+                <th>说明</th>
+                <th>创建时间</th>
+                <th>操作</th>
+            </tr>
+            <tr v-for="(tag,i) in tags">
+                <td>@{{ i+1 }}</td>
+                <td>@{{ tag.name }}</td>
+                <td>@{{ tag.explanation }}</td>
+                <td>@{{ tag.createdAt }}</td>
+                <td>
+                    @can("客户-客户标签-编辑")<button class="btn btn-sm btn-outline-info" @click="openModal(tag)">改</button>@endcan
+                    @can("客户-客户标签-删除")<button class="btn btn-sm btn-outline-danger" @click="deleteModel(tag,i)">删</button>@endcan
+                </td>
+            </tr>
+        </table>
+    </div>
+@stop
+
+@section("lastScript")
+    <script>
+        new Vue({
+            el:"#container",
+            data:{
+                tags:[
+                    @foreach($tags as $tag)
+                    {id:"{{$tag->id}}",name:"{{$tag->name}}",explanation:"{{$tag->explanation}}",createdAt:"{{$tag->created_at}}"},
+                    @endforeach
+                ],
+                tag:{},
+            },
+            methods:{
+                openModal(tag = null){
+                    if (model) this.tag={id:tag.id,name:tag.name,explanation:tag.explanation};
+                    else this.tag={id:"",name:"",explanation:""};
+                    $("#modal").modal("show");
+                },
+            },
+            deleteModel(tag,index){
+                window.tempTip.setDuration(3000);
+                let url="{{url('customer/customer/customerTag')}}"+"/"+tag.id;
+                let msg="成功删除状态“"+tag.name+"”";
+                window.axios.delete(url).then(res=>{
+                    if (res.data.success){
+                        this.$delete(this.tags,index);
+                        window.tempTip.setDuration(2000);
+                        window.tempTip.showSuccess(msg);
+                        return;
+                    }
+                    window.tempTip.show(res.data.data);
+                }).catch(err=>{
+                    window.tempTip.show("网络错误:"+err);
+                });
+            },
+        });
+    </script>
+@stop

+ 3 - 3
resources/views/customer/customerLogStatus/index.blade.php

@@ -12,7 +12,7 @@
             <div class="card-body">
                 @include("customer.customerLogStatus._edit")
                 <div class="row pull-right">
-                    @can("客户管理-客户-客户状态-录入")<button class="btn btn-outline-info mb-1 mr-3" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>@endcan
+                    @can("客户-客户状态-录入")<button class="btn btn-outline-info mb-1 mr-3" @click="openModal()"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>@endcan
                 </div>
                 <table class="table table-striped table-bordered table-hover">
                     <tr>
@@ -30,8 +30,8 @@
                         <td>@{{ model.createdAt }}</td>
                         <td>@{{ model.updatedAt }}</td>
                         <td>
-                            @can("客户管理-客户-客户状态-编辑")<button class="btn btn-sm btn-outline-info" @click="openModal(model)">改</button>@endcan
-                            @can("客户管理-客户-客户状态-删除")<button class="btn btn-sm btn-outline-danger" @click="deleteModel(model,i)">删</button>@endcan
+                            @can("客户-客户状态-编辑")<button class="btn btn-sm btn-outline-info" @click="openModal(model)">改</button>@endcan
+                            @can("客户-客户状态-删除")<button class="btn btn-sm btn-outline-danger" @click="deleteModel(model,i)">删</button>@endcan
                         </td>
                     </tr>
                 </table>

+ 5 - 0
routes/web.php

@@ -605,10 +605,15 @@ Route::group(['prefix'=>'customer'],function(){
         Route::post('editLog', 'CustomerLogController@update');
         Route::post('getLogStatus', 'CustomerLogStatusController@get');
         Route::post('storeLog', 'CustomerLogController@store');
+        Route::post('relatedOwner', 'CustomerBaseController@relatedOwner');
         Route::group(['prefix' => 'customerLogStatus'], function () {
             Route::post('save', 'CustomerLogStatusController@save');
             Route::post('destroy', 'CustomerLogStatusController@destroy');
         });
+        Route::group(['prefix' => 'customerTag'], function () {
+            Route::post('save', 'CustomerTagController@save');
+        });
+        Route::resource('customerTag', 'CustomerTagController',['only' => ['index',"destroy"]]);
         Route::resource('customerLog', 'CustomerLogController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);
     });
     Route::group(['prefix' => 'ownerContract'], function () {