Commit 24566176 authored by 王波's avatar 王波

修改模板接口

parent 16a0fbee
......@@ -24,7 +24,7 @@ export default class Share {
{ inviteUserInfo }: IPreCheckData
) {
// 如果邀请任务是每日的,则需要请求每日任务信息
const task = await getTask(context, inviteUserInfo.openId)
const task = await growTaskService.getTask(context, inviteUserInfo.openId)
const result = await growTaskService.completeTask('invites', activityInfo, inviteUserInfo, task)
statService.addStat(STAT_TYPE.INITE_SUCCESS, userInfo)
......
......@@ -5,8 +5,10 @@
*/
import UserService from './user.service'
import { BaseDao } from '../../sdk'
import { getToday, getUserOrderlist, generateVipUrl, formatVipCbUrl, setNewFollowUserData } from '../../utils'
import { TASK_RATE_TYPE, TASK_STATUS } from '../../constants'
import { TASK_DB_NAME } from '../../db'
import {
getTotalCompleteTask,
setGrowTaskStatus,
......@@ -30,8 +32,10 @@ export interface ITaskInfo {
status: number // 任务状态 1未完成 2 待领取 3 已完成
}
export default class TaskService extends UserService {
taskInfodao: IBaseDao
constructor(context: IContext<IParams>) {
super(context)
this.taskInfodao = new BaseDao(context, TASK_DB_NAME)
}
// 根据活动tasks字段渲染任务
......@@ -207,4 +211,38 @@ export default class TaskService extends UserService {
})
}
}
/**
* 获取用户任务参与信息
* @param context
* @param openId
* @param activityId
*/
async getTask(context: IContext<IParams>, openId: string = '', activityId?: string): Promise<ITask> {
activityId = activityId ? activityId : context.data.activityId
openId = openId ? openId : context.openId
const createDay = getToday()
//查询每日任务完成记录
const result: ITask = await this.taskInfodao.findOne({
openId,
activityId,
createDay
})
//如果还没有今天的任务数据,则新增一条用户任务数据
if (!result) {
const insertObj = {
openId,
activityId,
taskInfo: {},
createTime: Date.now(),
createDay: createDay
}
const insertResult = await this.taskInfodao.insertOne(insertObj)
return { ...insertObj, _id: insertResult }
}
return result
}
}
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