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 })