Files
spacestation/api/controllers/wxapp/licheb/User.php
T
lin fan 797108edfb 1
2024-11-22 14:56:53 +08:00

628 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 User extends Wxapp
{
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array('get_ukey');//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg = array();//授权微信信息
$this->load->model("biz/biz_model");
$this->load->model('auto/auto_brand_model');
// $this->load->model('auto/auto_brand_biz_model');
// $this->load->model('items/items_model', 'mdItems');
// $this->load->model('items/items_oplogs_model', 'mdItemsOplogs');
$this->load->model('sys/sys_city_model');
// $this->load->library('receiver/orders_v2_entity');
$this->load->model('receiver/receiver_clues_model', 'clues_model');
$this->load->model('receiver/order/receiver_orders_model', 'orders_model');
}
/**
* 获取ukey
* @return array
* @throws Exception
*/
protected function get_ukey()
{
$mobile_white = ['18350451617', '13850003412', '13860199666', '13860199646'];
$code = $this->input_param('code');
$mobile = $this->input_param('mobile');
$sms_code = $this->input_param('sms_code');
$by_code = $this->input_param('by_code');
if ($by_code) { //普通用户code登录
return $this->get_cUkey();
}
if (!$code || !$mobile || !$sms_code) {
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
}
//判断验证码
if (!in_array($mobile, $mobile_white) && $this->env != 'd') {//测试环境和测试号码
$key = "licheb_login_code_" . $mobile;
$cache_code = $this->app_redis->get($key);
if ($sms_code != $cache_code) {
throw new Exception('验证码错误', API_CODE_FAIL);
}
}
$user = $this->app_user_model->get(['mobile' => $mobile, 'status>' => -1, 'group_id>' => 0]);
if (!$user) {
throw new Exception('用户不存在', API_CODE_FAIL);
}
if (!$user['status']) {
throw new Exception('该账号已停用', API_CODE_FAIL);
}
//判断门店是否存在
if ($user['group_id'] < 4) {
$biz_id = intval($user['biz_id']);
$biz = $this->biz_model->get(['id' => $biz_id, 'status' => 1]);
if (!$biz) {
throw new Exception('门店不存在', API_CODE_FAIL);
}
}
$session = $this->wx_session($code);
if (!$session['session_key']) {
throw new Exception('登录失败', API_CODE_FAIL);
}
$uid = $user['id'];
if (!$user['openid']) { //未绑定微信
$upd = [
'openid' => $session['openid']
];
$session['unionid'] && $upd['unionid'] = $session['unionid'];
$ret = $this->app_user_model->update($upd, array('id' => $uid));
if (!$ret) {
debug_log("[error]# code:{$code}; " . $this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
throw new Exception('授权用户信息失败', API_CODE_FAIL);
}
}
$udata = array('uid' => $uid, 'session_key' => $session['session_key']);
$ukey = $this->refresh_login($udata);
return array('ukey' => $ukey);
}
protected function get_cUkey()
{
$code = $this->input_param('code');
if (!$code) throw new Exception('参数错误', API_CODE_INVILD_PARAM);
$session = $this->wx_session($code);
if (!$session['session_key']) {
throw new Exception('登录失败', API_CODE_FAIL);
}
$open_id = $session['openid'];
$user = $this->app_user_model->get(['openid' => $open_id, 'group_id' => 0]);
if (!$user) {
$userData = [
'openid' => $open_id,
'group_id' => 0,
'group_id1' => 0,
'c_time' => time(),
];
$session['unionid'] && $userData['unionid'] = $session['unionid'];
$uid = $this->app_user_model->add($userData);
} else {
$uid = $user['id'];
}
$udata = array('uid' => $uid, 'session_key' => $session['session_key']);
$ukey = $this->refresh_login($udata);
return array('ukey' => $ukey);
}
/**
* Notes:用户信息
* Created on: 2022/10/12 14:09
* Created by: dengbw
* @return array
* @throws Exception
*/
protected function get()
{
$this->add_user_score();
$uid = $this->session['uid'];
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
$user = $this->app_user_model->get(array('id' => $uid));
//获取所属店铺字段
$biz = $this->biz_model->get(['id' => $biz_id, 'status' => 1], 'biz_name,type');
//判断门店是否存在
if (!$biz && $this->session['group_id'] < 4) {
$this->logout();
throw new Exception('门店不存在', API_CODE_FAIL);
}
$group_arr = $this->app_user_model->get_group();
$group_name = $group_arr[$user['group_id']] ? $group_arr[$user['group_id']] : '';
//获取拨打电话
$json = $this->session['jsondata'] ? json_decode($this->session['jsondata'], true) : array();
$tel = $this->session['mobile'];
if ($json && $json['licheb'] && $json['licheb']['tel']) {
$tel = $json['licheb']['tel'];
}
$data = array(
'uid' => $uid,
'uname' => $user['uname'],
'mobile' => $user['mobile'],
'headimg' => $user['headimg'],
'tel' => $tel,
'group_id' => $user['group_id'],
'group_name' => $group_name,
'biz_id' => $biz_id,
'biz_name' => $biz['biz_name'] ? $biz['biz_name'] : '',
'biz_type' => $biz['type'] ? $biz['type'] : '',
'show_sa' => $biz_id == 70 ? true : false,
'new_biz_id' => $this->session['new_biz_id'] ? $this->session['new_biz_id'] : '',
'group_id_type' => $this->session['group_id_type'] ? $this->session['group_id_type'] : '',
);
# 用户可切换的组别
$group_name1 = $group_arr[$user['group_id1']] ? $group_arr[$user['group_id1']] : '';
$group_name_arr = array();
if ($user['group_id'] && $user['group_id1']) {
# 渠道角色 再显示下城市名称,门店角色 再显示下门店名称
$where_biz = ["id in ({$user['biz_id']}, {$user['biz_id1']})" => null];
$map_biz = $this->biz_model->map('id', 'biz_name', $where_biz, '', 0, 0, 'id,biz_name');
$where_city = ["city_id in ({$user['city_id']}, {$user['city_id1']})" => null];
$map_city = $this->sys_city_model->map('city_id', 'name', $where_city, '', 0, 0, 'city_id,name');
$group_name_ = '默认角色:' . $group_name;
if ($user['group_id'] == 4) {
$group_name_ = $user['city_id'] ? $group_name_ . "({$map_city[$user['city_id']]})" : $group_name_;
} else {
$group_name_ = $user['biz_id'] ? $group_name_ . "({$map_biz[$user['biz_id']]})" : $group_name_;
}
$group_name1_ = '第二角色:' . $group_name1;
if ($user['group_id1'] == 4) {
$group_name1_ = $user['city_id1'] ? $group_name1_ . "({$map_city[$user['city_id1']]})" : $group_name1_;
} else {
$group_name1_ = $user['biz_id1'] ? $group_name1_ . "({$map_biz[$user['biz_id1']]})" : $group_name1_;
}
$this->session['group_id_type'] && $group_name_arr[] = array('group_id' => 'group_id', "geoup_name" => $group_name_);
!$this->session['group_id_type'] && $group_name_arr[] = array('group_id' => 'group_id1', "geoup_name" => $group_name1_);
}
$data['group_name_arr'] = $group_name_arr;
if ($this->session['group_id_type']) {
$data['group_id'] = $user['group_id1'];
$data['group_name'] = $group_name1;
if ($user['group_id1'] != 4) {
$biz_id1 = $user['biz_id1'];
$data['biz_id'] = $biz_id1;
$biz1 = $this->biz_model->get(['id' => $biz_id1, 'status' => 1], 'biz_name,type');
$data['biz_name'] = $biz1['biz_name'] ? $biz1['biz_name'] : '';
$data['biz_type'] = $biz1['type'] ? $biz1['type'] : '';
}
}
return $data;
}
/**
* 更新用户信息
* @return array
* @throws Exception
*/
protected function put()
{
$encrypted = $this->input_param('encryptedData');
$iv = $this->input_param('iv');
$intro = $this->input_param('intro');
//获取用户信息
$uid = $this->session['uid'];
$user = $this->app_user_model->get(array('id' => $uid));
$upd = array();
$mobile = '';
//授权
if (!is_null($encrypted)) {
if (!$encrypted || !$iv) {
throw new Exception('授权失败,请重启小程序进行尝试', API_CODE_INVILD_PARAM);
}
$wxdata = $this->wx_data($encrypted, $iv);
if (!$wxdata) {
throw new Exception('授权失败,请重启小程序进行尝试', API_CODE_FAIL);
}
$openid = $wxdata['openId'];
$nickname = $wxdata['nickName'];
$sex = $wxdata['gender'];
$headimg = $wxdata['avatarUrl'];
$unionid = $wxdata['unionId'];
$mobile = $wxdata['phoneNumber'];
if (!$mobile && isset($wxdata['phoneNumber'])) {
throw new Exception('微信未绑定手机号', API_CODE_FAIL);
}
$mobile && $upd['mobile'] = $mobile;
$nickname && $upd['nickname'] = $nickname;
$headimg && $upd['headimg'] = $headimg;
if ($mobile) {//判断手机号是否重复
if (!mobile_valid($mobile)) {
throw new Exception("请输入正确的手机号", API_CODE_FAIL);
}
if ($user['group_id'] > 0) { //后台用户不判断手机号是否被绑定
$where = array('mobile' => $mobile, 'id <>' => $uid, "status<>" => -1);
$count = $this->app_user_model->count($where);
if ($count > 0) {
$mobile = substr($mobile, 0, 3) . '****' . substr($mobile, -4);
throw new Exception("{$mobile} 已被绑定", API_CODE_FAIL);
}
}
}
} else {//编辑其他信息
$userInfo = $this->input_param('userInfo');
$userInfo['nickName'] && $upd['nickname'] = $userInfo['nickName'];
$userInfo['avatarUrl'] && $upd['headimg'] = $userInfo['avatarUrl'];
if ($intro) {
if (mb_strlen($intro, 'utf8') > 20) {
throw new Exception('介绍自己20个字够啦', API_CODE_FAIL);
}
$upd['signature'] = $intro;
}
}
if ($upd) {
$ret = $this->app_user_model->update($upd, array('id' => $uid));
if (!$ret) {
debug_log("[error]# " . $this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
throw new Exception('请求失败', API_CODE_FAIL);
}
}
$data = array(
'mobile' => $mobile,
'nickname' => $upd['nickname'] ? $upd['nickname'] : $user['nickname'],
'headimg' => $upd['headimg'] ? $upd['headimg'] : $user['headimg'],
);
return $data;
}
/**
* 统计数据
*/
protected function get_cal()
{
$uid = $this->session['uid'];
$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_model', 'customers_model');
// $this->load->model('receiver/order/receiver_order_signs_model', 'order_signs_model');
$this->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData');
$where = ['status>' => -1, 'is_top' => 1, 'biz_id' => $biz_id, 'status!=' => 2];
$group_id == 1 && $where['admin_id'] = $uid;
$gz_count = $this->customers_model->count($where);
$where = ['status' => 0, 'biz_id' => $biz_id];
$group_id == 1 && $where['admin_id'] = $uid;
$sign_count = 0;
$where = ['status' => 1, 'biz_id' => $biz_id];
$group_id == 1 && $where['admin_id'] = $uid;
$loan_count = 0;
//客户代办事项--未派单客户
if ($group_id == 1) {
$customer_op_list = [];
} else {
$where = ['admin_id' => 0, 'biz_id' => $biz_id, 'status>=' => 0];
$unuse_count = $this->customers_model->count($where);
$defeat_count = $this->customers_model->count(['biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'if_defeat' => 1, 'status>' => -1]);
$clues_count = $this->clues_model->count(['biz_id' => $biz_id, 'status' => 1, 'status2' => 1]);
$customer_op_list = [
['title' => '线索池(人)', 'icon' => 'icon-daifenpei', 'total' => $clues_count, 'page' => '/pages/clues/index'],
['title' => '待分配客户(人)', 'icon' => 'icon-daifenpei', 'total' => $unuse_count, 'page' => '/pages/customer/allot/index'],
['title' => '战败申请(人)', 'icon' => 'icon-statistics-custom-5', 'total' => $defeat_count, 'page' => '/pages/customer/optDefeat/index'],
];
}
$where = ['status' => 0, 'biz_id' => $biz_id];
$group_id == 1 && $where['sale_id'] = $uid;
$fq_total = $this->orders_model->count($where);
$where = [
'status' => 1,
'biz_id' => $biz_id,
];
$group_id == 1 && $where['sale_id'] = $uid;
$kp_total = $this->orders_model->count($where);
$where = [
'status' => 2,
'biz_id' => $biz_id,
];
$group_id == 1 && $where['sale_id'] = $uid;
$ck_total = $this->orders_model->count($where);
$deallist = [
['title' => '签约下定 ', 'icon' => 'icon-banfenqi', 'total' => $fq_total, 'page' => '/pages/order/filterList/index2?type=0&title=签约下定'],
['title' => '发票开具', 'icon' => 'icon-kaipiao1', 'total' => $kp_total, 'page' => '/pages/order/filterList/index2?type=1&title=发票开具'],
['title' => '车辆交付', 'icon' => 'icon-jiaofu', 'total' => $ck_total, 'page' => '/pages/order/filterList/index2?type=2&title=车辆交付'],
];
$where_v = ['a.biz_id' => $biz_id, 'a.cs_biz_id<>' => -1, 'a.status in(0,1)' => null, 'b.t_day' => date('Y-m-d')];
$where_c = ['biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'status in(0,1)' => null];
$group_id == 4 && $where_c['brand_id!='] = 3;
if ($group_id == 1) {
$where_v['b.sales_id'] = $uid;
$where_c['admin_id'] = $uid;
}
$h_num = $this->customers_model->count(array_merge($where_c, ['level' => 'H']));
$h_num_1 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'H', 'b.status<>' => 2]));
$h_num_2 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'H', 'b.status' => 2]));
$a_num = $this->customers_model->count(array_merge($where_c, ['level' => 'A']));
$a_num_1 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'A', 'b.status<>' => 2]));
$a_num_2 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'A', 'b.status' => 2]));
$b_num = $this->customers_model->count(array_merge($where_c, ['level' => 'B']));
$b_num_1 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'B', 'b.status<>' => 2]));
$b_num_2 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'B', 'b.status' => 2]));
$c_num = $this->customers_model->count(array_merge($where_c, ['level' => 'C']));
$c_num_1 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'C', 'b.status<>' => 2]));
$c_num_2 = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['a.level' => 'C', 'b.status' => 2]));
$levelSt = [
['title' => 'H级客户', 'list' => [['title' => '总数 >', 'num' => $h_num, 'url' => '/pages/customer/filterList/index?level=H&status_tp=1&title=H级客户']
, ['title' => '今日需跟进 >', 'num' => $h_num_1, 'url' => '/pages/customer/filterList/index?level=H&status=1&visit=1&title=H级今日需跟进']
, ['title' => '今日已跟进 >', 'num' => $h_num_2, 'url' => '/pages/customer/filterList/index?level=H&status=2&visit=1&title=H级今日已跟进']]],
['title' => 'A级客户', 'list' => [['title' => '总数 >', 'num' => $a_num, 'url' => '/pages/customer/filterList/index?level=A&status_tp=1&title=A级客户']
, ['title' => '今日需跟进 >', 'num' => $a_num_1, 'url' => '/pages/customer/filterList/index?level=A&status=1&visit=1&title=A级今日需跟进']
, ['title' => '今日已跟进 >', 'num' => $a_num_2, 'url' => '/pages/customer/filterList/index?level=A&status=2&visit=1&title=A级今日已跟进']]],
['title' => 'B级客户', 'list' => [['title' => '总数 >', 'num' => $b_num, 'url' => '/pages/customer/filterList/index?level=B&status_tp=1&title=B级客户']
, ['title' => '今日需跟进 >', 'num' => $b_num_1, 'url' => '/pages/customer/filterList/index?level=B&status=1&visit=1&title=B级今日需跟进']
, ['title' => '今日已跟进 >', 'num' => $b_num_2, 'url' => '/pages/customer/filterList/index?level=B&status=2&visit=1&title=B级今日已跟进']]],
['title' => 'C级客户', 'list' => [['title' => '总数 >', 'num' => $c_num, 'url' => '/pages/customer/filterList/index?level=C&status_tp=1&title=C级客户']
, ['title' => '今日需跟进 >', 'num' => $c_num_1, 'url' => '/pages/customer/filterList/index?level=C&status=1&visit=1&title=C级今日需跟进']
, ['title' => '今日已跟进 >', 'num' => $c_num_2, 'url' => '/pages/customer/filterList/index?level=C&status=2&visit=1&title=C级今日已跟进']]],
];
$wl_num = $this->mdCustomerVisitData->count_visit(array_merge($where_v, ['b.status<>' => 2]));
//数据统计
$str_uids = $str_userids = '';
if ($group_id == 1) {
$str_uids = $uid;
$str_userids = $this->session['userid'];
} else {
$res_user = $this->app_user_model->select(['biz_id' => $biz_id, 'group_id <' => 4, 'status>=' => 0], 'id asc', 0, 0, 'id,userid');
foreach ($res_user as $k => $v) {
$str_uids = $str_uids ? $str_uids . ',' . $v['id'] : $v['id'];
$v['userid'] && $str_userids = $str_userids ? $str_userids . "','" . $v['userid'] : $v['userid'];
}
}
!$str_uids && $str_uids = '-1';
!$str_userids && $str_userids = '-1';
$this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOpLogs');
$s_today = date('Y-m-d') . ' 00:00:00';
$e_today = date('Y-m-d') . ' 23:59:59';
$s_month = date('Y-m-01', strtotime(date("Y-m-d"))) . ' 00:00:00';
$e_month = date('Y-m-d', strtotime("$s_month +1 month -1 day")) . ' 23:59:59';
//线索
$where_today_xs = ['biz_id' => $biz_id, 'status>=' => 0, 'p_time>=' => $s_today, 'p_time<=' => $e_today];
$where_month_xs = ['biz_id' => $biz_id, 'status>=' => 0, 'p_time>=' => $s_month, 'p_time<=' => $e_month];
//到店
$where_today_dd = ['biz_id' => $biz_id, 'status>=' => 0, 'dt_time >= ' => $s_today, 'dt_time<=' => $e_today];
$where_month_dd = ['biz_id' => $biz_id, 'status>=' => 0, 'dt_time >= ' => $s_month, 'dt_time<=' => $e_month];
//订单
$where_today_order = ['biz_id' => $biz_id, 'status>=' => 0, 'c_time>=' => strtotime($s_today), 'c_time<=' => strtotime($e_today)];
$where_month_order = ['biz_id' => $biz_id, 'status>=' => 0, 'c_time>=' => strtotime($s_month), 'c_time<=' => strtotime($e_month)];
//战败
$where_today_defeat = ['biz_id' => $biz_id, 'status>=' => 0, 'cs_biz_id<>' => -1, 'def_time >= ' => $s_today, 'def_time<=' => $e_today];
$where_month_defeat = ['biz_id' => $biz_id, 'status>=' => 0, 'cs_biz_id<>' => -1, 'def_time >= ' => $s_month, 'def_time<=' => $e_month];
if ($group_id == 1) {
$where_today_xs['admin_id'] = $uid;
$where_month_xs['admin_id'] = $uid;
}
$statistics = [
['today' => ['title' => '今日', 'value' => $this->customers_model->count($where_today_xs), 'url' => '/pages/customer/filterList/index?status=3&visit=3&title=客户']
, 'month' => ['title' => '本月客户', 'value' => $this->customers_model->count($where_month_xs)]],
['today' => ['title' => '今日', 'value' => $this->customers_model->count($where_today_dd), 'url' => '/pages/customer/filterList/index?status=5&visit=5&title=到店']
, 'month' => ['title' => '本月到店', 'value' => $this->customers_model->count($where_month_dd)]],
['today' => ['title' => '今日', 'value' => $this->orders_model->count($where_today_order), 'url' => '/pages/order/filterList/index2?status=6&visit=6&title=订单']
, 'month' => ['title' => '本月订单', 'value' => $this->orders_model->count($where_month_order)]],
['today' => ['title' => '今日', 'value' => $this->customers_model->count($where_today_defeat), 'url' => '/pages/customer/filterList/index?status=7&visit=7&title=战败']
, 'month' => ['title' => '本月战败', 'value' => $this->customers_model->count($where_month_defeat)]]
];
$data = [
'wl_count' => ['title' => '待跟进客户(人)', 'num' => $wl_num, 'url' => '/pages/customer/filterList/index?status=1&visit=1&title=待跟进客户'],
'gz_count' => ['title' => '特别关注客户(人)', 'num' => $gz_count, 'url' => '/pages/customer/filterList/index?istop=1&title=特别关注客户'],
'sign_count' => $sign_count,
'loan_count' => $loan_count,
'deallist' => $deallist,
'customer_op_list' => $customer_op_list,
'levelSt' => $levelSt,
'where_today_qy' => [],
'statistics' => $statistics,
'str_uids' => $str_uids
];
return $data;
}
/**
* 更新联系手机号
* @return array
* @throws Hd_Exception
*/
protected function put_tel()
{
$tel = $this->input_param('tel');
if (!mobile_valid($tel)) {
throw new Hd_Exception('确认一下手机号是否正确', API_CODE_INVILD_PARAM);
}
$uid = $this->session['uid'];
$user = $this->app_user_model->get(array('id' => $uid));
$json = $user['jsondata'] ? json_decode($user['jsondata'], true) : array();
$json['licheb']['tel'] = $tel;
$upd = array('jsondata' => json_encode($json, JSON_UNESCAPED_UNICODE));
$ret = $this->app_user_model->update($upd, array('id' => $uid));
if (!$ret) {
throw new Hd_Exception('更新失败', API_CODE_FAIL);
}
$data = array('tel' => $tel);
return $data;
}
/**
* 获取门店信息
* @return array
*/
protected function get_bizs()
{
$province_id = $this->input_param('province_id');
$city_id = $this->input_param('city_id');
$lists = [];
$biz_id_arr = explode(',', $this->session['biz_id']);
$fileds = 'id,biz_name';
if ($this->session['biz_id'] && $biz_id_arr) {
$province_id && $o_where = ['province_id' => $province_id];
$city_id && $o_where = ['city_id' => $city_id];
$o_where['status'] = 1;
$bizs = $this->biz_model->get_by_id_arr($biz_id_arr, $o_where, $fileds);
} else {
!$province_id && $province_id = '350000';
$province_id && $o_where = ['province_id' => $province_id];
$city_id && $o_where = ['city_id' => $city_id];
$o_where['status'] = 1;
$bizs = $this->biz_model->select($o_where, 'id desc', '', '', $fileds);
}
if ($bizs) {
foreach ($bizs as $key => $val) {
$where = ['status' => 0, 'biz_id' => $val['id']];
$fq_total = $this->orders_model->count($where);
$where = ['status' => 1, 'biz_id' => $val['id']];
$kp_total = $this->orders_model->count($where);
$where = ['status' => 2, 'biz_id' => $val['id'],];
$ck_total = $this->orders_model->count($where);
$lists[] = [
'id' => $val['id'],
'name' => $val['biz_name'],
'orders' => array(
array('name' => '签约下定 '.$fq_total, 'bg_color' => $fq_total ? '#fff' : '#999'),
array('name' => '发票开具 '.$kp_total, 'bg_color' => $kp_total ? '#fff' : '#999'),
array('name' => '车辆交付 '.$ck_total, 'bg_color' => $ck_total ? '#fff' : '#999'),
)
];
}
}
$data = [
'list' => $lists,
];
return $data;
}
//获取门店管理员
protected function get_admins()
{
$biz_id = $this->input_param('biz_id');
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 10;
if (!$biz_id) {
$biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']);
}
$where = [
'status' => 1,
'biz_id' => $biz_id
];
$lists = [];
$count = $this->app_user_model->count($where);
if ($count) {
$rows = $this->app_user_model->select($where, 'id desc', $page, $size, 'id,uname');
$lists = $rows;
}
$tabs = $bizs = [];
$re_biz = $this->biz_model->get(['id' => $biz_id, 'status' => 1]);
if ($re_biz['type'] == 1) {//品牌店
$tabs = [['id' => 1, 'name' => '本店'], ['id' => 2, 'name' => '其它门店']];
$bizs = $this->biz_model->select(['type' => 1, 'status' => 1], 'id desc', 0, 0, 'id, biz_name as name');
}
$data = [
'list' => $lists,
'total' => $count,
'tabs' => $tabs,
'bizs' => $bizs,
];
return $data;
}
/**
* 重新设置用户session里的biz_id
*/
protected function put_resetbiz()
{
$ukey = $this->input_param('ukey');
$biz_id = $this->input_param('biz_id');
if (!$biz_id) {
throw new Hd_Exception('参数错误', API_CODE_INVILD_PARAM);
}
$this->session['new_biz_id'] = $biz_id;
$this->app_redis->save($this->redis_login . $ukey, json_encode($this->session, JSON_UNESCAPED_UNICODE), 30 * 24 * 3600);
throw new Exception('保存成功', API_CODE_SUCCESS);
}
/**
* 切换角色:重新设置用户session里的group_id
*/
protected function put_resetgroupid()
{
$ukey = $this->input_param('ukey');
$group_id_type = $this->input_param('group_id');
if (!$group_id_type) {
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
}
$uid = $this->session['uid'];
$user = $this->app_user_model->get(array('id' => $uid));
if ($group_id_type == 'group_id1') {
$this->session['group_id'] = $user['group_id1'];
$this->session['biz_id'] = $user['biz_id1'];
$this->session['city_id'] = $user['city_id1'];
$this->session['province_id'] = $user['province_id1'];
$this->session['group_id_type'] = $group_id_type;
$this->session['new_biz_id'] = intval($user['biz_id1']);
} else {
$this->session['group_id'] = $user['group_id'];
$this->session['biz_id'] = $user['biz_id'];
$this->session['city_id'] = $user['city_id'];
$this->session['province_id'] = $user['province_id'];
$this->session['group_id_type'] = '';
$this->session['new_biz_id'] = '';
}
$this->app_redis->save($this->redis_login . $ukey, json_encode($this->session, JSON_UNESCAPED_UNICODE), 30 * 24 * 3600);
throw new Exception('保存成功', API_CODE_SUCCESS);
}
//获取用户手机号
protected function get_tel()
{
$uid = $this->session['uid'];
$user = $this->app_user_model->get(array('id' => $uid, 'group_id' => 0));
$data = [
'mobile' => $user['mobile'] ? $user['mobile'] : '',
];
return $data;
}
}