获取店铺信息接口增加上报生成二维码的额外参数

This commit is contained in:
zhl 2021-06-08 11:37:37 +08:00
parent f74a27ca41
commit eb8dea1ddf
3 changed files with 24 additions and 13 deletions

View File

@ -25,6 +25,14 @@ class GameUserController extends BaseController {
} }
let user = (await GameUser.findOrCreate({ accountId })).doc let user = (await GameUser.findOrCreate({ accountId })).doc
user.updateFromReq(req.params) user.updateFromReq(req.params)
let sid = req.params.shop
if (sid) {
const shop = await Shop.fetchByID(sid)
if (shop) {
user.shop = shop.id
user.shops.pushOnce(shop.id)
}
}
await user.save() await user.save()
const token = await res.jwtSign({ id: user.id, accountId }) const token = await res.jwtSign({ id: user.id, accountId })
return { token } return { token }

View File

@ -5,6 +5,7 @@ import { ZError } from '../../common/ZError'
import { ShopExam } from '../../models/shop/ShopExam' import { ShopExam } from '../../models/shop/ShopExam'
import { ShopActivity } from '../../models/shop/ShopActivity' import { ShopActivity } from '../../models/shop/ShopActivity'
import { ShopGameExt } from '../../models/shop/ShopGameExt' import { ShopGameExt } from '../../models/shop/ShopGameExt'
import { GameUser } from '../../models/user/GameUser'
class ShopController extends BaseController { class ShopController extends BaseController {
/** /**
@ -79,21 +80,26 @@ class ShopController extends BaseController {
} }
@role('anon') @role('anon')
@router('post /api/:accountid/shop') @router('post /api/:accountId/shop')
async shopInfo(req) { async shopInfo(req) {
let { sid } = req.params let { sid, accountId } = req.params
if (!sid) { if (!sid) {
throw new ZError(10, `shopInfo 没有店铺id: ${sid}`) throw new ZError(10, `shopInfo 没有店铺id: ${sid}`)
} }
sid = sid.split('|')[0] const shopId = sid.split('|')[0]
if (!validShopId(sid)) { if (!validShopId(shopId)) {
throw new ZError(10, `shopInfo 没有店铺id或者店铺id格式不正确: ${sid}`) throw new ZError(10, `shopInfo 没有店铺id或者店铺id格式不正确: ${shopId}`)
} }
let rspData: any = {} let rspData: any = {}
let shop = await Shop.fetchByID(sid) let shop = await Shop.fetchByID(shopId)
if (!shop) { if (!shop) {
throw new ZError(11, '未找到对应的店铺') throw new ZError(11, '未找到对应的店铺')
} }
let user = (await GameUser.findOrCreate({ accountId })).doc
user.shop = shop.id
user.shops.pushOnce(shop.id)
user.loginParams = sid.split('|').slice(1)
await user.save()
rspData.gameCfg = {} rspData.gameCfg = {}
if (!!shop.gameInfo) { if (!!shop.gameInfo) {
let gameInfo = shop.gameInfo let gameInfo = shop.gameInfo

View File

@ -1,6 +1,7 @@
import { getModelForClass, index, modelOptions, prop, ReturnModelType } from '@typegoose/typegoose' import { getModelForClass, index, modelOptions, prop, ReturnModelType } from '@typegoose/typegoose'
import { BaseModule } from '../Base' import { BaseModule } from '../Base'
import { dbconn } from '../../decorators/dbconn' import { dbconn } from '../../decorators/dbconn'
import { Shop } from '../shop/Shop'
@dbconn() @dbconn()
@index({ accountId: 1 }, { unique: true }) @index({ accountId: 1 }, { unique: true })
@ -45,6 +46,9 @@ class GameUserClass extends BaseModule {
@prop() @prop()
public shop: string public shop: string
@prop({ type: () => [String] })
public loginParams: string[]
public static async getByAccountID(this: ReturnModelType<typeof GameUserClass>, accountId: string) { public static async getByAccountID(this: ReturnModelType<typeof GameUserClass>, accountId: string) {
let records = await this.find({ accountId }).limit(1) let records = await this.find({ accountId }).limit(1)
return records.length > 0 ? records[0] : null return records.length > 0 ? records[0] : null
@ -58,13 +62,6 @@ class GameUserClass extends BaseModule {
} }
return map 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 }) export const GameUser = getModelForClass(GameUserClass, { existingConnection: GameUserClass.db })