12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\index\model;
- use think\Model;
- class UserModel extends Model{
- // 确定链接表名
- protected $name = 'user';
- /**
- * 根据用户名检测用户数据
- * @param $userName
- */
- public function checkUser($userName,$password)
- {
- return $this->alias('u')
- ->field('u.id,u.user_name,r.role_name,u.role_id,r.rules,u.password,u.status')
- ->join('role r', 'u.role_id = r.id')
- ->where('u.user_name', $userName)
- ->find();
- }
- /**
- * 根据搜索条件获取用户列表信息
- * @param $where
- * @param $offset
- * @param $limit
- */
- public function getUsersByWhere($where, $offset, $limit)
- {
- return $this->alias('user')->field( 'user.*,role_name')
- ->join('role rol', 'user.role_id = ' . 'rol.id')
- ->where($where)->limit($offset, $limit)->order('id desc')->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());
- }
- }
- }
|