ThemeDao.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\diy;
  12. use app\dao\BaseDao;
  13. use app\model\diy\Theme;
  14. /**
  15. * 自定义主题
  16. * @author wuhaotian
  17. * @email 442384644@qq.com
  18. * @date 2025/12/18
  19. */
  20. class ThemeDao extends BaseDao
  21. {
  22. /**
  23. * 获取模型类名
  24. * @return string
  25. * @author wuhaotian
  26. * @email 442384644@qq.com
  27. * @date 2025/12/18
  28. */
  29. protected function setModel(): string
  30. {
  31. return Theme::class;
  32. }
  33. /**
  34. * 条件查询模型对象
  35. * @param $where
  36. * @return \crmeb\basic\BaseModel
  37. * @author wuhaotian
  38. * @email 442384644@qq.com
  39. * @date 2025/12/18
  40. */
  41. public function getConditionModel($where)
  42. {
  43. return $this->getModel()->where('is_del', 0)
  44. ->when(isset($where['title']) && $where['title'] !== '', function ($query) use ($where) {
  45. $query->where('title|info', 'like', '%' . $where['title'] . '%');
  46. })->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
  47. $query->where('is_del', $where['is_del']);
  48. })->when(isset($where['is_use']) && $where['is_use'] !== '', function ($query) use ($where) {
  49. $query->where('is_use', $where['is_use']);
  50. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  51. $query->where('type', $where['type']);
  52. })->when(isset($where['page_type']) && $where['page_type'] !== '', function ($query) use ($where) {
  53. $query->where('page_type', $where['page_type']);
  54. });
  55. }
  56. /**
  57. * 获取自定义主题列表
  58. * @param $where
  59. * @param $field
  60. * @param int $page
  61. * @param int $limit
  62. * @param string $order
  63. * @return array
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @author wuhaotian
  68. * @email 442384644@qq.com
  69. * @date 2025/12/18
  70. */
  71. public function themeList($where, $field, $page = 0, $limit = 0, $order = 'id desc')
  72. {
  73. return $this->getConditionModel($where)
  74. ->field($field)
  75. ->order($order)
  76. ->when($page != 0, function ($query) use ($page, $limit) {
  77. $query->page($page, $limit);
  78. })->select()->toArray();
  79. }
  80. /**
  81. * 获取自定义主题数量
  82. * @param $where
  83. * @return int
  84. * @author wuhaotian
  85. * @email 442384644@qq.com
  86. * @date 2025/12/18
  87. */
  88. public function themeCount($where)
  89. {
  90. return $this->getConditionModel($where)->count();
  91. }
  92. }