Commit 9075a0be authored by qinhaitao's avatar qinhaitao

refactor: 💡 getTaskList

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