1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?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.user_name,u.password,u.status')
- ->where('u.user_name', $userName)
- ->find();
- }
- /**
- * 根据搜索条件获取用户列表信息
- * @param $where
- * @param $offset
- * @param $limit
- */
- public function getUsersByWhere($where, $offset, $limit)
- {
- return $this->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());
- }
- }
- }
|