login_white = array('get_ukey');//登录白名单 $this->majia_white = array('get_ukey', 'get');//超级管理员披上马甲可操作权限 $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('items/items_model', 'mdItems'); } /** * 获取ukey * @return array * @throws Exception */ protected function get_ukey() { $mobile_white = ['15359333655', '18050017004', '18350451617', '13860199666']; $code = $this->input_param('code'); $mobile = $this->input_param('mobile'); $sms_code = $this->input_param('sms_code'); if (!$code || !$mobile || !$sms_code) { throw new Exception('参数错误', API_CODE_INVILD_PARAM); } //判断验证码 if (!in_array($mobile, $mobile_white) && $this->env != 'd') {//测试环境和测试号码 $mc = &load_cache(); $key = "licheb_login_code_" . $mobile; $cache_code = $mc->get($key); if ($sms_code != $cache_code) { throw new Exception('验证码错误', API_CODE_FAIL); } } $user = $this->app_user_model->get(['mobile' => $mobile, 'status>' => -1]); 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); //print_r($session); 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); } /** * 用户信息 * @return array */ protected function get() { $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'], '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'] : '' ); 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_orders_model', 'orders_model'); $this->load->model('receiver/order/receiver_order_signs_model', 'order_signs_model'); $this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit'); $where = [ "cont_time = '0000-00-00 00:00:00'" => null, 'biz_id' => $biz_id ]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $wl_count = $this->customers_model->count($where); $where = [ 'status>' => -1, 'is_top' => 1, 'biz_id' => $biz_id ]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $gz_count = $this->customers_model->count($where); $where = [ 'status' => 0, 'biz_id' => $biz_id ]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $sign_count = $this->orders_model->count($where); $where = [ 'status' => 1, 'biz_id' => $biz_id ]; $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $loan_count = $this->orders_model->count($where); //为创建订单客户 $where = [ 'lc_receiver_customers.status' => 2, 'lc_receiver_customers.biz_id' => $biz_id, 'lc_receiver_orders.id is null' => null ]; $group_id == 1 && $where['lc_receiver_customers.admin_id'] = $uid; $group_id == 4 && $where['lc_receiver_customers.brand_id!='] = 3; //渠道经理过滤 $uncre_count = $this->customers_model->count_order($where); $t1 = 'lc_receiver_order_signs'; $t2 = 'lc_receiver_orders'; $where = [ "status" => 0, "biz_id" => $biz_id ]; $group_id == 1 && $where["admin_id"] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $need_sign = $this->orders_model->count($where);//需要签名 //$where = [ // "status"=>1, // "biz_id" => $biz_id //]; //$group_id == 1 && $where["admin_id"] = $uid; //$group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 //$loan_count = $this->orders_model->count($where);//未选择分期 $where = [ "status" => 3, "biz_id" => $biz_id ]; $group_id == 1 && $where["admin_id"] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $bill_count = $this->orders_model->count($where);//开票相关 $where = [ "status" => 5, "biz_id" => $biz_id ]; $group_id == 1 && $where["admin_id"] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $del_count = $this->orders_model->count($where);//交付确认 $deallist = [ ['title' => '登记订单', 'icon' => 'icon-dengji', 'total' => $uncre_count, 'page' => '/pages/order/register/index'], ['title' => '需邀请签名', 'icon' => 'icon-qianming1', 'total' => $need_sign, 'page' => '/pages/order/filterList/index?key=0&ismy=1'], //['title'=>'未选择分期','icon'=>'icon-fenpei','total'=>$loan_count,'page'=>'/pages/order/filterList/index?key=1&ismy=1'], ['title' => '开票相关', 'icon' => 'icon-kaipiao1', 'total' => $bill_count, 'page' => '/pages/order/filterList/index?key=3&ismy=1'], ['title' => '交付确认', 'icon' => 'icon-jiaofu', 'total' => $del_count, 'page' => '/pages/order/filterList/index?key=5&ismy=1'], ]; //客户代办事项 $where_v = array('a.biz_id' => $biz_id, 'b.contact' => 1, 'b.status' => 1); $group_id == 1 && $where_v['a.admin_id'] = $uid; $visit_count = $this->mdCustomersVisit->count_visit($where_v); if ($group_id == 1) { $customer_op_list = [ ['title' => '待回访客户(人)', 'icon' => 'icon-dengji', 'total' => $visit_count, 'page' => '/pages/customer/filterList/index?visit=1&title=待回访客户'], ]; } else { //未派单客户 $where = ['admin_id' => 0, 'biz_id' => $biz_id, 'status>=' => 0]; if ($group_id == 4 && $biz_id != 1) { $where['brand_id!='] = 3; //渠道经理过滤 } $unuse_count = $this->customers_model->count($where); $defeat_count = $this->customers_model->count(array('biz_id' => $biz_id, 'defeat_time >' => 0, 'status>' => -1)); $customer_op_list = [ ['title' => '待分配客户(人)', 'icon' => 'icon-daifenpei', 'total' => $unuse_count, 'page' => '/pages/customer/allot/index'], ['title' => '待回访客户(人)', 'icon' => 'icon-statistics-custom-4', 'total' => $visit_count, 'page' => '/pages/customer/filterList/index?visit=1&title=待回访客户'], ['title' => '战败申请(人)', 'icon' => 'icon-statistics-custom-5', 'total' => $defeat_count, 'page' => '/pages/customer/optDefeat/index'], ]; } $data = [ 'wl_count' => $wl_count, 'gz_count' => $gz_count, 'sign_count' => $sign_count, 'loan_count' => $loan_count, 'deallist' => $deallist, 'customer_op_list' => $customer_op_list, ]; 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() { $city_id = $this->input_param('city_id'); $lists = []; $biz_id_arr = explode(',', $this->session['biz_id']); $fileds = 'id,biz_name,jsondata'; if ($this->session['biz_id'] && $biz_id_arr) { $city_id && $o_where = ['city_id' => $city_id]; $bizs = $this->biz_model->get_by_id_arr($biz_id_arr, $o_where, $fileds); } else { $bizs = $this->biz_model->select(['status' => 1, 'city_id' => $city_id], 'id desc', '', '', $fileds); } if ($bizs) { foreach ($bizs as $key => $val) { $auto_brands = []; $jsondata = json_decode($val['jsondata'], true); $auto_brands_arr = $jsondata['auto_brands']; $brand_ids = implode(',', $auto_brands_arr); if ($auto_brands_arr && $brand_ids) { $where = [ "id in ($brand_ids)" => null, "id !=" => 3 //过滤狸车品牌 ]; $brands = $this->auto_brand_model->select($where, '', 0, 0, 'id,name'); foreach ($brands as $key2 => $val2) { $count_items = $this->mdItems->count(['brand_id' => $val2['id'], 'status<>' => 0, 'biz_id' => $val['id'] , 'bill_time' => '0000-00-00 00:00:00']); $bg_color = $count_items ? '#fff' : '#999'; $auto_brands[] = ['name' => $val2['name'], 'bg_color' => $bg_color]; } } $lists[] = [ 'id' => $val['id'], 'name' => $val['biz_name'], 'auto_brands' => $auto_brands ]; } } $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; } $data = [ 'list' => $lists, 'total' => $count ]; 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); } }