Commit 94369362 authored by maggie's avatar maggie

save

parent 66c67294
......@@ -98,7 +98,8 @@
}
]
}
]
],
"main": []
}
}
}
......
......@@ -5,6 +5,23 @@ const config = require('./config.json')
const serverTemplatePath = 'templates'
const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
//生成控制器service
const controllerServices = {
common: {},
custom: {}
}
//通用控制器
for (let commonController in config.controllers.common) {
controllerServices.common[commonController] = {}
for (let fn in config.controllers.common[commonController]) {
for (let main of config.controllers.common[commonController][fn].main) {
if (!controllerServices.common[commonController][main.type]) {
controllerServices.common[commonController][main.type] = {}
}
controllerServices.common[commonController][main.type][main.service] = true
}
}
}
//编译controller.common
for (let commonController in config.controllers.common) {
await gulp
......@@ -13,7 +30,8 @@ const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
nunjucksRender({
...nunjucksRenderConfig,
data: {
model: config.controllers.common[commonController]
model: config.controllers.common[commonController],
service: controllerServices.common[commonController]
}
})
)
......
......@@ -3,7 +3,7 @@
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
{{-macro.genControllerService(service)}}
export interface IVipParams {
activityId: string
......
{# 生成控制器引用的服务 #}
{% macro genControllerService(controller)%}
{% macro genControllerService(service)%}
{%- for type, item1 in service %}
import { {% for s, item2 in item1 %}{{s | capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{% endfor %} } from '../../service'
{%- endfor -%}
{% endmacro %}
{# 生成装饰器 #}
{% macro genDecorator(decorators) %}
{%- for decorator in decorators %}
......
/** @format */
import { CODE_TYPES } from './../constants'
import { checkParams, services, registeInfos, preCheck } from '../decorator/common'
import { resultsModel } from '../sdk'
import { TaskService, BaseService } from '../service'
import { ITaskInfo } from '../service/task.service'
import { checkActivityTime } from '../utils/common/check/checkActivityTime'
import { getTotalCompleteTask } from '../utils/common/task'
import { update } from '../decorator/common/update'
import { updateVip } from '../utils/common/update/updateVip'
import { checkTaskLimit } from '../utils/common/check/checkTaskLimit'
import { checkExchangeCreditsTask } from '../utils/common/check/checkExchangeCreditsTask'
import { checkRemainTimes } from '../utils/common/check/checkRemainTimes'
export default class Task {
/**
* 任务列表
*/
@checkParams(['activityId'])
@registeInfos(['vipInfo'])
@services([TaskService])
@preCheck([checkActivityTime])
@update([updateVip])
async getTaskList(
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, updatedUserInfo)
])
}
/**
* 完成任务
*
* 商品相关任务 需要传itemId参数
* 积分兑换任务 需要传credits参数
*/
@checkParams(['activityId', 'taskType'])
@registeInfos(['session'])
@services([TaskService])
@preCheck([checkActivityTime, checkTaskLimit, checkExchangeCreditsTask])
async doCompleteTask(
context: IContext<{
activityId: string
taskType: ITaskType
itemId?: string // 涉及到商品的任务需传itemId
credits?: number
}>,
{ userInfo, activityInfo }: IControllerInfos,
[taskService]: [TaskService]
): Promise<IResult<boolean>> {
const { taskType, itemId } = context.data
// 更新user表
const result = await taskService.completeTask(taskType, activityInfo, userInfo, { itemId })
return result ? resultsModel.success(true) : resultsModel.error(CODE_TYPES.SYSTEM_ERROR, '任务完成失败')
}
/**
* 领取任务奖励
*/
@checkParams(['activityId', 'taskType', 'rewardsKey'])
@services([TaskService])
@preCheck([checkActivityTime, checkRemainTimes])
async receiveTaskRewards(
context: IContext<{
activityId: string
taskType: ITaskType
rewardsKey: string //领取的奖励增加的key值 如: gameTimes 前端传入
}>,
{ userInfo }: IControllerInfos,
[taskService]: [TaskService]
): Promise<IResult<{ rewards: number }>> {
const { rewardsKey } = context.data
const { taskType } = context.data
const rewards = await taskService.receiveTaskRewards(taskType, rewardsKey, userInfo)
return resultsModel.success({
rewards
})
}
/**
* 获取收藏商品列表
*/
@checkParams(['activityId', 'itemIds'])
@registeInfos(['session'])
@services([BaseService])
async getCollectGoodsList(
context: IContext<IParams>,
{ session, userInfo }: IControllerInfos,
[baseService]: [BaseService]
) {
const { itemIds } = context.data
const list = await baseService.getItemListByIds(itemIds, session)
const { taskInfo } = getTotalCompleteTask('collectGoods', userInfo)
const listWithCollectStatus = list.map(v => {
return {
...v,
// 完成列表是否含有itemId
collected: taskInfo.some(completeItem => completeItem.itemId === v.itemId)
}
})
return resultsModel.success(listWithCollectStatus)
}
}
......@@ -35,7 +35,11 @@ export default class User {
{ session, activityUserNick }: IControllerInfos,
[userService]: [UserService]
): Promise<IResult<IVipInfo>> {
const commonUserGetshopvipResult = await userService.getShopVip(context, session, activityUserNick)
const commonUserGetshopvipResult = await userService.getShopVip(
context,
session,
activityUserNick
)
return resultsModel.success({
...commonUserGetshopvipResult
})
......
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