Commit 37702f50 authored by maggie's avatar maggie

Merge branch 'c_server_ts_perf' of...

Merge branch 'c_server_ts_perf' of http://gitlab2.dui88.com/qinhaitao/taobao-mini-template into c_server_ts_perf
parents 03ceceb4 811ef1b2
/** @format */ /** @format */
import { services, checkParams, registeInfos } from '../decorator/common' import { services, checkParams, preUpdate } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { UserService, AccessService } from '../service' import { UserService } from '../service'
export default class User { export default class User {
/** /**
* 获取游戏信息 * 获取游戏信息
*
* needKeys 根据需求自取字段 格式: { gameTimes: 1}
*/ */
@checkParams(['activityId', 'needKeys']) @checkParams(['activityId', 'needKeys'])
@services([UserService, AccessService]) @services([UserService])
async getGameInfo( async getGameInfo(
context: IContext<IParams>, context: IContext<IParams>,
{ userInfo, activityInfo }: IControllerInfos, { userInfo, activityInfo }: IControllerInfos,
[userService, accessService]: [UserService, AccessService] [userService]: [UserService]
) { ) {
const { needKeys } = context.data const { needKeys } = context.data
const gameInfoResult = await userService.getUserInfo(needKeys) const gameInfoResult = await userService.getUserInfo(needKeys)
return resultsModel.success({
...gameInfoResult
})
} }
} }
...@@ -23,7 +23,7 @@ export default class Task { ...@@ -23,7 +23,7 @@ export default class Task {
[taskService]: [TaskService] [taskService]: [TaskService]
): Promise<IResult<{ list: ITaskInfo[] }>> { ): Promise<IResult<{ list: ITaskInfo[] }>> {
// 读取B端 tasks字段配置自动生成任务列表 // 读取B端 tasks字段配置自动生成任务列表
const result = taskService.initTaskList(userInfo, activityInfo) const result = await taskService.initTaskList(userInfo, activityInfo)
return resultsModel.success({ return resultsModel.success({
...result ...result
...@@ -88,7 +88,7 @@ export default class Task { ...@@ -88,7 +88,7 @@ export default class Task {
const list = await baseService.getItemListByIds(itemIds, session) const list = await baseService.getItemListByIds(itemIds, session)
const listWithCollectStatus = taskService.getItemListWithCollectStatus(list, userInfo) const listWithCollectStatus = await taskService.getItemListWithCollectStatus(list, userInfo)
return resultsModel.success(listWithCollectStatus) return resultsModel.success(listWithCollectStatus)
} }
......
/** @format */ /** @format */
import { isArray, isEmpty, isObject, merge } from 'lodash' import { isEmpty, merge } from 'lodash'
import { UserService } from '../../service' import { UserService } from '../../service'
import { recordErrorLog } from '../../utils/common/logger' import { recordErrorLog } from '../../utils/common/logger'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
......
...@@ -7,10 +7,12 @@ import AwardsController from './controller/awards.controller' ...@@ -7,10 +7,12 @@ import AwardsController from './controller/awards.controller'
import ShareController from './controller/share.controller' import ShareController from './controller/share.controller'
import StatController from './controller/stat.controller' import StatController from './controller/stat.controller'
import LoginController from './controller/login.controller' import LoginController from './controller/login.controller'
import GameController from './controller/game.controller'
const { getVipInfo, getRankList } = new UserController() const { getVipInfo, getRankList } = new UserController()
const { login } = new LoginController() const { login } = new LoginController()
const { getGameInfo } = new GameController()
const { const {
getTaskList, getTaskList,
receiveTaskRewards, receiveTaskRewards,
...@@ -39,5 +41,6 @@ export default { ...@@ -39,5 +41,6 @@ export default {
doHelp, doHelp,
getStats, getStats,
addStat, addStat,
getRankList getRankList,
getGameInfo
} }
...@@ -29,7 +29,7 @@ export default class TaskService extends UserService { ...@@ -29,7 +29,7 @@ export default class TaskService extends UserService {
} }
// 根据活动tasks字段渲染任务 // 根据活动tasks字段渲染任务
initTaskList(userInfo: IUserInfo, activityInfo: IActivityInfo) { async initTaskList(userInfo: IUserInfo, activityInfo: IActivityInfo) {
return { return {
list: Object.keys(activityInfo?.tasks || {}).map((task: ITaskType) => { list: Object.keys(activityInfo?.tasks || {}).map((task: ITaskType) => {
return this.initTask(task, activityInfo?.tasks?.[task]?.title, userInfo, activityInfo) return this.initTask(task, activityInfo?.tasks?.[task]?.title, userInfo, activityInfo)
...@@ -115,7 +115,8 @@ export default class TaskService extends UserService { ...@@ -115,7 +115,8 @@ export default class TaskService extends UserService {
async completeTask( async completeTask(
taskType: ITaskType, taskType: ITaskType,
activityInfo: IActivityInfo, activityInfo: IActivityInfo,
userInfo: IUserInfo userInfo: IUserInfo,
customRecord: Object = {}
): Promise<boolean | ICodeType> { ): Promise<boolean | ICodeType> {
const today = getToday() const today = getToday()
const rewards = activityInfo?.tasks?.[taskType]?.value || 0 const rewards = activityInfo?.tasks?.[taskType]?.value || 0
...@@ -124,7 +125,7 @@ export default class TaskService extends UserService { ...@@ -124,7 +125,7 @@ export default class TaskService extends UserService {
data: { itemId } data: { itemId }
} = this.context } = this.context
const record = { itemId, openId: taskType === 'invites' ? openId : undefined } const record = { itemId, openId: taskType === 'invites' ? openId : undefined, ...customRecord }
const result = await this.updateUser(userInfo._id, { const result = await this.updateUser(userInfo._id, {
$inc: { $inc: {
[`remainTimes.${taskType}`]: rewards [`remainTimes.${taskType}`]: rewards
...@@ -196,7 +197,7 @@ export default class TaskService extends UserService { ...@@ -196,7 +197,7 @@ export default class TaskService extends UserService {
return projection return projection
} }
getItemListWithCollectStatus(list: ITaoBaoItems[], userInfo: IUserInfo) { async getItemListWithCollectStatus(list: ITaoBaoItems[], userInfo: IUserInfo) {
const { taskInfo } = getTotalCompleteTask('collectGoods', userInfo) const { taskInfo } = getTotalCompleteTask('collectGoods', userInfo)
return list.map(v => { return list.map(v => {
......
...@@ -21,10 +21,10 @@ class UserService extends BaseService { ...@@ -21,10 +21,10 @@ class UserService extends BaseService {
* @desc 获取当前打开活动的用户详情 * @desc 获取当前打开活动的用户详情
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象) * @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/ */
async getUserInfo(projection: IFindProjection = {}) { async getUserInfo(projection = {}) {
let { openId, data } = this.context let { openId, data } = this.context
let { activityId } = data let { activityId } = data
return await this.userdao.findOne<IUserInfo>({ openId, activityId }, projection) return await this.userdao.findOne<IUserInfo>({ openId, activityId }, { projection })
} }
/** /**
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
import updateVip from './updateVip' import updateVip from './updateVip'
import updateSignTask from './updateSignTask' import updateSignTask from './updateSignTask'
import updateOrderGoods from './updateOrderGoods' import updateOrderGoods from './updateOrderGoods'
import updateFirstLogin from './updateFirstLogin'
const update = { const update = {
updateVip, updateVip,
updateSignTask, updateSignTask,
updateOrderGoods updateOrderGoods,
updateFirstLogin
} }
export default update export default update
export { updateVip, updateSignTask, updateOrderGoods } export { updateVip, updateSignTask, updateOrderGoods, updateFirstLogin }
/** @format */
import { getToday } from '../getToday'
import { isNewVip, setNewVipUserData } from '../userUpdate'
export default async function updateFirstLogin(
context: IContext<IParams>,
{ vipInfo, userInfo, activityInfo }: IControllerInfos
): Promise<IPreUpdateQuery> {
let { member } = userInfo
const memberReWards = activityInfo?.tasks?.member?.value
return isNewVip(userInfo, vipInfo)
? {
$set: {
member: setNewVipUserData(member)
},
$inc: {
'remainTimes.member': +memberReWards
},
$push: {
[`taskInfo.${getToday()}.member`]: { creatTime: Date.now() }
}
}
: {}
}
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