| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace app\common\model;
- class AdminModel extends BaseModel
- {
- protected $table = 'erp_admin';
- public function genSchema(array $schema)
- {
- $this->schema = [
- 'id' => 'number',
- 'account' => 'string',
- 'nickname' => 'string',
- 'password' => 'string',
- 'token' => 'string',
- 'delete_time' => 'number',
- 'create_time' => 'number',
- 'update_time' => 'number'
- ];
- }
- public function access()
- {
- return self::hasOne(AuthGroupAccessModel::class,'admin_id','id');
- }
- public function loadByLogin($username, $password) {
- return $this->where([
- ['account|id', '=', $username],
- ['password', '=', $password],
- ['is_delete', '=',0]
- ])->find();
- }
- public function refreshToken($adminId,$token) {
- return $this->where([
- ['id', '=',$adminId],
- ['is_delete', '=',0]
- ])->update(['token' => $token]);
- }
- /**
- * @return \think\Paginator
- * @throws \think\db\exception\DbException
- */
- public function findByPaginate() {
- return $this->where('is_delete',0)->with(['access','access.group'])->paginate(10);
- }
- public function doesItExist($account) {
- $customer = $this->where([
- ["account", '=',$account],
- ["is_delete", '=', 0],
- ])->find();
- return $customer;
- }
- public function findById($id) {
- return $this->where('id',$id)->with(['access','access.group'])->find();
- }
- }
|