AdminModel.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\common\model;
  3. class AdminModel extends BaseModel
  4. {
  5. protected $table = 'erp_admin';
  6. public function genSchema(array $schema)
  7. {
  8. $this->schema = [
  9. 'id' => 'number',
  10. 'account' => 'string',
  11. 'nickname' => 'string',
  12. 'password' => 'string',
  13. 'token' => 'string',
  14. 'delete_time' => 'number',
  15. 'create_time' => 'number',
  16. 'update_time' => 'number'
  17. ];
  18. }
  19. public function access()
  20. {
  21. return self::hasOne(AuthGroupAccessModel::class,'admin_id','id');
  22. }
  23. public function loadByLogin($username, $password) {
  24. return $this->where([
  25. ['account|id', '=', $username],
  26. ['password', '=', $password],
  27. ['is_delete', '=',0]
  28. ])->find();
  29. }
  30. public function refreshToken($adminId,$token) {
  31. return $this->where([
  32. ['id', '=',$adminId],
  33. ['is_delete', '=',0]
  34. ])->update(['token' => $token]);
  35. }
  36. /**
  37. * @return \think\Paginator
  38. * @throws \think\db\exception\DbException
  39. */
  40. public function findByPaginate() {
  41. return $this->where('is_delete',0)->with(['access','access.group'])->paginate(10);
  42. }
  43. public function doesItExist($account) {
  44. $customer = $this->where([
  45. ["account", '=',$account],
  46. ["is_delete", '=', 0],
  47. ])->find();
  48. return $customer;
  49. }
  50. public function findById($id) {
  51. return $this->where('id',$id)->with(['access','access.group'])->find();
  52. }
  53. }