GroupDao.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\common\dao\system\groupData;
  3. use app\common\dao\BaseDao;
  4. use app\common\model\system\groupData\SystemGroup;
  5. use think\Collection;
  6. use think\db\BaseQuery;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. /**
  11. * Class GroupDao
  12. * @package app\common\dao\system\groupData
  13. * @author xaboy
  14. * @day 2020-03-27
  15. */
  16. class GroupDao extends BaseDao
  17. {
  18. /**
  19. * @return string
  20. * @author xaboy
  21. * @day 2020-03-30
  22. */
  23. protected function getModel(): string
  24. {
  25. return SystemGroup::class;
  26. }
  27. /**
  28. * @return Collection
  29. * @throws DataNotFoundException
  30. * @throws DbException
  31. * @throws ModelNotFoundException
  32. * @author xaboy
  33. * @day 2020-04-01
  34. */
  35. public function all()
  36. {
  37. return SystemGroup::getDB()->select();
  38. }
  39. /**
  40. * @return int
  41. * @author xaboy
  42. * @day 2020-04-01
  43. */
  44. public function count()
  45. {
  46. return SystemGroup::getDB()->count();
  47. }
  48. /**
  49. * @param $page
  50. * @param $limit
  51. * @return BaseQuery
  52. * @author xaboy
  53. * @day 2020-04-01
  54. */
  55. public function page($page, $limit)
  56. {
  57. return SystemGroup::getDB()->page($page, $limit);
  58. }
  59. /**
  60. * @param $key
  61. * @param int|null $except
  62. * @return bool
  63. * @author xaboy
  64. * @day 2020-03-27
  65. */
  66. public function keyExists($key, ?int $except = null): bool
  67. {
  68. return parent::fieldExists('group_key', $key, $except);
  69. }
  70. /**
  71. * @param $id
  72. * @return mixed
  73. * @author xaboy
  74. * @day 2020-04-02
  75. */
  76. public function fields($id)
  77. {
  78. return json_decode(SystemGroup::getDB()->where('group_id', $id)->value('fields'), true);
  79. }
  80. /**
  81. * @param string $key
  82. * @return mixed
  83. * @author xaboy
  84. * @day 2020/5/27
  85. */
  86. public function keyById(string $key)
  87. {
  88. return SystemGroup::getDB()->where('group_key', $key)->value('group_id');
  89. }
  90. }