Files
spacestation/admin/controllers/receiver/Clues.php
T
2025-09-15 15:28:59 +08:00

1385 lines
63 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
private $maintainAry = ['0-0' => '待处理', '1-10' => '已加微信', '3-7' => '明确拒绝', '2-4' => '未接通', '2-5' => '未完整触碰'];//保养客户专用
private $role_id = 2;
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_yx_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->load->model('area_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$this->load->model('app/paic/app_paic_users_model');
$this->load->model('receiver/receiver_enroll_model');
$this->log_dir = 'receiver_clues';
}
//首页信息
public function index()
{
$params = $this->input->get();
list($lists, $count) = $this->lists();
$map_cfrom = $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => 0, 'type' => 0), '', 0, 0, 'id, title');
$map_cfrom2 = $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => $params['cfrom_id']), '', 0, 0, 'id, title');
$statusList = array();
foreach ($this->clues_model->statusAry() as $key => $value) {
$cate = array();
$where = array("status" => $key);
if ($this->admin_biz_str) {
$where["belong_id in ($this->admin_biz_str)"] = null;
} else {
$this->belong && $where["belong_id"] = $this->belong;
}
$count1 = $this->clues_model->count($where);
if ($value['list']) {
foreach ($value['list'] as $key2 => $value2) {
$where['status2'] = $key2;
$count2 = $this->clues_model->count($where);
$cate[] = array("id" => $key2, "name" => $value2, "count" => $count2);
}
}
$statusList[] = array("id" => $key, "name" => $value['name'], "cate" => $cate, "count" => $count1);
}
$export_button = (SUPER_ADMIN == $this->role || $this->uid == 4) ? 1 : 0;
$this->data['province_id'] = intval($params['province_id']);
$this->data['city_id'] = intval($params['city_id']);
$this->data['county_id'] = intval($params['county_id']);
$this->data['provinces'] = $this->province_ary();
$this->data['lists'] = $lists;
$this->data['searchTpAry'] = $this->searchTpAry;
$this->data['params'] = $params;
$this->data['cfromAry'] = $map_cfrom;
$this->data['cfromAry2'] = $map_cfrom2;
$this->data['statusList'] = $statusList;
$this->data['maintainAry'] = $this->maintainAry;
$this->data['export_button'] = $export_button;
$this->data['role'] = $this->role;
$this->data['_title'] = '线索池列表';
return $this->show_view('receiver/clues/lists', true);
}
public function lists($export = false)
{
$where = [];
$statusAry = $this->clues_model->statusAry();
$params = $this->input->get();
$province_id = intval($params['province_id']);
$city_id = intval($params['city_id']);
$county_id = intval($params['county_id']);
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
$export && $size = 10000;
if ($params['title']) {
$where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
}
if ($this->admin_biz_str) {
$where["belong_id in ($this->admin_biz_str)"] = null;
} else {
$params['belong_id'] && $where["belong_id"] = $params['belong_id'];
}
//创建时间
if ($params['c_time']) {
$c_time = explode(' ~ ', $params['c_time']);
if ($c_time[0]) {
$where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
}
if ($c_time[1]) {
$where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
}
}
//最后报名时间
if ($params['p_time']) {
$en_time = explode(' ~ ', $params['p_time']);
if ($en_time[0]) {
$where["p_time >="] = $en_time[0] . ' 00:00:00';
}
if ($en_time[1]) {
$where["p_time <="] = $en_time[1] . ' 23:59:59';
}
}
if (strlen($params['status'])) {
$where["status"] = $params['status'];
} else {
$where["status > "] = '-1';
}
if (strlen($params['wxgr'])) {
$where["wxgr"] = $params['wxgr'];
}
strlen($params['status2']) && $where["status2"] = $params['status2'];
$province_id && $where['province_id'] = $province_id;
$city_id && $where['city_id'] = $city_id;
$county_id && $where['county_id'] = $county_id;
$params['cfrom_id'] && $where['cf_id'] = $params['cfrom_id'];
$params['cfrom_id2'] && $where['cf2_id'] = $params['cfrom_id2'];
$params['brand_id'] && $where['brand_id'] = $params['brand_id'];
$params['series_id'] && $where['series_id'] = $params['series_id'];
strlen($params['admin_id']) && $where['admin_id'] = $params['admin_id'];
//门店筛选
if ($params['biz_id_admin']) {
$where['biz_id'] = $params['biz_id_admin'];
} else if ($params['county_id_admin']) {
$where["biz_id in(select id from lc_biz where county_id={$params['county_id_admin']})"] = null;
} else if ($params['city_id_admin']) {
$where["biz_id in(select id from lc_biz where city_id={$params['city_id_admin']})"] = null;
} else if ($params['province_id_admin']) {
$where["biz_id in(select id from lc_biz where province_id={$params['province_id_admin']})"] = null;
}
!$params['province_id_admin'] && $params['province_id_admin'] = '';
!$params['city_id_admin'] && $params['city_id_admin'] = '';
!$params['county_id_admin'] && $params['county_id_admin'] = '';
!$params['biz_id_admin'] && $params['biz_id_admin'] = '';
!$params['brand_id'] && $params['brand_id'] = 0;
!$params['series_id'] && $params['series_id'] = 0;
!strlen($params['admin_id']) && $params['admin_id'] = '';
$count = $this->clues_model->count($where);
$lists = [];
if ($count) {
$fileds = 'id,name,mobile,brand_id,series_id,cf_id,cf2_id,c_time,admin_id,status,status2,en_time,
province_id,city_id,county_id,biz_id,p_time,u_time,rec_time';
$rows = $this->clues_model->select($where, 'en_time desc,id desc', $page, $size, $fileds);
$map_admin = $map_cf_pid = $cf_title_arr = [];
//获取来源
$cf_id_arr = array_unique(array_column($rows, 'cf2_id'));
if ($cf_id_arr) {
$cf_id_str = implode(',', $cf_id_arr);
$res_cfrom = $this->clues_cfrom_model->select(["id in({$cf_id_str})" => null], 'id desc', 0, 0, 'id,title,pid');
$cf_pid_arr = array_unique(array_column($res_cfrom, 'pid'));
if ($cf_pid_arr) {
$cf_pid_str = implode(',', $cf_pid_arr);
$map_cf_pid = $this->clues_cfrom_model->map('id', 'title', ["id in({$cf_pid_str})" => null]);
}
foreach ($res_cfrom as $key => $val) {
$title = $val['title'];
if ($val['pid']) {//一级分类
$map_cf_pid[$val['pid']] && $title = $map_cf_pid[$val['pid']] . '-' . $title;
}
$cf_title_arr[$val['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);
$map_admin = $this->admin_model->map('id', 'username', ["id in ({$str_ids})" => null]);
}
//门店
$biz_id_arr = array_unique(array_column($rows, 'biz_id'));
$str_ids = implode(',', $biz_id_arr);
$biz_id_arr && $biz_rows = $this->biz_model->map('id', 'id,biz_name,county_id', ["id in ({$str_ids})" => null], '', '', '', 'id,biz_name,county_id');
//门店位置
$biz_rows && $county_id_bizarr = array_filter(array_unique(array_column($biz_rows, 'county_id')));
if ($county_id_bizarr) {
$str_ids = implode(',', $county_id_bizarr);
$map_area_biz = $this->area_model->map('county_id', '', ["county_id in ({$str_ids})" => null], '', 0, $size, 'county_id,province_name,city_name,county_name');
}
//所在地区
$county_id_arr = array_filter(array_unique(array_column($rows, 'county_id')));
if ($county_id_arr) {
$str_ids = implode(',', $county_id_arr);
$map_area_county = $this->area_model->map('county_id', '', ["county_id in ({$str_ids})" => null], '', 0, $size, 'county_id,province_name,city_name,county_name');
}
$city_id_arr = array_filter(array_unique(array_column($rows, 'city_id')));
if ($city_id_arr) {
$str_ids = implode(',', $city_id_arr);
$map_area_city = $this->area_model->map('city_id', '', ["city_id in ({$str_ids})" => null], '', 0, $size, 'city_id,province_name,city_name');
}
$province_id_arr = array_filter(array_unique(array_column($rows, 'province_id')));
if ($province_id_arr) {
$str_ids = implode(',', $province_id_arr);
$map_area_province = $this->area_model->map('province_id', '', ["province_id in ({$str_ids})" => null], '', 0, $size, 'province_id,province_name');
}
$brands = $this->auto_brand_model->get_map_by_ids(array_column($rows, 'brand_id'));
$series = $this->auto_series_model->get_map_by_ids(array_column($rows, 'series_id'));
foreach ($rows as $key => $val) {
$val['cf_title'] = $cf_title_arr[$val['cf2_id']] ? $cf_title_arr[$val['cf2_id']] : $cf_title_arr[$val['cf_id']];
$status_name = $statusAry[$val['status']]['name'];
$val['status2'] && $status_name .= '' . $statusAry[$val['status']]['list'][$val['status2']];
$val['status_name'] = $status_name;
$val['admin_name'] = $map_admin[$val['admin_id']] ? $map_admin[$val['admin_id']] : '';
$val['mobile_sub'] = $val['mobile'];
if ($val['county_id']) {
$area = $map_area_county[$val['county_id']][0];
$val['poi'] = "{$area['province_name']}-{$area['city_name']}-{$area['county_name']}";
} elseif ($val['city_id']) {
$area = $map_area_city[$val['city_id']][0];
$val['poi'] = "{$area['province_name']}-{$area['city_name']}";
} elseif ($val['province_id']) {
$area = $map_area_province[$val['province_id']][0];
$val['poi'] = "{$area['province_name']}";
}
$val['biz_name'] = isset($biz_rows[$val['biz_id']]) ? $biz_rows[$val['biz_id']]['biz_name'] : '';
$bizarea = $map_area_biz[$biz_rows[$val['biz_id']]['county_id']][0];
$val['biz_poi'] = "{$bizarea['province_name']}-{$bizarea['city_name']}-{$bizarea['county_name']}";
if ($brands[$val['brand_id']]) {
$val['brand_detail'] = $brands[$val['brand_id']][0]['name'];
$val['series_detail'] = $series[$val['series_id']][0]['name'];
}
if ($val['p_time'] == '0000-00-00 00:00:00') {
$val['p_time'] = '';
}
$val['rec_time'] = $val['rec_time'] != '0000-00-00 00:00:00' ? $val['rec_time'] : '';
$lists[] = $val;
}
}
$where = ['status' => 1, 'role_id' => $this->role_id];
$adminLists = $this->sys_admin_model->select($where, 'id desc', 0, 0, 'id,username');
$this->data['adminLists'] = $adminLists;
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
return [$lists, $count];
}
public function get()
{
$params = $this->input->get();
$id = intval($params['id']);
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '非法参数!');
}
$statusList = $status2List = $logsList = [];
$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->statusAry() as $key => $value) {
$statusList[] = array("id" => $key, "name" => $value['name']);
}
if (strlen($re['status'])) {
foreach ($this->clues_model->statusAry($re['status'])['list'] as $key => $value) {
$status2List[] = array("id" => $key, "name" => $value);
}
}
$dataInfo['editType'] = 0;
$info_show['statusList'] = $statusList;
$info_show['status2List'] = $status2List;
$info_show['c_time'] = date('Y-m-d H:i', $re['c_time']);
$info_show['en_time'] = $re['en_time'];
$info_show['mobile_sub'] = $re['mobile'];
$info_show['buy_time_cn'] = $re['buy_time'] ? Receiver_clues_model::BUY_TIME_LIST[$re['buy_time']] : '';
$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']);
list($rec_url,$rec_text) = $this->mdOplogs->getRecordUrl($value['id']);
// 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;
$dataInfo['rec_time'] = $dataInfo['rec_time'] == '0000-00-00 00:00:00' ? '' : $dataInfo['rec_time'];
//获取所在地区
$dataInfo['province_id'] = $re['province_id'];
$dataInfo['city_id'] = $re['city_id'];
$dataInfo['county_id'] = $re['county_id'];
//门店
$biz = $this->biz_model->get(['id' => $re['biz_id']]);
$dataInfo['province_id_admin'] = $biz ? $biz['province_id'] : 0;
$dataInfo['city_id_admin'] = $biz ? $biz['city_id'] : 0;
$dataInfo['county_id_admin'] = $biz ? $biz['county_id'] : 0;
$customer = $this->customers_model->get(array('rid' => $re['id'], 'biz_id' => $re['biz_id'], 'status >' => -1));
$dataInfo['customer_id'] = $customer['id'];
$dataInfo['cf_pid'] = $dataInfo['cf_pid'] ?: '';
$dataInfo['brand_id'] = $dataInfo['brand_id'] ?: '';
$map_cfrom = $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => 0, 'type' => 0), '', 0, 0, 'id, title');
$map_cfrom2 = $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => $params['cfrom_id']), '', 0, 0, 'id, title');
//已分配门店
$selectedBrands1 = [];
if ($dataInfo['app_id'] == Receiver_clues_model::APP_ID_ACTIVITY) {
$customerRows = $this->customers_model->select(['rid' => $re['id'], 'status >' => -1], '', '', '', 'biz_id');
$ids = implode(',', array_column($customerRows, 'biz_id'));
$ids && $selectedBrands1 = $this->biz_model->select(["id in ($ids)" => null, 'status' => 1], '', 0, 0, 'id as biz_id,biz_name as name');
}
$this->data['cfromAry'] = $map_cfrom;
$this->data['cfromAry2'] = $map_cfrom2;
$this->data['provinces'] = $this->province_ary();
$this->data['info'] = $dataInfo;
$this->data['info_show'] = $info_show;
$this->data['selectedBrands1'] = $selectedBrands1;
$this->data['buyTimeList'] = Receiver_clues_model::BUY_TIME_LIST;
$this->data['_title'] = '线索详情';
return $this->show_view('receiver/clues/edit', true);
}
/**
* Notes:二级分类
* Created on: 2021/9/15 14:16
* Created by: dengbw
* @return bool
*/
public function get_status2()
{
$params = $this->input->post();
$status = $params['status'];
$status2List = array();
if (strlen($status)) {
foreach ($this->clues_model->statusAry($status)['list'] as $key => $value) {
$status2List[] = array("id" => $key, "name" => $value);
}
}
$this->data = $status2List;
return $this->show_json(SYS_CODE_SUCCESS);
}
/**
* 新增
* @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, '记录不存在');
}
$this->data['citys'] = $this->area_model->select(array('province_id' => $row['province_id']), '', 0, 0, 'distinct(city_id), city_name');
$this->data['countys'] = $this->area_model->select(array('city_id' => $row['city_id']));
$info = array(
'name' => $row['name'],
'mobile' => $row['mobile'],
'cf_id' => $row['cf_id'],
'cf2_id' => $row['cf2_id'],
'province_id' => $row['province_id'],
'city_id' => $row['city_id'],
'county_id' => $row['county_id'],
'biz_id' => $row['biz_id'],
);
$title = "编辑线索";
$action = "edit";
} else {
$info = array(
'name' => '',
'mobile' => '',
'cf_id' => '',
'cf2_id' => '',
'province_id' => $this->limit_province_id,
'city_id' => 0,
'county_id' => 0,
'biz_id' => 0,
'brand_id' => 0,
'series_id' => 0,
);
$title = "新增线索";
$action = "add";
}
$where = array('status' => 1, 'pid' => 0, 'type' => 0);
$select = 'id, title';
$map_cfrom = $this->clues_cfrom_model->map('id', 'title', $where, '', 0, 0, $select);
$this->data['provinces'] = $this->province_ary();
$this->data['info'] = $info;
$this->data['cfromAry'] = $map_cfrom;
$this->data['action'] = $action;
$this->data['limit_province_id'] = $this->limit_province_id;
$this->data['_title'] = $title;
return $this->show_view('receiver/clues/get', true);
}
//添加单条数据
public function add()
{
$info = $this->input->post('info');
if (!$info['name'] && !$info['sex']) {
return $this->show_json(SYS_CODE_FAIL, '请填写姓名或称谓');
}
if (!mobile_valid($info['mobile']) && strlen($info['mobile']) != 14) {
return $this->show_json(SYS_CODE_FAIL, '手机号码不准确');
}
if ($clue = $this->clues_model->get(['mobile' => $info['mobile']])) {
$this->clues_model->update(array('en_time' => date('Y-m-d H:i:s')), array('mobile' => $info['mobile']));
$log = '重复留资';
$this->addLog(array('clue_id' => $clue['id'], 'type' => 9, 'log' => $log));
return $this->show_json(SYS_CODE_FAIL, '线索已存在,请直接跟进');
}
if (!$info['cf_id'] || !$info['cf2_id']) {
return $this->show_json(SYS_CODE_FAIL, '来源需填写完整');
}
$add = array(
'name' => $info['name'] . $info['sex'],
'mobile' => $info['mobile'],
'cf_id' => $info['cf_id'],
'cf2_id' => $info['cf2_id'],
'brand_id' => $info['brand_id'],
'series_id' => $info['series_id'],
'admin_id' => $this->uid,
'belong_id' => $this->belong,
'c_time' => time(),
'en_time' => date('Y-m-d H:i:s'),
);
$info['province_id'] && $add['province_id'] = $info['province_id'];
$info['city_id'] && $add['city_id'] = $info['city_id'];
$info['county_id'] && $add['county_id'] = $info['county_id'];
$info['biz_id'] && $add['biz_id'] = $info['biz_id'];
$info['biz_id'] && $add['status'] = 1;
$info['biz_id'] && $add['status2'] = 1;
$info['biz_id'] && $add['p_time'] = date('Y-m-d H:i:s');
$info['cf_pid'] && $add['cf_pid'] = $info['cf_pid'];
$ret = $this->clues_model->add($add);
if ($ret) {
$log = '新增线索';
$this->addLog(array('clue_id' => $ret, 'type' => 3, 'log' => $log));
if ($info['text']) {
$log = $info['text'];
sleep(1);
$this->addLog(array('clue_id' => $ret, 'type' => 0, 'log' => $log));
}
if ($info['push'] && $info['biz_id']) {
if ($this->customers_model->get(array('mobile' => $info['mobile'], 'status >' => -1, 'biz_id' => $info['biz_id']))) {
$code = SYS_CODE_FAIL;
$msg = '门店已在跟踪';
} else {
$this->load->helper("order");
$biz = $this->biz_model->get(array('id' => $info['biz_id']));
$add = array(
'rid' => $ret,
'cid' => create_customer_no($biz['county_id']),
'name' => $info['name'] . $info['sex'],
'mobile' => $info['mobile'],
'biz_id' => $info['biz_id'],
'level' => 'H',
'cf_title' => '数字营销中台',
'of_id' => $info['cf_id'],
'of2_id' => $info['cf2_id'],
'brand_id' => $info['brand_id'],
'series_id' => $info['series_id'],
'p_time' => date('Y-m-d H:i:s'),
'c_time' => time(),
);
$info['province_id'] && $add['province_id'] = $info['province_id'];
$info['city_id'] && $add['city_id'] = $info['city_id'];
$info['county_id'] && $add['county_id'] = $info['county_id'];
$info['cf_pid'] && $add['cf_pid'] = $info['cf_pid'];
$customers_id = $this->customers_model->add($add);
if ($customers_id) {
sleep(1);
$this->addLog(array('clue_id' => $ret, 'type' => 3, 'log' => '转交门店跟进'));
$this->clues_model->update(['status' => 1, 'status2' => 2], ['id' => $ret]);
//同步线索日志到客户日志
$this->load->library('receiver/customers_entity');
$this->customers_entity->syn_clues($customers_id, $ret);
//短信通知店长
$this->load->model('app/licheb/app_licheb_users_model');
$where = array('biz_id' => $info['biz_id'], 'status' => 1, 'group_id' => 2);
$res_u = $this->app_licheb_users_model->select($where);
if ($res_u) {
foreach ($res_u as $v) {
if ($info['biz_id'] != 1) {
// b2m_send_sms($v['mobile'], '【好店云】您好,门店新增了1个客户线索。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
ems_sms($v['mobile'], '您好,门店新增了1个客户线索。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
}
}
}
$code = SYS_CODE_SUCCESS;
$msg = '转交成功';
} else {
$code = SYS_CODE_FAIL;
$msg = '转交失败';
}
}
return $this->show_json($code, $msg);
}
return $this->show_json(SYS_CODE_SUCCESS, '新增成功');
} else {
debug_log("[error]# add fail; " . $this->clues_model->db->last_query(), __FUNCTION__, $this->log_dir);
return $this->show_json(SYS_CODE_FAIL, '新增失败');
}
}
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, '请输入内容!');
}
if(strlen($params['buy_time'])){
$buy_time_cn = Receiver_clues_model::BUY_TIME_LIST[$params['buy_time']];
$addData = array(
'clue_id' => $params['id'],
'uid' => $this->uid,
'uname' => $this->username,
'type' => intval($params['type']),
'log' => '修改意向购车周期为:'.$buy_time_cn,
'c_time' => time()
);
$this->mdOplogs->add($addData);
$this->clues_model->update(['buy_time' => $params['buy_time']], ['id' => $params['id']]);
}
$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(),
'cfrom1' => $objWorksheet->getCell('C' . $_row)->getValue(),
'cfrom2' => $objWorksheet->getCell('D' . $_row)->getValue(),
'province_name' => $objWorksheet->getCell('E' . $_row)->getValue(),
'city_name' => $objWorksheet->getCell('F' . $_row)->getValue(),
'county_name' => $objWorksheet->getCell('G' . $_row)->getValue(),
'biz_name' => $objWorksheet->getCell('H' . $_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) {
$statusAry = $this->clues_model->statusAry();
if ($info['status'] == $re['status'] && $info['status2'] == $re['status2']) {
return $this->show_json(SYS_CODE_FAIL, '状态未修改!');
}
$status_name = $statusAry[$re['status']]['name'];
$status_name_up = $statusAry[$info['status']]['name'];
if ($info['status2']) {
$status_name .= '-' . $statusAry[$re['status']]['list'][$re['status2']];
$status_name_up .= '-' . $statusAry[$info['status']]['list'][$info['status2']];
}
$log = '更新状态(' . $status_name . ')为(' . $status_name_up . ')';
$ret = $this->clues_model->update(array('status' => $info['status'], 'status2' => $info['status2']), 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) {
$log = '';
$up = [];
if (!$info['cf2_id']) {
$code = SYS_CODE_FAIL;
$msg = '修改用户信息失败';
} else {
if ($info['name'] != $re['name']) {
$log .= '更新客户姓名 ';
$up['name'] = $info['name'];
}
if ($info['mobile'] != $re['mobile']) {
$log .= '更新客户手机号 ';
$up['mobile'] = $info['mobile'];
if ($this->clues_model->get(['mobile' => $info['mobile']])) {
return $this->show_json(SYS_CODE_FAIL, '线索已存在');
}
}
if ($info['wxgr'] != $re['wxgr']) {
$up['wxgr'] = $info['wxgr'];
}
if ($info['province_id'] != $re['province_id'] || $info['city_id'] != $re['city_id'] || $info['county_id'] != $re['county_id']) {
$log .= '更新客户所在地区 ';
$up['province_id'] = $info['province_id'];
$up['city_id'] = $info['city_id'];
$up['county_id'] = $info['county_id'];
}
if ($info['cf_id'] != $re['cf_id'] || $info['cf2_id'] != $re['cf2_id']) {
$log .= '更新客户来源 ';
$up['cf_id'] = $info['cf_id'];
$up['cf2_id'] = $info['cf2_id'];
}
if ($info['brand_id'] != $re['brand_id'] || $info['series_id'] != $re['series_id']) {
$log .= '更新客户关注车型 ';
$up['brand_id'] = $info['brand_id'];
$up['series_id'] = $info['series_id'];
}
if ($info['cf_pid'] != $re['cf_pid']) {
$up['cf_pid'] = $info['cf_pid'];
}
$ret = $this->clues_model->update($up, 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 || $info['editType'] == 5) {
$cus = $this->customers_model->get(array('mobile' => $re['mobile'], 'status >' => -1, 'biz_id' => $info['biz_id']));
if ($cus = $this->customers_model->get(array('mobile' => $re['mobile'], 'status >' => -1, 'biz_id' => $info['biz_id']))) {
$code = SYS_CODE_FAIL;
$msg = '门店已有该线索';
} else {
if ($clue = $this->clues_model->get(array('mobile' => $re['mobile'], 'status >' => -1, 'biz_id' => $info['biz_id']))) {
$code = SYS_CODE_FAIL;
$msg = '门店已派单';
} else {
$up_data = [
'biz_id' => $info['biz_id'],
'status' => 1,
'status2' => 1,
'p_time' => date('Y-m-d H:i:s'),
];
$info['rec_time'] && $up_data['rec_time'] = $info['rec_time'];
$ret = $this->clues_model->update($up_data, array('id' => $info['id']));
if (!$ret) {
$code = SYS_CODE_FAIL;
$msg = '派单门店失败';
} else {
$msg = $info['editType'] == 3 ? '派单门店成功' : '改派门店成功';
$log = $info['editType'] == 3 ? '派单门店' : '改派门店';
$this->addLog(array('clue_id' => $info['id'], 'type' => 3, 'log' => $log));
}
}
}
} else if ($info['editType'] == 4) {
if ($cus = $this->customers_model->get(array('mobile' => $re['mobile'], 'status >' => -1, 'biz_id' => $re['biz_id']))) {
$code = SYS_CODE_FAIL;
$msg = '门店已在跟踪';
} else {
$this->load->helper("order");
$biz = $this->biz_model->get(array('id' => $re['biz_id']));
$add = array(
'rid' => $re['id'],
'cid' => create_customer_no($biz['county_id']),
'name' => $re['name'],
'province_id' => $re['province_id'],
'city_id' => $re['city_id'],
'county_id' => $re['county_id'],
'mobile' => $re['mobile'],
'biz_id' => $re['biz_id'],
'level' => 'H',
'cf_title' => '数字营销中台',
'of_id' => $re['cf_id'],
'of2_id' => $re['cf2_id'],
'brand_id' => $re['brand_id'],
'series_id' => $re['series_id'],
'p_time' => $re['p_time'],
'cont_time' => $re['cont_time'],
'cf_pid' => $re['cf_pid'],
'c_time' => $re['c_time'],
);
$customers_id = $this->customers_model->add($add);
if ($customers_id) {
$this->addLog(array('clue_id' => $re['id'], 'type' => 3, 'log' => '转交门店跟进'));
$this->clues_model->update(['status' => 1, 'status2' => 2], ['id' => $re['id']]);
//同步线索日志到客户日志
$this->load->library('receiver/customers_entity');
$this->customers_entity->syn_clues($customers_id, $re['id']);
//短信通知店长
$this->load->model('app/licheb/app_licheb_users_model');
$where = array('biz_id' => $re['biz_id'], 'status' => 1, 'group_id' => 2);
$res_u = $this->app_licheb_users_model->select($where);
if ($res_u) {
foreach ($res_u as $v) {
if ($re['biz_id'] != 1) {
// b2m_send_sms($v['mobile'], '【好店云】您好,门店新增了1个客户线索。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
ems_sms($v['mobile'], '您好,门店新增了1个客户线索。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
}
}
}
$msg = '转交成功';
} else {
$code = SYS_CODE_FAIL;
$msg = '转交失败';
}
}
}
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()
{
$id = intval($this->input->post('id'));
$status = $this->input->post('value');
if (!$id || !$status) {
$this->show_json(0, '参数错误');
}
$status_ary = explode('-', $status);
$up_data['status'] = intval($status_ary[0]);
$up_data['status2'] = intval($status_ary[1]);
$this->clues_model->update($up_data, ['id' => $id]);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
//导出数据列表
public function export()
{
list($lists, $count) = $this->lists(1);
$indexs = [
'id' => 'ID',
'name' => '客户姓名',
'mobile' => '手机',
'poi' => '所在地区',
'cf_title' => "来源",
'wxgr' => '是否添加微信',
'biz_name' => '派单门店',
'biz_poi' => '门店所在地区',
'brand_detail' => '关注品牌',
'series_detail' => '关注车型',
'status_name' => '状态',
'p_time' => '分配时间',
'c_time' => '创建时间',
'u_time' => '更新时间'
];
$data = [];
if ($lists) {
foreach ($lists as $key => $val) {
$item = [
'id' => $val['id'],
'name' => $val['name'],
'mobile' => $val['mobile'],
'poi' => $val['poi'],
'cf_title' => $val['cf_title'],
'wxgr' => $val['wxgr'] ? '是' : '否',
'biz_name' => $val['biz_name'],
'biz_poi' => $val['biz_poi'],
'brand_detail' => $val['brand_detail'],
'series_detail' => $val['series_detail'],
'status_name' => $val['status_name'],
'p_time' => $val['p_time'],
'c_time' => date('Y-m-d H:i:s', $val['c_time']),
'u_time' => $val['u_time']
];
$data[] = $item;
}
}
$fileName = '线索列表';
array_unshift($data, $indexs);
$this->load->library('excel');
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
//分配
public function get_adviser()
{
$ids = $this->input->get('ids');
if ($this->input->method() == 'post') {
$city_id = $this->input->post('city_id');
$county_id = $this->input->post('county_id');
$where = [
'status' => 1,
];
$city_id && $where['city_id'] = $city_id;
$county_id && $where['county_id'] = $county_id;
$bizList = $this->biz_model->select($where, '', '', '', 'id,biz_name');
$this->data['bizList'] = $bizList;
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
$this->data['provinces'] = $this->province_ary();
$this->data['ids'] = $ids;
return $this->show_view('receiver/clues/get_adviser');
}
public function edit_adviser()
{
$this->load->library('receiver/clues_entity');
$this->load->library('receiver/customers_entity');
$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>=' => 0]);
if ($clues_row && !$cus_row) {
$add_data = [
'rid' => $val,
'name' => $clues_row['name'],
'mobile' => $clues_row['mobile'],
'biz_id' => $biz_id,
'province_id' => $biz['province_id'],
'city_id' => $biz['city_id'],
'county_id' => $biz['county_id'],
'brand_id' => $clues_row['brand_id'],
'series_id' => $clues_row['series_id'],
'if_driver' => $clues_row['if_driver'],
'cf_title' => '平台分配',
'of_id' => 3,
'of2_id' => 37,
'cf_id' => $clues_row['cf_id'],
'p_time' => date('Y-m-d H:i:s'),
'c_time' => $clues_row['en_time'] == '0000-00-00 00:00:00' ? $clues_row['c_time'] : strtotime($clues_row['en_time']),
'cf_pid' => $clues_row['cf_pid'],
];
$customers_id = $this->customers_model->add($add_data);
if ($customers_id) {
$this->clues_model->update(['status' => 1], ['id' => $val]);
//同步线索日志到客户日志
// $this->customers_entity->syn_clues($customers_id, $val);
$this->customers_entity->add_log($customers_id, $this->uid, $this->username, "平台分配", 0, 'admin');
$this->clues_entity->add_log($val, $this->uid, $this->username, "分配给【{$biz['biz_name']}】商家");
}
}
}
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('ycall', TRUE);
$mobiles = $this->config->item('mobile_list', 'ycall');
$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');
$type = $this->input->post('type');
$status = $this->input->post('status');
$where = array();
if (strlen($pid) > 0) {
$where['pid'] = $pid;
} else {
!$type && $type = 0;
$where['type'] = $type;
}
if (strlen($status) > 0) {
$where['status'] = $status;
} else {
$where["status>-1"] = null;
}
$total = $this->clues_cfrom_model->count($where);
$map = array();
if ($total) {
$orderby = 'sort 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 = $map_province = $map_city = $map_county = $map_biz = [];
$where = array('status' => 1);
$select = 'id, title';
$map_cfrom = $this->clues_cfrom_model->map('title', 'id', $where, '', 0, 0, $select);
$biz_strings = implode("','", array_unique(array_column($lists, 'biz_name')));
if ($biz_strings) $where = ["biz_name in ('{$biz_strings}')" => null];
$biz_strings && $map_biz = $this->biz_model->map('biz_name', 'id', $where, '', 0, 0, 'id,biz_name');
$province_strings = implode("','", array_unique(array_column($lists, 'province_name')));
if ($province_strings) $where = ["province_name in ('{$province_strings}')" => null];
$province_strings && $map_province = $this->area_model->map('province_name', 'province_id', $where, '', 0, 0, 'DISTINCT(province_id),province_name');
$city_strings = implode("','", array_unique(array_column($lists, 'city_name')));
if ($city_strings) $where = ["city_name in ('{$city_strings}')" => null];
$city_strings && $map_city = $this->area_model->map('city_name', 'city_id', $where, '', 0, 0, 'DISTINCT(city_id),city_name');
$county_strings = implode("','", array_unique(array_column($lists, 'county_name')));
if ($county_strings) $where = ["county_name in ('{$county_strings}')" => null];
$county_strings && $map_county = $this->area_model->map('county_name', 'county_id', $where, '', 0, 0, 'DISTINCT(county_id),county_name');
$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;
}
if ($clue = $this->clues_model->get(['mobile' => $v['mobile']])) {
$this->clues_model->update(array('en_time' => date('Y-m-d H:i:s')), array('mobile' => $v['mobile']));
$log = '重复留资';
$this->addLog(array('clue_id' => $clue['id'], 'type' => 9, 'log' => $log));
continue;
}
$cf_id = $map_cfrom[$v['cfrom1']];
$cf2_id = $map_cfrom[$v['cfrom2']];
$temp = array(
'name' => $v['name'],
'mobile' => $v['mobile'],
'cf_id' => $cf_id ? $cf_id : 0,
'cf2_id' => $cf2_id ? $cf_id : 0,
'c_time' => time(),
'en_time' => date('Y-m-d H:i:s'),
'province_id' => $map_province[$v['province_name']] ? $map_province[$v['province_name']] : 0,
'city_id' => $map_city[$v['city_name']] ? $map_city[$v['city_name']] : 0,
'county_id' => $map_county[$v['county_name']] ? $map_county[$v['county_name']] : 0,
'biz_id' => $map_biz[$v['biz_name']] ? $map_biz[$v['biz_name']] : 0,
'belong_id' => $this->belong,
'p_time' => $map_biz[$v['biz_name']] ? date('Y-m-d H:i:s') : 0,
);
$adds[] = $temp;
$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;
}
//获取线索来源
public function get_cfroms()
{
$id = $this->input->get('id');
$where = [
'status' => 1,
'pid' => 0
];
$id && $where['pid'] = $id;
$rows = $this->clues_cfrom_model->select($where, 'id desc', '', '', 'id,title');
$this->data['data'] = $rows;
return $this->show_json(SYS_CODE_SUCCESS);
}
public function get_bizInfo()
{
$id = $this->input->get('id');
$info = $this->biz_model->get(['id' => $id], 'city_id,county_id,address');
$city = $this->area_model->get(['county_id' => $info['county_id']]);
$bizinfo['city_name'] = $city['city_name'];
$bizinfo['county_name'] = $city['county_name'];
$bizinfo['address'] = $info['address'];
$this->data['bizinfo'] = $bizinfo;
return $this->show_json(SYS_CODE_SUCCESS);
}
//分配管理员
public function edit_admins()
{
$ids = $this->input->get_post('ids');
if ($this->input->method() == 'post') {
$ids_array = explode(',', $ids);
$admin_id = $this->input->post('admin_id');
if (is_array($ids_array)) {
foreach ($ids_array as $item) {
$this->clues_model->update(['admin_id' => $admin_id, 'p_time' => date('Y-m-d H:i:s')], ['id' => $item]);
}
}
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
$where = ['status' => 1, 'role_id' => $this->role_id];
$adminLists = $this->sys_admin_model->select($where, 'id desc', 0, 0, 'id,username');
$this->data['adminLists'] = $adminLists;
$this->data['ids'] = $ids;
return $this->show_view('receiver/clues/get_admin');
}
//派单到客户池
public function add_customer()
{
$this->load->helper("order");
$info = $this->input->post('info');
$bizList = $this->input->post('bizList');
if (!count($bizList)) {
return $this->show_json(SYS_CODE_FAIL, '请选择门店');
}
if (!$info['rec_time']) {
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, '线索不存在!');
}
foreach ($bizList as $item) {
$customers = $this->customers_model->get(array('rid' => $re['id'], 'status >' => -1, 'biz_id' => $item['biz_id']));
if ($customers) {
continue;
}
$biz = $this->biz_model->get(array('id' => $item['biz_id']));
$add = array(
'rid' => $re['id'],
'cid' => create_customer_no($biz['county_id']),
'name' => $re['name'],
'province_id' => $biz['province_id'],
'city_id' => $biz['city_id'],
'county_id' => $biz['county_id'],
'mobile' => $re['mobile'],
'biz_id' => $item['biz_id'],
'level' => 'H',
'cf_title' => '数字营销中台',
'of_id' => $re['cf_id'],
'of2_id' => $re['cf2_id'],
'brand_id' => $re['brand_id'],
'series_id' => $re['series_id'],
'p_time' => date('Y-m-d H:i:s'),
'cont_time' => $re['cont_time'],
'cf_pid' => $re['cf_pid'],
'c_time' => $re['c_time'],
'rec_time' => $info['rec_time']
);
$customers_id = $this->customers_model->add($add);
if (!$customers_id) {
continue;
}
//同步线索日志到客户日志
$this->load->library('receiver/customers_entity');
$this->customers_entity->syn_clues($customers_id, $re['id']);
//短信通知店长
$this->load->model('app/licheb/app_licheb_users_model');
$where = array('biz_id' => $biz['biz_id'], 'status' => 1, 'group_id' => 2);
$res_u = $this->app_licheb_users_model->select($where);
if ($res_u) {
foreach ($res_u as $v) {
if ($re['biz_id'] != 1) {
// b2m_send_sms($v['mobile'], '【理车宝】您好,门店新增了1个客户线索。请及时到小程序"理车宝-待分配客户”分配给销售顾问跟进。祝您生活愉快!');
ems_sms($v['mobile'], '您好,门店新增了1个客户线索,请及时到微信小程序"理车宝”进行查看。');
}
}
}
}
$this->clues_model->update(['rec_time' => $info['rec_time'], 'p_time' => date('Y-m-d H:i:s')], ['id' => $re['id']]);
return $this->show_json(SYS_CODE_SUCCESS, '修改成功');
}
/**
* 删除客户派单
* @return bool
*/
public function delete_customer()
{
$info = $this->input->post('info');
$bizId = $this->input->post('bizId');
if (!$bizId) {
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, '线索不存在!');
}
$this->customers_model->update(array('status' => -1), ['rid' => $re['id'], 'biz_id' => $bizId]);
return $this->show_json(SYS_CODE_SUCCESS, '修改成功');
}
public function lists_enroll()
{
$params = $this->input->get();
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
$list = [];
$id = intval($params['id']);
$clues = $this->clues_model->get(['id' => $id]);
if (!$clues) {
return $this->show_json(SYS_CODE_FAIL, '线索不存在!');
}
$where = ['mobile' => $clues['mobile']];
$count = $this->receiver_enroll_model->count($where);
if ($count) {
$rows = $this->receiver_enroll_model->select($where, 'id desc', $page, $size);
$brands = $this->auto_brand_model->get_map_by_ids(array_column($rows, 'brand_id'));
$series = $this->auto_series_model->get_map_by_ids(array_column($rows, 'series_id'));
foreach ($rows as $key => $value) {
$setValue = $value;
$setValue['mobile'] = $value['mobile'];
$setValue['c_time'] = date('Y-m-d H:i:s');
$brandName = $brands[$value['brand_id']] ? $brands[$value['brand_id']][0]['name'] : '';
$seriesName = $series[$value['series_id']] ? $series[$value['series_id']][0]['name'] : '';
$cfRow = $this->clues_cfrom_model->get(['id' => $value['cf2_id']]);
$cfrom2 = $cfRow['title'] ?: '';
$setValue['brandName'] = "{$brandName} {$seriesName}";
$setValue['cfrom2'] = $cfrom2;
$list[] = $setValue;
}
}
$this->data['list'] = $list;
$this->data['count'] = $count;
return $this->show_json(SYS_CODE_SUCCESS);
}
}