GroupDao.php 2.1 KB

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