获取店铺信息接口增加上报生成二维码的额外参数
This commit is contained in:
parent
f74a27ca41
commit
eb8dea1ddf
@ -25,6 +25,14 @@ class GameUserController extends BaseController {
|
||||
}
|
||||
let user = (await GameUser.findOrCreate({ accountId })).doc
|
||||
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()
|
||||
const token = await res.jwtSign({ id: user.id, accountId })
|
||||
return { token }
|
||||
|
@ -5,6 +5,7 @@ import { ZError } from '../../common/ZError'
|
||||
import { ShopExam } from '../../models/shop/ShopExam'
|
||||
import { ShopActivity } from '../../models/shop/ShopActivity'
|
||||
import { ShopGameExt } from '../../models/shop/ShopGameExt'
|
||||
import { GameUser } from '../../models/user/GameUser'
|
||||
|
||||
class ShopController extends BaseController {
|
||||
/**
|
||||
@ -79,21 +80,26 @@ class ShopController extends BaseController {
|
||||
}
|
||||
|
||||
@role('anon')
|
||||
@router('post /api/:accountid/shop')
|
||||
@router('post /api/:accountId/shop')
|
||||
async shopInfo(req) {
|
||||
let { sid } = req.params
|
||||
let { sid, accountId } = req.params
|
||||
if (!sid) {
|
||||
throw new ZError(10, `shopInfo 没有店铺id: ${sid}`)
|
||||
}
|
||||
sid = sid.split('|')[0]
|
||||
if (!validShopId(sid)) {
|
||||
throw new ZError(10, `shopInfo 没有店铺id或者店铺id格式不正确: ${sid}`)
|
||||
const shopId = sid.split('|')[0]
|
||||
if (!validShopId(shopId)) {
|
||||
throw new ZError(10, `shopInfo 没有店铺id或者店铺id格式不正确: ${shopId}`)
|
||||
}
|
||||
let rspData: any = {}
|
||||
let shop = await Shop.fetchByID(sid)
|
||||
let shop = await Shop.fetchByID(shopId)
|
||||
if (!shop) {
|
||||
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 = {}
|
||||
if (!!shop.gameInfo) {
|
||||
let gameInfo = shop.gameInfo
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { getModelForClass, index, modelOptions, prop, ReturnModelType } from '@typegoose/typegoose'
|
||||
import { BaseModule } from '../Base'
|
||||
import { dbconn } from '../../decorators/dbconn'
|
||||
import { Shop } from '../shop/Shop'
|
||||
|
||||
@dbconn()
|
||||
@index({ accountId: 1 }, { unique: true })
|
||||
@ -45,6 +46,9 @@ class GameUserClass extends BaseModule {
|
||||
@prop()
|
||||
public shop: string
|
||||
|
||||
@prop({ type: () => [String] })
|
||||
public loginParams: string[]
|
||||
|
||||
public static async getByAccountID(this: ReturnModelType<typeof GameUserClass>, accountId: string) {
|
||||
let records = await this.find({ accountId }).limit(1)
|
||||
return records.length > 0 ? records[0] : null
|
||||
@ -58,13 +62,6 @@ 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 })
|
||||
|
Loading…
x
Reference in New Issue
Block a user