|
@@ -106,4 +106,240 @@ class Crontab extends Controller
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 计划任务 每五分钟请求一次,检测有无导入的新文件
|
|
|
+ */
|
|
|
+ public function excelImport()
|
|
|
+ {
|
|
|
+ set_time_limit(6000);
|
|
|
+ $serialzierData = Db::name('serialize')->where('status',1)->find();
|
|
|
+ $excel_arrays =unserialize($serialzierData['text']);
|
|
|
+ $uni = $serialzierData['uni'];
|
|
|
+ $uid = $serialzierData['admin_id'];
|
|
|
+ $num['error_num'] = 0;
|
|
|
+ $excel_array = array_slice($excel_arrays,0,400);
|
|
|
+ $success = [];
|
|
|
+ $error = [];
|
|
|
+// var_dump($excel_array);die;
|
|
|
+ foreach ($excel_array as $k => $v) {
|
|
|
+ $status = 1; // 为1标识此行正常
|
|
|
+ // 判断邮件
|
|
|
+ if (!empty($v[2])) {
|
|
|
+ $checkEmail = Db::name('customer')->where('email',$v[2])->where('spread_id',$uid)->find();
|
|
|
+ if ($checkEmail) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '此客户邮箱已存在',
|
|
|
+ 'content' => $v[2],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ } else {
|
|
|
+ if (!filter_var($v[2], FILTER_VALIDATE_EMAIL)) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '邮箱格式不正确',
|
|
|
+ 'content' => $v[2],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $customer_chengk = new CustomerModel();
|
|
|
+ if ($customer_chengk->checkCustomer($v[2],$v[1],$v[3])) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '此客户已存在其他状态',
|
|
|
+ 'content' => $v[2],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ }
|
|
|
+ if (!empty($v[2])) {
|
|
|
+ $ckeckWebsiteCompany = Db::name('customer')->where('website','like','%'.$v[3].'%')->where('status',0)->where('email','')->find();
|
|
|
+ if ($ckeckWebsiteCompany) {
|
|
|
+ Db::name('customer')->where('id',$ckeckWebsiteCompany['id'])->update(['spread_id'=>$uid,'emial' => $v[2]]);
|
|
|
+ Db::name('customer')->where('emial',$v[2])->setInc('people',1);
|
|
|
+ Db::name('ranking')->where('c_id',$ckeckWebsiteCompany['id'])->update([['admin_id' => $uid]]);
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '已存在此公司,网站客户,直接更新,不计入添加次数',
|
|
|
+ 'content' => "已存在此公司,网站客户,直接更新,不计入添加次数",
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 判断网站
|
|
|
+ if (empty($v[3])) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '网站不能为空',
|
|
|
+ 'content' => $v[3],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ } else {
|
|
|
+ $website =explode(chr(10), $v[3]);
|
|
|
+ $v[3] = implode("##",$website);
|
|
|
+ }
|
|
|
+ // 判断评分
|
|
|
+ if ($v[4] == '') {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '评分不能为空',
|
|
|
+ 'content' => $v[4],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ } else {
|
|
|
+ // 判断评分
|
|
|
+ if (!is_numeric($v[4])) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '评分必须为整数',
|
|
|
+ 'content' => $v[4],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断国家
|
|
|
+ $country = Db::name('countries')->where('country', $v[5])->find();
|
|
|
+ if (!$country) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '国家名称不正确',
|
|
|
+ 'content' => $v[5],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ }
|
|
|
+ $v[5] = $country['id'];
|
|
|
+
|
|
|
+ // 判断行业
|
|
|
+ if (empty($v[7])) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '行业不能为空',
|
|
|
+ 'content' => $v[7],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $tapeNanme = explode('&',$v[7]);
|
|
|
+ foreach ($tapeNanme as $vo) {
|
|
|
+ $type = Db::name('type d')
|
|
|
+ ->join('admin a','a.id = d.admin_id')
|
|
|
+ ->where('d.name', $vo)
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->whereOr('d.admin_id',session('uid'));
|
|
|
+ $query->whereOr('a.groupid','3');
|
|
|
+ $query->whereOr('a.groupid','5');
|
|
|
+ })
|
|
|
+ ->field('d.name,d.id')
|
|
|
+ ->find();
|
|
|
+ if (!$type) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '未设置此行业名称-'.$vo,
|
|
|
+ 'content' => $v[7],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ } else {
|
|
|
+ $typdIds[] = $type['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $v[7] = ','.implode(',',$typdIds).','; // 改为id
|
|
|
+ unset($typdIds);
|
|
|
+ // 主营产品
|
|
|
+ if (empty($v[8])) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '主营产品不能为空',
|
|
|
+ 'content' => $v[8],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $productName = explode('&',$v[8]);
|
|
|
+ foreach ($productName as $vo) {
|
|
|
+ $produc = Db::name('product d')
|
|
|
+ ->join('admin a','d.admin_id=a.id')
|
|
|
+ ->where('d.product_name', $vo)
|
|
|
+ ->where(function ($query) {
|
|
|
+ $query->whereOr('d.admin_id',session('uid'));
|
|
|
+ $query->whereOr('a.groupid','3');
|
|
|
+ $query->whereOr('a.groupid','5');
|
|
|
+ })
|
|
|
+ ->field('d.product_name,d.id')
|
|
|
+ ->find();
|
|
|
+ if (!$produc) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '未设置此主营产品名称-'.$vo,
|
|
|
+ 'content' => $v[8],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ } else {
|
|
|
+ $producIds[] = $produc['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $v[8] = ','.implode(',',$producIds).','; // 改为id
|
|
|
+ unset($producIds);
|
|
|
+ $where = [
|
|
|
+ 'email' => $v[2],
|
|
|
+ 'company' => $v[1],
|
|
|
+ 'website' => $v[3],
|
|
|
+ 'spread_id' => $uid,
|
|
|
+ ];
|
|
|
+ $isset = Db::name('customer')->where($where)->find();
|
|
|
+ if ($isset) {
|
|
|
+ $error[] = [
|
|
|
+ 'rows' => $k,
|
|
|
+ 'msg' => '此客户已经存在已经自动过滤',
|
|
|
+ 'content' => $v[0],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $status = 0; // 设置为0标识此行有错误
|
|
|
+ }
|
|
|
+ if ($status == 1) {
|
|
|
+ $success[] = [
|
|
|
+ 'name' => $v[0],
|
|
|
+ 'company' => $v[1],
|
|
|
+ 'email' => $v[2],
|
|
|
+ 'website' => $v[3],
|
|
|
+ 'grade' => $v[4],
|
|
|
+ 'country' => $v[5],
|
|
|
+ 'phone' => $v[6],
|
|
|
+ 'type' => $v[7],
|
|
|
+ 'product' => $v[8],
|
|
|
+ 'spread_id' => $uid,
|
|
|
+ 'follow_time' => time(),
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ $import_success[] = [
|
|
|
+ 'name' => $v[0],
|
|
|
+ 'email' => $v[2],
|
|
|
+ 'uni' => $uni,
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $num['error_num'] = $num['error_num'] + 1; // 记录失败条数
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $num['success_num'] = count($success);
|
|
|
+ $num['zong'] = count($excel_array);
|
|
|
+ if ($num['success_num'] > 0) {
|
|
|
+ $customer = new CustomerModel();
|
|
|
+ $customer->add_all($success,$uid); // 保存处理所有数据;
|
|
|
+ Db::name("import_success")->insertAll($import_success);
|
|
|
+ }
|
|
|
+ if ($num['error_num'] > 0) {
|
|
|
+ Db::name('import_error')->insertAll($error);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|