SystemAdmin.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\admin\model;
  3. use support\Model;
  4. /**
  5. * 悦享家后台管理员模型
  6. * Class SystemAdmin
  7. * @package app\admin\model
  8. */
  9. class SystemAdmin extends Model
  10. {
  11. const DISABLED = 0;
  12. const VALID = 1;
  13. /**
  14. * The table associated with the model.
  15. *
  16. * @var string
  17. */
  18. protected $table = 'system_admin';
  19. public $timestamps = false;
  20. /**
  21. * Notes:获取管理员列表
  22. * @param string $keywords
  23. * @param int $page
  24. * @param int $limit
  25. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  26. * User: yym
  27. * Date: 2022/9/14
  28. */
  29. public static function adminList(string $keywords, int $page, int $limit, $status)
  30. {
  31. $list = static::select('*')
  32. ->where(['admin_is_del'=>0])
  33. ->when($keywords != '', function ($query) use ($keywords){
  34. $query->where('admin_account', 'like', '%' . $keywords . '%');
  35. })
  36. ->when($status != '', function ($query) use ($status){
  37. $query->where('admin_status', $status);
  38. })
  39. ->orderBy('admin_create_time','DESC')
  40. ->forPage($page, $limit)
  41. ->get();
  42. $count = static::where(['admin_is_del'=>0])
  43. ->when($keywords != '', function ($query) use ($keywords){
  44. $query->where('admin_account', 'like', '%' . $keywords . '%');
  45. })
  46. ->count();
  47. return [$list, $count];
  48. }
  49. /**
  50. * Notes:获取管理员信息
  51. * @param string $account
  52. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  53. * User: yym
  54. * Date: 2022/9/14
  55. */
  56. public static function getInfo(string $account)
  57. {
  58. return static::where(['admin_account' => $account])->first();
  59. }
  60. /**
  61. * Notes:获取管理员信息
  62. * @param int $admin_id
  63. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  64. * User: yym
  65. * Date: 2022/9/14
  66. */
  67. public static function getAdminInfo(int $admin_id)
  68. {
  69. return static::where(['admin_id' => $admin_id])->first();
  70. }
  71. /**
  72. * Notes:更新内容
  73. * @param int $admin_id
  74. * @param array $update
  75. * @return int
  76. * User: yym
  77. * Date: 2022/9/14
  78. */
  79. public static function updateInfo(int $admin_id, array $update)
  80. {
  81. return static::where(['admin_id' => $admin_id])->update($update);
  82. }
  83. }