Files
liche/api/controllers/wxapp/licheb/User.php
T
2021-07-22 15:46:18 +08:00

116 lines
3.7 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();//授权微信信息
}
/**
* 获取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);
}
//判断验证码
$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'];
$user = $this->app_user_model->get(array('id' => $uid));
$data = array(
'uid' => $uid,
'uname' => $user['uname'],
'mobile' => $user['mobile'],
'group_id' => $user['group_id']
);
return $data;
}
/**
* 统计数据
*/
protected function get_cal(){
$uid = $this->session['uid'];
$this->load->model('receiver/receiver_customers_model','customers_model');
$this->load->model('receiver/order/receiver_orders_model','orders_model');
$wl_count = $this->customers_model->count(['status'=>0,'admin_id'=>$uid]);
$gz_count = $this->customers_model->count(['status>-1'=>null,'is_top'=>1,'admin_id'=>$uid]);
$sign_count = $this->orders_model->count(['status'=>0,'admin_id'=>$uid]);
$loan_count = $this->orders_model->count(['status'=>1,'admin_id'=>$uid]);
$data = [
'wl_count' => $wl_count,
'gz_count' => $gz_count,
'sign_count' => $sign_count,
'loan_count' => $loan_count
];
return $data;
}
}