Files
liche/admin/controllers/receiver/Customer.php
T
2022-12-22 09:22:50 +08:00

658 lines
29 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' => '客户姓名');
private $searchTimeAry = array('c_time' => '创建时间', 'p_time' => '分配时间', 'cont_time' => '最后联系时间', 'u_time' => '最后操作时间'
, 'dt_time' => '首次到店时间', 'order_time' => '下单时间');
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_customer_tag_model', 'mdCustomerTag');
$this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
$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_xz_model');
$this->load->model('app/licheb/app_licheb_users_model');
$this->load->model("biz/biz_model");
$this->load->model('auto/auto_brand_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();
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
$where = $this->get_where($params);
$count = $this->customers_model->count($where);
$lists = [];
$offlineSources = $this->customers_model->offlineSources();
$wxqyAry = $this->customers_model->wxqyAry();
if ($count) {
$fileds = 'id,name,mobile,cf_title,cont_time,admin_id,status,biz_id,level,of_id,of2_id,wxqy';
$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) {
if (SUPER_ADMIN == $this->role || $this->role == 35) {
$mobile_sub = $val['mobile'];
} else {
$mobile_sub = $val['mobile'] ? substr_replace($val['mobile'], '*****', 0, 5) : '';
}
$of_title = '';
if ($val['of_id']) {
$of_ary = $offlineSources[$val['of_id']];
$of_title = $of_ary['name'];
$val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']];
}
$lists[] = array(
'id' => $val['id'],
'name' => $val['name'],
'mobile' => $val['mobile'],
'mobile_sub' => $mobile_sub,
'level' => $val['level'],
'of_title' => $of_title,
'of2_id' => $val['of2_id'],
'status_name' => $status_arr[$val['status']],
'wxqy_name' => $wxqyAry[$val['wxqy']],
'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'] : '',
'cont_time' => $val['cont_time'] != '0000-00-00 00:00:00' ? $val['cont_time'] : '',
);
}
}
//渠道经理
$qdjl_lists = $this->app_licheb_users_model->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0'), 'id desc', 0, 0, 'id,uname as name');
$show_info['levelAry'] = $this->customers_model->get_sdata('level');
$show_info['offlineSourcesAry'] = $offlineSources;
$show_info['wxqyAry'] = $wxqyAry;
$this->data['show_info'] = $show_info;
$this->data['lists'] = $lists;
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
$this->data['searchTpAry'] = $this->searchTpAry;
$this->data['searchTimeAry'] = $this->searchTimeAry;
$this->data['params'] = $params;
$this->data['status_arr'] = $status_arr;
$this->data['qdjl_lists'] = $qdjl_lists;
$this->data['export_button'] = $this->uid == 1 ? 1 : 0;
$this->data['_title'] = '客户列表';
return $this->show_view('receiver/customer/lists', true);
}
private function get_where(&$params){
!$params['biz_id'] && $params['biz_id'] = '';
!$params['cf_title'] && $params['cf_title'] = '';
!$params['qdjl_id'] && $params['qdjl_id'] = '';
!$params['level'] && $params['level'] = '';
!$params['of_id'] && $params['of_id'] = '';
!$params['of2_id'] && $params['of2_id'] = '';
!$params['biz_type'] && $params['biz_type'] = '';
$where = array('status>=0' => null);
if ($_SESSION['admin_info']['biz_id']) {
$biz_ids = implode(',', $_SESSION['admin_info']['biz_id']);
if ($params['biz_type']) {
$where["biz_id in(select id from lc_biz where type={$params['biz_type']} and id in({$biz_ids}))"] = null;
} else {
$where["biz_id in ($biz_ids)"] = null;
}
} else if ($params['biz_type']) {
$where["biz_id in(select id from lc_biz where type={$params['biz_type']})"] = null;
}
if (false == strpos($_SERVER['HTTP_HOST'], 'dev')) {//dev时不限制
$where['biz_id<>'] = 1;
$where['brand_id<>'] = 3;
}
if ($params['title']) {
$where["{$params['search_tp']} like '%{$params['title']}%'"] = null;
}
if ($params['level']) {
$where['level'] = $params['level'];
}
if ($params['of_id']) {
$where['of_id'] = $params['of_id'];
}
if ($params['of2_id']) {
$where['of2_id'] = $params['of2_id'];
}
if (strlen($params['wxqy'])) {
$where["wxqy"] = $params['wxqy'];
} else {
$params['wxqy'] = '';
}
!$params['search_tp'] && $params['search_tp'] = 'mobile';
strlen($params['status']) && $where["status"] = $params['status'];
if ($params['qdjl_id']) {
$where["biz_id in(select biz_id from lc_app_licheb_channel_biz where uid={$params['qdjl_id']})"] = null;
}
//销售员筛选
if ($params['admin_id']) {
$where['admin_id'] = $params['admin_id'];
} else 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;
}
!$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['admin_id'] && $params['admin_id'] = '';
if ($params['c_time']) {
$c_time = explode(' ~ ', $params['c_time']);
$c_time[0] && $where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
$c_time[1] && $where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
}
if ($params['p_time']) {
$p_time = explode(' ~ ', $params['p_time']);
$p_time[0] && $where["p_time >="] = $p_time[0] . ' 00:00:00';
$p_time[1] && $where["p_time <="] = $p_time[1] . ' 23:59:59';
}
if ($params['cont_time']) {
$cont_time = explode(' ~ ', $params['cont_time']);
$cont_time[0] && $where["cont_time >="] = $cont_time[0] . ' 00:00:00';
$cont_time[1] && $where["cont_time <="] = $cont_time[1] . ' 23:59:59';
}
if ($params['u_time']) {
$u_time = explode(' ~ ', $params['u_time']);
$u_time[0] && $where["u_time >="] = $u_time[0] . ' 00:00:00';
$u_time[1] && $where["u_time <="] = $u_time[1] . ' 23:59:59';
}
if ($params['dt_time']) {
$dt_time = explode(' ~ ', $params['dt_time']);
$dt_time[0] && $where["dt_time >="] = $dt_time[0] . ' 00:00:00';
$dt_time[1] && $where["dt_time <="] = $dt_time[1] . ' 23:59:59';
}
if ($params['order_time']) {
$order_time = explode(' ~ ', $params['order_time']);
$order_time[0] && $where["order_time >="] = $order_time[0] . ' 00:00:00';
$order_time[1] && $where["order_time <="] = $order_time[1] . ' 23:59:59';
}
if ($params['cfrom_id'] || $params['cfrom_id2']) {
if ($params['cfrom_id'] == 24) {
$where['cf_id'] = 24;
$params['cfrom_id2'] && $where['t_id'] = $params['cfrom_id2'];
} else {
if ($params['cfrom_id2']) {
$where['cf_id'] = $params['cfrom_id2'];
} else {
$cf_rows = $this->clues_cfrom_model->select(['pid' => $params['cfrom_id']], '', '', '', 'id');
$cf_ids = array_column($cf_rows, 'id');
$cf_ids[] = $params['cfrom_id'];
$cf_str_ids = implode(',', array_filter($cf_ids));
$cf_str_ids && $where["cf_id in ({$cf_str_ids})"] = null;
}
}
}
return $where;
}
public function get()
{
$id = $this->input->get('id');
$this->load->model('auto/auto_series_model');
$this->load->model('auto/auto_attr_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);
//$version = $this->auto_attr_model->get(['id' => $car_json['v_id']], 'title');
//$color = $this->auto_attr_model->get(['id' => $car_json['c_id']], 'title');
//$side = $version ? $version['title'] : '';
//$color = $color ? $color['title'] : '';
//$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_biz = $this->biz_model->get(array('id' => $row['biz_id']));
//获取销售员
$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), 'id desc', 0, 0);
//用户信息
if (SUPER_ADMIN == $this->role || 35 == $this->role) {
$mobile_sub = $row['mobile'];
} else {
$mobile_sub = $row['mobile'] ? substr_replace($row['mobile'], '*****', 0, 5) : '';
}
//获取分销用户
$cf_user = '';
$clues = $this->clues_model->get(['id' => $row['rid']], 'recommend_id');
if ($clues['recommend_id']) {
$this->load->model('app/liche/app_liche_users_model');
$user = $this->app_liche_users_model->get(['id' => $clues['recommend_id']], 'id,nickname,up_uid');
$user['up_uid'] && $up_user = $this->app_liche_users_model->get(['id' => $user['up_uid']], 'id,nickname'); //上一级分销用户
if ($up_user) {
$cf_user = "{$up_user['nickname']}(一级) => {$user['nickname']}(二级)";
} else {
$cf_user = $user['nickname'];
}
}
$of_title = '';
if ($row['of_id']) {
$of_ary = $this->customers_model->offlineSources()[$row['of_id']];
$of_title = $of_ary['name'];
$row['of2_id'] && $of_title .= '-' . $of_ary['list'][$row['of2_id']];
}
$tag = $tag_group = [];
$biz_type = intval($row_biz['type']);
if ($biz_type == 5) {
$jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : [];
$jsondata['tag_group'] && $tag_group = $jsondata['tag_group'];
} else {
$tag = $this->get_tag($row['id']);
}
$to_send = '';
if ($row['cs_biz_id'] == -1) {
$to_send = '已改派';
} else if ($row['cs_biz_id'] > 0) {
$to_send = '接收线索';
}
$info = array(
'id' => $row['id'],
'name' => $row['name'],
'level' => $row['level'],
'mobile' => $mobile_sub,
'of_title' => $of_title,
'wxqy_name' => $this->customers_model->wxqyAry($row['wxqy']),
'cf_user' => $cf_user,
'to_send' => $to_send,
'c_time' => date('Y-m-d H:i:s', $row['c_time']),
'status' => $row['status'],
'tag' => $tag,
'tag_group' => $tag_group,
'biz_type' => $biz_type,
);
//到店信息
$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'] != '0000-00-00 00:00:00' ? $row['p_time'] : ''),
array('title' => '最后联系', 'value' => $row['cont_time'] != '0000-00-00 00:00:00' ? $row['cont_time'] : ''),
array('title' => '首次到店', 'value' => $row['dt_time'] != '0000-00-00 00:00:00' ? $row['dt_time'] : ''),
array('title' => '下单时间', 'value' => $row['order_time'] != '0000-00-00 00:00:00' ? $row['order_time'] : ''),
),
array(
array('title' => '预计购买时间', 'value' => "{$row['buy_time']} 天内"),
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 = '未接通';
}
}
$imgs = [];
if ($value['imgs']) {
$json_imgs = json_decode($value['imgs'], true);
foreach ($json_imgs as $key1 => $value1) {
$imgs[] = build_qiniu_image_url($value1);
}
}
$logs[] = array(
'uname' => $value['uname'],
'log' => $value['log'],
'imgs' => $imgs,
'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 . ')';
$up_data['status'] = $info['status'];
if ($info['status'] == 1 && $row['dt_time'] == '0000-00-00 00:00:00') {//修改首次到店时间
$up_data['dt_time'] = date('Y-m-d H:i:s');
}
$ret = $this->customers_model->update($up_data, 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));
}
} else if ($info['editType'] == 3) {
$id = $info['id'];
//客户标签
if (!$info['tag']) {
return $this->show_json(SYS_CODE_FAIL, '客户画像不存在!');
}
$add_tag = [];
//查找已加入标签
$res_td = $this->mdCustomerTagdata->select(['c_id' => $id], 'id desc', 0, 0, 't_id');
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
foreach ($info['tag'] as $key => $val) {
foreach ($val['list'] as $key2 => $val2) {
if ($val['type'] == 'checkbox') {
if ($val2['checked'] == 'true') {
if (!$tag_data || !in_array($val2['id'], $tag_data)) {//未加标签,新增
$add_tag[] = ['c_id' => $id, 't_id' => $val2['id'], 'c_time' => time()];
}
} else {
if ($tag_data && in_array($val2['id'], $tag_data)) {//删除标签
$this->mdCustomerTagdata->delete(['c_id' => $id, 't_id' => $val2['id']]);
}
}
} else {
if ($val['value'] == $val2['id']) {
if (!$tag_data || !in_array($val2['id'], $tag_data)) {//未加标签,新增
$add_tag[] = ['c_id' => $id, 't_id' => $val2['id'], 'c_time' => time()];
}
} else {
if ($tag_data && in_array($val2['id'], $tag_data)) {//删除标签
$this->mdCustomerTagdata->delete(['c_id' => $id, 't_id' => $val2['id']]);
}
}
}
}
}
if ($add_tag && count($add_tag)) {
$this->mdCustomerTagdata->add_batch($add_tag);
}
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => '修改用户画像'));
}
return $this->show_json($code, $msg);
}
public function del()
{
$id = $this->input->post('id');
$row = $this->customers_model->get(['id' => $id, 'cf_title' => '平台分配']);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '客户不存在!');
}
$res = $this->customers_model->update(['status' => -1], ['id' => $id]);
if ($res) {
return $this->show_json(SYS_CODE_SUCCESS, '删除成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '删除失败');
}
}
public function batch()
{
// TODO: Implement batch() method.
}
public function export()
{
if ($this->uid != 1){
return $this->show_json(SYS_CODE_FAIL, '无权限导出');
}
$params = $this->input->get();
$where = $this->get_where($params);
$where["cs_biz_id >= 0"] = null;
$page = 1;
$size = 10000;
$count = $this->customers_model->count($where);
$data = [];
$offlineSources = $this->customers_model->offlineSources();
$status_arr = $this->customers_model->get_status();
unset($status_arr['-1']);
if ($count) {
$fileds = "id, name, mobile, level, status, FROM_UNIXTIME(c_time) as c_time, if(dt_time>0, dt_time,'') as dt_time, if(order_time>0, order_time,'') as order_time, if(cont_time>0, cont_time,'') as cont_time, cf_title, cf_id, of_id, of2_id, (SELECT biz_name FROM `lc_biz` where id = `lc_receiver_customers`.biz_id) as biz_name, (SELECT uname FROM `lc_app_licheb_users` where id = `lc_receiver_customers`.admin_id) as admin_name, biz_id, admin_id";
$rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds);
foreach ($rows as $key => $val) {
$of_title = '';
if ($val['of_id']) {
$of_ary = $offlineSources[$val['of_id']];
$of_title = $of_ary['name'];
$val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']];
}
$data[] = array(
'id' => 'ID',
'name' => $val['name'],
'mobile' => $val['mobile'],
'level' => $val['level'],
'status_name' => $status_arr[$val['status']],
'c_time' => $val['c_time'],
'dt_time' => $val['dt_time'],
'order_time' => $val['order_time'],
'cont_time' => $val['cont_time'],
'of_title' => $of_title,
'biz_name' => $val['biz_name'],
'admin_name' => $val['admin_name'],
);
}
}
$indexs = [
'name' => '客户姓名',
'mobile' => '手机',
'level' => '客户等级',
'status_name' => '客户类型',
'c_time' => '建档时间',
"dt_time" => "到店时间",
"order_time" => "下单时间",
"cont_time" => "最后联系时间",
"of_title" => "来源",
"biz_name" => "归属门店",
"admin_name" => "归属顾问",
];
$fileName = '客户列表';
array_unshift($data, $indexs);
$this->load->library('excel');
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
//改派
public function edit_adviser()
{
$id = $this->input->get_post('id');
$biz_id = $this->input->post('biz_id');
$row = $this->customers_model->get(['id' => $id, 'cf_title' => '平台分配']);
if (!$row) {
return $this->show_json(SYS_CODE_FAIL, '客户不存在!');
}
if ($this->input->post()) {
if (!$biz_id) return $this->show_json(SYS_CODE_FAIL, '请选择门店');
if ($biz_id == $row['biz_id']) return $this->show_json(SYS_CODE_FAIL, '请选择不同门店');
$res = $this->customers_model->update(['biz_id' => $biz_id, 'admin_id' => 0], ['id' => $id]);
if ($res) {
$log = "改派订单";
$this->addLog(['customer_id' => $row['id'], 'log' => $log, 'type' => 0]);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
} else {
return $this->show_json(SYS_CODE_FAIL, '保存失败');
}
}
$this->data['id'] = $id;
return $this->show_view('receiver/customer/get_adviser');
}
/**
* 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;
}
private function get_tag($id)
{
$show = $res_td = [];
$res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0, 'show<>' => 1], 'sort desc,id desc', 0, 0, 'id,name,type');
if ($res) {
$id && $res_td = $this->mdCustomerTagdata->select(['c_id' => $id], 'id desc', 0, 0, 't_id');//查找用户选择
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
foreach ($res as $key => $val) {
$list = [];
$value = '';
$res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name');
foreach ($res2 as $key2 => $val2) {
//检查是否选中标签
$setValue = ['id' => $val2['id'], 'name' => $val2['name']];
if ($val['type'] == 'checkbox') {
$setValue['checked'] = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
} else {
if ($tag_data && in_array($val2['id'], $tag_data)) {
$value = $val2['id'];
}
}
$list[] = $setValue;
}
$show[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'value' => $value, 'list' => $list];
}
}
return $show;
}
}