329 lines
12 KiB
PHP
329 lines
12 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: xuxb
|
|
* Date: 2021/7/26
|
|
* Time: 11:20
|
|
*/
|
|
class Customer extends HD_Controller
|
|
{
|
|
private $searchTpAry = array('mobile' => '客户手机号', 'name' => '客户姓名');
|
|
|
|
protected $log_dir;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('receiver/receiver_customers_model', 'customers_model');
|
|
$this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
|
|
$this->load->model('receiver/receiver_xz_model');
|
|
$this->load->model('app/licheb/app_licheb_users_model');
|
|
$this->load->model("biz/biz_model");
|
|
$this->log_dir = 'receiver_' . get_class($this);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
$status_arr = $this->customers_model->get_status();
|
|
unset($status_arr['-1']);
|
|
$params = $this->input->get();
|
|
!$params['city_id'] && $params['city_id'] = '';
|
|
!$params['county_id'] && $params['county_id'] = '';
|
|
!$params['city_id'] && $params['city_id'] = '';
|
|
!$params['county_id'] && $params['county_id'] = '';
|
|
!$params['biz_id'] && $params['biz_id'] = '';
|
|
!$params['cf_title'] && $params['cf_title'] = '';
|
|
|
|
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
|
|
$where = array('status>=0' => null);
|
|
if ($params['title']) {
|
|
$where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
|
|
}
|
|
!$params['search_tp'] && $params['search_tp'] = 'mobile';
|
|
|
|
//创建时间
|
|
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');
|
|
}
|
|
}
|
|
strlen($params['status']) && $where["status"] = $params['status'];
|
|
$params['city_id'] && $where['city_id'] = $params['city_id'];
|
|
$params['county_id'] && $where['county_id'] = $params['county_id'];
|
|
$params['biz_id'] && $where['biz_id'] = $params['biz_id'];
|
|
$params['cf_title'] && $where['cf_title'] = $params['cf_title'];
|
|
|
|
$count = $this->customers_model->count($where);
|
|
$lists = [];
|
|
if ($count) {
|
|
$fileds = 'id,name,mobile,cf_title,c_time,admin_id,status,biz_id';
|
|
$rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds);
|
|
//获取销售员
|
|
$admin_id_arr = array_unique(array_column($rows, 'admin_id'));
|
|
$admin_id_arr && $admin_rows = $this->app_licheb_users_model->get_map_by_ids($admin_id_arr, 'id,uname');
|
|
//获取门店
|
|
$biz_id_arr = array_unique(array_column($rows, 'biz_id'));
|
|
$biz_id_arr && $biz_rows = $this->biz_model->get_map_by_ids($biz_id_arr, 'id,biz_name');
|
|
foreach ($rows as $key => $val) {
|
|
$lists[] = array(
|
|
'id' => $val['id'],
|
|
'name' => $val['name'],
|
|
'mobile' => $val['mobile'],
|
|
'mobile_sub' => $val['mobile'] ? substr_replace($val['mobile'], '*****', 0, 5) : '',
|
|
'cf_title' => $val['cf_title'],
|
|
'status_name' => $status_arr[$val['status']],
|
|
'admin_name' => isset($admin_rows[$val['admin_id']]) ? $admin_rows[$val['admin_id']][0]['uname'] : '',
|
|
'biz_name' => isset($biz_rows[$val['biz_id']]) ? $biz_rows[$val['biz_id']][0]['biz_name'] : '',
|
|
'c_time' => $val['c_time'] > 0 ? date('Y-m-d H:i:s', $val['c_time']) : '',
|
|
);
|
|
}
|
|
}
|
|
$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/customer/lists', true);
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
$id = $this->input->get('id');
|
|
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_series_model');
|
|
|
|
$row = $this->customers_model->get(array('id' => $id));
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户不存在!');
|
|
}
|
|
|
|
$if_driver = 1 == $row['if_driver'] ? '是' : '否';
|
|
$is_top = 1 == $row['is_top'] ? '是' : '否';
|
|
$car_json = json_decode($row['car_json'], true);
|
|
$side = $car_json['version']['title'] ? $car_json['version']['title'] : '';
|
|
$color = $car_json['color']['title'] ? $car_json['color']['title'] : '';
|
|
|
|
$row_biz = $this->biz_model->get(array('id' => $row['biz_id']));
|
|
$row_brand = $this->auto_brand_model->get(array('id' => $row['brand_id']), 'name');
|
|
$row_seriy = $this->auto_series_model->get(array('id' => $row['s_id']), 'name');
|
|
//获取销售员
|
|
$row_admin = $this->app_licheb_users_model->get(array('id' => $row['admin_id']), 'id,uname');
|
|
|
|
//操作日志
|
|
$rows_log = $this->customer_oplogs_model->select(array('customer_id' => $id), 'c_time desc', 0, 0);
|
|
|
|
//用户信息
|
|
$info = array(
|
|
'id' => $row['id'],
|
|
'name' => $row['name'],
|
|
'mobile' => $row['mobile'] ? substr_replace($row['mobile'], '*****', 0, 5) : '',
|
|
'cf_title' => $row['cf_title'],
|
|
'c_time' => date('Y-m-d H:i:s', $row['c_time']),
|
|
'status' => $row['status'],
|
|
);
|
|
|
|
//到店信息
|
|
$toshop = array(
|
|
array(
|
|
array('title' => '门店', 'value' => $row_biz['biz_name']),
|
|
array('title' => '试驾', 'value' => $if_driver),
|
|
array('title' => '到店次数', 'value' => $row['a_num']),
|
|
array('title' => '试驾次数', 'value' => $row['t_num']),
|
|
),
|
|
array(
|
|
array('title' => '品牌', 'value' => $row_brand['name']),
|
|
array('title' => '车系', 'value' => $row_seriy['name']),
|
|
array('title' => '车型', 'value' => $side),
|
|
array('title' => '颜色', 'value' => $color),
|
|
),
|
|
array(
|
|
array('title' => '分配时间', 'value' => $row['p_time']),
|
|
array('title' => '最后联系', 'value' => $row['cont_time']),
|
|
array('title' => '预计购买', 'value' => $row['buy_time']),
|
|
),
|
|
array(
|
|
array('title' => '置顶', 'value' => $is_top),
|
|
array('title' => '销售员', 'value' => $row_admin['uname']),
|
|
),
|
|
);
|
|
|
|
//操作日志
|
|
$logs = array();
|
|
foreach ($rows_log as $key => $value) {
|
|
$rec_text = $rec_url = '';
|
|
if ($value['type'] == 2) {
|
|
$rec_row = $this->receiver_xz_model->get(['id' => $value['log']], 'rec_url,duration');
|
|
if ($rec_row['duration']) {
|
|
$rec_row['rec_url'] && $rec_url = $rec_row['rec_url'];
|
|
!$rec_row['rec_url'] && $rec_text = '录音暂未生成';
|
|
} else {
|
|
$rec_text = '未接通';
|
|
}
|
|
}
|
|
$logs[] = array(
|
|
'uname' => $value['uname'],
|
|
'log' => $value['log'],
|
|
'rec_url' => $rec_url,
|
|
'rec_text' => $rec_text,
|
|
'type_name' => $this->customer_oplogs_model->typeAry()[$value['type']],
|
|
'c_time' => date('Y-m-d H:i', $value['c_time'])
|
|
);
|
|
}
|
|
|
|
//状态值,-1不显示
|
|
$statusAry = $this->customers_model->get_status();
|
|
unset($statusAry['-1']);
|
|
|
|
$this->data['statusAry'] = $statusAry;
|
|
$this->data['info'] = $info;
|
|
$this->data['toshop'] = $toshop;
|
|
$this->data['logs'] = $logs;
|
|
$this->data['_title'] = '客户详情';
|
|
return $this->show_view('receiver/customer/get', true);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
// TODO: Implement add() method.
|
|
}
|
|
|
|
/**
|
|
* 新增日志
|
|
* @return bool
|
|
*/
|
|
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(
|
|
'customer_id' => $params['id'],
|
|
'uid' => $this->uid,
|
|
'uname' => $this->username,
|
|
'type' => intval($params['type']),
|
|
'log' => $params['log'],
|
|
'c_time' => time()
|
|
);
|
|
$id = $this->customer_oplogs_model->add($addData);
|
|
if ($id) {
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
} else {
|
|
debug_log("[error]" . $this->customer_oplogs_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '添加失败');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
* @return bool
|
|
*/
|
|
public function edit()
|
|
{
|
|
$info = $this->input->post('info');
|
|
if (!$info) {
|
|
return $this->show_json(SYS_CODE_FAIL, '非法参数!');
|
|
}
|
|
|
|
$row = $this->customers_model->get(array('id' => $info['id']));
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户信息不存在!');
|
|
}
|
|
|
|
$msg = '修改成功';
|
|
$code = SYS_CODE_SUCCESS;
|
|
if ($info['editType'] == 1) {
|
|
//更新状态
|
|
$statuAry = $this->customers_model->get_status();
|
|
$status_name = $statuAry[$row['status']];
|
|
$status_name_up = $statuAry[$info['status']];
|
|
$log = '更新状态(' . $status_name . ')为(' . $status_name_up . ')';
|
|
$ret = $this->customers_model->update(array('status' => $info['status']), array('id' => $info['id']));
|
|
if (!$ret) {
|
|
debug_log("[error]" . $this->customers_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
$code = SYS_CODE_FAIL;
|
|
$msg = '修改状态失败';
|
|
} else {
|
|
$msg = '修改状态成功';
|
|
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log));
|
|
}
|
|
} else if ($info['editType'] == 2) {
|
|
//更新客户信息
|
|
if ($info['name'] == $row['name']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户姓名未修改!');
|
|
}
|
|
$log = '更新客户姓名(' . $row['name'] . ')为(' . $info['name'] . ')';
|
|
$ret = $this->customers_model->update(array('name' => $info['name']), array('id' => $info['id']));
|
|
if (!$ret) {
|
|
debug_log("[error]" . $this->customers_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
$code = SYS_CODE_FAIL;
|
|
$msg = '修改用户信息失败';
|
|
} else {
|
|
$msg = '修改用户信息成功';
|
|
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log));
|
|
}
|
|
}
|
|
|
|
return $this->show_json($code, $msg);
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
// TODO: Implement del() method.
|
|
}
|
|
|
|
public function batch()
|
|
{
|
|
// TODO: Implement batch() method.
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
// TODO: Implement export() method.
|
|
}
|
|
|
|
/**
|
|
* 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(
|
|
'customer_id' => $ary['customer_id'],
|
|
'uid' => $this->uid,
|
|
'uname' => $this->username,
|
|
'type' => intval($ary['type']),
|
|
'log' => $ary['log'],
|
|
'cf_platform' => 'admin',
|
|
'c_time' => time()
|
|
);
|
|
$id = $this->customer_oplogs_model->add($addData);
|
|
}
|
|
return $id;
|
|
}
|
|
|
|
}
|