SystemConfigClassifyDao.php 3.4 KB

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