382 lines
17 KiB
PHP
382 lines
17 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/pingan/BaseController.php';
|
|
|
|
class Clues extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('area_model');
|
|
$this->load->model('agent/pingan/pingan_users_model');
|
|
$this->load->model('agent/auto_product_model', 'autoProduct');
|
|
$this->load->model('receiver/receiver_clues_model', 'clues_model');
|
|
$this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs');
|
|
$this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model');
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs');
|
|
$this->load->model('receiver/receiver_yx_model', 'mdReceiverXz');
|
|
$this->load->model('receiver/receiver_enroll_model');
|
|
$this->clues_model->set_db('ssdb');
|
|
$this->clues_cfrom_model->set_db('ssdb');
|
|
$this->auto_brand_model->set_db('ssdb');
|
|
$this->auto_series_model->set_db('ssdb');
|
|
$this->mdOplogs->set_db('ssdb');
|
|
$this->mdReceiverXz->set_db('ssdb');
|
|
$this->mdOplogs->set_db('ssdb');
|
|
$this->receiver_enroll_model->set_db('ssdb');
|
|
}
|
|
|
|
public function page_get()
|
|
{
|
|
$params = $this->input_param();
|
|
$page = $params['page'] ?: 1;
|
|
$limit = $params['limit'] ?: 10;
|
|
$sort_order = 'id desc';
|
|
$statusList = $list = [];
|
|
foreach ($this->clues_model->statusAry() as $key => $value) {
|
|
$statusList[$key] = $value['name'];
|
|
}
|
|
$where = $this->buildWhere();
|
|
$count = $this->clues_model->count($where);
|
|
if ($count) {
|
|
$rows = $this->clues_model->select($where, $sort_order, $page, $limit);
|
|
$users = $this->pingan_users_model->get_map_by_ids(array_column($rows, 'pingan_user_id'), 'id,userCode,username,centerNumber,orgName');
|
|
//所在地区
|
|
$map_area_county = [];
|
|
$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, 0, 'county_id,province_name,city_name,county_name');
|
|
}
|
|
foreach ($rows as $v) {
|
|
$belongUserName = $users[$v['pingan_user_id']] ? $users[$v['pingan_user_id']][0] : '';
|
|
// $cfRow = $this->clues_cfrom_model->get(['id' => $v['cf2_id']]);
|
|
// $cfrom2 = $cfRow['title'] ?: '';
|
|
// if ($v['cf2_id'] == self::CF2_PRODUCT) {
|
|
// $product = $this->autoProduct->get(['id' => $v['out_id']]);
|
|
// if ($product) {
|
|
// $cfrom2 .= '-' . $product['title'];
|
|
// }
|
|
// };
|
|
$brandList = $this->receiver_enroll_model->getBrandsByMobile($v['mobile']);
|
|
$poi = '';
|
|
if ($v['county_id']) {
|
|
$area = $map_area_county[$v['county_id']][0];
|
|
$poi = "{$area['province_name']}-{$area['city_name']}-{$area['county_name']}";
|
|
}
|
|
$temp = [
|
|
'id' => $v['id'],
|
|
'sid' => $v['sid'],
|
|
'name' => $v['name'],
|
|
'mobile' => mobile_asterisk($v['mobile']),
|
|
'statusCn' => $statusList[$v['status']],
|
|
// 'cfrom' => $cfrom2,
|
|
// 'brandSeries' => "$brandName-$seriesName",
|
|
'enTime' => $v['en_time'],
|
|
'belongUserName' => $belongUserName,
|
|
'brandList' => $brandList,
|
|
'poi' => $poi
|
|
];
|
|
$list[] = $temp;
|
|
}
|
|
}
|
|
$data = ['list' => $list, 'count' => $count, 'statusList' => $statusList];
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
/**
|
|
* 详情
|
|
* @return void
|
|
*/
|
|
public function index_get()
|
|
{
|
|
$params = $this->input_param();
|
|
$id = intval($params['id']);
|
|
if (!$id) {
|
|
$this->return_json('非法参数!');
|
|
}
|
|
$re = $this->clues_model->get(array('id' => $id));
|
|
if (!$re || empty($re)) {
|
|
$this->return_json('线索不存在!');
|
|
}
|
|
$dataInfo = $re;
|
|
$dataInfo['mobile'] = mobile_asterisk($dataInfo['mobile']);
|
|
$dataInfo['c_time'] = date('Y-m-d H:i', $re['c_time']);
|
|
$selectedCar = ['brandId' => $re['brand_id'], 'seriesId' => $re['series_id'], 'modelId' => ''];
|
|
$dataInfo['selectedCar'] = $selectedCar;
|
|
$dataInfo['provinceCity'] = [$re['province_id'], $re['city_id'], $re['county_id']];
|
|
$cfRow = $this->clues_cfrom_model->get(['id' => $re['cf2_id']]);
|
|
$cfrom2 = $cfRow['title'] ?: '';
|
|
if ($re['cf2_id'] == self::CF2_PRODUCT) {
|
|
$product = $this->autoProduct->get(['id' => $re['out_id']]);
|
|
if ($product) {
|
|
$cfrom2 .= '-' . $product['title'];
|
|
}
|
|
};
|
|
$dataInfo['cfrom'] = $cfrom2;
|
|
$dataInfo['buyTimeList'] = Receiver_clues_model::BUY_TIME_LIST;
|
|
$this->return_response($dataInfo);
|
|
}
|
|
|
|
/**
|
|
* 操作日志
|
|
* @return void
|
|
*/
|
|
public function opt_get()
|
|
{
|
|
$params = $this->input_param();
|
|
$page = $params['page'] ?: 1;
|
|
$limit = $params['limit'] ?: 10;
|
|
$list = [];
|
|
$params = $this->input_param();
|
|
$id = intval($params['id']);
|
|
if (!$id) {
|
|
$this->return_json('非法参数!');
|
|
}
|
|
$where = ['clue_id' => $id];
|
|
$count = $this->mdOplogs->count($where);
|
|
if ($count) {
|
|
$resLogs = $this->mdOplogs->select($where, 'c_time desc', $page, $limit);
|
|
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;
|
|
$list[] = $setValue;
|
|
}
|
|
}
|
|
$data = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
public function addLog_post()
|
|
{
|
|
$params = $this->input_param();
|
|
if (!$params['id']) {
|
|
$this->return_json('参数错误!');
|
|
}
|
|
if (!$params['content']) {
|
|
$this->return_json('请输入内容!');
|
|
}
|
|
if (strlen($params['buy_time'])) {
|
|
$buy_time_cn = Receiver_clues_model::BUY_TIME_LIST[$params['buy_time']];
|
|
$addData = array(
|
|
'clue_id' => $params['id'],
|
|
'pingan_user_id' => $_SESSION['id'],
|
|
'uname' => $_SESSION['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'],
|
|
'pingan_user_id' => $_SESSION['id'],
|
|
'uname' => $_SESSION['username'],
|
|
'log' => $params['content'],
|
|
'c_time' => time()
|
|
);
|
|
$id = $this->mdOplogs->add($addData);
|
|
if ($id) {
|
|
$this->return_response();
|
|
} else {
|
|
$this->return_json('添加失败!');
|
|
}
|
|
}
|
|
|
|
//搜索条件
|
|
public function search_get()
|
|
{
|
|
$belongList = $statusList = [];
|
|
$sList = $this->clues_model->statusAry();
|
|
foreach ($sList as $key => $value) {
|
|
$statusList[] = [
|
|
'value' => $key,
|
|
'label' => $value['name'],
|
|
];
|
|
}
|
|
$belongList = $this->pingan_users_model->levelListTree($_SESSION['id'], $_SESSION['groupType']);
|
|
$data = ['statusList' => $statusList, 'belongList' => $belongList];
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
private function buildWhere()
|
|
{
|
|
$params = $this->input_param();
|
|
$title = $this->input_param('title');
|
|
$sid = trim($this->input_param('sid'));
|
|
$brands = $this->input_param('brands');
|
|
$status = $this->input_param('status');
|
|
$citys = $this->input_param('citys');
|
|
// $belong = $this->input_param('belong');
|
|
$where = [
|
|
'app_id' => self::APP_ID
|
|
];
|
|
if ($_SESSION['groupType'] == Pingan_users_model::GROUP_TYPE_TEAM
|
|
|| $_SESSION['groupType'] == Pingan_users_model::GROUP_TYPE_TEAM_CONTACT) {
|
|
$where['team_id'] = $_SESSION['id'];
|
|
} elseif ($_SESSION['groupType'] == Pingan_users_model::GROUP_TYPE_DEP) {
|
|
$where['dep_id'] = $_SESSION['id'];
|
|
} elseif ($_SESSION['groupType'] == Pingan_users_model::GROUP_TYPE_AREA) {
|
|
$where['area_id'] = $_SESSION['id'];
|
|
} elseif (in_array($_SESSION['groupType'],
|
|
[Pingan_users_model::GROUP_TYPE_ORG_CONTACT])) { //机构对接人
|
|
$orgName = $_SESSION['orgName'];
|
|
$areaUserIds = $this->pingan_users_model->select(['orgName' => $orgName, 'groupType' => Pingan_users_model::GROUP_TYPE_AREA], '', 0, 0, 'id');
|
|
$areaUserIdsString = implode(',', $areaUserIds);
|
|
!$areaUserIdsString && $areaUserIdsString = 0;
|
|
$where["area_id in ({$areaUserIdsString})"] = null;
|
|
}elseif($_SESSION['groupType'] == Pingan_users_model::GROUP_TYPE_CENTER_CONTACT){ //中心对接人
|
|
$centerNumber = $_SESSION['centerNumber'];
|
|
$areaUserIds = $this->pingan_users_model->select(['centerNumber' => $centerNumber, 'groupType' => Pingan_users_model::GROUP_TYPE_AREA], '', 0, 0, 'id');
|
|
$areaUserIdsString = implode(',', $areaUserIds);
|
|
!$areaUserIdsString && $areaUserIdsString = 0;
|
|
$where["area_id in ({$areaUserIdsString})"] = null;
|
|
} elseif ($_SESSION['groupType'] == Pingan_users_model::GROUP_TYPE_ATTEND) {
|
|
$where['pingan_user_id'] = $_SESSION['id'];
|
|
} else { //其它角色看到所有数据
|
|
|
|
}
|
|
$title && $where['mobile LIKE "%' . trim($title) . '%"'] = null;
|
|
$sid && $where['sid LIKE "%' . trim($sid) . '%"'] = null;
|
|
if ($brands) {
|
|
$seriesIdArr = [];
|
|
foreach ($brands as $item) {
|
|
$itemArray = json_decode($item, true);
|
|
$itemArray[1] && $seriesIdArr[] = $itemArray[1];
|
|
}
|
|
$seriesIdString = implode(',', $seriesIdArr);
|
|
$seriesIdString && $where["series_id in ($seriesIdString)"] = null;
|
|
}
|
|
strlen($status) && $where['status'] = intval($status);
|
|
$citys && $where['city_id'] = $citys[1];
|
|
if ($params['dateRange'][0] && $params['dateRange'][1]) {
|
|
$where['en_time >='] = $params['dateRange'][0] . ' 00:00:00';
|
|
$where['en_time <='] = $params['dateRange'][1] . ' 23:59:59';
|
|
}
|
|
if ($params['userCode']) {
|
|
$user = $this->pingan_users_model->get(["userCode like '%{$params['userCode']}%'" => null], 'id');
|
|
!isset($where['pingan_user_id']) && $where['pingan_user_id'] = $user['id'] ?: 0;
|
|
}
|
|
if ($params['centerNumber']) {
|
|
$users = $this->pingan_users_model->select(['centerNumber' => $params['centerNumber'], 'status' => Pingan_users_model::STATUS_NORMAL], '', '', '', 'id');
|
|
$userIdArray = array_column($users, 'id');
|
|
$userIds = $userIdArray ? implode(',', $userIdArray) : 0;
|
|
$where['pingan_user_id in (' . $userIds . ')'] = null;
|
|
}
|
|
if ($params['orgName']) {
|
|
$users = $this->pingan_users_model->select(['orgName' => $params['orgName'], 'status' => Pingan_users_model::STATUS_NORMAL], '', '', '', 'id');
|
|
$userIdArray = array_column($users, 'id');
|
|
$userIds = $userIdArray ? implode(',', $userIdArray) : 0;
|
|
$where['pingan_user_id in (' . $userIds . ')'] = null;
|
|
}
|
|
return $where;
|
|
}
|
|
|
|
/**
|
|
* 留资记录
|
|
* @return void
|
|
*/
|
|
public function enroll_get()
|
|
{
|
|
$params = $this->input_param();
|
|
$page = $params['page'] ?: 1;
|
|
$limit = $params['limit'] ?: 10;
|
|
$list = [];
|
|
$params = $this->input_param();
|
|
$id = intval($params['id']);
|
|
$clues = $this->clues_model->get(['id' => $id]);
|
|
if (!$clues) {
|
|
$this->return_json('非法参数!');
|
|
}
|
|
$where = ['mobile' => $clues['mobile']];
|
|
$count = $this->receiver_enroll_model->count($where);
|
|
if ($count) {
|
|
$rows = $this->receiver_enroll_model->select($where, 'id desc', $page, $limit);
|
|
$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'] = mobile_asterisk($value['mobile']);
|
|
$setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']);
|
|
$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'] ?: '';
|
|
if ($value['cf2_id'] == self::CF2_PRODUCT) {
|
|
$product = $this->autoProduct->get(['id' => $value['out_id']]);
|
|
if ($product) {
|
|
$cfrom2 .= '-' . $product['title'];
|
|
}
|
|
};
|
|
$setValue['brandName'] = "{$brandName} {$seriesName}";
|
|
$setValue['cfrom2'] = $cfrom2;
|
|
$list[] = $setValue;
|
|
}
|
|
}
|
|
$data = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($data);
|
|
}
|
|
|
|
public function index_put()
|
|
{
|
|
$params = $this->input_param();
|
|
if (!$params['name']) {
|
|
$this->return_json('请填写客户姓名!');
|
|
}
|
|
$row = $this->clues_model->get(['id' => $params['id']]);
|
|
if (!$row) {
|
|
$this->return_json('数据不存在!');
|
|
}
|
|
$provinceCity = $params['provinceCity'];
|
|
$update = [
|
|
'name' => $params['name'],
|
|
'province_id' => $provinceCity[0] ?: 0,
|
|
'city_id' => $provinceCity[1] ?: 0,
|
|
'county_id' => $provinceCity[2] ?: 0,
|
|
];
|
|
$result = $this->clues_model->update($update, ['id' => $row['id']]);
|
|
if (!$result) {
|
|
$this->return_json('保存失败!');
|
|
}
|
|
//添加日志
|
|
$log = '';
|
|
if ($update['name'] != $row['name']) {
|
|
$log .= '更新客户姓名 ';
|
|
}
|
|
if ($update['province_id'] != $row['province_id'] || $update['city_id'] != $row['city_id'] || $update['county_id'] != $row['county_id']) {
|
|
$log .= '更新客户所在地区 ';
|
|
}
|
|
if ($log) {
|
|
$addData = array(
|
|
'clue_id' => $row['id'],
|
|
'pingan_user_id' => $_SESSION['id'],
|
|
'uname' => $_SESSION['username'],
|
|
'type' => 0,
|
|
'log' => $log,
|
|
'c_time' => time()
|
|
);
|
|
$this->mdOplogs->add($addData);
|
|
}
|
|
$this->return_response();
|
|
}
|
|
}
|
|
|