diff --git a/backend/app/adminapi/controller/diy/ThemeController.php b/backend/app/adminapi/controller/diy/ThemeController.php index 57cfee8f4..668d3d486 100644 --- a/backend/app/adminapi/controller/diy/ThemeController.php +++ b/backend/app/adminapi/controller/diy/ThemeController.php @@ -107,6 +107,18 @@ class ThemeController extends AuthController return app('json')->success($data); } + /** + * 主题预览小程序二维码 + * @param int $id 主题ID + * @return \think\Response + */ + public function getRoutineCode($id) + { + $pageType = (string)$this->request->param('page_type', 'home'); + $image = $this->services->getRoutineCode((int)$id, $pageType); + return app('json')->success(compact('image')); + } + /** * 保存主题基本信息 * @param int $id 主题ID diff --git a/backend/app/adminapi/route/diy.php b/backend/app/adminapi/route/diy.php index 36b465aa3..99fb5f022 100644 --- a/backend/app/adminapi/route/diy.php +++ b/backend/app/adminapi/route/diy.php @@ -87,6 +87,7 @@ Route::group('theme', function () { Route::get('plugin_status', [\app\adminapi\controller\diy\ThemeController::class, 'getPluginStatus'])->option(['real_name' => '主题活动插件安装状态']); Route::get('list', [\app\adminapi\controller\diy\ThemeController::class, 'getThemeList'])->option(['real_name' => '主题列表']); Route::get('info/:id/[:type]', [\app\adminapi\controller\diy\ThemeController::class, 'getThemeInfo'])->option(['real_name' => '主题详情']); + Route::get('routine_code/:id', [\app\adminapi\controller\diy\ThemeController::class, 'getRoutineCode'])->option(['real_name' => '主题预览小程序码']); Route::post('save/:id', [\app\adminapi\controller\diy\ThemeController::class, 'saveTheme'])->option(['real_name' => '保存主题']); Route::post('save_title/:id', [\app\adminapi\controller\diy\ThemeController::class, 'saveThemeTitle'])->option(['real_name' => '保存主题名称和简介']); Route::post('save_image/:id', [\app\adminapi\controller\diy\ThemeController::class, 'saveThemeImage'])->option(['real_name' => '保存主题的图片']); diff --git a/backend/app/services/diy/ThemeServices.php b/backend/app/services/diy/ThemeServices.php index 2e9f8b6b7..9839d157b 100644 --- a/backend/app/services/diy/ThemeServices.php +++ b/backend/app/services/diy/ThemeServices.php @@ -13,6 +13,7 @@ namespace app\services\diy; use app\dao\diy\ThemeDao; +use app\services\other\QrcodeServices; use crmeb\basic\BaseService; use crmeb\exceptions\AdminException; use crmeb\exceptions\ApiException; @@ -699,6 +700,27 @@ class ThemeServices extends BaseService return $navigation; } + /** + * 取主题预览小程序二维码 + * + * @param int $id 主题ID(eb_theme 表主键) + * @param string $pageType micro 时二维码指向微页面预览页,其余指向首页 + * @return string|false + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getRoutineCode(int $id, string $pageType = 'home') + { + $theme = $this->dao->getOne(['id' => $id, 'is_del' => 0]); + if (!$theme) { + throw new AdminException('数据不存在'); + } + /** @var QrcodeServices $QrcodeService */ + $QrcodeService = app()->make(QrcodeServices::class); + return $QrcodeService->getThemeRoutineQrcodePath($id, $pageType); + } + /** * 获取微页面列表 * diff --git a/backend/app/services/other/QrcodeServices.php b/backend/app/services/other/QrcodeServices.php index 6fb202009..b1c1dd4b7 100644 --- a/backend/app/services/other/QrcodeServices.php +++ b/backend/app/services/other/QrcodeServices.php @@ -238,8 +238,6 @@ class QrcodeServices extends BaseService */ public function getRoutineQrcodePath(int $id, int $uid, int $type, array $param = [], bool $isSaveAttach = true) { - /** @var SystemAttachmentServices $systemAttachmentService */ - $systemAttachmentService = app()->make(SystemAttachmentServices::class); $page = ''; $namePath = ''; $data = 'id=' . $id . '&pid=' . $uid; @@ -281,6 +279,39 @@ class QrcodeServices extends BaseService if (!$page || !$namePath) { return false; } + return $this->createRoutineQrcode($data, $page, $namePath, $isSaveAttach); + } + + /** + * 主题预览小程序码(scene 携带 theme_id,与移动端 pages/index/index、pages/annex/special/index 的 scene 解析一致) + * @param int $themeId + * @param string $pageType micro 时指向微页面预览页,其余指向首页 + * @return false|mixed|string + */ + public function getThemeRoutineQrcodePath(int $themeId, string $pageType = 'home') + { + if ($pageType === 'micro') { + $page = 'pages/annex/special/index'; + $namePath = 'theme_micro_' . $themeId . '_routine_index_code.jpg'; + } else { + $page = 'pages/index/index'; + $namePath = 'theme_' . $themeId . '_routine_index_code.jpg'; + } + return $this->createRoutineQrcode('theme_id=' . $themeId, $page, $namePath, false); + } + + /** + * 通过事件代理生成小程序码并上传,返回图片地址 + * @param string $data scene 参数 + * @param string $page 小程序页面路径 + * @param string $namePath 上传文件名(同时作为附件缓存键) + * @param bool $isSaveAttach 是否按附件名缓存复用 + * @return false|mixed|string + */ + protected function createRoutineQrcode(string $data, string $page, string $namePath, bool $isSaveAttach) + { + /** @var SystemAttachmentServices $systemAttachmentService */ + $systemAttachmentService = app()->make(SystemAttachmentServices::class); try { if (!$isSaveAttach) { $imageInfo = ""; diff --git a/frontend/admin/src/diy/api/index.js b/frontend/admin/src/diy/api/index.js index dd9bd7e56..a4441f0ec 100644 --- a/frontend/admin/src/diy/api/index.js +++ b/frontend/admin/src/diy/api/index.js @@ -284,6 +284,17 @@ export function getRoutineCode(id) { }); } +/** + * @description 主题预览 -- 小程序二维码(theme/routine_code/:id,page_type=micro 时指向微页面预览页); + */ +export function getThemeRoutineCode(id, pageType) { + return request({ + url: `theme/routine_code/${id}`, + method: 'get', + params: pageType ? { page_type: pageType } : {}, + }); +} + /** * @description 个人中心-提交信息; */ diff --git a/frontend/admin/src/diy/pages/devise/diyIndex.vue b/frontend/admin/src/diy/pages/devise/diyIndex.vue index 3fe5c24fe..26da5ae45 100644 --- a/frontend/admin/src/diy/pages/devise/diyIndex.vue +++ b/frontend/admin/src/diy/pages/devise/diyIndex.vue @@ -223,7 +223,8 @@