From 280a8251b7414f7e14bb39289a2a90f0efceae0b Mon Sep 17 00:00:00 2001 From: zhl Date: Tue, 8 Jun 2021 10:10:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3=E5=A2=9E=E5=8A=A0=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E5=BA=97=E9=93=BAid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/api.md | 6 ++++-- src/api/controllers/game_user.controller.ts | 2 +- src/common/Extend.ts | 2 +- src/models/user/GameUser.ts | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/api.md b/doc/api.md index 07d6986..98ce9a1 100644 --- a/doc/api.md +++ b/doc/api.md @@ -6,7 +6,8 @@ 1. [增加用户信息](#212), [抽奖转盘信息](#213), [抽奖](#214), [邀请奖励信息](#215), [挑战详情](#216) 接口 2. 所有接口增加post字段 version(当前版本固定取1.0.1)和sessionid(取自jcfw) 3. 获取店铺信息 增加返回店铺的数字编号 -4. 上报测验题目答案接口的 奖励信息 增加返回rewardType, 0: 表明该奖励为优惠券, 1: 抽奖券 +4. 上报测验题目答案相关接口的 奖励信息 增加返回rewardType, 0: 表明该奖励为优惠券, 1: 抽奖券 +5. 用户信息上报接口 增加上报当前店铺 @@ -444,6 +445,7 @@ | country | 国家 | | province | 省份 | | city | 城市 | +| shop | 店铺id | 3. Response: JSON @@ -528,7 +530,7 @@ ```js [ // 奖励列表 { - coupon: '优惠券的id', + coupon: '优惠券的id', // 如果该值为 empty, 说明是留空的, name: '优惠券名', count: 1, //数量 couponUrl: '优惠券详情图的url', diff --git a/src/api/controllers/game_user.controller.ts b/src/api/controllers/game_user.controller.ts index a89fd8b..9911c0a 100644 --- a/src/api/controllers/game_user.controller.ts +++ b/src/api/controllers/game_user.controller.ts @@ -81,7 +81,7 @@ class GameUserController extends BaseController { @router('post /api/:accountId/share_rewards') async shareRewards(req: any) { const { accountId, sid, sessionid } = req.params - if (!sid) { + if (!sid || !sessionid) { throw new ZError(10, '缺少必要参数: sid') } const shop = await Shop.fetchByID(sid) diff --git a/src/common/Extend.ts b/src/common/Extend.ts index 07a3f4b..c4a53ec 100644 --- a/src/common/Extend.ts +++ b/src/common/Extend.ts @@ -665,7 +665,7 @@ Object.defineProperties(Array.prototype, { let idx = this.indexOf(t) if (!~idx) { idx = this.length - this[idx] = t + this.push(t) } return idx }, diff --git a/src/models/user/GameUser.ts b/src/models/user/GameUser.ts index d2656ea..0ede4fd 100644 --- a/src/models/user/GameUser.ts +++ b/src/models/user/GameUser.ts @@ -32,6 +32,18 @@ class GameUserClass extends BaseModule { public locked: boolean @prop() public lockedTime?: Date + /** + * 该帐号关联的所有店铺 + * @type {string[]} + */ + @prop({ type: () => [String] }) + public shops: string[] + /** + * 当前关联店铺 + * @type {string} + */ + @prop() + public shop: string public static async getByAccountID(this: ReturnModelType, accountId: string) { let records = await this.find({ accountId }).limit(1) @@ -46,6 +58,13 @@ class GameUserClass extends BaseModule { } return map } + + public updateFromReq(data: any) { + super.updateFromReq(data) + if (data.shop) { + this.shops.pushOnce(data.shop) + } + } } export const GameUser = getModelForClass(GameUserClass, { existingConnection: GameUserClass.db })