GroupDao.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\system\groupData;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\system\groupData\SystemGroup;
  14. use think\Collection;
  15. use think\db\BaseQuery;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. /**
  20. * Class GroupDao
  21. * @package app\common\dao\system\groupData
  22. * @author xaboy
  23. * @day 2020-03-27
  24. */
  25. class GroupDao extends BaseDao
  26. {
  27. /**
  28. * @return string
  29. * @author xaboy
  30. * @day 2020-03-30
  31. */
  32. protected function getModel(): string
  33. {
  34. return SystemGroup::class;
  35. }
  36. /**
  37. * @return Collection
  38. * @throws DataNotFoundException
  39. * @throws DbException
  40. * @throws ModelNotFoundException
  41. * @author xaboy
  42. * @day 2020-04-01
  43. */
  44. public function all()
  45. {
  46. return SystemGroup::getDB()->select();
  47. }
  48. /**
  49. * @return int
  50. * @author xaboy
  51. * @day 2020-04-01
  52. */
  53. public function count()
  54. {
  55. return SystemGroup::getDB()->count();
  56. }
  57. /**
  58. * @param $page
  59. * @param $limit
  60. * @return BaseQuery
  61. * @author xaboy
  62. * @day 2020-04-01
  63. */
  64. public function page($page, $limit)
  65. {
  66. return SystemGroup::getDB()->page($page, $limit);
  67. }
  68. /**
  69. * @param $key
  70. * @param int|null $except
  71. * @return bool
  72. * @author xaboy
  73. * @day 2020-03-27
  74. */
  75. public function keyExists($key, ?int $except = null): bool
  76. {
  77. return parent::fieldExists('group_key', $key, $except);
  78. }
  79. /**
  80. * @param $id
  81. * @return mixed
  82. * @author xaboy
  83. * @day 2020-04-02
  84. */
  85. public function fields($id)
  86. {
  87. return json_decode(SystemGroup::getDB()->where('group_id', $id)->value('fields'), true);
  88. }
  89. /**
  90. * @param string $key
  91. * @return mixed
  92. * @author xaboy
  93. * @day 2020/5/27
  94. */
  95. public function keyById(string $key)
  96. {
  97. return SystemGroup::getDB()->where('group_key', $key)->value('group_id');
  98. }
  99. }