Commit ff0eace9 authored by maggie's avatar maggie

设置模板宏

parent d0b32ac5
{
"controllers": {
"common": {
"awards": {
"getMyPrizeList": {
"user": {
"getVipInfo": {
"decorators": [
{
"type": "common",
......@@ -15,32 +15,45 @@
"type": "common",
"name": "registeInfos",
"params": [
"activityInfo"
"session"
]
}
]
],
"main": [],
"return": []
},
"receiveObjectPrize": {
"getRankList": {
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId",
"id",
"name",
"phone",
"province",
"city",
"addressDetail",
"streetName"
"key",
"timeKey",
"limit"
]
}
],
"main": [],
"return": []
}
},
"task": {
"getTaskList": {
"decorators": [
{
"type": "common",
"name": "checkParams",
"params": [
"activityId"
]
},
{
"type": "common",
"name": "registeInfos",
"params": [
"activityInfo"
"vipInfo"
]
},
{
......@@ -48,17 +61,7 @@
"name": "preCheck",
"params": [
{
"type": "common",
"behave": "check",
"name": "checkAwardReceiveExpired"
},
{
"type": "common",
"behave": "check",
"name": "checkReceivePrize",
"params": {
"prizeType": 5
}
"type": "common"
}
]
}
......
......@@ -40,6 +40,7 @@ export default class AwardsController {
@services([AwardsService])
async getMyPrizeList(
context: IContext<IPrizeListParams>,
{ activityInfo, vipInfo },
[awardSer]: [AwardsService]
): Promise<IResult<{ list: IAwards[] }>> {
const {
......@@ -88,11 +89,13 @@ export default class AwardsController {
/**
* 领取实物
*/
@checkParams(['activityId', 'id', 'name', 'phone', 'province', 'city', 'area', 'addressDetail', 'streetName'])
{%- for decorator in model.receiveObjectPrize.decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([{% for param in decorator.params -%}'{{ param }}',{%- endfor %}])
{%- endfor %}
@services([AwardsService])
async receiveObjectPrize(
context: IContext<IReceiveOjectParams>,
{ activityInfo }: IControllerInfos,
{ activityInfo, vipInfo }: IControllerInfos,
[awardSer]: [AwardsService]
): Promise<IResult<boolean>> {
let { province, city, area, streetName, addressDetail, id, name, phone, activityId } = context.data
......@@ -123,7 +126,9 @@ export default class AwardsController {
/**
* 权益重新领取
*/
@checkParams(['activityId', 'id'])
{%- for decorator in model.receiveEnamePrize.decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([{% for param in decorator.params -%}'{{ param }}',{%- endfor %}])
{%- endfor %}
@services([AwardsService])
async receiveEnamePrize(context: IContext<IReceiveEnameParams>, {}, [awardSer]: [AwardsService]) {
let { id, activityId } = context.data
......
/** @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)
}
}
/** @format */
{% import "macro.njk" as macro -%}
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
import { formatVipCbUrl, getShopVip } from '../../utils/common/vip'
export interface IVipParams {
activityId: string
callbackUrl?: string
inviteId?: string // 需要助力回调时请求该接口
}
export default class User {
/**
* 获取会员信息
*/
{{-macro.genDecorator(model.getVipInfo.decorators)}}
@services([])
async getVipInfo(
context: IContext<IVipParams>,
{ session, activityUserNick }: IControllerInfos
): Promise<IResult<IVipInfo>> {
const { callbackUrl } = context.data
// 拼接回调参数
const result = await getShopVip(context, session, callbackUrl || formatVipCbUrl(context), activityUserNick)
return resultsModel.success(result)
}
/**
* 获取排行榜
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([UserService])
async getRankList(
context: IContext<{
activityId: string
key: string // 排序的key值 如 score
timeKey: string // 排序时间的key值 如:updateScoreTime
limit: number
}>,
{ userInfo }: IControllerInfos,
[userService]: [UserService]
) {
const { key, timeKey, limit = 200 } = context.data
const { userNick, avatar } = userInfo
const rank = await userService.getMyRank(key, timeKey, userInfo[key])
const list = await userService.getRank(key, timeKey, limit)
return resultsModel.success({
userNick,
avatar,
rank,
score: userInfo[key],
list
})
}
}
{% macro genDecorator(decorators) %}
{%- for decorator in decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([
{%- for param in decorator.params -%}'{{ param }}'{%- if loop.last %}{% else %}, {% endif %}{%- endfor -%}
])
{%- endfor -%}
{% endmacro %}
\ No newline at end of file
......@@ -39,7 +39,7 @@ export default class AwardsController {
@services([AwardsService])
async getMyPrizeList(
context: IContext<IPrizeListParams>,
{ activityInfo },
{ activityInfo, vipInfo },
[awardSer]: [AwardsService]
): Promise<IResult<{ list: IAwards[] }>> {
const {
......@@ -88,11 +88,13 @@ export default class AwardsController {
/**
* 领取实物
*/
@checkParams(['activityId', 'id', 'name', 'phone', 'province', 'city', 'area', 'addressDetail', 'streetName'])
@commonDecorator.checkParams(['activityId','id','name','phone','province','city','addressDetail','streetName',])
@commonDecorator.registeInfos(['activityInfo',])
@commonDecorator.preCheck(['[object Object]','[object Object]',])
@services([AwardsService])
async receiveObjectPrize(
context: IContext<IReceiveOjectParams>,
{ activityInfo }: IControllerInfos,
{ activityInfo, vipInfo }: IControllerInfos,
[awardSer]: [AwardsService]
): Promise<IResult<boolean>> {
let { province, city, area, streetName, addressDetail, id, name, phone, activityId } = context.data
......@@ -123,7 +125,6 @@ export default class AwardsController {
/**
* 权益重新领取
*/
@checkParams(['activityId', 'id'])
@services([AwardsService])
async receiveEnamePrize(context: IContext<IReceiveEnameParams>, {}, [awardSer]: [AwardsService]) {
let { id, activityId } = context.data
......
/** @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)
}
}
/** @format */
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
import { formatVipCbUrl, getShopVip } from '../../utils/common/vip'
export interface IVipParams {
activityId: string
callbackUrl?: string
inviteId?: string // 需要助力回调时请求该接口
}
export default class User {
/**
* 获取会员信息
*/
@commonDecorator.checkParams(['activityId'])
@commonDecorator.registeInfos(['session'])
@services([])
async getVipInfo(
context: IContext<IVipParams>,
{ session, activityUserNick }: IControllerInfos
): Promise<IResult<IVipInfo>> {
const { callbackUrl } = context.data
// 拼接回调参数
const result = await getShopVip(context, session, callbackUrl || formatVipCbUrl(context), activityUserNick)
return resultsModel.success(result)
}
/**
* 获取排行榜
*/
@commonDecorator.checkParams(['activityId', 'key', 'timeKey', 'limit'])
@services([UserService])
async getRankList(
context: IContext<{
activityId: string
key: string // 排序的key值 如 score
timeKey: string // 排序时间的key值 如:updateScoreTime
limit: number
}>,
{ userInfo }: IControllerInfos,
[userService]: [UserService]
) {
const { key, timeKey, limit = 200 } = context.data
const { userNick, avatar } = userInfo
const rank = await userService.getMyRank(key, timeKey, userInfo[key])
const list = await userService.getRank(key, timeKey, limit)
return resultsModel.success({
userNick,
avatar,
rank,
score: userInfo[key],
list
})
}
}
......@@ -14,9 +14,6 @@ export default class User {
/**
* 获取会员信息
*/
@checkParams(['activityId'])
@registeInfos(['session'])
@services([])
async getVipInfo(
context: IContext<IVipParams>,
{ session, activityUserNick }: IControllerInfos
......
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