93 lines
2.7 KiB
PHP
93 lines
2.7 KiB
PHP
<?php
|
|
namespace app\api\model;
|
|
|
|
|
|
/**
|
|
* 管理员模型
|
|
* @mixin \think\Model
|
|
*/
|
|
class Admin extends BaseModel
|
|
{
|
|
protected $schema = [
|
|
'id' => 'int',
|
|
'code' => 'string',
|
|
'username' => 'string',
|
|
'nickname' => 'string',
|
|
'password' => 'string',
|
|
'avatar' => 'string',
|
|
'role_id' => 'int',
|
|
'org_id' => 'int',
|
|
'dept_group_id' => 'int',
|
|
'dept_id' => 'int',
|
|
'mobile' => 'string',
|
|
'create_time' => 'int',
|
|
'create_ip' => 'string',
|
|
'last_time' => 'int',
|
|
'last_ip' => 'string',
|
|
'status' => 'int',
|
|
'update_time' => 'int',
|
|
];
|
|
|
|
/**
|
|
* 获取管理员列表
|
|
* @param array $where
|
|
* @param int $page
|
|
* @param int $size
|
|
* @param string $order
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getList($where, $page=1, $size=12, $order='id asc')
|
|
{
|
|
$w = [];
|
|
if (isset($where['username']) && $where['username'] != '') {
|
|
$w[] = ['username', 'like', $where['username'] . '%'];
|
|
}
|
|
|
|
if (isset($where['role_id']) && $where['role_id'] != 0) {
|
|
$w[] = ['role_id', '=', $where['role_id']];
|
|
}
|
|
|
|
if ($page < 0) $page = 1;
|
|
if ($size > 100) $size = 100;
|
|
|
|
$result = $this->where($w)->limit(($page-1)*$size, intval($size))->order($order)->withoutField(['password'])->select()->toArray();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 通过用户名获取信息
|
|
* @param string $username
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getInfoByUserName($username)
|
|
{
|
|
$result = $this->where(['username' => $username])->find();
|
|
return $result ? $result->toArray() : [];
|
|
}
|
|
|
|
/**
|
|
* 获取用户信息
|
|
* @param int $id 管理员表主键
|
|
* @param bool $type
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getUserInfo(int $id,bool $type=false):array
|
|
{
|
|
if ($type) {
|
|
$result = $this->find($id);
|
|
} else {
|
|
$result = $this->withoutField('password')->find($id);
|
|
}
|
|
return $result ? $result->toArray() : [];
|
|
}
|
|
}
|