|
@@ -5,6 +5,7 @@ namespace App\Service;
|
|
use App\Model\BasicType;
|
|
use App\Model\BasicType;
|
|
use App\Model\Customer;
|
|
use App\Model\Customer;
|
|
use App\Model\CustomerInfo;
|
|
use App\Model\CustomerInfo;
|
|
|
|
+use App\Model\CustomerRepeat;
|
|
use App\Model\Depart;
|
|
use App\Model\Depart;
|
|
use App\Model\Employee;
|
|
use App\Model\Employee;
|
|
use App\Model\FollowUpRecord;
|
|
use App\Model\FollowUpRecord;
|
|
@@ -767,6 +768,122 @@ class CustomerService extends Service
|
|
return [true, $list];
|
|
return [true, $list];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 客户重复
|
|
|
|
+ * @param $data
|
|
|
|
+ * @param $user
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function customerRepeatList($data,$user){
|
|
|
|
+ $model = $this->customerRepeatCommonSearch($data,$user);
|
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
|
+ $list = $this->fillRepeatData($list,$data, $user);
|
|
|
|
+
|
|
|
|
+ return [true, $list];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function customerRepeatCommonSearch($data,$user, $field = []){
|
|
|
|
+ if(empty($field)){
|
|
|
|
+ $field = ['title','id','model_type','customer_from','car_type','address2','crt_id','crt_time','enter_time','contact_type','contact','mark'];
|
|
|
|
+ }
|
|
|
|
+ $model = CustomerRepeat::Clear($user,$data);
|
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
|
+ ->select($field)
|
|
|
|
+ ->orderby('id', 'desc');
|
|
|
|
+
|
|
|
|
+ if(! empty($data['title_t'])) {
|
|
|
|
+ // 清理用户输入,去除前后空白并替换多个连续空格为单个空格
|
|
|
|
+ $cleanTitle = preg_replace('/\s+/', ' ', trim($data['title_t']));
|
|
|
|
+ // 构建查询时使用 TRIM 和 REPLACE 来清理数据库字段中的空白字符
|
|
|
|
+ $model->whereRaw("TRIM(REPLACE(title, ' ', '')) LIKE ?", ['%' . str_replace(' ', '', $cleanTitle) . '%'])
|
|
|
|
+ ->orWhere('consulting_product', 'LIKE', '%'.$data['title_t'].'%')
|
|
|
|
+ ->orWhere('contact', 'LIKE', '%'.$data['title_t'].'%');
|
|
|
|
+ }
|
|
|
|
+ if(! empty($data['customer_id'])){
|
|
|
|
+ $customer_id = explode(',',$data['customer_id']);
|
|
|
|
+ $model->whereIn('id', $customer_id);
|
|
|
|
+ }
|
|
|
|
+ if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
|
+ if(! empty($data['address2'])) $model->where('address2', 'LIKE', '%'.$data['address2'].'%');
|
|
|
|
+ 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['customer_intention_title'])){
|
|
|
|
+ $id = (new RangeService())->customerBasicTypeSearch($data['customer_intention_title'],[1]);
|
|
|
|
+ $model->whereIn('customer_intention', $id);
|
|
|
|
+ }
|
|
|
|
+ if(! empty($data['customer_from_title'])){
|
|
|
|
+ $id = (new RangeService())->customerBasicTypeSearch($data['customer_from_title'],[2]);
|
|
|
|
+ $model->whereIn('customer_from', $id);
|
|
|
|
+ }
|
|
|
|
+ if(! empty($data['customer_type_title'])) {
|
|
|
|
+ $id = (new RangeService())->customerBasicTypeSearch($data['customer_type_title'],[3,30,31]);
|
|
|
|
+ $model->whereIn('customer_type', $id);
|
|
|
|
+ }
|
|
|
|
+ if(! empty($data['progress_stage_title'])){
|
|
|
|
+ $id = (new RangeService())->customerBasicTypeSearch($data['progress_stage_title'],[5]);
|
|
|
|
+ $model->whereIn('progress_stage', $id);
|
|
|
|
+ }
|
|
|
|
+ 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['enter_time'][0]) && ! empty($data['enter_time'][1])) {
|
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ $model->where('enter_time','>=',$return[0]);
|
|
|
|
+ $model->where('enter_time','<=',$return[1]);
|
|
|
|
+ }
|
|
|
|
+ if(! empty($data['crt_name'])){
|
|
|
|
+ $id = (new RangeService())->crtNameSearch($data);
|
|
|
|
+ $model->whereIn('crt_id',$id);
|
|
|
|
+ }
|
|
|
|
+ if(! empty($data['fz'])){
|
|
|
|
+ $emp_id = Employee::where('del_time',0)
|
|
|
|
+ ->where('emp_name','LIKE', '%'.$data['fz'].'%')
|
|
|
|
+ ->select('id')->get()->toArray();
|
|
|
|
+ $emp_id = array_column($emp_id,'id');
|
|
|
|
+ $model->whereIn('fz_man', $emp_id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(! empty($data['contact_info'])) $model->where('contact', 'LIKE', '%'.$data['contact_info'].'%');
|
|
|
|
+
|
|
|
|
+ return $model;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 拼接数据
|
|
|
|
+ * @param $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function fillRepeatData($data,$ergs,$user){
|
|
|
|
+ if(empty($data['data'])) return $data;
|
|
|
|
+
|
|
|
|
+ $array = array_unique(array_merge_recursive(array_column($data['data'],'customer_from'),array_column($data['data'],'car_type')));
|
|
|
|
+ $basic_map = BasicType::whereIn('id',$array)
|
|
|
|
+ ->pluck('title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
|
|
|
|
+ ->pluck('emp_name','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
|
+ $data['data'][$key]['address'] = $value['address2'];
|
|
|
|
+ //客户来源
|
|
|
|
+ $data['data'][$key]['customer_from_title'] = $basic_map[$value['customer_from']] ?? '';
|
|
|
|
+// $this->isTopDispatch($user, $data['data'][$key]);
|
|
|
|
+ $data['data'][$key]['car_type_title'] = $basic_map[$value['car_type']] ?? '';
|
|
|
|
+ $data['data'][$key]['enter_time'] = $value['enter_time'] ? date('Y-m-d H:i:s',$value['enter_time']) : '';
|
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
|
|
|
|
+ $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public function getCustomerId($data,$user){
|
|
public function getCustomerId($data,$user){
|
|
$return = [];
|
|
$return = [];
|
|
if(! empty($data['my_fz'])){
|
|
if(! empty($data['my_fz'])){
|