Commit 71207cb3 authored by qinhaitao's avatar qinhaitao

feat: 🎸 集卡接口

parent e50a7390
...@@ -16,8 +16,7 @@ ...@@ -16,8 +16,7 @@
}, },
"scripts": { "scripts": {
"start": "tsc", "start": "tsc",
"mock": "cd mockServer && npm start", "mock": "cd mockServer && npm start"
"preinstall": "cd mockServer && yarn"
}, },
"config": { "config": {
"notNeedLogin": [] "notNeedLogin": []
......
/** @format */
import { services, checkParams, preCheck, preUpdate } from '../decorator/common'
import { resultsModel } from '../sdk'
import { CommonUserService, CommonGameService } from '../service/common'
import {
checkActivityTime,
checkJoinId,
checkUserInfo,
checkVip,
checkGameTimes,
checkOpenPrizeStatus
} from '../utils/common/check'
import { updateUserInfo, reduceGameTimes } from '../utils/common/update'
export interface ISumitGameControllerInfos extends IControllerInfos {
joinInfo: IJoinRecord
}
export default class Card {
@checkParams(['activityId'])
@services([CommonGameService])
async getCollectCardInfo(
context: IContext<IParams>,
{ userInfo, activityInfo }: IControllerInfos,
[gameService]: [CommonGameService]
) {
// const joinResult = await gameService.addJoinRecord(userInfo)
// return resultsModel.success({
// ...joinResult
// })
}
}
/** @format */
export const customInitUserInfo: ICustomUserInfo = {
gameTimes: 0,
maxScore: 0,
totalScore: 0
}
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
import { BaseDao } from '../../sdk' import { BaseDao } from '../../sdk'
import BaseService from './base.service' import BaseService from './base.service'
import { USER_DB_NAME } from '../../db' import { USER_DB_NAME } from '../../db'
import { getToday, formatUpdateUserProjection } from '../../utils' import { customInitUserInfo } from '../../customUser'
import { getToday, formatUpdateUserProjection, initCustomUser } from '../../utils'
import { isNewVip } from '../../utils/common/userUpdate' import { isNewVip } from '../../utils/common/userUpdate'
import { formatUserNick, formatUpdatedDataByProjection } from '../../utils/common/format' import { formatUserNick, formatUpdatedDataByProjection } from '../../utils/common/format'
import { setNewFollowUserData, setNewVipUserData } from '../../utils/common/userUpdate' import { setNewFollowUserData, setNewVipUserData } from '../../utils/common/userUpdate'
import { getShopVip, formatVipCbUrl } from '../../utils/common/vip' import { getShopVip, formatVipCbUrl } from '../../utils/common/vip'
import { get } from 'mpath' import { get } from 'mpath'
...@@ -45,7 +45,8 @@ class UserService extends BaseService { ...@@ -45,7 +45,8 @@ class UserService extends BaseService {
async doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo) { async doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo) {
if (!userInfo) { if (!userInfo) {
userInfo = await this.initUserData(vipInfo, activityInfo) const customUserInfo = initCustomUser(this.context, customInitUserInfo)
userInfo = await this.initUserData(vipInfo, activityInfo, customUserInfo)
} else { } else {
userInfo = await this.updateUserData(vipInfo, userInfo, activityInfo) userInfo = await this.updateUserData(vipInfo, userInfo, activityInfo)
} }
...@@ -60,22 +61,22 @@ class UserService extends BaseService { ...@@ -60,22 +61,22 @@ class UserService extends BaseService {
* @returns * @returns
* @memberof UserService * @memberof UserService
*/ */
async initUserData(vipInfo: IVipInfo, activityInfo: IActivityInfo) { async initUserData(vipInfo: IVipInfo, activityInfo: IActivityInfo, customUserInfo: ICustomUserInfo) {
const { openId, data } = this.context const { openId, data } = this.context
const { activityId, isFollow, avatar, inviteId, userNick } = data const { activityId, isFollow, avatar, inviteId, userNick } = data
const today = getToday() const today = getToday()
console.log(`----------${today}----------`, today) console.log(`----------${today}----------`, today)
const { tasks } = activityInfo const { tasks } = activityInfo
const { follow = {} as ITaskConfig, member = {} as ITaskConfig } = tasks const { follow = {} as ITaskConfig, member = {} as ITaskConfig } = tasks
const user: IUserInfo = { const user: ICommonUserInfo = {
activityId, activityId,
avatar, avatar,
inviteId, inviteId,
userNick, userNick,
openId, openId,
gameTimes: 0, // gameTimes: 0,
totalScore: 0, // totalScore: 0,
maxScore: 0, // maxScore: 0,
// 待领取次数初始化, 根据需自定义添加 // 待领取次数初始化, 根据需自定义添加
remainTimes: { remainTimes: {
follow: isFollow ? follow.value : 0, follow: isFollow ? follow.value : 0,
...@@ -118,9 +119,15 @@ class UserService extends BaseService { ...@@ -118,9 +119,15 @@ class UserService extends BaseService {
user.taskInfo[today].member = [{ createTime: Date.now() }] user.taskInfo[today].member = [{ createTime: Date.now() }]
} }
await this.userdao.insertOne(user) await this.userdao.insertOne({
...user,
...customUserInfo
})
return user return {
...user,
...customUserInfo
}
} }
async updateUserData(vipInfo: IVipInfo, userInfo: IUserInfo, activityInfo: IActivityInfo): Promise<IUserInfo> { async updateUserData(vipInfo: IVipInfo, userInfo: IUserInfo, activityInfo: IActivityInfo): Promise<IUserInfo> {
......
...@@ -20,7 +20,7 @@ interface IBaseDao { ...@@ -20,7 +20,7 @@ interface IBaseDao {
* 插入单条数据 * 插入单条数据
* @param document * @param document
*/ */
insertOne(document: any): Promise<string> insertOne<T>(document: T): Promise<string>
/** /**
* 插入多条数据 * 插入多条数据
* @param documents 插入对象 * @param documents 插入对象
......
/** @format */ /** @format */
type IUserInfo = ICustomUserInfo & ICommonUserInfo
interface IUserInfo { interface ICustomUserInfo {
// 游戏类
gameTimes?: number
maxScore?: number
totalScore?: number
updateScoreTime?: number
}
interface ICommonUserInfo {
_id?: string _id?: string
id?: string id?: string
activityId: string activityId: string
...@@ -16,11 +25,6 @@ interface IUserInfo { ...@@ -16,11 +25,6 @@ interface IUserInfo {
remainTimes?: IRemainTimesInfo remainTimes?: IRemainTimesInfo
taskInfo?: object taskInfo?: object
login?: object login?: object
// 游戏类
gameTimes?: number
maxScore?: number
totalScore?: number
updateScoreTime?: number
} }
interface IRemainTimesInfo { interface IRemainTimesInfo {
......
/** @format */
export const initCustomUser = (context: IContext<IParams>, customUserInfo: ICustomUserInfo) => {
return customUserInfo
}
...@@ -27,3 +27,5 @@ export * from './common/userUpdate' ...@@ -27,3 +27,5 @@ export * from './common/userUpdate'
export * from './common/format' export * from './common/format'
export * from './common/doHandler' export * from './common/doHandler'
export * from './common/initCustomUser'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment