AdminModel.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. * @param array $params
  38. * @return \think\Paginator
  39. * @throws \think\db\exception\DbException
  40. */
  41. public function findByPaginate(array $params) {
  42. $where = [
  43. ['is_delete', '=', 0]
  44. ];
  45. if(isset($params['group_id']))
  46. array_push($where,['group_id', 'like', "%".$params['group_id']."%"]);
  47. return $this->where('erp_admin.is_delete', 0)
  48. ->with(['access','access.group'])
  49. ->hasWhere('access', $where)
  50. ->order('create_time','desc')
  51. ->paginate(['list_rows'=>10, "query" => $params]);
  52. }
  53. public function doesItExist($account) {
  54. $customer = $this->where([
  55. ["account", '=',$account],
  56. ["is_delete", '=', 0],
  57. ])->find();
  58. return $customer;
  59. }
  60. public function findById($id) {
  61. return $this->where('id',$id)->with(['access','access.group'])->find();
  62. }
  63. }