|
@@ -9,6 +9,7 @@ use App\Model\BasicType;
|
|
|
use App\Model\BasicTypeAllUse;
|
|
|
use App\Model\Customer;
|
|
|
use App\Model\CustomerInfo;
|
|
|
+use App\Model\CustomerRemain;
|
|
|
use App\Model\CustomerRepeat;
|
|
|
use App\Model\Depart;
|
|
|
use App\Model\Employee;
|
|
@@ -313,7 +314,7 @@ class ImportService extends Service
|
|
|
//第一次表格数据校验 非空 已经过滤数据
|
|
|
list($status, $msg) = $this->customerFilterFirst($array, $time);
|
|
|
if(! $status) return [0, $msg];
|
|
|
- $contact_info = $msg;
|
|
|
+ list($contact_info, $fz, $fp) = $msg;
|
|
|
|
|
|
if(empty($array)) return [false, '导入数据不能为空'];
|
|
|
|
|
@@ -358,9 +359,25 @@ class ImportService extends Service
|
|
|
->pluck('id','title')
|
|
|
->toArray();
|
|
|
|
|
|
- $emp = Employee::where('del_time',0)
|
|
|
- ->whereIn('number',array_unique(array_column($array,'13')))
|
|
|
- ->pluck('id','number')
|
|
|
+ $empList = Employee::where('del_time',0)
|
|
|
+ ->when(! empty($fz), function($query) use($fz) {
|
|
|
+ return $query->where(function ($q) use ($fz) {
|
|
|
+ $q->whereIn('emp_name', $fz)
|
|
|
+ ->orWhereIn("number", $fz);
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->select('id','number','emp_name as name')
|
|
|
+ ->get()->toArray();
|
|
|
+ $emp_map = $emp_map1 = [];
|
|
|
+ foreach ($empList as $value){
|
|
|
+ $emp_map[$value['name']][] = $value['id'];
|
|
|
+ $emp_map1[$value['number']] = $value['id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $depart = Depart::where('del_time',0)
|
|
|
+ ->where('parent_id', 0)
|
|
|
+ ->whereIn('title', $fp)
|
|
|
+ ->pluck('title','id')
|
|
|
->toArray();
|
|
|
|
|
|
$top_depart_id = $user['depart_top'][0] ?? [];
|
|
@@ -374,9 +391,9 @@ class ImportService extends Service
|
|
|
->select('a.contact_info')->get()->toArray();
|
|
|
$contact_info_array = array_column($contact_info_array,'contact_info');
|
|
|
|
|
|
- list($status, $msg) = $this->customerFilterSecond($array,$time,$head,$user,$contact_info_array,$customer,$basic_list,$emp,$basic_use);
|
|
|
+ list($status, $msg) = $this->customerFilterSecond($array,$time,$head,$user,$contact_info_array,$customer,$basic_list,$emp_map,$emp_map1,$basic_use,$depart);
|
|
|
if(! $status) return [0, $msg];
|
|
|
- list($insert, $insert_detail, $insert_detail2) = $msg;
|
|
|
+ list($insert, $insert_detail, $insert_detail2,$insert_detail3) = $msg;
|
|
|
|
|
|
try{
|
|
|
DB::beginTransaction();
|
|
@@ -404,9 +421,15 @@ class ImportService extends Service
|
|
|
$value['customer_id'] = $last_insert_id[$key];
|
|
|
$insert_detail_2[] = $value;
|
|
|
}unset($insert_detail2);
|
|
|
+ $insert_detail_3 = [];
|
|
|
+ foreach ($insert_detail3 as $key => $value){
|
|
|
+ $value['customer_id'] = $last_insert_id[$key];
|
|
|
+ $insert_detail_3[] = $value;
|
|
|
+ }unset($insert_detail3);
|
|
|
|
|
|
if(! empty($insert_detail_1)) CustomerInfo::insert($insert_detail_1);
|
|
|
if(! empty($insert_detail_2)) CustomerInfo::insert($insert_detail_2);
|
|
|
+ if(! empty($insert_detail_3)) CustomerRemain::insert($insert_detail_3);
|
|
|
|
|
|
DB::commit();
|
|
|
}catch (\Exception $e){
|
|
@@ -418,7 +441,7 @@ class ImportService extends Service
|
|
|
}
|
|
|
|
|
|
function customerFilterFirst(&$array, $time){
|
|
|
- $array_clean = $contact_info = [];
|
|
|
+ $array_clean = $contact_info = $fz = $fp =[];
|
|
|
|
|
|
$error = [];
|
|
|
foreach ($array as $key => $value){
|
|
@@ -458,6 +481,12 @@ class ImportService extends Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(empty($value[13])) {
|
|
|
+ $error[] = $line . '负责人名或负责人工号必须填写';
|
|
|
+ }else{
|
|
|
+ if(! in_array($value[13], $fz)) $fz[] = $value[13];
|
|
|
+ }
|
|
|
+
|
|
|
if(! empty($value[14])){
|
|
|
list($status, $msg) = $this->convertExcelCellToDate($value[14]);
|
|
|
if(! $status) {
|
|
@@ -469,6 +498,12 @@ class ImportService extends Service
|
|
|
$value[14] = $time;
|
|
|
}
|
|
|
|
|
|
+ if(empty($value[15])) {
|
|
|
+ $error[] = $line . '分配门店必须填写';
|
|
|
+ }else{
|
|
|
+ if(! in_array($value[15], $fp)) $fp[] = $value[15];
|
|
|
+ }
|
|
|
+
|
|
|
$array[$key] = $value;
|
|
|
}
|
|
|
}unset($array_clean);
|
|
@@ -478,11 +513,11 @@ class ImportService extends Service
|
|
|
return [false, $error];
|
|
|
}
|
|
|
|
|
|
- return [true, $contact_info];
|
|
|
+ return [true, [$contact_info, $fz, $fp]];
|
|
|
}
|
|
|
|
|
|
- function customerFilterSecond($array, $time, $head, $user, $contact_info_array,$customer,$basic_list,$emp,$basic_use){
|
|
|
- $error = $insert = $insert_detail = $insert_detail2 = $repeat_array = [];
|
|
|
+ function customerFilterSecond($array, $time, $head, $user, $contact_info_array,$customer,$basic_list,$emp_name,$emp_number,$basic_use,$depart){
|
|
|
+ $error = $insert = $insert_detail = $insert_detail2 = $insert_detail3 = $repeat_array = [];
|
|
|
foreach ($array as $key => $value){
|
|
|
$line = '第' . $key . '行';
|
|
|
$tmp = [
|
|
@@ -587,12 +622,26 @@ class ImportService extends Service
|
|
|
$error[] = $line . '联系方式内容:' . $value['12'] . '已存在';
|
|
|
}
|
|
|
$man = 0;
|
|
|
- if($value['13']){
|
|
|
- if(empty($emp[$value['13']])) {
|
|
|
- $error[] = $line . '负责人:' . $value['13'] . '不存在';
|
|
|
+ if(! empty($emp_name[$value['13']])){
|
|
|
+ $name = $emp_name[$value['13']];
|
|
|
+ if(count($name) > 1) {
|
|
|
+ $error[] = $line . '负责人名:' . $value['13'] . '在系统中多次出现,请填写工号精准定位负责人';
|
|
|
}else{
|
|
|
- $man = $emp[$value['13']];
|
|
|
+ $man = $name[0];
|
|
|
}
|
|
|
+ }else{
|
|
|
+ if(! empty($emp_number[$value['13']])){
|
|
|
+ $man = $emp_number[$value['13']];
|
|
|
+ }else{
|
|
|
+ $error[] = $line . '负责人工号:' . $value['13'] . '不存在';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $fp = 0;
|
|
|
+ if(empty($depart[$value['15']])) {
|
|
|
+ $error[] = $line . '分配门店:' . $value['15'] . '不存在';
|
|
|
+ }else{
|
|
|
+ $fp = $depart[$value['15']];
|
|
|
}
|
|
|
|
|
|
$insert[] = $tmp;
|
|
@@ -609,6 +658,12 @@ class ImportService extends Service
|
|
|
'crt_time' => $time,
|
|
|
'type' => CustomerInfo::type_two
|
|
|
];
|
|
|
+ $insert_detail3[] = [
|
|
|
+ 'customer_id' => 0,
|
|
|
+ 'fp' => $fp,
|
|
|
+ 'fz' => $man,
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
if($repeat){
|
|
|
$tmp['contact_type'] = $contact_id;
|
|
|
$tmp['contact'] = $value['12'];
|
|
@@ -625,7 +680,7 @@ class ImportService extends Service
|
|
|
return [false, $error];
|
|
|
}
|
|
|
|
|
|
- return [true, [$insert, $insert_detail, $insert_detail2]];
|
|
|
+ return [true, [$insert, $insert_detail, $insert_detail2, $insert_detail3]];
|
|
|
}
|
|
|
|
|
|
function convertExcelCellToDate($cellValue) {
|