cqpCow 11 mesiacov pred
rodič
commit
64740d98e9

+ 13 - 0
app/Http/Controllers/Api/CustomerController.php

@@ -59,6 +59,19 @@ class CustomerController extends BaseController
         }
     }
 
+    public function customerList2(Request $request)
+    {
+        $service = new CustomerService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->customerList2($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     public function customerDetail(Request $request)
     {
         $service = new CustomerService();

+ 92 - 2
app/Service/CustomerService.php

@@ -500,9 +500,13 @@ class CustomerService extends Service
     public function customerList($data,$user){
         $model = Customer::Clear($user,$data);
         $model = $model->where('del_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','code')
+            ->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')
             ->orderby('id', 'desc');
 
+        if(! empty($data['my_fz']) || ! empty($data['my_xt'])){
+            $id = $this->getCustomerId($data,$user);
+            $model->whereIn('id',$id);
+        }
         if(! empty($data['pond_state'])) {
             $search_depart_id = $data['top_depart_id'] ?? 0; //顶级公司
             if(empty($search_depart_id)){
@@ -567,6 +571,93 @@ class CustomerService extends Service
         return [true, $list];
     }
 
+    public function customerList2($data,$user){
+        $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')
+            ->orderby('id', 'desc')
+            ->orderby('fp_time', 'desc');
+
+        if(! empty($data['my_fz']) || ! empty($data['my_xt'])){
+            $id = $this->getCustomerId($data,$user);
+            $model->whereIn('id',$id);
+        }
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(! empty($data['time_type'])) {
+            if($data['time_type'] == 1) {
+                $start = strtotime('today');
+                $end = strtotime('tomorrow') - 1;
+            }elseif ($data['time_type'] == 2){
+                $start = strtotime('this week',strtotime('today'));
+                $end = strtotime('this week +6 days 23:59:59', strtotime('today'));
+            }
+            if(! empty($start) && ! empty($end)) {
+                $model->where('crt_time','>=',$start);
+                $model->where('crt_time','<=',$end);
+            }
+        }
+        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['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']);
+        if(! empty($data['customer_type'])) $model->where('customer_type',$data['customer_type']);
+        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
+            $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
+            $model->where('crt_time','>=',$return[0]);
+            $model->where('crt_time','<=',$return[1]);
+        }
+        if(! empty($data['crt_name'])){
+            $id = (new RangeService())->crtNameSearch($data);
+            $model->whereIn('crt_id',$id);
+        }
+        if(! empty($data['fz'])){
+            $id = (new RangeService())->customerSearch($data);
+            $model->whereIn('id',$id);
+        }
+        if(! empty($data['last_visit_time'])){
+            $id = (new FollowUpRecordService())->getLastVisitData($data['last_visit_time']);
+            $model->whereIn('id',$id);
+        }
+        if(! empty($data['contact_info'])){
+            $customer_info = CustomerInfo::where('del_time',0)
+                ->where("type",CustomerInfo::type_one)
+                ->where('contact_info','LIKE', '%'.$data['contact_info'].'%')
+                ->select('customer_id')
+                ->get()->toArray();
+            $model->whereIn('id',array_column($customer_info,'customer_id'));
+        }
+
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$data);
+
+        return [true, $list];
+    }
+
+    public function getCustomerId($data,$user){
+        $return = [];
+        if(! empty($data['my_fz'])){
+            $info = CustomerInfo::where('del_time',0)
+                ->where('data_id',$user['id'])
+                ->where('type',CustomerInfo::type_two)
+                ->select('customer_id')
+                ->get()->toArray();
+            $return = array_unique(array_column($info,'customer_id'));
+        }
+
+        if(! empty($data['my_xt'])){
+            $info = CustomerInfo::where('del_time',0)
+                ->where('data_id',$user['id'])
+                ->where('type',CustomerInfo::type_three)
+                ->select('customer_id')
+                ->get()->toArray();
+            $return = array_unique(array_column($info,'customer_id'));
+        }
+
+        return $return;
+    }
+
     /**
      * 客户参数规则
      * @param $data
@@ -690,7 +781,6 @@ class CustomerService extends Service
             }
         }
 
-
         $customer_info = CustomerInfo::where('del_time',0)
             ->whereIn('customer_id',array_column($data['data'],'id'))
             ->whereIn('type',[CustomerInfo::type_one,CustomerInfo::type_two])

+ 25 - 1
app/Service/DeleteService.php

@@ -132,6 +132,14 @@ class DeleteService extends Service
         $time = time();
         if(! empty($data['man'])){
             $insert = [];
+
+            //协同人
+            $bool = CustomerInfo::where('del_time',0)
+                ->where('type',CustomerInfo::type_three)
+                ->where('data_id','>',0)
+                ->exists();
+
+            //负责人
             foreach ($data['man'] as $value){
                 if(! is_array($data['id'])){
                     $insert[] = [
@@ -140,6 +148,14 @@ class DeleteService extends Service
                         'type' => CustomerInfo::type_two,
                         'crt_time' => $time,
                     ];
+                    if(! $bool){
+                        $insert[] = [
+                            'customer_id' => $data['id'],
+                            'data_id' => $user['id'],
+                            'type' => CustomerInfo::type_three,
+                            'crt_time' => $time,
+                        ];
+                    }
                 }else{
                     foreach ($data['id'] as $data_id){
                         $insert[] = [
@@ -148,9 +164,18 @@ class DeleteService extends Service
                             'type' => CustomerInfo::type_two,
                             'crt_time' => $time,
                         ];
+                        if(! $bool){
+                            $insert[] = [
+                                'customer_id' =>$data_id,
+                                'data_id' => $user['id'],
+                                'type' => CustomerInfo::type_three,
+                                'crt_time' => $time,
+                            ];
+                        }
                     }
                 }
             }
+
             CustomerInfo::insert($insert);
 
             if(! is_array($data['id'])){
@@ -174,7 +199,6 @@ class DeleteService extends Service
                 Customer::whereIn('id',$data['id'])->update(['fp_time' => $time]);
             }
 
-
 //            foreach ($data['man'] as $value){
 //                $tmp_data = [
 //                    "测试",

+ 1 - 0
routes/api.php

@@ -118,6 +118,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     //客户
     $route->any('customerList', 'Api\CustomerController@customerList');
+    $route->any('customerCapitalList', 'Api\CustomerController@customerList2');
     $route->any('customerEdit', 'Api\CustomerController@customerEdit');
     $route->any('customerAdd', 'Api\CustomerController@customerAdd');
     $route->any('customerDel', 'Api\CustomerController@customerDel');

+ 1 - 0
routes/wx.php

@@ -67,6 +67,7 @@ Route::group(['middleware'=> ['checkWx']],function ($route){
     $route->any('productList', 'Api\ProductController@productList');
     $route->any('supplierList', 'Api\SupplierController@customerList');
     $route->any('customerList', 'Api\CustomerController@customerList');
+    $route->any('customerCapitalList', 'Api\CustomerController@customerList2');
     $route->any('sportsBagOrderList', 'Api\SportsBagController@orderList');
     $route->any('productAdd', 'Api\ProductController@productAdd');
     $route->any('productCategoryList', 'Api\ProductController@productCategoryList');