Explorar o código

通用基础规则增加
客户增加咨询产品

cqp hai 3 meses
pai
achega
8726a4e8bd

+ 52 - 0
app/Http/Controllers/Api/BasicTypeController.php

@@ -71,4 +71,56 @@ class BasicTypeController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function basicTypeAllUseAdd(Request $request)
+    {
+        $service = new BasicTypeService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->basicTypeAllUseAdd($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function basicTypeAllUseEdit(Request $request)
+    {
+        $service = new BasicTypeService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->basicTypeAllUseEdit($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function basicTypeAllUseDel(Request $request)
+    {
+        $service = new BasicTypeService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->basicTypeAllUseDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function basicTypeAllUseList(Request $request)
+    {
+        $service = new BasicTypeService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->basicTypeList($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 18 - 0
app/Model/BasicTypeAllUse.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BasicTypeAllUse extends Model
+{
+    protected $table = "basic_type_all_use"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    const type_one = 1;
+    public static $type = [
+        self::type_one => "咨询客户",
+    ];
+}

+ 113 - 0
app/Service/BasicTypeService.php

@@ -3,6 +3,7 @@
 namespace App\Service;
 
 use App\Model\BasicType;
+use App\Model\BasicTypeAllUse;
 use App\Model\Depart;
 use Illuminate\Support\Facades\DB;
 
@@ -263,4 +264,116 @@ class BasicTypeService extends Service
         if(! empty($insert)) BasicType::insert($insert);
         dd('ok');
     }
+
+    public function basicTypeAllUseEdit($data, $user){
+        list($status,$msg) = $this->basicTypeAllUseRule($data,$user,false);
+        if(!$status) return [$status,$msg];
+
+        $update = $msg['data'][0];
+        BasicTypeAllUse::where('id',$data['id'])->update($update);
+
+        return [true,''];
+    }
+
+    public function basicTypeAllUseAdd($data,$user){
+        list($status,$msg) = $this->basicTypeRule($data, $user);
+        if(!$status) return [$status,$msg];
+
+        BasicTypeAllUse::insert($msg['data']);
+
+        return [true,''];
+    }
+
+    public function basicTypeAllUseDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        BasicTypeAllUse::whereIn('id',$data['id'])->update([
+            'del_time'=>time()
+        ]);
+
+        return [true,''];
+    }
+
+    public function basicTypeAllUseList($data, $user){
+        $model = BasicTypeAllUse::where('del_time',0)
+            ->select('title','id','type')
+            ->orderby('id', 'asc');
+
+        if(! empty($data['type'])) $model->where('type',$data['type']);
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillAllUseData($list);
+
+        return [true, $list];
+    }
+
+    public function fillAllUseData($data){
+        if(empty($data['data'])) return $data;
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['type_name'] = BasicTypeAllUse::$type[$value['type']] ?? '';
+        }
+
+        return $data;
+    }
+
+    public function basicTypeAllUseRule($data,$user, $is_check = true){
+        if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
+
+        $type = array_column($data['data'],'type');
+        $type = array_map(function($val) {
+            return $val !== null ? $val : 0;
+        }, $type);
+        foreach ($type as $value){
+            if(empty($value)) return [false,'类型不能为空!'];
+            if(! isset(BasicTypeAllUse::$type[$value])) return [false,'类型不存在!'];
+        }
+
+        $map = [];
+        foreach ($data['data'] as $value){
+            if(! isset($map[$value['title']])){
+                $map[$value['title']][] = $value['type'];
+            }else{
+                if(! in_array($value['type'],$map[$value['title']])){
+                    $map[$value['title']][] = $value['type'];
+                }
+            }
+        }
+
+        $title = array_column($data['data'],'title');
+        $title = array_map(function($val) {
+            return $val !== null ? $val : 0;
+        }, $title);
+        $title_count = array_count_values($title);
+        foreach ($title as $value){
+            if(empty($value)) return [false,'名称不能为空!'];
+            if($title_count[$value] > 1 && count($map[$value]) != $title_count[$value]) return [false,'同一归属类别下,名称不能重复'];
+        }
+
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['type'] = $value['type'];
+            $data['data'][$key]['upd_time'] = time();
+            if($is_check){
+                $bool = BasicTypeAllUse::where('title',$value['title'])
+                    ->where('type',$value['type'])
+                    ->where('del_time',0)
+                    ->exists();
+                $data['data'][$key]['crt_time'] = time();
+                $data['data'][$key]['crt_id'] = $user['id'];
+                $data['data'][$key]['depart_id'] = $data['depart_id'];
+                $data['data'][$key]['top_depart_id'] = $data['top_depart_id'];
+            }else{
+                if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
+                $bool = BasicTypeAllUse::where('title',$value['title'])
+                    ->where('type',$value['type'])
+                    ->where('id','<>',$data['id'])
+                    ->where('del_time',0)
+                    ->exists();
+            }
+            if($bool) return [false,'名称不能重复'];
+        }
+
+        return [true, $data];
+    }
 }

+ 18 - 2
app/Service/CustomerService.php

@@ -3,6 +3,7 @@
 namespace App\Service;
 
 use App\Model\BasicType;
+use App\Model\BasicTypeAllUse;
 use App\Model\Customer;
 use App\Model\CustomerInfo;
 use App\Model\CustomerRepeat;
@@ -60,6 +61,7 @@ class CustomerService extends Service
             $model->customer_type = $data['customer_type'] ?? 0;
             $model->car_type = $data['car_type'] ?? 0;
             $model->consulting_product = $data['consulting_product'] ?? '';
+            $model->consulting_product_new = $data['consulting_product_new'] ?? 0;
             $model->intention_product = $data['intention_product'] ?? 0;
             $model->progress_stage = $data['progress_stage'] ?? 0;
             $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
@@ -224,6 +226,7 @@ class CustomerService extends Service
             $model->customer_type = $data['customer_type'] ?? 0;
             $model->car_type = $data['car_type'] ?? 0;
             $model->consulting_product = $data['consulting_product'] ?? '';
+            $model->consulting_product_new = $data['consulting_product_new'] ?? 0;
             $model->intention_product = $data['intention_product'] ?? 0;
             $model->progress_stage = $data['progress_stage'] ?? 0;
             $model->address1 = ! empty($data['address1']) ? json_encode($data['address1']) : '';
@@ -398,6 +401,9 @@ class CustomerService extends Service
         $customer['is_belong_to_main'] = $is_main;
         $customer['order_number'] = Customer::$order_number . "|" . $data['id'] . "|" . $customer['title'];
         $customer['intention_product_title'] = Product::where('id',$customer['intention_product'])->value('title') ?? "";
+        $customer['consulting_product_new_title'] = BasicTypeAllUse::where('id',$customer['consulting_product_new'])
+                ->where('type', BasicTypeAllUse::type_one)
+                ->value('title') ?? "";
         $customer['product_category'] = [];
         if(! empty($customer['intention_product'])){
             $pro = (new ProductService())->getProductDetail([$customer['intention_product']]);
@@ -525,7 +531,7 @@ class CustomerService extends Service
 
     public function customerCommonSearch($data,$user, $field = []){
         if(empty($field)){
-            $field = ['title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time'];
+            $field = ['title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','consulting_product_new','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time'];
         }
         $model = Customer::Clear($user,$data);
         $model = $model->where('del_time',0)
@@ -579,6 +585,7 @@ class CustomerService extends Service
         }
         if(! empty($data['model_type'])) $model->where('model_type',$data['model_type']);
         if(! empty($data['consulting_product'])) $model->where('consulting_product','LIKE', '%'.$data['consulting_product'].'%');
+        if(! empty($data['consulting_product_new'])) $model->where('consulting_product_new',$data['consulting_product_new']);
         if(! empty($data['mark'])) $model->where('mark','LIKE', '%'.$data['mark'].'%');
         if(! empty($data['customer_intention'])) $model->where('customer_intention',$data['customer_intention']);
         if(! empty($data['customer_from'])) $model->where('customer_from',$data['customer_from']);
@@ -587,6 +594,10 @@ class CustomerService extends Service
             $id = (new RangeService())->customerBasicTypeSearch($data['customer_intention_title'],[1]);
             $model->whereIn('customer_intention', $id);
         }
+        if(! empty($data['consulting_product_new_title'])) {
+            $id = (new RangeService())->customerBasicTypeAllUseSearch($data['customer_from_title'],[BasicTypeAllUse::type_one]);
+            $model->whereIn('consulting_product_new', $id);
+        }
         if(! empty($data['customer_from_title'])){
             $id = (new RangeService())->customerBasicTypeSearch($data['customer_from_title'],[2]);
             $model->whereIn('customer_from', $id);
@@ -709,7 +720,7 @@ class CustomerService extends Service
         $model = Customer::Clear($user,$data);
         $model = $model->where('del_time',0)
             ->where('fp_time','>',0)
-            ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time')
+            ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','consulting_product_new','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time')
             ->orderby('fp_time', 'desc');
 
         if(! empty($data['customer_id'])){
@@ -1045,6 +1056,10 @@ class CustomerService extends Service
         $basic_map = BasicType::whereIn('id',$array)
             ->pluck('title','id')
             ->toArray();
+        $basic_all_map = BasicTypeAllUse::where('type', BasicTypeAllUse::type_one)
+            ->whereIn('id',array_unique(array_column($data['data'],'consulting_product_new')))
+            ->pluck('title','id')
+            ->toArray();
         $depart_title = Depart::where('id',array_unique(array_column($data['data'],'depart_id')))
             ->pluck('title','id')
             ->toArray();
@@ -1130,6 +1145,7 @@ class CustomerService extends Service
             $data['data'][$key]['customer_type_title'] = $basic_map[$value['customer_type']] ?? '';
             $data['data'][$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
             $data['data'][$key]['intention_product_title'] = $product[$value['intention_product']] ?? '';
+            $data['data'][$key]['consulting_product_new_title'] = $basic_all_map[$value['consulting_product_new']] ?? '';
             $data['data'][$key]['progress_stage_title'] = $basic_map[$value['progress_stage']] ?? '';
             $data['data'][$key]['state_type_title'] = $basic_map[$value['state_type']] ?? '';
             $data['data'][$key]['customer_state_title'] = $basic_map[$value['customer_state']] ?? '';

+ 1 - 1
app/Service/ExportFileService.php

@@ -1381,7 +1381,7 @@ class ExportFileService extends Service
 
         DB::table('customer')
             ->whereIn('id', $id)
-            ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time')
+            ->select('title','id','model_type','customer_intention','customer_from','customer_type','car_type','consulting_product','intention_product','consulting_product_new','progress_stage','address1','address2','crt_id','crt_time','mark','importance','company','company_short_name','depart_id','state_type','customer_state','pond_state','top_depart_id','fp_time','fp_top_depart_id','enter_time')
             ->orderBy('id','desc')
             ->chunk(200,function ($data) use(&$return,$user,$ergs){
                 $data = Collect($data)->map(function ($object) {

+ 9 - 0
app/Service/RangeService.php

@@ -3,6 +3,7 @@
 namespace App\Service;
 
 use App\Model\BasicType;
+use App\Model\BasicTypeAllUse;
 use App\Model\Construction;
 use App\Model\ConstructionInfo;
 use App\Model\Customer;
@@ -637,6 +638,14 @@ class RangeService extends Service
         return array_column($result,'id');
     }
 
+    public function customerBasicTypeAllUseSearch($customer_type, $type){
+        $result = BasicTypeAllUse::where('del_time',0)
+            ->whereIn('type',$type)
+            ->where('title', $customer_type)
+            ->select('id')->get()->toArray();
+        return array_column($result,'id');
+    }
+
     //全部 待审 已审核 -----------------------------------------------
     public static function sportsBagCheck($user,$search){
         $args = "";

+ 6 - 0
routes/api.php

@@ -121,6 +121,12 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('basicTypeDel', 'Api\BasicTypeController@basicTypeDel');
     $route->any('basicTypeCustomerList', 'Api\BasicTypeController@basicTypeCustomerList');
 
+    //通用基础类型
+    $route->any('basicTypeUseList', 'Api\BasicTypeController@basicTypeUseList');
+    $route->any('basicTypeUseEdit', 'Api\BasicTypeController@basicTypeUseEdit');
+    $route->any('basicTypeUseAdd', 'Api\BasicTypeController@basicTypeUseAdd');
+    $route->any('basicTypeUseDel', 'Api\BasicTypeController@basicTypeUseDel');
+
     //跟进记录
     $route->any('followUpRecordList', 'Api\FollowUpRecordController@followUpRecordList');
     $route->any('followUpRecordEdit', 'Api\FollowUpRecordController@followUpRecordEdit')->middleware('OssFileDeal');