Commit 71207cb3 authored by qinhaitao's avatar qinhaitao

feat: 🎸 集卡接口

parent e50a7390
......@@ -16,8 +16,7 @@
},
"scripts": {
"start": "tsc",
"mock": "cd mockServer && npm start",
"preinstall": "cd mockServer && yarn"
"mock": "cd mockServer && npm start"
},
"config": {
"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 @@
import { BaseDao } from '../../sdk'
import BaseService from './base.service'
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 { formatUserNick, formatUpdatedDataByProjection } from '../../utils/common/format'
import { setNewFollowUserData, setNewVipUserData } from '../../utils/common/userUpdate'
import { getShopVip, formatVipCbUrl } from '../../utils/common/vip'
import { get } from 'mpath'
......@@ -45,7 +45,8 @@ class UserService extends BaseService {
async doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo) {
if (!userInfo) {
userInfo = await this.initUserData(vipInfo, activityInfo)
const customUserInfo = initCustomUser(this.context, customInitUserInfo)
userInfo = await this.initUserData(vipInfo, activityInfo, customUserInfo)
} else {
userInfo = await this.updateUserData(vipInfo, userInfo, activityInfo)
}
......@@ -60,22 +61,22 @@ class UserService extends BaseService {
* @returns
* @memberof UserService
*/
async initUserData(vipInfo: IVipInfo, activityInfo: IActivityInfo) {
async initUserData(vipInfo: IVipInfo, activityInfo: IActivityInfo, customUserInfo: ICustomUserInfo) {
const { openId, data } = this.context
const { activityId, isFollow, avatar, inviteId, userNick } = data
const today = getToday()
console.log(`----------${today}----------`, today)
const { tasks } = activityInfo
const { follow = {} as ITaskConfig, member = {} as ITaskConfig } = tasks
const user: IUserInfo = {
const user: ICommonUserInfo = {
activityId,
avatar,
inviteId,
userNick,
openId,
gameTimes: 0,
totalScore: 0,
maxScore: 0,
// gameTimes: 0,
// totalScore: 0,
// maxScore: 0,
// 待领取次数初始化, 根据需自定义添加
remainTimes: {
follow: isFollow ? follow.value : 0,
......@@ -118,9 +119,15 @@ class UserService extends BaseService {
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> {
......
......@@ -20,7 +20,7 @@ interface IBaseDao {
* 插入单条数据
* @param document
*/
insertOne(document: any): Promise<string>
insertOne<T>(document: T): Promise<string>
/**
* 插入多条数据
* @param documents 插入对象
......
/** @format */
type IUserInfo = ICustomUserInfo & ICommonUserInfo
interface IUserInfo {
interface ICustomUserInfo {
// 游戏类
gameTimes?: number
maxScore?: number
totalScore?: number
updateScoreTime?: number
}
interface ICommonUserInfo {
_id?: string
id?: string
activityId: string
......@@ -16,11 +25,6 @@ interface IUserInfo {
remainTimes?: IRemainTimesInfo
taskInfo?: object
login?: object
// 游戏类
gameTimes?: number
maxScore?: number
totalScore?: number
updateScoreTime?: number
}
interface IRemainTimesInfo {
......
/** @format */
export const initCustomUser = (context: IContext<IParams>, customUserInfo: ICustomUserInfo) => {
return customUserInfo
}
......@@ -27,3 +27,5 @@ export * from './common/userUpdate'
export * from './common/format'
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