Files
liche/admin/controllers/receiver/Clues.php
T

718 lines
28 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Clues extends HD_Controller
{
private $searchTpAry = array('mobile' => '客户手机号', 'name' => '客户姓名');
private $cacheKeyPhone = 'xz_admin_phone';
protected $log_dir;
public function __construct()
{
parent::__construct();
$this->load->model('receiver/receiver_clues_model', 'clues_model');
$this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model');
$this->load->model('receiver/receiver_customers_model', 'customers_model');
$this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs');
$this->load->model('receiver/receiver_xz_model', 'mdReceiverXz');
$this->load->model('app/licheb/app_licheb_users_model');
$this->load->model("biz/biz_model");
$this->load->model('auto/auto_brand_model', 'mdAutoBrand');
$this->load->model('auto/auto_series_model', 'mdAutoSeries');
$this->load->model('auto/auto_attr_model', 'mdAutoAttr');
$this->log_dir = 'receiver_clues';
}
//首页信息
public function index()
{
$this->lists();
}
public function lists($where = array())
{
$status_arr = $this->clues_model->get_status();
$params = $this->input->get();
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
if ($params['title']) {
$where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
}
//创建时间
if ($params['c_time']) {
$c_time = explode(' ~ ', $params['c_time']);
if ($c_time[0]) {
$where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
$where_yx["c.c_time >="] = strtotime($c_time[0] . ' 00:00:00');
}
if ($c_time[1]) {
$where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
$where_yx["c.c_time <="] = strtotime($c_time[1] . ' 23:59:59');
}
}
strlen($params['status']) && $where["status"] = $params['status'];
$count = $this->clues_model->count($where);
$lists = [];
if ($count) {
$fileds = 'id,name,mobile,cf_id,status_id,c_time,admin_id,status';
$rows = $this->clues_model->select($where, 'id desc', $page, $size, $fileds);
//获取来源
$cf_id_arr = array_unique(array_column($rows, 'cf_id'));
$cf_rows = $this->clues_cfrom_model->get_map_by_ids($cf_id_arr, 'id,title');
//获取管理员
$this->load->model('sys/sys_admin_model', 'admin_model');
$admin_id_arr = array_unique(array_column($rows, 'admin_id'));
if($admin_id_arr){
$str_ids = implode(',', $admin_id_arr);
$where = array("id in ({$str_ids})" => null);
$map_admin = $this->admin_model->map('id', 'username', $where);
}
foreach ($rows as $key => $val) {
$val['cf_title'] = isset($cf_rows[$val['cf_id']]) ? $cf_rows[$val['cf_id']][0]['title'] : '';
$val['status_name'] = $status_arr[$val['status']];
$val['admin_name'] = isset($map_admin[$val['admin_id']]) ? $map_admin[$val['admin_id']] : '';
$val['mobile_sub'] = $val['mobile'] ? substr_replace($val['mobile'], '*****', 0, 5) : '';
$lists[] = $val;
}
}
$this->data['lists'] = $lists;
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
$this->data['searchTpAry'] = $this->searchTpAry;
$this->data['params'] = $params;
$this->data['status_arr'] = $status_arr;
$this->data['_title'] = '线索池列表';
return $this->show_view('receiver/clues/lists', true);
}
public function get()
{
$params = $this->input->get();
$id = intval($params['id']);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '非法参数!');
}
$statusList = $logsList = $intention = $autoList = array();
$re = $this->clues_model->get(array('id' => $id));
if (!$re || empty($re)) {
return $this->show_json(SYS_CODE_FAIL, '线索不存在!');
}
$dataInfo = $re;
foreach ($this->clues_model->get_status() as $key => $value) {
$statusList[] = array("id" => $key, "name" => $value);
}
$dataInfo['editType'] = 0;
$re_cf = $this->clues_cfrom_model->get(array('id' => $re['cf_id']));
$info_show['cfrom_title'] = $re_cf['title'] ? $re_cf['title'] : '';
$info_show['statusList'] = $statusList;
$info_show['status2List'] = array(array("id" => 1, "name" => '未回访'), array("id" => 2, "name" => '已回访'));
$info_show['c_time'] = date('Y-m-d H:i', $re['c_time']);
$info_show['mobile_sub'] = $re['mobile'] ? substr_replace($re['mobile'], '*****', 0, 5) : '';
$resLogs = $this->mdOplogs->select(array('clue_id' => $id), 'c_time desc', 0, 0);
foreach ($resLogs as $key => $value) {
$setValue = array();
$setValue['uname'] = $value['uname'];
$setValue['log'] = $value['log'];
$setValue['type_name'] = $this->mdOplogs->typeAry()[$value['type']];
$setValue['c_time'] = date('Y-m-d H:i', $value['c_time']);
$rec_url = $rec_text = '';
if ($value['type'] == 2) {//拨打电话
$rec_text = '未接通';
$row = $this->mdReceiverXz->get(array('id' => $value['log']));
if ($row['duration']) {
$rec_url = $row['rec_url'] ? build_qiniu_image_url($row['rec_url'], 0, 0, 'video') : '';
$rec_text = '录音文件未生成';
}
}
$setValue['rec_url'] = $rec_url;
$setValue['rec_text'] = $rec_text;
$logsList[] = $setValue;
}
$info_show['logsList'] = $logsList;
//意向信息
$re_b = $this->mdAutoBrand->get(array('id' => $re['brand_id']), 'name');
$re_s = $this->mdAutoSeries->get(array('id' => $re['s_id']), 'name');
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : array();
$intention['brand_name'] = '品牌:' . ($re_b ? $re_b['name'] : '');
$intention['s_name'] = '车系:' . ($re_s ? $re_s['name'] : '');
$intention['v_name'] = '车型:' . ($jsondata['car']['version']['title'] ? $jsondata['car']['version']['title'] : '');
$intention['cor_name'] = '车身颜色:' . ($jsondata['car']['color']['title'] ? $jsondata['car']['color']['title'] : '');
$info_show['intention'] = $intention;
//获取城市区域
$city_id = '';
$county_id = '';
if($jsondata['info'] && $jsondata['info']['city_code']){
$city_code = $jsondata['info']['city_code'];
if('0' === $city_code[5]){
$city_id = $city_code;
} else {
$county_id = $city_code;
$city_id = substr_replace($county_id, '00', 4, 2);
}
}
$dataInfo['city_id'] = $city_id;
$dataInfo['county_id'] = $county_id;
$autoList[1] = $this->mdAutoBrand->select(array('status' => 1), 'id desc', 0, 0, 'id,name');
if ($re['brand_id']) {
$autoList[2] = $this->mdAutoSeries->select(array('status' => 1, 'brand_id' => $re['brand_id']), 'id desc', 0, 0, 'id,name');
}
$dataInfo['v_id'] = intval($jsondata['car']['version']['id']);
$dataInfo['cor_id'] = intval($jsondata['car']['color']['id']);
if ($re['s_id']) {
$autoList[3] = $this->mdAutoAttr->select(array('type' => 1, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name');
$autoList[4] = $this->mdAutoAttr->select(array('type' => 0, 's_id' => $re['s_id']), 'id desc', 0, 0, 'id,title as name');
}
$info_show['autoList'] = $autoList;
$this->data['info'] = $dataInfo;
$this->data['info_show'] = $info_show;
$this->data['_title'] = '线索详情';
return $this->show_view('receiver/clues/edit', true);
}
/**
* 新增
* @return bool
*/
function get_add()
{
$id = $this->input->get('id');
if ($id) {
$row = $this->clues_model->get(array('id' => $id));
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '记录不存在');
}
$cf_id1 = '';
$cf_id2 = '';
if($row['cf_id']){
$row_cfrom = $this->clues_cfrom_model->get(array('id' => $row['cf_id']));
if($row_cfrom['pid']){
$cf_id1 = $row_cfrom['pid'];
$cf_id2 = $row['cf_id'];
} else {
$cf_id1 = $row['cf_id'];
}
}
$info = array(
'name' => $row['name'],
'mobile' => $row['mobile'],
'cf_id1' => $cf_id1,
'cf_id2' => $cf_id2,
);
$title = "编辑线索";
$action = "edit";
} else {
$info = array(
'name' => '',
'mobile' => '',
'cf_id1' => '',
'cf_id2' => '',
);
$title = "新增线索";
$action = "add";
}
$where = array('status' => 1, 'pid' => 0);
$select = 'id, title';
$map_cfrom = $this->clues_cfrom_model->map('id', 'title', $where, '', 0, 0, $select);
$this->data['info'] = $info;
$this->data['cfromAry'] = $map_cfrom;
$this->data['action'] = $action;
$this->data['_title'] = $title;
return $this->show_view('receiver/clues/get');
}
//添加单条数据
public function add()
{
$info = $this->input->post('info');
if (!$info['name']) {
return $this->show_json(SYS_CODE_FAIL, '请填写姓名');
}
if (!mobile_valid($info['mobile'])) {
return $this->show_json(SYS_CODE_FAIL, '手机号码不准确');
}
$cf_id = 0;
if($info['cf_id2']){
$cf_id = $info['cf_id2'];
} else if($info['cf_id1']) {
$cf_id = $info['cf_id1'];
}
$add = array(
'name' => $info['name'],
'mobile' => $info['mobile'],
'cf_id' => $cf_id,
'admin_id' => $this->uid,
'c_time' => time(),
);
$ret = $this->clues_model->add($add);
if (!$ret) {
debug_log("[error]# add fail; " . $this->clues_model->db->last_query(), __FUNCTION__, $this->log_dir);
return $this->show_json(SYS_CODE_FAIL, '添加失败');
}
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
}
public function add_log()
{
$params = $this->input->post();
if (!$params['id']) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if (!$params['log']) {
return $this->show_json(SYS_CODE_FAIL, '请输入内容!');
}
$addData = array(
'clue_id' => $params['id'],
'uid' => $this->uid,
'uname' => $this->username,
'type' => intval($params['type']),
'log' => $params['log'],
'c_time' => time()
);
$id = $this->mdOplogs->add($addData);
if ($id) {
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '添加失败');
}
}
function add_excel()
{
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
$res = $this->upload();
if (!$res['code']) {
return $this->show_json(0, $res['message']);
}
$file = $res['path'];
if ($res['file_ext'] == '.xls') {
$reader = \PHPExcel_IOFactory::createReader('Excel5'); // 读取 excel 文档
} elseif ($res['file_ext'] == '.xlsx') {
$reader = \PHPExcel_IOFactory::createReader('Excel2007'); // 读取 excel 文档
} else {
return $this->show_json(SYS_CODE_FAIL, '文件无法识别');
}
$PHPExcel = $reader->load($file); // 文档名称
$objWorksheet = $PHPExcel->getActiveSheet();
$rowCnt = $objWorksheet->getHighestRow(); //获取总行数
if ($rowCnt > 800) {
@unlink($file);
return $this->show_json(0, '数据大于800请拆分多个表格导入');
}
$data = array();
for ($_row = 2; $_row <= $rowCnt; $_row++) { //读取内容
$data[] = array(
'name' => $objWorksheet->getCell('A' . $_row)->getValue(),
'mobile' => $objWorksheet->getCell('B' . $_row)->getValue(),
'cfrom' => $objWorksheet->getCell('C' . $_row)->getValue(),
);
}
$done = $this->add_batch($data);
@unlink($file);
$this->data['load_num'] = count($data);
$this->data['done'] = $done;
return $this->show_json(SYS_CODE_SUCCESS, "成功导入{$done}");
}
//编辑单条数据
public function edit()
{
$info = $this->input->post('info');
if (!$info) {
return $this->show_json(SYS_CODE_FAIL, '非法参数!');
}
$re = $this->clues_model->get(array('id' => $info['id']));
if (!$re || empty($re)) {
return $this->show_json(SYS_CODE_FAIL, '线索不存在!');
}
$msg = '修改成功';
$code = SYS_CODE_SUCCESS;
if ($info['editType'] == 1) {
$status_name = $this->clues_model->get_status()[$re['status']];
$status_name_up = $this->clues_model->get_status()[$info['status']];
$log = '更新状态(' . $status_name . ')为(' . $status_name_up . ')';
$ret = $this->clues_model->update(array('status' => $info['status']), array('id' => $info['id']));
if (!$ret) {
$code = SYS_CODE_FAIL;
$msg = '修改状态失败';
} else {
$msg = '修改状态成功';
$this->addLog(array('clue_id' => $info['id'], 'type' => 0, 'log' => $log));
}
} else if ($info['editType'] == 2) {
if ($info['name'] == $re['name']) {
return $this->show_json(SYS_CODE_FAIL, '客户姓名未修改!');
}
$log = '更新客户姓名(' . $re['name'] . ')为(' . $info['name'] . ')';
$ret = $this->clues_model->update(array('name' => $info['name']), array('id' => $info['id']));
if (!$ret) {
$code = SYS_CODE_FAIL;
$msg = '修改用户信息失败';
} else {
$msg = '修改用户信息成功';
$this->addLog(array('clue_id' => $info['id'], 'type' => 0, 'log' => $log));
}
} else if ($info['editType'] == 3) {
if (!$info['brand_id']) {
return $this->show_json(SYS_CODE_FAIL, '请选择品牌');
}
$jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : array();
$jsondata['car']['version']['id'] = intval($info['v_id']);
$jsondata['car']['color']['id'] = intval($info['cor_id']);
if($info['city_id'] || $info['county_id']){
$jsondata['info']['city_code'] = $info['county_id'] ? $info['county_id'] : $info['city_id'];
} else {
if($jsondata['info'] && $jsondata['info']['city_code']){
unset($jsondata['info']['city_code']);
}
}
$ret = $this->clues_model->update(array('brand_id' => $info['brand_id'],
's_id' => $info['s_id'], 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)), array('id' => $info['id']));
if (!$ret) {
$code = SYS_CODE_FAIL;
$msg = '修改意向信息失败';
} else {
$msg = '修改意向信息成功';
if ($info['brand_id']) {
$re_b = $this->mdAutoBrand->get(array('id' => $info['brand_id']), 'name');
$log = $re_b['name'];
if ($info['s_id']) {
$re_s = $this->mdAutoSeries->get(array('id' => $info['s_id']), 'name');
$log .= '-' . $re_s['name'];
}
if ($info['v_id']) {
$re_v = $this->mdAutoAttr->get(array('id' => $info['v_id']), 'title');
$log .= '-' . $re_v['title'];
}
if ($info['cor_id']) {
$re_cor = $this->mdAutoAttr->get(array('id' => $info['cor_id']), 'title');
$log .= '-' . $re_cor['title'];
}
$this->addLog(array('clue_id' => $info['id'], 'type' => 0, 'log' => '更新意向信息为(' . $log . ')'));
}
}
}
return $this->show_json($code, $msg);
}
/**
* Notes:增加日志
* Created on: 2021/7/23 10:48
* Created by: dengbw
* @param array $ary
* @return mixed
*/
private function addLog($ary = array())
{
$id = 0;
if ($ary['log']) {
$addData = array(
'clue_id' => $ary['clue_id'],
'uid' => $this->uid,
'uname' => $this->username,
'type' => intval($ary['type']),
'log' => $ary['log'],
'c_time' => time()
);
$id = $this->mdOplogs->add($addData);
}
return $id;
}
//删除单条数据
public function del()
{
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
}
//分配
public function get_adviser()
{
$ids = $this->input->get('ids');
$where = [
'status' => 1,
];
$bizList = $this->biz_model->select($where, '', '', '', 'id,biz_name');
$this->data['bizList'] = $bizList;
$this->data['ids'] = $ids;
return $this->show_view('receiver/clues/get_adviser');
}
public function edit_adviser()
{
$biz_id = $this->input->post('biz_id');
$ids = $this->input->post('ids');
$ids_arr = explode(',', $ids);
$biz = $this->biz_model->get(['id' => $biz_id]);
if (!$biz) {
return $this->show_json(SYS_CODE_FAIL, '请选择分配门店!');
}
if (!is_array($ids_arr)) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$where = [
"id in ($ids)" => null
];
$clues_rows = $this->clues_model->map('id', '', $where);
foreach ($ids_arr as $val) {
$clues_row = $clues_rows[$val][0];
//判断是否已分配
$cus_row = $this->customers_model->get(['rid' => $val, 'status != 3' => null]);
if ($clues_row && !$cus_row) {
$jsondata = json_decode($clues_row['jsondata'], true);
$add_data = [
'rid' => $val,
'name' => $clues_row['name'],
'mobile' => $clues_row['mobile'],
'biz_id' => $biz_id,
'brand_id' => $clues_row['brand_id'],
's_id' => $clues_row['s_id'],
'if_driver' => $clues_row['if_driver'],
'cf_title' => '平台分配',
'p_time' => date('Y-m-d H:i:s'),
'c_time' => time()
];
if ($jsondata['car']) {
isset($jsondata['car']['version']) && $add_data['v_id'] = $jsondata['car']['version']['id'];
$add_data['car_json'] = json_encode($jsondata['car'], JSON_UNESCAPED_UNICODE);
unset($jsondata['car']);
}
$jsondata && $add_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$customers_id = $this->customers_model->add($add_data);
if ($customers_id) {
$this->clues_model->update(['status' => 1], ['id' => $val]);
$this->load->library('receiver/clues_entity');
$this->clues_entity->add_log($val, $this->uid, $this->username, "分配给【{$biz['biz_name']}】商家");
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($customers_id, $this->uid, $this->username, "平台分配", 0, 'admin');
}
}
}
return $this->show_json(SYS_CODE_SUCCESS, '分配成功!');
}
public function lists_call()
{
$this->load->model('sys/sys_admin_model', 'mdAdmin');
$cache = &load_cache('redis');
$xz_admin_phone = $cache->get($this->cacheKeyPhone);
$params = $this->input->get();
$username = $params['username'];
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 20;
$lists = array();
$where['status'] = 1;
if (!empty($username)) $where["username like '%$username%'"] = null;
if (!empty($params['mobile'])) $where['mobile'] = $params['mobile'];
$count = $this->mdAdmin->count($where);
if ($count) {
$res = $this->mdAdmin->select($where, 'id desc', $params['page'], $params['size'], 'id,username,mobile');
foreach ($res as $key => $value) {
$setValue = array();
$setValue['id'] = $value['id'];
$setValue['username'] = $value['username'];
$setValue['mobile'] = $value['mobile'];
$phone = $xz_admin_phone['admins'][$value['id']];
if ($phone) {
$phone_btn = '<a class="am-btn am-btn-danger am-btn-xs" data-action="/receiver/clues/edit_call" data-ajax="post"
data-params-type="1" data-params-id="' . $value['id'] . '" >取消分配</a>';
} else {
$phone = '未分配';
$phone_btn = '<a class="am-btn am-btn-primary am-btn-xs" data-action="/receiver/clues/edit_call" data-ajax="post"
data-params-type="0" data-params-id="' . $value['id'] . '" >分配号码</a>';
}
$setValue['phone'] = $phone;
$setValue['phone_btn'] = $phone_btn;
$lists[] = $setValue;
}
}
$this->data['params'] = $params;
$this->data['_title'] = '虚似号分配';
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
$this->data['lists'] = $lists;
return $this->show_view('receiver/clues/lists_call', true);
}
public function edit_call()
{
$id = intval($this->input->post('id'));
$type = $this->input->post('type');
if ($type != 3 && !$id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$cache = &load_cache('redis');
$xz_admin_phone = $cache->get($this->cacheKeyPhone);
$this->config->load('xcall', TRUE);
$mobiles = $this->config->item('mobile_list', 'xcall');
$mobiles && shuffle($mobiles);
if ($type == 0) {//分配手机
if (!$mobiles) {
return $this->show_json(SYS_CODE_FAIL, '无号码库!');
}
$number = '';
foreach ($mobiles as $key => $value) {
if (!$xz_admin_phone['numbers'][$value]) {
$number = $value;
break;
}
}
if ($number) {
$xz_admin_phone['admins'][$id] = $number;
$xz_admin_phone['numbers'][$number] = $id;
$cache->save($this->cacheKeyPhone, $xz_admin_phone);
return $this->show_json(SYS_CODE_SUCCESS, '分配号码成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '号码已全部分配完了');
}
} else if ($type == 1) {//取消分配
$number = $xz_admin_phone['admins'][$id];
unset($xz_admin_phone['admins'][$id]);
unset($xz_admin_phone['numbers'][$number]);
$cache->save($this->cacheKeyPhone, $xz_admin_phone);
return $this->show_json(SYS_CODE_SUCCESS, '取消分配成功');
} else if ($type == 3) {//全部重新分配
if (!$mobiles) {
return $this->show_json(SYS_CODE_FAIL, '无号码库!');
}
if (!$xz_admin_phone['admins']) {
return $this->show_json(SYS_CODE_FAIL, '未分配号码,不能重置');
}
$xz_admin_phone_new = array();
$i = 0;
foreach ($xz_admin_phone['admins'] as $key => $value) {
$number = $mobiles[$i];
$id = $key;
if ($number) {
$xz_admin_phone_new['admins'][$id] = $number;
$xz_admin_phone_new['numbers'][$number] = $id;
}
$i++;
}
$cache->save($this->cacheKeyPhone, $xz_admin_phone_new);
return $this->show_json(SYS_CODE_SUCCESS, '重置已分配成功');
}
}
/**
* 返回map select数据
* @return bool
*/
function json_map_cfrom(){
$pid = $this->input->post('pid');
$status = $this->input->post('status');
$where = array();
if(strlen($pid) > 0){
$where['pid'] = $pid;
}
if(strlen($status) > 0){
$where['status'] = $status;
} else {
$where["status>-1"] = null;
}
$total = $this->clues_cfrom_model->count($where);
$map = array();
if($total){
$orderby = 'id desc';
$select= 'id, title';
$rows = $this->clues_cfrom_model->select($where, $orderby, 0, 0, $select);
foreach($rows as $v){
$map[$v['id']] = $v['title'];
}
}
$this->data = $map;
return $this->show_json(SYS_CODE_SUCCESS);
}
private function upload()
{
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/temp/';
$config['allowed_types'] = 'xls|xlsx';
$config['max_size'] = 5120;
$config['file_name'] = 'receiver_clues' . time() . rand(1, 99999);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('file')) {
return array('code' => SYS_CODE_FAIL, 'message' => $this->upload->display_errors('', ''));
} else {
$data = $this->upload->data();
return array('code' => SYS_CODE_SUCCESS, 'path' => $data['full_path'], 'file_ext' => $data['file_ext']);
}
}
/**
* 批量新增
* @param $lists
* @return int
*/
private function add_batch($lists)
{
$done = 0;
$adds = array();
$where = array('status' => 1);
$select = 'id, title';
$map_cfrom = $this->clues_cfrom_model->map('title', 'id', $where, '', 0, 0, $select);
$fails = array();
foreach ($lists as $k => $v) {
if (!$v['name']) {
$fails[] = array('data' => $v, 'msg' => 'name is null');
continue;
}
if (!mobile_valid($v['mobile'])) {
$fails[] = array('data' => $v, 'msg' => 'mobile valid fail');
continue;
}
$cf_id = $map_cfrom[$v['cfrom']];
$adds[] = array(
'name' => $v['name'],
'mobile' => $v['mobile'],
'cf_id' => $cf_id ? $cf_id : 0,
'c_time' => time(),
);
$done++;
}
$fails && debug_log('[warning]# fails=' . json_encode($fails), __FUNCTION__, $this->log_dir);
if ($adds) {
$ret = $this->clues_model->add_batch($adds);
if (!$ret) {
debug_log("[error] add_batch fail; " . $this->clues_model->db->last_query(), __FUNCTION__, $this->log_dir);
$done = 0;
}
}
return $done;
}
}