ThemeDownloadServices.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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\services\diy;
  12. use app\dao\diy\ThemeDownloadDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\AdminException;
  15. /**
  16. * 主题下载记录服务类
  17. * @author wuhaotian
  18. * @email 442384644@qq.com
  19. * @date 2026/3/10
  20. */
  21. class ThemeDownloadServices extends BaseServices
  22. {
  23. /**
  24. * 构造方法
  25. * @param ThemeDownloadDao $dao
  26. */
  27. public function __construct(ThemeDownloadDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. /**
  32. * 获取下载记录列表
  33. * @param array $where
  34. * @param int $page
  35. * @param int $limit
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. * @author wuhaotian
  41. * @email 442384644@qq.com
  42. * @date 2026/3/10
  43. */
  44. public function getDownloadList(array $where, int $page = 0, int $limit = 0): array
  45. {
  46. $list = $this->dao->themeDownloadList($where, '*', $page, $limit);
  47. $count = $this->dao->themeDownloadCount($where);
  48. return compact('list', 'count');
  49. }
  50. /**
  51. * 获取下载记录详情
  52. * @param int $id
  53. * @return array
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @author wuhaotian
  58. * @email 442384644@qq.com
  59. * @date 2026/3/10
  60. */
  61. public function getDownloadInfo(int $id): array
  62. {
  63. $info = $this->dao->get($id);
  64. if (!$info) {
  65. throw new AdminException('下载记录不存在');
  66. }
  67. return $info->toArray();
  68. }
  69. /**
  70. * 新增下载记录
  71. * @param int $tid 主题ID
  72. * @param string $title 主题名称
  73. * @param string $downloadUrl 下载地址
  74. * @return int 新记录ID
  75. * @author wuhaotian
  76. * @email 442384644@qq.com
  77. * @date 2026/3/10
  78. */
  79. public function addDownloadRecord(int $tid, string $title, string $downloadUrl): int
  80. {
  81. return $this->dao->insertGetId([
  82. 'tid' => $tid,
  83. 'title' => $title,
  84. 'download_time' => time(),
  85. 'download_url' => $downloadUrl,
  86. ]);
  87. }
  88. /**
  89. * 删除下载记录
  90. * @param int $id
  91. * @return bool
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\DbException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @author wuhaotian
  96. * @email 442384644@qq.com
  97. * @date 2026/3/10
  98. */
  99. public function deleteDownloadRecord(int $id): bool
  100. {
  101. if (!$this->dao->get($id)) {
  102. throw new AdminException('下载记录不存在');
  103. }
  104. return (bool)$this->dao->delete($id);
  105. }
  106. /**
  107. * 更新下载地址
  108. * @param int $id 记录ID
  109. * @param string $downloadUrl 下载地址
  110. * @return bool
  111. * @author wuhaotian
  112. * @email 442384644@qq.com
  113. * @date 2026/3/10
  114. */
  115. public function updateDownloadUrl(int $id, string $downloadUrl): bool
  116. {
  117. return (bool)$this->dao->update($id, ['download_url' => $downloadUrl]);
  118. }
  119. }