优化客户的导入功能

This commit is contained in:
hdm 2023-04-06 14:42:54 +08:00
parent c4ff39855b
commit 2443f4b55b
5 changed files with 83 additions and 39 deletions

View File

@ -228,30 +228,54 @@ class Import extends BaseController
return to_assign(1, '数据不能为空');
exit();
}
$name_array = [];
$source_array = Db::name('CustomerSource')->where(['status' => 1])->column('title', 'id');
$grade_array = Db::name('CustomerGrade')->where(['status' => 1])->column('title', 'id');
$industry_array = Db::name('Industry')->where(['status' => 1])->column('title', 'id');
//循环读取excel表格整合成数组。如果是不指定key的二维就用$data[i][j]表示。
for ($j = 3; $j <= $highestRow; $j++) {
$file_check = [];
$name = $objPHPExcel->getActiveSheet()->getCell("A" . $j)->getValue();
if(empty($name)){
continue;
}
$count_name = Db::name('Customer')->where('name',$name)->count();
if($count_name>0){
return to_assign(1, '第'.($j - 2).'行的客户名称已经存在');
}
if(in_array($name,$name_array)){
return to_assign(1, '上传的文件存在相同的客户名称,请删除再操作');
}
array_push($name_array,$name);
$source_id = arraySearch($source_array,$objPHPExcel->getActiveSheet()->getCell("B" . $j)->getValue());
$grade_id = arraySearch($grade_array,$objPHPExcel->getActiveSheet()->getCell("C" . $j)->getValue());
$industry_id = arraySearch($industry_array,$objPHPExcel->getActiveSheet()->getCell("D" . $j)->getValue());
$industry_id = arraySearch($industry_array,$objPHPExcel->getActiveSheet()->getCell("D" . $j)->getValue());
$tax_num = $objPHPExcel->getActiveSheet()->getCell("E" . $j)->getValue();
$bank = $objPHPExcel->getActiveSheet()->getCell("F" . $j)->getValue();
$bank_sn = $objPHPExcel->getActiveSheet()->getCell("G" . $j)->getValue();
$c_name = $objPHPExcel->getActiveSheet()->getCell("E" . $j)->getValue();
$c_mobile = $objPHPExcel->getActiveSheet()->getCell("F" . $j)->getValue();
$file_check['c_mobile'] = $c_mobile;
$tax_num = $objPHPExcel->getActiveSheet()->getCell("G" . $j)->getValue();
$bank = $objPHPExcel->getActiveSheet()->getCell("H" . $j)->getValue();
$bank_sn = $objPHPExcel->getActiveSheet()->getCell("I" . $j)->getValue();
$file_check['bank_sn'] = $bank_sn;
$bank_no = $objPHPExcel->getActiveSheet()->getCell("H" . $j)->getValue();
$cperson_mobile = $objPHPExcel->getActiveSheet()->getCell("I" . $j)->getValue();
$address = $objPHPExcel->getActiveSheet()->getCell("J" . $j)->getValue();
$content = $objPHPExcel->getActiveSheet()->getCell("K" . $j)->getValue();
$market = $objPHPExcel->getActiveSheet()->getCell("L" . $j)->getValue();
$bank_no = $objPHPExcel->getActiveSheet()->getCell("K" . $j)->getValue();
$cperson_mobile = $objPHPExcel->getActiveSheet()->getCell("K" . $j)->getValue();
$address = $objPHPExcel->getActiveSheet()->getCell("L" . $j)->getValue();
$content = $objPHPExcel->getActiveSheet()->getCell("M" . $j)->getValue();
$market = $objPHPExcel->getActiveSheet()->getCell("N" . $j)->getValue();
if(empty($c_name)){
return to_assign(1, '第'.($j - 2).'行的客户联系人姓名没完善');
}
if(empty($c_mobile)){
return to_assign(1, '第'.($j - 2).'行的客户联系人手机号码没完善');
}
$validate_mobile = \think\facade\Validate::rule([
'c_mobile' => 'mobile',
]);
if (!$validate_mobile->check($file_check)) {
return to_assign(1, '第'.($j - 2).'行的客户联系人手机号码格式错误');
}
if(empty($source_id)){
return to_assign(1, '第'.($j - 2).'行的客户来源错误');
}
@ -261,17 +285,38 @@ class Import extends BaseController
if(empty($industry_id)){
return to_assign(1, '第'.($j - 2).'行的所属行业错误');
}
if(empty($tax_num)){
$tax_num='';
}
if(empty($bank)){
$bank='';
}
$validate_bank = \think\facade\Validate::rule([
'bank_sn' => 'number',
]);
if(!empty($bank_sn)){
if (!$validate_bank->check($file_check)) {
return to_assign(1, '第'.($j - 2).'行的银行卡账号'.$validate->getError());
return to_assign(1, '第'.($j - 2).'行的银行卡账号格式错误');
}
}
else{
$bank_sn='';
}
if(empty($bank_no)){
$bank_no='';
}
if(empty($cperson_mobile)){
$cperson_mobile='';
}
if(empty($address)){
$address='';
}
if(empty($content)){
$content='';
}
if(empty($market)){
$market='';
}
$data[$j - 3] = [
'name' => $name,
'source_id' => $source_id,
@ -286,17 +331,31 @@ class Import extends BaseController
'content' => $content,
'market' => $market,
'admin_id' => $this->uid,
'c_mobile' => $c_mobile,
'c_name' => $c_name,
'create_time' => time()
];
}
//dd($data);exit;
//dd($data);exit;
// 批量添加数据
if ((new Customer())->saveAll($data)) {
return to_assign(0, '导入成功');
}
else{
return to_assign(1, '导入失败请检查excel文件再试');
$count=0;
foreach ($data as $a => $aa) {
$cid = Customer::strict(false)->field(true)->insertGetId($aa);
if($cid>0){
$contact = [
'name' => $aa['c_name'],
'mobile' => $aa['c_mobile'],
'sex' => 1,
'cid' => $cid,
'is_default' => 1,
'create_time' => time(),
'admin_id' => $this->uid
];
Db::name('CustomerContact')->strict(false)->field(true)->insert($contact);
$count++;
}
}
return to_assign(0, '共成功导入了'.$count.'条客户数据');
} catch (\think\exception\ValidateException $e) {
return to_assign(1, $e->getMessage());
}

