Files
liche/api/controllers/wxapp/licheb/Customers.php
T
2021-12-02 15:00:00 +08:00

704 lines
29 KiB
PHP

<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by Vim
* User: lcc
* Date: 2021/06/23
* Time: 14:08
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
class Customers extends Wxapp
{
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
$this->load->model('receiver/receiver_customers_model', 'customers_model');
$this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
$this->load->model('auto/auto_series_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_attr_model');
$this->load->model("biz/biz_model");
}
protected function get()
{
$id = $this->input_param('id');
if ($id) {
$where = [
'id' => $id,
];
$row = $this->customers_model->get($where);
if (!$row) {
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
}
$admin = $this->app_user_model->get(['id' => $row['admin_id']], 'id,uname');
$brand = $this->auto_brand_model->get(['id' => $row['brand_id']], 'name');
$series = $this->auto_series_model->get(['id' => $row['s_id']], 'name');
$car_json = json_decode($row['car_json'], true);
$color = isset($car_json['color']) ? $car_json['color']['title'] : '';
$version = isset($car_json['version']) ? $car_json['version']['title'] : '';
$tags = [$row['level'] . '级用户'];
$status_name = $this->customers_model->get_status();
$tip = $status_name[$row['status']] ? $status_name[$row['status']] : '';
$other_data = [
'品牌车型' => $brand['name'] . $series['name'],
'颜色型号' => $color . '-' . $version,
'建卡时间' => date('Y-m-d', $row['c_time']),
'客户来源' => $row['cf_title'],
'销售顾问' => isset($admin) ? $admin['uname'] : '',
];
$row['cont_time'] != '0000-00-00 00:00:00' && $other_data['上次联系'] = date('Y-m-d', strtotime($row['cont_time']));
$data = [
'id' => $row['id'],
'name' => $row['name'],
'mobile' => '****' . substr($row['mobile'], -4),
'complete_mobile' => $row['mobile'],
'tip' => $tip,
'is_top' => $row['is_top'],
'status' => $row['status'],
'other_data' => $other_data,
'tags' => $tags
];
return $data;
} else {
return $this->lists();
}
}
//获取客户其它信息
protected function get_data()
{
$id = $this->input_param('id');
$where = [
'id' => $id
];
$row = $this->customers_model->get($where);
if (!$row) {
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
}
$car_json = json_decode($row['car_json'], true);
$data['baseinfo'] = [
'name' => ['value' => $row['name'], 'cn' => '客户姓名'],
'mobile' => ['value' => mobile_asterisk($row['mobile']), 'cn' => '客户电话'],
'brand_id' => ['value' => $row['brand_id'], 'cn' => '车辆品牌'],
'car_id' => ['value' => $row['s_id'], 'cn' => '车辆车系'],
'v_id' => ['value' => $row['v_id'], 'cn' => '车型级别'],
'color_id' => ['value' => $car_json['c_id'], 'cn' => '车型颜色'],
'cf_clues' => ['value' => $row['cf_clues'], 'cn' => '线索来源'],
'buy_time' => ['value' => $row['buy_time'], 'cn' => '预计购车时间'],
];
return $data;
}
//修改基本信息
protected function put_data()
{
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$id = $this->input_param('cus_id');
$name = $this->input_param('name');
$mobile = $this->input_param('mobile');
$car_id = $this->input_param('car_id'); //品牌车型id
$v_id = $this->input_param('v_id'); //车型id
$color_id = $this->input_param('color_id'); //颜色id
$cf_clues = $this->input_param('cf_clues'); //线索来源
$buy_time = $this->input_param('buy_time'); //预计购车时间
$row = $this->customers_model->get(['id' => $id]);
if (!$row) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$car_json = json_decode($row['car_json'], true);
$update = [];
if ($mobile) {
if (!mobile_valid($mobile)) {
throw new Exception('手机号格式错误', ERR_PARAMS_ERROR);
}
if ($this->customers_model->count(['biz_id' => $biz_id, 'mobile' => $mobile])) {
throw new Exception('客户已存在', API_CODE_FAIL);
}
$update['mobile'] = $mobile;
}
$s_row = $this->auto_series_model->get(['id' => $car_id]);
$ids_arr = [];
if ($v_id) {
$car_json['v_id'] = $v_id;
$ids_arr[] = $v_id;
}
if ($color_id) {
$car_json['c_id'] = $color_id;
$ids_arr[] = $color_id;
}
$attr_row = $this->auto_attr_model->get_map_by_ids($ids_arr);
if ($attr_row[$color_id]) {
$color_row = $attr_row[$color_id][0];
$color_row['jsondata'] = json_decode($color_row['jsondata'], true);
isset($color_row) && $car_json['color'] = $color_row;
}
if ($attr_row[$v_id]) {
$version_row = $attr_row[$v_id][0];
$version_row['jsondata'] = json_decode($version_row['jsondata'], true);
isset($version_row) && $car_json['version'] = $version_row;
}
$update['car_json'] = json_encode($car_json, JSON_UNESCAPED_UNICODE);
$name && $update['name'] = $name;
$cf_clues && $update['cf_clues'] = $cf_clues;
$v_id && $update['v_id'] = $v_id;
if ($s_row) {
$update['s_id'] = $s_row['id'];
$update['brand_id'] = $s_row['brand_id'];
}
if ($buy_time) {
$this->load->library('receiver/customers_entity');
$update['level'] = $this->customers_entity->cal_level($buy_time);
$update['buy_time'] = $buy_time;
}
$result = $this->customers_model->update($update, ['id' => $id]);
if ($result) {
$uname = $this->session['uname'];
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($id, $this->session['uid'], $uname, "修改用户基本信息");
throw new Exception('保存成功', API_CODE_SUCCESS);
} else {
throw new Exception('保存失败', ERR_PARAMS_ERROR);
}
}
//创建客户
protected function post()
{
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$name = $this->input_param('name');
$mobile = $this->input_param('mobile');
$car_id = $this->input_param('car_id'); //品牌车型id
$v_id = $this->input_param('v_id'); //车型id
$color_id = $this->input_param('color_id'); //颜色id
$back_s_id = $this->input_param('b_s_id'); //备选车型
$cf_clues = $this->input_param('cf_clues'); //线索来源
$buy_time = $this->input_param('buy_time'); //预计购车时间
if (!mobile_valid($mobile)) throw new Exception('请输入正确的手机号码', ERR_PARAMS_ERROR);
if (!$name || !$car_id || !$v_id || !$color_id) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
if ($this->customers_model->count(['biz_id' => $biz_id, 'mobile' => $mobile])) {
throw new Exception('客户已存在', API_CODE_FAIL);
}
$biz_row = $this->biz_model->get(['id' => $biz_id]);
$row = $this->auto_series_model->get(['id' => $car_id]);
$where = [
"id in ($v_id,$color_id)" => null
];
$attr_row = $this->auto_attr_model->map('id', '', $where);
if ($attr_row[$color_id]) {
$color_row = $attr_row[$color_id][0];
$color_row['jsondata'] = json_decode($color_row['jsondata'], true);
}
if ($attr_row[$v_id]) {
$version_row = $attr_row[$v_id][0];
$version_row['jsondata'] = json_decode($version_row['jsondata'], true);
}
$car_json = [
'c_id' => $color_id,
'v_id' => $v_id,
'back_s_id' => $back_s_id,
'color' => isset($color_row) ? $color_row : '',
'version' => isset($version_row) ? $version_row : ''
];
$this->load->library('receiver/customers_entity');
$level = $this->customers_entity->cal_level($buy_time);
$add_data = [
'name' => $name,
'mobile' => $mobile,
'biz_id' => $biz_id,
'brand_id' => $row['brand_id'],
's_id' => $row['id'],
'v_id' => $v_id,
'admin_id' => $this->session['uid'],
'level' => $level,
'cf_title' => '自有资源',
'car_json' => json_encode($car_json, JSON_UNESCAPED_UNICODE),
'cont_time' => date('Y-m-d H:i:s'),
'c_time' => time()
];
$biz_row['city_id'] && $add_data['city_id'] = $biz_row['city_id'];
$biz_row['county_id'] && $add_data['county_id'] = $biz_row['county_id'];
$buy_time && $add_data['buy_time'] = $buy_time;
$cf_clues && $add_data['cf_clues'] = $cf_clues;
$result = $this->customers_model->add($add_data);
if ($result) {
$uname = $this->session['uname'];
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($result, $this->session['uid'], $uname, "创建客户");
throw new Exception('创建成功', API_CODE_SUCCESS);
} else {
throw new Exception('创建失败', ERR_PARAMS_ERROR);
}
}
//修改客户
protected function put()
{
$uid = $this->session['uid'];
$id = $this->input_param('id');
$status = $this->input_param('status');
$t_num = $this->input_param('t_num');
$a_num = $this->input_param('a_num');
$is_top = $this->input_param('is_top');
$defeat_reason = $this->input_param('defeat_reason');
$row = $this->customers_model->get(['id' => $id]);
if (!$row) {
throw new Exception('数据不存在', ERR_PARAMS_ERROR);
}
$log = '';
$up_data = [];
//变成到店
if (!$row['admin_id'] && $status == 1) {
$up_data['admin_id'] = $uid;
}
if ($row['admin_id'] != $uid) {
throw new Exception('无法操作该客户', ERR_PARAMS_ERROR);
}
if ($status == 3) {
if (!$defeat_reason) {
throw new Exception('请输入战败理由', ERR_PARAMS_ERROR);
}
$defeat_time = date("Y-m-d H:i:s");
$jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : array();
$jsondata['defeat']['time'] = $defeat_time;
$jsondata['defeat']['reason'] = $defeat_reason;
$up_data['defeat_time'] = strtotime($defeat_time);
$up_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$log = '申请战败:' . $defeat_reason;
} else {
if (strlen($status)) { //变更状态
$up_data['status'] = $status;
$status_name = $this->customers_model->get_status();
$log = '状态变更为' . $status_name[$status];
}
}
strlen($is_top) && $up_data['is_top'] = $is_top;
$t_num && $up_data['t_num = t_num+1'] = null;
$a_num && $up_data['a_num = a_num+1'] = null;
$result = true;
if ($up_data) {
$status == 1 && $up_data['cont_time'] = date('Y-m-d H:i:s'); //修改到店状态修改最后联系时间
if (($status == 1 || $a_num) && $row['dt_time'] == '0000-00-00 00:00:00') {//首次到店时间
$up_data['dt_time'] = date('Y-m-d H:i:s');
}
$result = $this->customers_model->update($up_data, ['id' => $id]);
if ($result) { //添加日志
$this->load->library('receiver/customers_entity');
if ($t_num) {
$msg = '试驾+1';
$log = $log ? $log . ',' . $msg : $msg;
}
if ($a_num) {
$msg = '到店+1';
$log = $log ? $log . ',' . $msg : $msg;
}
$visit = $status == 2 ? 1 : 0;//变成订单客户,更新客户已回访
$this->customers_entity->add_log_visit($id, $uid, $this->session['uname'], $log,0,$visit);
}
}
if ($result) {
throw new Exception('修改成功', API_CODE_SUCCESS);
} else {
throw new Exception('修改失败', ERR_PARAMS_ERROR);
}
}
//订单列表头部
protected function get_tabs()
{
$rows = $this->customers_model->get_status();
$lists = [];
if ($rows) {
foreach ($rows as $key => $val) {
if ($key != -1) {
$lists[] = [
'key' => $key,
'name' => $val
];
}
}
}
return $lists;
}
//获取筛选条件
protected function get_filter()
{
$level = $this->customers_model->get_sdata('level');
$cfrom = $this->customers_model->get_sdata();
$buy_time = $this->customers_model->get_sdata('btime');
$data = [
'level' => $level,
'cfrom' => $cfrom,
'buy_time' => $buy_time
];
return $data;
}
//获取客户列表
private function lists()
{
$visit = $this->input_param('visit');
if ($visit) {//待回访客户
return $this->visit_lists($this->input_param());
}
$uid = $this->session['uid'];
$group_id = $this->session['group_id'];
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$s_time = $this->input_param('s_time');
$e_time = $this->input_param('e_time');
$if_driver = $this->input_param('if_driver');
$level = $this->input_param('level');
$brand_id = $this->input_param('brand_id');
$s_id = $this->input_param('s_id'); //车系id
$v_id = $this->input_param('v_id'); //车型级别id
$cfrom = $this->input_param('cfrom'); //客户来源id
$status = $this->input_param('status'); //状态
$o_type = $this->input_param('o_type'); //排序
$page = $this->input_param('page');
$size = $this->input_param('size');
$istop = $this->input_param('istop');
$iscall = $this->input_param('iscall');
$unuse = $this->input_param('unuse'); //未派客户
$ismy = $this->input_param('ismy'); //是否只显示自己
$name = $this->input_param('name');
$mobile = $this->input_param('mobile');
$cf_clues = $this->input_param('cf_clues');//线索来源
$admin_id = $this->input_param('admin_id');
$id = $this->input_param('cus_id');
!$page && $page = 1;
!$size && $size = 10;
if ($o_type == 1) { //创建时间排序
$orderby = 'c_time desc';
} elseif ($o_type == 2) {//最近联系
$orderby = 'cont_time desc';
} else { //特别关注
if ($group_id == 1) {
$orderby = 'is_top desc,c_time desc';
} else {
$orderby = 'c_time desc';
}
}
$where = [
'biz_id' => $biz_id,
'status>=' => 0
];
if ($group_id == 1 || $ismy) {
$where["admin_id"] = $uid;
}
if ($group_id == 4 && $biz_id != 1) {
$where['brand_id!='] = 3; //渠道经理过滤
}
if ($s_time && $e_time) {
$where['c_time >='] = strtotime($s_time);
$where['c_time <='] = strtotime(date('Y-m-d 23:59:59', strtotime($e_time)));
}
if (strlen($iscall)) {
if ($iscall) {
$where['cont_time!='] = '0000-00-00 00:00:00';
} else {
$where['cont_time'] = '0000-00-00 00:00:00';
}
}
$unuse && $where['admin_id'] = 0;
$admin_id && $where['admin_id'] = $admin_id;
$id && $where['id'] = $id;
strlen($istop) && $where['is_top'] = $istop;
strlen($if_driver) && $where['if_driver'] = 1;
strlen($status) && $where['status'] = $status;
$brand_id && $where['brand_id'] = $brand_id;
$level && $where['level'] = $level;
$cfrom && $where['cf_title'] = $cfrom;
$name && $where["name like '%{$name}%'"] = null;
$mobile && $where["mobile like '%$mobile%'"] = null;
$cf_clues && $where['cf_clues'] = $cf_clues;
$count = $this->customers_model->count($where);
$lists = [];
if ($count) {
$fileds = 'id,name,admin_id,mobile,level,car_json,is_top,cf_title,brand_id,s_id,cont_time,c_time,defeat_time';
$rows = $this->customers_model->select($where, $orderby, $page, $size, $fileds);
//获取管理员
$admin_arr = array_unique(array_column($rows, 'admin_id'));
$admin_ids = implode(',', $admin_arr);
$admins = [];
if ($admin_ids) {
$where = [
"id in ({$admin_ids})" => null
];
$admins = $this->app_user_model->map('id', '', $where, '', '', '', 'id,uname');
}
//品牌车型
$brand_arr = array_unique(array_column($rows, 'brand_id'));
$brands = $this->auto_brand_model->get_map_by_ids($brand_arr, 'id,name');
//车系车型
$series_arr = array_unique(array_column($rows, 's_id'));
$series = $this->auto_series_model->get_map_by_ids($series_arr, 'id,name');
foreach ($rows as $key => $val) {
$car_json = json_decode($val['car_json'], true);
$color = isset($car_json['color']) ? $car_json['color']['title'] : '';
$version = isset($car_json['version']) ? $car_json['version']['title'] : '';
$brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
$serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : '';
$other_data = [
'品牌车型' => $brand_name . $serie_name,
'颜色型号' => $color . '-' . $version,
'建卡时间' => date('Y-m-d', $val['c_time']),
'客户来源' => $val['cf_title'],
'销售顾问' => isset($admins[$val['admin_id']]) ? $admins[$val['admin_id']][0]['uname'] : '',
];
$val['cont_time'] != '0000-00-00 00:00:00' && $other_data['上次联系'] = date('Y-m-d', strtotime($val['cont_time']));
$tags = [$val['level'] . '级用户'];
$defeat = '';
if ($val['defeat_time'] > 0) {
$defeat = '战败申请中';
} else if ($val['defeat_time'] == -1) {
$defeat = '再战';
}
$lists[] = [
'id' => $val['id'],
'name' => $val['name'],
'mobile' => mobile_asterisk($val['mobile']),
'complete_mobile' => $val['mobile'],
'is_top' => $val['is_top'],
'other_data' => $other_data,
'tags' => $tags,
'defeat' => $defeat
];
}
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
//派单给店员
protected function put_admins()
{
$uname = $this->session['uname'];
$uid = $this->session['uid'];
$id_arr = $this->input_param('ids');
$admin_id = $this->input_param('admin_id');
$admin = $this->app_user_model->get(['id' => $admin_id, 'status' => 1]);
if (!$id_arr || !$admin) {
throw new Hd_exception('参数错误', API_CODE_INVILD_PARAM);
}
$ids = implode(',', $id_arr);
$ret = $this->customers_model->update(['admin_id' => $admin_id], ["id in ({$ids})" => null]);
if (is_bool($ret)) {
debug_log("[error]# " . $this->customers_model->db->last_query(), __FUNCTION__, $this->log_dir);
throw new Exception('分派失败', API_CODE_FAIL);
}
//写日志
$this->load->library('receiver/customers_entity');
//$customers = $this->customers_model->get_map_by_ids($id_arr, 'id,rid');
foreach ($id_arr as $val) {
$log = "分配客户";
$this->customers_entity->add_log($val, $uid, $uname, $log);
//发送短信
$re = $this->customers_model->get(['id' => $val]);
$num = $re['mobile'] ? substr($re['mobile'], -4) : 0;
send_alisms(array('mobile' => $admin['mobile'], 'template' => 'SMS_226945702', 'param' => ['num' => $num]));
}
throw new Exception('分配成功', API_CODE_SUCCESS);
}
/**
* Notes:待回访客户列表
* Created on: 2021/10/21 14:27
* Created by: dengbw
* @param array $params
* @return array
*/
private function visit_lists($params = array())
{
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$group_id = $this->session['group_id'];
$this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
$page = $params['page'];
$size = $params['size'];
!$page && $page = 1;
!$size && $size = 10;
$where = array('a.biz_id' => $biz_id, 'b.contact' => 1, 'b.status' => 1);
$group_id == 1 && $where['a.admin_id'] = $this->session['uid'];
$count = $this->mdCustomersVisit->count_visit($where);
$lists = [];
if ($count) {
$fileds = 'a.id,a.name,a.admin_id,a.mobile,a.level,a.car_json,a.is_top,a.cf_title,a.brand_id,a.s_id
,a.cont_time,a.c_time,a.defeat_time';
$rows = $this->mdCustomersVisit->select_visit($where, 'a.id desc', $page, $size, $fileds);
//获取管理员
$admin_arr = array_unique(array_column($rows, 'admin_id'));
$admin_ids = implode(',', $admin_arr);
$admins = [];
if ($admin_ids) {
$admins = $this->app_user_model->map('id', '', ["id in ({$admin_ids})" => null], '', '', '', 'id,uname');
}
//品牌车型
$brand_arr = array_unique(array_column($rows, 'brand_id'));
$brands = $this->auto_brand_model->get_map_by_ids($brand_arr, 'id,name');
//车系车型
$series_arr = array_unique(array_column($rows, 's_id'));
$series = $this->auto_series_model->get_map_by_ids($series_arr, 'id,name');
foreach ($rows as $key => $val) {
$car_json = json_decode($val['car_json'], true);
$color = isset($car_json['color']) ? $car_json['color']['title'] : '';
$version = isset($car_json['version']) ? $car_json['version']['title'] : '';
$brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
$serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : '';
$other_data = [
'品牌车型' => $brand_name . $serie_name,
'颜色型号' => $color . '-' . $version,
'建卡时间' => date('Y-m-d', $val['c_time']),
'客户来源' => $val['cf_title'],
'销售顾问' => isset($admins[$val['admin_id']]) ? $admins[$val['admin_id']][0]['uname'] : '',
];
$val['cont_time'] != '0000-00-00 00:00:00' && $other_data['上次联系'] = date('Y-m-d', strtotime($val['cont_time']));
$tags = [$val['level'] . '级用户'];
$defeat = '';
if ($val['defeat_time'] > 0) {
$defeat = '战败申请中';
} else if ($val['defeat_time'] == -1) {
$defeat = '再战';
}
$lists[] = [
'id' => $val['id'],
'name' => $val['name'],
'mobile' => mobile_asterisk($val['mobile']),
'complete_mobile' => $val['mobile'],
'is_top' => $val['is_top'],
'other_data' => $other_data,
'tags' => $tags,
'defeat' => $defeat
];
}
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
/**
* Notes:战败申请列表
* Created on: 2021/10/21 15:19
* Created by: dengbw
* @return array
* @throws Hd_exception
*/
protected function get_defeats()
{
$group_id = $this->session['group_id'];
if ($group_id == 1) {
return $data = ['list' => [], 'total' => 0];
}
$params = $this->input_param();
$page = $params['page'];
$size = $params['size'];
!$page && $page = 1;
!$size && $size = 10;
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$where = array('biz_id' => $biz_id, 'defeat_time >' => 0, 'status>' => -1);
$count = $this->customers_model->count($where);
$lists = [];
if ($count) {
$fileds = 'id,name,mobile,jsondata';
$rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds);
foreach ($rows as $key => $val) {
$jsondata = $val['jsondata'] ? json_decode($val['jsondata'], true) : array();
$reason = $jsondata['defeat']['reason'] ? '战败理由:' . $jsondata['defeat']['reason'] : '';
$lists[] = [
'id' => $val['id'],
'name' => $val['name'],
'mobile' => mobile_asterisk($val['mobile']),
'reason' => $reason,
];
}
}
$data = [
'list' => $lists,
'total' => $count
];
return $data;
}
/**
* Notes:通过战败申请
* Created on: 2021/10/21 16:19
* Created by: dengbw
* @throws Exception
*/
protected function put_defeats()
{
$group_id = $this->session['group_id'];
if ($group_id == 1) {
throw new Exception('无操作权限', ERR_PARAMS_ERROR);
}
$params = $this->input_param();
$id = intval($params['id']);
$type = intval($params['type']);
if (!$id) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$row = $this->customers_model->get(array('id' => $id));
if (!$row) {
throw new Exception('用户不存在', ERR_PARAMS_ERROR);
}
if (!$row['defeat_time']) {
throw new Exception('未申请战败', ERR_PARAMS_ERROR);
}
$jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : array();
if ($type == 1) {
$log = '拒绝战败申请';
$update['defeat_time'] = -1;//再战
} else {
$jsondata['defeat']['pass_time'] = date("Y-m-d H:i:s");
$update['status'] = 3;
$log = '通过战败申请';
$update['defeat_time'] = 0;
}
$update['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
$ret = $this->customers_model->update($update, ['id' => $id]);
if ($ret) {
$this->load->library('receiver/customers_entity');
$visit = $update['status'] == 3 ? 1 : 0;
$this->customers_entity->add_log_visit($id, $this->session['uid'], $this->session['uname'], $log,0,$visit);
throw new Exception('操作成功', API_CODE_SUCCESS);
}
throw new Exception('操作失败', ERR_PARAMS_ERROR);
}
}