SystemConfigClassifyDao.php 3.3 KB

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