SystemConfigClassifyDao.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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\config;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\BaseModel;
  14. use app\common\model\system\config\SystemConfigClassify;
  15. use think\Collection;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. use think\Model;
  20. /**
  21. * Class SystemConfigClassifyDao
  22. * @package app\common\dao\system\config
  23. * @author xaboy
  24. * @day 2020-03-27
  25. */
  26. class SystemConfigClassifyDao extends BaseDao
  27. {
  28. /**
  29. * @return BaseModel
  30. * @author xaboy
  31. * @day 2020-03-30
  32. */
  33. protected function getModel(): string
  34. {
  35. return SystemConfigClassify::class;
  36. }
  37. /**
  38. * @return array
  39. * @author xaboy
  40. * @day 2020-03-27
  41. */
  42. public function getOptions()
  43. {
  44. return SystemConfigClassify::column('pid,classify_name', 'config_classify_id');
  45. }
  46. /**
  47. * @return array
  48. * @author xaboy
  49. * @day 2020-04-22
  50. */
  51. public function getTopOptions()
  52. {
  53. return SystemConfigClassify::getDB()->where('pid', 0)->column('classify_name', 'config_classify_id');
  54. }
  55. /**
  56. * @return Collection
  57. * @throws DataNotFoundException
  58. * @throws DbException
  59. * @throws ModelNotFoundException
  60. * @author xaboy
  61. * @day 2020-03-31
  62. */
  63. public function all()
  64. {
  65. return SystemConfigClassify::getDB()->select();
  66. }
  67. /**
  68. * @return int
  69. * @author xaboy
  70. * @day 2020-03-31
  71. */
  72. public function count()
  73. {
  74. return SystemConfigClassify::getDB()->count();
  75. }
  76. /**
  77. * @param int $pid
  78. * @param string $field
  79. * @return Collection
  80. * @throws DataNotFoundException
  81. * @throws DbException
  82. * @throws ModelNotFoundException
  83. * @author xaboy
  84. * @day 2020-03-27
  85. */
  86. public function children(int $pid, string $field = 'id,classify_name')
  87. {
  88. return SystemConfigClassify::getDB()->where('pid', $pid)->field($field)->select();
  89. }
  90. /**
  91. * @param int $id
  92. * @return bool
  93. * @author xaboy
  94. * @day 2020-03-27
  95. */
  96. public function existsChild(int $id): bool
  97. {
  98. return $this->fieldExists('pid', $id);
  99. }
  100. /**
  101. * @param $key
  102. * @param int|null $except
  103. * @return bool
  104. * @author xaboy
  105. * @day 2020-03-27
  106. */
  107. public function keyExists($key, ?int $except = null): bool
  108. {
  109. return $this->fieldExists('classify_key', $key, $except);
  110. }
  111. /**
  112. * @param int $pid
  113. * @param int|null $except
  114. * @return bool
  115. * @author xaboy
  116. * @day 2020-03-27
  117. */
  118. public function pidExists(int $pid, ?int $except = null): bool
  119. {
  120. return $this->fieldExists('config_classify_id', $pid, $except);
  121. }
  122. /**
  123. * @param string $key
  124. * @return mixed
  125. * @author xaboy
  126. * @day 2020-04-22
  127. */
  128. public function keyById(string $key)
  129. {
  130. return SystemConfigClassify::getDB()->where('classify_key', $key)->value('config_classify_id');
  131. }
  132. /**
  133. * @param string $key
  134. * @return array|Model|null
  135. * @throws DataNotFoundException
  136. * @throws DbException
  137. * @throws ModelNotFoundException
  138. * @author xaboy
  139. * @day 2020-04-22
  140. */
  141. public function keyByData(string $key)
  142. {
  143. return SystemConfigClassify::getDB()->where('classify_key', $key)->find();
  144. }
  145. }