ThemeDownloadDao.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\ThemeDownload;
  14. /**
  15. * 主题下载记录 Dao
  16. * @author wuhaotian
  17. * @email 442384644@qq.com
  18. * @date 2026/3/10
  19. */
  20. class ThemeDownloadDao extends BaseDao
  21. {
  22. /**
  23. * 获取模型类名
  24. * @return string
  25. * @author wuhaotian
  26. * @email 442384644@qq.com
  27. * @date 2026/3/10
  28. */
  29. protected function setModel(): string
  30. {
  31. return ThemeDownload::class;
  32. }
  33. /**
  34. * 条件查询模型对象
  35. * @param array $where
  36. * @return \crmeb\basic\BaseModel
  37. * @author wuhaotian
  38. * @email 442384644@qq.com
  39. * @date 2026/3/10
  40. */
  41. public function getConditionModel(array $where)
  42. {
  43. return $this->getModel()
  44. ->when(isset($where['tid']) && $where['tid'] !== '', function ($query) use ($where) {
  45. $query->where('tid', $where['tid']);
  46. })
  47. ->when(isset($where['title']) && $where['title'] !== '', function ($query) use ($where) {
  48. $query->where('title', 'like', '%' . $where['title'] . '%');
  49. });
  50. }
  51. /**
  52. * 获取下载记录列表
  53. * @param array $where
  54. * @param string $field
  55. * @param int $page
  56. * @param int $limit
  57. * @param string $order
  58. * @return array
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @author wuhaotian
  63. * @email 442384644@qq.com
  64. * @date 2026/3/10
  65. */
  66. public function themeDownloadList(array $where, string $field = '*', int $page = 0, int $limit = 0, string $order = 'id desc'): array
  67. {
  68. return $this->getConditionModel($where)
  69. ->field($field)
  70. ->order($order)
  71. ->when($page != 0, function ($query) use ($page, $limit) {
  72. $query->page($page, $limit);
  73. })->select()->toArray();
  74. }
  75. /**
  76. * 获取下载记录数量
  77. * @param array $where
  78. * @return int
  79. * @author wuhaotian
  80. * @email 442384644@qq.com
  81. * @date 2026/3/10
  82. */
  83. public function themeDownloadCount(array $where): int
  84. {
  85. return $this->getConditionModel($where)->count();
  86. }
  87. }