Commit 1322aad3 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 eb0d4012 9075a0be
......@@ -116,7 +116,7 @@ export default class AwardsController {
> {
const { activityId, prizeDataType } = context.data
const drawResult = await awardSer.drawPrize(activityId, prizeDataType, userInfo)
const drawResult = await awardSer.drawLottery(activityId, prizeDataType, userInfo)
return resultsModel.success(drawResult)
}
......
......@@ -13,11 +13,11 @@ export default class User {
@commonDecorator.registeInfos(['session'])
@services([UserService])
async getVipInfo(
context: IContext<IParams>,
{ activityInfo, userInfo, session }: IControllerInfos,
context: IContext<IVipParams>,
{ activityInfo }: IControllerInfos,
[userService]: [UserService]
) {
const commonUserGetshopvipResult1 = await userService.getShopVip(context, session)
): Promise<IResult<IVipInfo>> {
const commonUserGetshopvipResult = await userService.getShopVip(context, activityInfo)
return resultsModel.success({
...commonUserGetshopvipResult1
})
......
/** @format */
import { services, checkParams, registeInfos } from '../decorator/common'
import { resultsModel } from '../sdk'
import { UserService, AccessService } from '../service'
export default class User {
/**
* 获取游戏信息
*/
@checkParams(['activityId'])
@services([UserService, AccessService])
async getGameInfo(
context: IContext<IParams>,
{ userInfo, activityInfo, vipInfo }: IControllerInfos,
[userService, accessService]: [UserService, AccessService]
) {
const { openId } = context
}
}
......@@ -30,10 +30,10 @@ export default class User {
const updatedUserInfo = await userService.doLogin(userInfo, vipInfo, activityInfo)
// access表
await accessService.addAccess(updatedUserInfo, vipInfo)
const openIdResult = await accessService.addAccess(updatedUserInfo, vipInfo)
return resultsModel.success({
openId
...openIdResult
})
}
}
......@@ -21,18 +21,13 @@ export default class Task {
context: IContext<{ activityId: string }>,
{ userInfo, activityInfo }: IControllerInfos,
[taskService]: [TaskService]
): Promise<IResult<ITaskInfo[]>> {
return resultsModel.success([
taskService.initTask('member', '加入会员', activityInfo, userInfo),
taskService.initTask('follow', '关注店铺', activityInfo, userInfo)
// taskService.initTask('sign', '签到', activityInfo, userInfo),
// taskService.initTask('orderGoods', '购买商品', activityInfo, userInfo),
// taskService.initTask('browseGoods', '浏览商品', activityInfo, userInfo),
// taskService.initTask('collectGoods', '收藏商品', activityInfo, userInfo),
// taskService.initTask('jumpLink', '浏览页面', activityInfo, userInfo),
// taskService.initTask('invites', '邀请好友', activityInfo, userInfo)
// taskService.initTask('exchangeCredits', '积分兑换', activityInfo, userInfo)
])
): Promise<IResult<{ list: ITaskInfo[] }>> {
// 读取B端 tasks字段配置自动生成任务列表
const result = taskService.initTaskList(userInfo, activityInfo)
return resultsModel.success({
...result
})
}
/**
......
......@@ -3,7 +3,6 @@
import { services, checkParams, registeInfos } from '../decorator/common'
import { resultsModel } from '../sdk'
import { UserService } from '../service'
import { formatVipCbUrl, getShopVip } from '../utils/common/vip'
export interface IVipParams {
activityId: string
......@@ -30,15 +29,14 @@ export default class User {
* 获取会员信息
*/
@checkParams(['activityId'])
@registeInfos(['session'])
@services([UserService])
async getVipInfo(
context: IContext<IVipParams>,
{ session, activityUserNick }: IControllerInfos,
{ activityInfo }: IControllerInfos,
[userService]: [UserService]
): Promise<IResult<IVipInfo>> {
// 拼接回调参数
const result = await userService.getShopVip(context, session, activityUserNick)
const result = await userService.getShopVip(context, activityInfo)
return resultsModel.success(result)
}
......
......@@ -29,16 +29,14 @@ async function initBaseInfo(context: IContext<IParams>, baseInfos: ICheckControl
if (needInfos.includes('session') && !baseInfos.session) {
const { session, userNick } = await getSellerSession(context)
baseInfos.session = session
baseInfos.activityUserNick = userNick
}
if (needInfos.includes('vipInfo') && !baseInfos.vipInfo && handler !== 'getVipInfo') {
if (!baseInfos.session) {
const { session, userNick } = await getSellerSession(context)
baseInfos.session = session
baseInfos.activityUserNick = userNick
}
const vipInfo = await getShopVip(context, baseInfos.session, formatVipCbUrl(context), baseInfos.activityUserNick)
const vipInfo = await getShopVip(context, baseInfos.activityInfo, formatVipCbUrl(context))
baseInfos.vipInfo = vipInfo
}
return baseInfos
......
......@@ -23,7 +23,7 @@ export default class UserAccessService {
let { openId, data } = this.context
let { activityId, userNick, avatar, inviteId } = data
return await this.accessdao.insertOne({
await this.accessdao.insertOne({
openId,
activityId,
userNick,
......@@ -39,6 +39,7 @@ export default class UserAccessService {
updateTime: Date.now(),
createDay: getToday()
})
return { openId }
}
async getAccessCount() {
......
......@@ -233,7 +233,7 @@ export default class AwardsService extends UserService {
return result
}
async drawPrize(activityId: string, prizeDataType: number, userInfo: IUserInfo) {
async drawLottery(activityId: string, prizeDataType: number, userInfo: IUserInfo) {
const { openId } = this.context
// 获取奖池配置
const prizesPool = await this.getPrizeConfig({
......
......@@ -20,6 +20,7 @@ import {
import { TASK_RATE_TYPE, TASK_STATUS } from '../constants'
import { getTodayCompleteTask, getTotalCompleteTask, setTaskStatus } from '../utils/common/task'
import { CODE_TYPES } from '../errorCode'
import { userInfo } from 'os'
export interface ITaskInfo {
taskType?: string // 任务类型
......@@ -38,6 +39,14 @@ export default class TaskService extends UserService {
constructor(context: IContext<IParams>) {
super(context)
}
initTaskList(userInfo: IUserInfo, activityInfo: IActivityInfo) {
return {
list: Object.keys(activityInfo?.tasks || {}).map((task: ITaskType) => {
return this.initTask(task, activityInfo?.tasks?.[task]?.title, userInfo, activityInfo)
})
}
}
/**
* 根据任务类型初始化 b端 tasks字段必须有相应的配置
*
......@@ -48,7 +57,7 @@ export default class TaskService extends UserService {
* @return {ITaskInfo} {ITaskInfo} 任务信息
* @memberof TaskService
*/
initTask(taskType: ITaskType, title: string, activityInfo: IActivityInfo, userInfo: IUserInfo): ITaskInfo {
initTask(taskType: ITaskType, title: string, userInfo: IUserInfo, activityInfo: IActivityInfo): ITaskInfo {
if (!activityInfo?.tasks?.[taskType]) {
console.error(`活动缺少${taskType}任务配置项`)
}
......
......@@ -235,13 +235,9 @@ class UserService extends BaseService {
return await this.userdao.findOne({ _id })
}
async getShopVip(
context: IContext<{ activityId: string; callbackUrl?: string }>,
session: string,
activityUserNick: string
) {
async getShopVip(context: IContext<{ activityId: string; callbackUrl?: string }>, activityInfo: IActivityInfo) {
const { callbackUrl } = context.data
return await getShopVip(context, session, callbackUrl || formatVipCbUrl(context), activityUserNick)
return await getShopVip(context, activityInfo, callbackUrl || formatVipCbUrl(context))
}
}
......
......@@ -13,6 +13,7 @@ interface IActivityInfo {
createTime: number
updateTime: number
awardReceiveExpiredTime?: number
activtiyInfoUserNick: string
tasks?: ITasks
}
type ITaskType =
......
......@@ -28,7 +28,6 @@ interface IControllerInfos {
vipInfo?: IVipInfo
activityInfo: IActivityInfo
session?: string
activityUserNick?: string // 活动创建账号昵称
}
interface ICheckControllerInfos extends IControllerInfos {
......
......@@ -12,6 +12,8 @@ export default async function updateOrderGoods(
const { value, itemIds, taskRateType, times } = activityInfo?.tasks?.[taskType] || {}
const { completeTimes, taskInfo } = getTotalCompleteTask(taskType, userInfo)
const { todayCompleteTimes } = getTodayCompleteTask(taskType, userInfo)
if (!activityInfo?.tasks?.[taskType]) return {}
// 永久任务且已完成
if (taskRateType === TASK_RATE_TYPE.FOREVER && completeTimes) {
return {}
......@@ -26,7 +28,7 @@ export default async function updateOrderGoods(
const orderResult = await getUserOrderlist(
this.context,
//@ts-ignore
activityStartTime || Date.now(),
activityInfo?.startTime || Date.now(),
Date.now()
)
......
......@@ -6,7 +6,8 @@ import { getTodayCompleteTask } from '../task'
export default async function updateSignTask(
context: IContext<IParams>,
{ userInfo, activityInfo }: IControllerInfos
): Promise<IPreUpdateQuery> {
): Promise<IPreUpdateQuery | undefined> {
if (!activityInfo?.tasks?.sign) return
// 获取签到奖励
const { value } = activityInfo?.tasks?.sign || {}
......
......@@ -9,10 +9,10 @@ import { TBAPIS } from '../../sdk'
/** @format */
// 测试环境 duib2账户mock数据 或者本地
export const isUseVipMock = (context: IContext<IParams>, userNick: string) => {
export const isUseVipMock = (context: IContext<IParams>, activtiyInfo: IActivityInfo) => {
const isTestEnv = context.env === 'test'
const isMockEnv = context.env === 'mock'
const isDuibaAccount = userNick.startsWith('duiba2')
const isDuibaAccount = activtiyInfo?.activtiyInfoUserNick?.startsWith('duiba2')
return (isTestEnv && isDuibaAccount) || isMockEnv
}
......@@ -24,21 +24,22 @@ export const isUseVipMock = (context: IContext<IParams>, userNick: string) => {
*/
export const getShopVip = async (
context: IContext<any>,
session: string,
callbackUrl: string = '',
activityUserNick: string = ''
activityInfo: IActivityInfo,
callbackUrl: string = ''
): Promise<IVipInfo> => {
if (isUseVipMock(context, activityUserNick)) {
return VIP_MOCK
const shopUrl = generateVipUrl(callbackUrl)
if (isUseVipMock(context, activityInfo)) {
return {
...VIP_MOCK,
url: shopUrl
}
}
let result = {
result: {
member_info: ''
}
}
result = await TBAPIS.queryVipinfo(context, session)
const shopUrl = generateVipUrl(callbackUrl)
result = await TBAPIS.queryVipinfo(context)
return {
isVip: !!(result.result && result.result.member_info),
......
......@@ -2,6 +2,5 @@
// 测试环境下 duiba2及其子账号自动开启VIP_MOCK, 返回数据可在此设置
export const VIP_MOCK = {
isVip: false,
url: '//taobao.com'
isVip: false
}
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