Housekeeper.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 管家模型
  7. * Class Housekeeper
  8. * @package app\admin\model
  9. */
  10. class Housekeeper extends Model
  11. {
  12. const UPDATED_AT = 'housekeeper_update_time';//模型自动更新时间字段
  13. const DEL_NO = 0;
  14. const DEL_YES = 1;
  15. const DEL_STATUS = [
  16. self::DEL_NO => '未删除',
  17. self::DEL_YES => '已删除'
  18. ];
  19. /**
  20. *
  21. * The table associated with the model.
  22. *
  23. * @var string
  24. */
  25. protected $table = 'housekeeper';
  26. protected $dateFormat = 'U';//操作数据库时间格式 时间戳
  27. /**
  28. * Notes:获取管家列表
  29. * @param $keywords
  30. * @param $page
  31. * @param $limit
  32. * @return array
  33. * User: yym
  34. * Date: 2022/10/28
  35. */
  36. public static function getHousekeeperList($keywords, $page, $limit)
  37. {
  38. $list = static::where(['housekeeper_del' => static::DEL_NO])
  39. ->when($keywords != '', function ($query) use ($keywords){
  40. $query->where('housekeeper_name', 'like', '%' . $keywords . '%')
  41. ->orWhere('housekeeper_real_name', 'like', '%' . $keywords . '%')
  42. ->orWhere('housekeeper_phone', 'like', '%' . $keywords . '%');
  43. })
  44. ->forPage($page, $limit)
  45. ->get()
  46. ->toArray();
  47. $count = static::where(['housekeeper_del' => static::DEL_NO])
  48. ->when($keywords != '', function ($query) use ($keywords){
  49. $query->where('housekeeper_name', 'like', '%' . $keywords . '%')
  50. ->orWhere('housekeeper_real_name', 'like', '%' . $keywords . '%')
  51. ->orWhere('housekeeper_phone', 'like', '%' . $keywords . '%');
  52. })
  53. ->count();
  54. return [$list, $count];
  55. }
  56. /**
  57. * Notes:检测账号是否存在
  58. * @param $account
  59. * @return bool
  60. * User: yym
  61. * Date: 2022/10/28
  62. */
  63. public static function checkAccount($account)
  64. {
  65. return static::where(['housekeeper_name' => $account, 'housekeeper_del' => static::DEL_NO])->exists();
  66. }
  67. /**
  68. * Notes:检测账号是否存在
  69. * @param $account
  70. * @param $id
  71. * @return bool
  72. * User: yym
  73. * Date: 2022/10/28
  74. */
  75. public static function checkAccountNo($account, $id)
  76. {
  77. return static::where(['housekeeper_name' => $account, 'housekeeper_del' => static::DEL_NO])->where('housekeeper_id', '!=', $id)->exists();
  78. }
  79. /**
  80. * Notes:插入数据
  81. * @param array $data
  82. * @return false|int
  83. * User: yym
  84. * Date: 2022/10/28
  85. */
  86. public static function insertData(array $data)
  87. {
  88. if(empty($data))
  89. {
  90. return false;
  91. }
  92. return static::insertGetId($data);
  93. }
  94. /**
  95. * Notes:根据主键更新数据
  96. * @param array $data
  97. * @param int $id
  98. * @return false|int
  99. * User: yym
  100. * Date: 2022/10/28
  101. */
  102. public static function updateData(array $data, int $id)
  103. {
  104. if(empty($data) || empty($id))
  105. {
  106. return false;
  107. }
  108. return static::where(['housekeeper_id' => $id])->update($data);
  109. }
  110. /**
  111. * Notes:获取详情
  112. * @param int $id
  113. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  114. * User: yym
  115. * Date: 2022/10/28
  116. */
  117. public static function getInfo(int $id)
  118. {
  119. return static::where(['housekeeper_id' => $id, 'housekeeper_del' => static::DEL_NO])->first();
  120. }
  121. }