AdminModel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 department()
  24. {
  25. return self::hasOne(DepartmentModel::class,'id','department_id');
  26. }
  27. public function loadByLogin($username, $password) {
  28. return $this->where([
  29. ['account|id|mobile', '=', $username],
  30. ['password', '=', $password],
  31. ['is_delete', '=',0]
  32. ])->find();
  33. }
  34. public function refreshToken($adminId,$token) {
  35. return $this->where([
  36. ['id', '=',$adminId],
  37. ['is_delete', '=',0]
  38. ])->update(['token' => $token]);
  39. }
  40. /**
  41. * @param array $params
  42. * @return \think\Paginator
  43. * @throws \think\db\exception\DbException
  44. */
  45. public function findByPaginate(array $params) {
  46. $where = [
  47. ['erp_admin.is_delete', '=', 0],
  48. ];
  49. $access_where = [
  50. ['is_delete', '=', 0]
  51. ];
  52. if(isset($params['group_id']) && $params['group_id'] > 0)
  53. array_push($access_where,['group_id', '=', $params['group_id']]);
  54. if(isset($params['department_id']) && $params['department_id'] > 0)
  55. array_push($where, ['erp_admin.department_id', '=', $params['department_id']]);
  56. return $this->where($where)
  57. ->with(['access','access.group', 'department'])
  58. ->hasWhere('access', $access_where)
  59. ->hasWhere('department')
  60. ->order('create_time','desc')
  61. ->paginate(['list_rows' => 10, "query" => $params]);
  62. }
  63. public function doesItExist($account) {
  64. $customer = $this->where([
  65. ["account", '=',$account],
  66. ["is_delete", '=', 0],
  67. ])->find();
  68. return $customer;
  69. }
  70. public function findById($id) {
  71. return $this->where('id',$id)->with(['access','access.group','department'])->find();
  72. }
  73. public function findAdmins($text) {
  74. $where = [
  75. ['is_delete', '=', 0]
  76. ];
  77. if($text != null) {
  78. array_push($where,['id|nickname','like', '%'.$text.'%']);
  79. }
  80. return $this->where($where)->limit(20)->order('id', 'desc')->select();
  81. }
  82. }