12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace app\index\model;
- use think\Model;
- use think\exception\PDOException;
- class UserModel extends Model{
- // 确定链接表名
- protected $name = 'user';
- /**
- * 根据用户名检测用户数据
- * @param $userName
- */
- public function checkUser($userName)
- {
- return $this->alias('u')
- ->field('u.id,u.username,u.password,u.status,u.rule')
- ->where('u.username', $userName)
- ->find();
- }
- /**
- * 根据搜索条件获取用户列表信息
- * @param $where
- * @param $offset
- * @param $limit
- */
- public function getUsersByWhere($where, $offset, $limit)
- {
- return $this->where($where)->limit($offset, $limit)->order('id desc')->field('id,username,create_timestamp,last_login_ip,last_login_time,status,update_timestamp,rule')->select();
- }
- /**
- * 根据搜索条件获取所有的用户数量
- * @param $where
- */
- public function getAllUsers($where)
- {
- return $this->where($where)->count();
- }
- /**
- * 管理员登录信息同步错误
- * @param array $param
- */
- public function updateStatus($param = [], $uid)
- {
- try{
- $this->where('id', $uid)->update($param);
- return msg(1, '', 'ok');
- }catch (\Exception $e){
- return msg(-1, '', $e->getMessage());
- }
- }
- /**
- * 插入管理员信息
- * @param $param
- */
- public function insertUser($param)
- {
- try{
- $param['create_timestamp'] = $param['update_timestamp'] = date('Y-m-d H:i:s');
- $result = $this->save($param);
- if(false === $result){
- // 验证失败 输出错误信息
- return msg(-1, '', $this->getError());
- }else{
- return msg(1, '', '添加用户成功');
- }
- }catch(PDOException $e){
- return msg(-2, '', $e->getMessage());
- }
- }
- /**
- * 删除管理员
- * @param $id
- */
- public function delUser($id)
- {
- try{
- $this->where('id', $id)->delete();
- return msg(1, '', '删除管理员成功');
- }catch( PDOException $e){
- return msg(-1, '', $e->getMessage());
- }
- }
- }
|