| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- /**
- * 短信服务
- * @author wesmiler
- */
- namespace app\index\service;
- use app\index\model\UserModel;
- class Users
- {
- /**
- * 更新数据
- * @param $params
- * @return int|string
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public static function saveData($params){
- $id = isset($params['id'])? intval($params['id']) : 0;
- $data = [
- 'mobile'=> isset($params['mobile'])? trim($params['mobile']) : '',
- 'user_login'=> isset($params['mobile'])? trim($params['mobile']) : '',
- 'user_nickname'=> isset($params['nickname'])? trim($params['nickname']) : '',
- 'user_type'=> isset($params['user_type'])? intval($params['user_type']) : 2,
- 'user_status'=> isset($params['user_status'])? intval($params['user_status']) : 1,
- 'avatar'=> isset($params['avatar'])? trim($params['avatar']) : '',
- ];
- $userPass = isset($params['password'])? trim($params['password']) : '';
- if($userPass){
- $data['user_pass'] = cmf_password($userPass);
- }
- if($id){
- return UserModel::where(['id'=> $id])->update($data);
- }else{
- return UserModel::insertGetId($data);
- }
- }
- /**
- * 获取会员信息
- * @param $where 条件
- * @param string $field 字段
- * @return array|false|\PDOStatement|string|Model
- */
- public static function getInfo($where, $field = "")
- {
- $field = $field ? $field : 'id,openid,user_nickname,user_type,avatar,user_login,user_status,mobile,balance,user_status';
- $info = UserModel::where($where)->field($field)->find();
- return $info ? $info->toArray() : [];
- }
- /**
- * 用户登录
- * @param $params 参数,mobile-必填,password-必填
- * @return array|int
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function login($params){
- $mobile = isset($params['mobile'])? trim($params['mobile']) : '';
- $password = isset($params['password'])? trim($params['password']) : '';
- $userInfo = UserModel::where(['mobile|user_login'=> $mobile])
- ->field('id,user_login,mobile,user_pass,user_nickname,user_status,avatar')
- ->find();
- if(is_null($userInfo) || empty($userInfo)){
- return 1015;
- }
- $userPassword = isset($userInfo['user_pass'])? $userInfo['user_pass'] : '';
- if(!cmf_compare_password($password, $userPassword)){
- return 1016;
- }
- $userStatus = isset($userInfo['user_status'])? intval($userInfo['user_status']) : 0;
- if($userStatus != 1){
- return 1017;
- }
- $userInfo['mobile'] = formatName($userInfo['mobile']);
- $userInfo['user_login'] = formatName($userInfo['user_login']);
- unset($userInfo['user_pass']);
- session('UID', $userInfo['id']);
- $token = md5($userInfo['id'].'qxq');
- PRedis::set('tokens:'.$token, $userInfo, 24*3600);
- return ['token'=> $token, 'userInfo'=> $userInfo];
- }
- }
|