Files
liche/api/controllers/wxapp/licheb/User.php
T
2021-09-18 14:48:43 +08:00

313 lines
11 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->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');
}
/**
* 获取ukey
* @return array
* @throws Exception
*/
protected function get_ukey(){
$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($mobile!='15359333655'){//测试号码
$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);
}
$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],'biz_name');
$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_name' => $biz['biz_name'] ? $biz['biz_name'] : ''
);
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');
$where = [
"cont_time = '0000-00-00 00:00:00'"=>null,
'biz_id'=>$biz_id
];
$group_id == 1 && $where['admin_id'] = $uid;
$wl_count = $this->customers_model->count($where);
$where = [
'status>'=>-1,
'is_top'=>1,
'biz_id'=>$biz_id
];
$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 = $this->orders_model->count($where);
$where = [
'status'=>1,
'biz_id'=>$biz_id
];
$group_id == 1 && $where['admin_id'] = $uid;
$loan_count = $this->orders_model->count($where);
//未派单客户
$unuse_count = $this->customers_model->count(['admin_id'=>0,'biz_id'=>$biz_id]);
//为创建订单客户
$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;
$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;
$need_sign = $this->orders_model->count($where);//需要签名
$where = [
"status"=>1,
"biz_id" => $biz_id
];
$group_id == 1 && $where["admin_id"] = $uid;
$loan_count = $this->orders_model->count($where);//未选择分期
$where = [
"status"=>3,
"biz_id" => $biz_id
];
$group_id == 1 && $where["admin_id"] = $uid;
$bill_count = $this->orders_model->count($where);//开票相关
$where = [
"status"=>5,
"biz_id" => $biz_id
];
$group_id == 1 && $where["admin_id"] = $uid;
$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'],
];
$data = [
'wl_count' => $wl_count,
'gz_count' => $gz_count,
'sign_count' => $sign_count,
'loan_count' => $loan_count,
'unuse_count' => $unuse_count,
'deallist' => $deallist
];
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,'name');
$auto_brands = array_column($brands,'name');
}
$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;
$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);
}
}