From b82ebead9db924cce08c40ad9e43a129c856d0d8 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 24 May 2021 16:41:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=BA=97=E9=93=BA=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E4=B8=BB=E9=A2=98=E7=BC=96=E8=BE=91=E7=9A=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/admin/controllers/shop.controller.ts | 42 +++++++++++++++++ src/models/shop/ShopExam.ts | 1 - src/models/shop/ShopGameExt.ts | 60 ++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/models/shop/ShopGameExt.ts diff --git a/src/admin/controllers/shop.controller.ts b/src/admin/controllers/shop.controller.ts index f9a0d83..55f638b 100644 --- a/src/admin/controllers/shop.controller.ts +++ b/src/admin/controllers/shop.controller.ts @@ -5,6 +5,7 @@ import { ZError } from '../../common/ZError' import { Game } from '../../models/content/Game' import { generateQrFile } from '../../services/File' import { isObjectId } from '../../utils/string.util' +import { ShopGameExt } from '../../models/shop/ShopGameExt' class ShopController extends BaseController { @@ -128,6 +129,10 @@ class ShopController extends BaseController { return {} } + /** + * 获取店铺游戏基本设置 + * @param req + */ @permission('shop:edit') @router('post /api/shop/gameinfo') async getGameInfo(req: any) { @@ -152,6 +157,43 @@ class ShopController extends BaseController { } } + /** + * 获取店铺游戏主题配置 + * @param req + */ + @permission('shop:edit') + @router('post /api/shop/gametheme') + async getGameTheme(req: any) { + let { shop, game, version } = req.params + if (!shop || !game || !version) { + throw new ZError(11, 'params mismatch') + } + let data = (await ShopGameExt.findOrCreate({shop, game, version})).doc + let cfg = data.cfg || {} + return cfg + } + + /** + * 保存店铺游戏主题配置 + * @param req + */ + @permission('shop:edit') + @router('post /api/shop/gametheme/save') + async saveGameTheme(req: any) { + let { shop, game, version } = req.params + if (!shop || !game || !version) { + throw new ZError(11, 'params mismatch') + } + let data = (await ShopGameExt.findOrCreate({shop, game, version})).doc + let cfg = req.params.clone() + delete cfg.shop + delete cfg.game + delete cfg.version + data.cfg = cfg + await data.save() + return {} + } + @permission('shop:edit') @router('post /api/shop/gameqr') async getGameQr(req: any) { diff --git a/src/models/shop/ShopExam.ts b/src/models/shop/ShopExam.ts index 1c01244..2ecc42f 100644 --- a/src/models/shop/ShopExam.ts +++ b/src/models/shop/ShopExam.ts @@ -8,7 +8,6 @@ import { BaseModule } from '../Base' import { noJson } from '../../decorators/nojson' import { Severity } from '@typegoose/typegoose/lib/internal/constants' import { Base } from '@typegoose/typegoose/lib/defaultClasses' -import { UserReward } from '../UserReward' export class ShopPuzzleClass extends Base{ @prop() diff --git a/src/models/shop/ShopGameExt.ts b/src/models/shop/ShopGameExt.ts new file mode 100644 index 0000000..184fe0d --- /dev/null +++ b/src/models/shop/ShopGameExt.ts @@ -0,0 +1,60 @@ +import { dbconn } from '../../decorators/dbconn' +import { + getModelForClass, + index, + modelOptions, + mongoose, + prop +} from '@typegoose/typegoose' +import { BaseModule } from '../Base' +import { Severity } from '@typegoose/typegoose/lib/internal/constants' +import { ShopExamClass } from './ShopExam' + +@dbconn() +@index({ shop:1, game:1}, { unique: false }) +@modelOptions({schemaOptions: {collection: "shop_game_ext", timestamps: true}, options: {allowMixed: Severity.ALLOW}}) +export class ShopGameExtClass extends BaseModule { + /** + * 所属店铺 + * @type {string} + */ + @prop() + public shop: string + + @prop() + public game: string + + @prop() + public version: string + + @prop({type: mongoose.Schema.Types.Mixed}) + public cfg: {} + + // /** + // * 背景图案 + // * @type {string} + // */ + // @prop() + // public bg_item_icon: string + // /** + // * 主页正中间图片 + // * @type {string} + // */ + // @prop() + // public game_main_pic: string + // /** + // * 主页上单人赛按钮文字 + // * @type {string} + // */ + // @prop() + // public game_single_btn: string + // + // /** + // * 主页上多人赛按钮名字 + // * @type {string} + // */ + // @prop() + // public game_multi_btn: string +} + +export const ShopGameExt = getModelForClass(ShopGameExtClass, { existingConnection: ShopGameExtClass.db })