View File

@ -2,10 +2,6 @@
{block name="style"}
<style>
.left-note{font-weight:800; vertical-align:top; padding-top:28px!important; text-align:center}
.left-note .layui-form-checkbox span{background-color: #969696;}
.left-note .layui-form-checkbox:hover span{background-color: #808080;}
.left-note .layui-form-checked span, .left-note .layui-form-checked:hover span { background-color: #5fb878;}
.checkbox14 .layui-form-checkbox span{font-size:15px;font-weight:800;}
.right-note .layui-checkbox-disabled span {color: #666666!important;}
</style>

View File

@ -2,8 +2,7 @@
{block name="style"}
<style>
.left-note{font-weight:800; vertical-align:top; padding-top:28px!important; text-align:center}
.left-note .layui-form-checkbox span{background-color: #bbbbbb!important;}
.left-note .layui-form-checkbox:hover span{background-color: #808080;}
.left-note .layui-checkbox-disabled span {color: #808080!important;}
.layui-form-checked.layui-checkbox-disabled i{background-color:#ababab!important;color: #ffffff!important;border-color:#ababab!important;}
.layui-form-checked.layui-checkbox-disabled[lay-skin=primary] i{background-color:#ababab!important;}

View File

@ -23,7 +23,7 @@
<h3>企业组织架构</h3>
<div id="depament"></div>
</div>
<div class="body-table" style="margin-left:228px;">
<div class="body-table" style="margin-left:228px; overflow:hidden;">
<form class="layui-form gg-form-bar border-t border-x" lay-filter="barsearchform">
<div class="layui-input-inline" style="width:136px">
<select name="status">
@ -67,9 +67,9 @@
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool'];
const moduleInit = ['tool','tablePlus'];
function gouguInit() {
var table = layui.table, tool = layui.tool,tree = layui.tree,form = layui.form,upload = layui.upload;
var table = layui.tablePlus, tool = layui.tool,tree = layui.tree,form = layui.form,upload = layui.upload;
$.ajax({
url: "/api/index/get_department_tree",
type:'get',
@ -185,10 +185,12 @@
elem: '#test',
title: '员工列表',
toolbar: '#toolbara',
defaultToolbar: [],
is_excel:true,
url: "/user/user/index", //数据接口
defaultToolbar:['filter', {title:'导出EXCEL',layEvent: 'LAYTABLE_EXCEL',icon: 'layui-icon-export'}],
page: true, //开启分页
limit: 20,
height: 'full-90',
cols: [
[
{type:'checkbox',fixed:'left'},
@ -320,18 +322,6 @@
table.on('toolbar(test)', function(obj){
var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
var data = checkStatus.data;
if(obj.event === 'LAYTABLE_EXCEL'){
var formSelect = form.val('barsearchform');
formSelect.limit=99999;
$.ajax({
url: '/user/user/index',
data: formSelect,
success:function(res){
table.exportFile('test', res.data,'xls');
}
});
return;
}
if (obj.event === 'add') {
tool.side("/user/user/add");
return;