|
@@ -75,7 +75,7 @@ class CustomerService extends Service
|
|
|
foreach ($data['employee_one'] as $value){
|
|
|
$insert[] = [
|
|
|
'customer_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
+ 'data_id' => $value,
|
|
|
'type' => CustomerInfo::type_two,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
@@ -88,7 +88,7 @@ class CustomerService extends Service
|
|
|
foreach ($data['employee_two'] as $value){
|
|
|
$insert[] = [
|
|
|
'customer_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
+ 'data_id' => $value,
|
|
|
'type' => CustomerInfo::type_three,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
@@ -101,7 +101,7 @@ class CustomerService extends Service
|
|
|
foreach ($data['employee_three'] as $value){
|
|
|
$insert[] = [
|
|
|
'customer_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
+ 'data_id' => $value,
|
|
|
'type' => CustomerInfo::type_four,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
@@ -137,6 +137,32 @@ class CustomerService extends Service
|
|
|
CustomerInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
+ if(! empty($data['employee'])){
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['employee'] as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'customer_id' => $model->id,
|
|
|
+ 'data_id' => $value,
|
|
|
+ 'type' => CustomerInfo::type_eight,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ CustomerInfo::insert($insert);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($data['depart'])){
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['depart'] as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'customer_id' => $model->id,
|
|
|
+ 'data_id' => $value,
|
|
|
+ 'type' => CustomerInfo::type_seven,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ CustomerInfo::insert($insert);
|
|
|
+ }
|
|
|
+
|
|
|
DB::commit();
|
|
|
}catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
@@ -203,7 +229,7 @@ class CustomerService extends Service
|
|
|
foreach ($data['employee_one'] as $value){
|
|
|
$insert[] = [
|
|
|
'customer_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
+ 'data_id' => $value,
|
|
|
'type' => CustomerInfo::type_two,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
@@ -216,7 +242,7 @@ class CustomerService extends Service
|
|
|
foreach ($data['employee_two'] as $value){
|
|
|
$insert[] = [
|
|
|
'customer_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
+ 'data_id' => $value,
|
|
|
'type' => CustomerInfo::type_three,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
@@ -229,7 +255,7 @@ class CustomerService extends Service
|
|
|
foreach ($data['employee_three'] as $value){
|
|
|
$insert[] = [
|
|
|
'customer_id' => $model->id,
|
|
|
- 'employee_id' => $value,
|
|
|
+ 'data_id' => $value,
|
|
|
'type' => CustomerInfo::type_four,
|
|
|
'crt_time' => $time,
|
|
|
];
|
|
@@ -265,6 +291,32 @@ class CustomerService extends Service
|
|
|
CustomerInfo::insert($insert);
|
|
|
}
|
|
|
|
|
|
+ if(! empty($data['employee'])){
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['employee'] as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'customer_id' => $model->id,
|
|
|
+ 'data_id' => $value,
|
|
|
+ 'type' => CustomerInfo::type_eight,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ CustomerInfo::insert($insert);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($data['depart'])){
|
|
|
+ $insert = [];
|
|
|
+ foreach ($data['depart'] as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'customer_id' => $model->id,
|
|
|
+ 'data_id' => $value,
|
|
|
+ 'type' => CustomerInfo::type_seven,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ CustomerInfo::insert($insert);
|
|
|
+ }
|
|
|
+
|
|
|
DB::commit();
|
|
|
}catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
@@ -325,7 +377,7 @@ class CustomerService extends Service
|
|
|
$address = $tmp;
|
|
|
}
|
|
|
$customer['address'] = $address;
|
|
|
- $customer['customer_contact'] = $customer['employee_one'] = $customer['employee_two'] = $customer['employee_three'] = $customer['img'] = $customer['file'] = [];
|
|
|
+ $customer['customer_contact'] = $customer['employee_one'] = $customer['employee_two'] = $customer['employee_three'] = $customer['img'] = $customer['file'] = $customer['employee'] = $customer['depart'] = [];
|
|
|
$array = [
|
|
|
$customer['customer_intention'],
|
|
|
$customer['customer_from'],
|
|
@@ -356,14 +408,29 @@ class CustomerService extends Service
|
|
|
|
|
|
$customer_info = CustomerInfo::where('del_time',0)
|
|
|
->where('customer_id',$customer['id'])
|
|
|
- ->select('id','customer_id','contact_type','contact_info','employee_id','file','type','name')
|
|
|
+ ->select('id','customer_id','contact_type','contact_info','data_id','file','type','name')
|
|
|
->get()->toArray();
|
|
|
- $emp_map = Employee::whereIn('id',array_unique(array_merge_recursive([$customer['crt_id']],array_column($customer_info,'employee_id'))))
|
|
|
+ $emp_id = [];
|
|
|
+ $emp_id[] = $customer['crt_id'];
|
|
|
+ $depart = [];
|
|
|
+ foreach ($customer_info as $value){
|
|
|
+ if(in_array($value['type'], CustomerInfo::$man)){
|
|
|
+ $emp_id[] = $value['data_id'];
|
|
|
+ }else{
|
|
|
+ if($value['type'] == CustomerInfo::type_seven){
|
|
|
+ $depart[] = $value['data_id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $emp_map = Employee::whereIn('id',array_unique($emp_id))
|
|
|
->pluck('emp_name','id')
|
|
|
->toArray();
|
|
|
$basic_map2 = BasicType::whereIn('id',array_unique(array_column($customer_info,'contact_type')))
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
+ $depart_map = Depart::whereIn('id',array_unique($depart))
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
foreach ($customer_info as $value){
|
|
|
if($value['type'] == CustomerInfo::type_one){
|
|
|
$tmp = [
|
|
@@ -402,6 +469,18 @@ class CustomerService extends Service
|
|
|
'name' => $value['name'],
|
|
|
];
|
|
|
$customer['file'][] = $tmp;
|
|
|
+ }elseif ($value['type'] == CustomerInfo::type_seven){
|
|
|
+ $tmp = [
|
|
|
+ 'id' => $value['depart_id'],
|
|
|
+ 'name' => $depart_map[$value['depart_id']],
|
|
|
+ ];
|
|
|
+ $customer['depart'][] = $tmp;
|
|
|
+ }elseif ($value['type'] == CustomerInfo::type_eight){
|
|
|
+ $tmp = [
|
|
|
+ 'id' => $value['employee_id'],
|
|
|
+ 'name' => $emp_map[$value['employee_id']] ?? '',
|
|
|
+ ];
|
|
|
+ $customer['employee'][] = $tmp;
|
|
|
}
|
|
|
}
|
|
|
$customer['crt_name'] = $emp_map[$customer['crt_id']] ?? '';
|
|
@@ -417,22 +496,31 @@ class CustomerService extends Service
|
|
|
* @return array
|
|
|
*/
|
|
|
public function customerList($data,$user){
|
|
|
- $model = new Customer(['userData' => $user]);
|
|
|
+ $model = new Customer(['userData' => $user,'search'=> $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','customer_grade','pond_state')
|
|
|
->orderby('id', 'desc');
|
|
|
|
|
|
- //getALL传入后无视设置范围
|
|
|
- if(empty($data['getAll']) && $user['id'] != Employee::SPECIAL_ADMIN) {
|
|
|
- // 销售人员/负责人 3协同人 可以看见
|
|
|
- $user_id = $user['id'];
|
|
|
- $customer_id = CustomerInfo::where('del_time',0)
|
|
|
- ->where(function ($query) use($user_id) {
|
|
|
- $query->where('employee_id',$user_id);
|
|
|
- })->select('customer_id')->get()
|
|
|
- ->toArray();
|
|
|
- $emp_id = array_unique(array_column($customer_id,'customer_id'));
|
|
|
- $model->WhereIn('id', $emp_id);
|
|
|
+ if(empty($data['pond_state'])) { // 未进入公海池的
|
|
|
+ //getALL传入后无视设置范围
|
|
|
+ if(empty($data['getAll']) && $user['id'] != Employee::SPECIAL_ADMIN) {
|
|
|
+ $user_id = $user['id'];
|
|
|
+ $depart_id = $user['depart_range'];
|
|
|
+ $type = implode(',',CustomerInfo::$man);
|
|
|
+ $type2 = CustomerInfo::type_eight;
|
|
|
+ $depart_str = implode(',',$depart_id);
|
|
|
+ $str = "(data_id = $user_id AND type IN({$type})) OR (data_id IN({$depart_str}) AND type = {$type2})";
|
|
|
+
|
|
|
+ // 销售人员/负责人 3协同人 可见部门 可见人 可以看见
|
|
|
+ $customer_id = CustomerInfo::where('del_time',0)
|
|
|
+ ->where(function ($query) use($str) {
|
|
|
+ $query->whereRaw($str);
|
|
|
+ })->select('customer_id')->get()->toArray();
|
|
|
+ $emp_id = array_unique(array_column($customer_id,'customer_id'));
|
|
|
+ $model->whereIn('id', $emp_id);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $model->where('pond_state', '>',0);
|
|
|
}
|
|
|
if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
if(! empty($data['time_type'])) {
|