Commit eb0d4012 authored by maggie's avatar maggie

save

parent fee2d5a8
......@@ -3,6 +3,7 @@
"common": {
"user": {
"getVipInfo": {
"desc": "获取会员信息",
"decorators": [
{
"type": "common",
......@@ -25,15 +26,15 @@
"service": "user",
"function": "getShopVip",
"params": [
"context",
"session",
"activityUserNick"
{ "type": "var", "value": "context" },
{ "type": "var", "value": "session" }
],
"return": true
}
]
},
"getRankList": {
"desc": "获取排行榜",
"decorators": [
{
"type": "common",
......@@ -52,9 +53,9 @@
"service": "user",
"function": "getMyRankInfo",
"params": [
"context.data.key",
"context.data.timeKey",
"userInfo"
{ "type": "var", "value": "context.data.key" },
{ "type": "var", "value": "context.data.timeKey" },
{ "type": "var", "value": "userInfo" }
],
"return": true
},
......@@ -63,9 +64,9 @@
"service": "user",
"function": "getRank",
"params": [
"context.data.key",
"context.data.timeKey",
"context.data.limit"
{ "type": "var", "value": "context.data.key" },
{ "type": "var", "value": "context.data.timeKey" },
{ "type": "var", "value": "context.data.limit" }
],
"return": true
}
......@@ -94,12 +95,60 @@
"name": "preCheck",
"params": [
{
"type": "common"
"type": "common",
"behave": "check",
"name": "checkActivityTime"
}
]
},
{
"type": "common",
"name": "preUpdate",
"params": [
{
"type": "common",
"behave": "update",
"name": "updateVip"
},
{
"type": "common",
"behave": "update",
"name": "updateSignTask"
},
{
"type": "common",
"behave": "update",
"name": "updateOrderGoods"
}
]
}
],
"main": []
"main": [
{
"type": "common",
"service": "task",
"function": "initTask",
"params": [
{ "type": "string", "value": "member" },
{ "type": "string", "value": "加入会员" },
{ "type": "var", "value": "activityInfo" },
{ "type": "var", "value": "userInfo" }
],
"return": true
},
{
"type": "common",
"service": "task",
"function": "initTask",
"params": [
{ "type": "string", "value": "follow" },
{ "type": "string", "value": "关注店铺" },
{ "type": "var", "value": "activityInfo" },
{ "type": "var", "value": "userInfo" }
],
"return": true
}
]
}
}
}
......
/** @format */
{% import "macro.njk" as macro -%}
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'
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
export default class Task {
{%- for fn, item in model %}
/**
* 任务列表
* {{item.desc}}
*/
@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(
{{-macro.genDecorator(model[fn].decorators)}}
@services([{{-macro.genServicesDecorator(model[fn].main)}}])
async {{fn}}(
context: IContext<IParams>,
{ session, userInfo }: IControllerInfos,
[baseService]: [BaseService]
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model[fn].decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model[fn].main)}}
) {
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)
}
})
{{-macro.genMain(model[fn].main)}}
return resultsModel.success(listWithCollectStatus)
{{-macro.genReturn(model[fn].main)}}
}
{%- endfor %}
}
......@@ -2,62 +2,26 @@
{% import "macro.njk" as macro -%}
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
{{-macro.genControllerService(service)}}
export interface IVipParams {
activityId: string
callbackUrl?: string
inviteId?: string // 需要助力回调时请求该接口
}
interface IRankList {
userNick: string
avatar: string
score: any
rank: number
}
export interface IRankResult {
rank: number
userNick: string
avatar: string
score: number
list: IRankList[]
}
export default class User {
{%- for fn, item in model %}
/**
* 获取会员信息
*/
{{-macro.genDecorator(model.getVipInfo.decorators)}}
@services([{{-macro.genServicesDecorator(model.getVipInfo.main)}}])
async getVipInfo(
context: IContext<IVipParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getVipInfo.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getVipInfo.main)}}
): Promise<IResult<IVipInfo>> {
{{-macro.genMain(model.getVipInfo.main)}}
{{-macro.genReturn(model.getVipInfo.main)}}
}
/**
* 获取排行榜
* {{item.desc}}
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([{{-macro.genServicesDecorator(model.getRankList.main)}}])
async getRankList(
context: IContext<{
activityId: string
key: string // 排序的key值 如 score
timeKey: string // 排序时间的key值 如:updateScoreTime
limit: number
}>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getRankList.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getRankList.main)}}
{{-macro.genDecorator(model[fn].decorators)}}
@services([{{-macro.genServicesDecorator(model[fn].main)}}])
async {{fn}}(
context: IContext<IParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model[fn].decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model[fn].main)}}
) {
{{-macro.genMain(model.getRankList.main)}}
{{-macro.genMain(model[fn].main)}}
{{-macro.genReturn(model.getRankList.main)}}
{{-macro.genReturn(model[fn].main)}}
}
{%- endfor %}
}
/** @format */
{# {% import "macro.njk" as macro -%} #}
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
{# {{-macro.genControllerService(service)}} #}
export interface IVipParams {
activityId: string
callbackUrl?: string
inviteId?: string // 需要助力回调时请求该接口
}
interface IRankList {
userNick: string
avatar: string
score: any
rank: number
}
export interface IRankResult {
rank: number
userNick: string
avatar: string
score: number
list: IRankList[]
}
{# export default class User {
/**
* 获取会员信息
*/
{{-macro.genDecorator(model.getVipInfo.decorators)}}
@services([{{-macro.genServicesDecorator(model.getVipInfo.main)}}])
async getVipInfo(
context: IContext<IVipParams>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getVipInfo.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getVipInfo.main)}}
): Promise<IResult<IVipInfo>> {
{{-macro.genMain(model.getVipInfo.main)}}
{{-macro.genReturn(model.getVipInfo.main)}}
}
/**
* 获取排行榜
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([{{-macro.genServicesDecorator(model.getRankList.main)}}])
async getRankList(
context: IContext<{
activityId: string
key: string // 排序的key值 如 score
timeKey: string // 排序时间的key值 如:updateScoreTime
limit: number
}>,
{ activityInfo, userInfo{{-macro.genRegisteInfosParams(model.getRankList.decorators)}} }: IControllerInfos,
{{-macro.genServicesParams(model.getRankList.main)}}
) {
{{-macro.genMain(model.getRankList.main)}}
{{-macro.genReturn(model.getRankList.main)}}
}
} #}
\ No newline at end of file
......@@ -9,7 +9,11 @@ import { {% for s, item2 in item1 %}{{s | capitalize}}Service{%- if loop.last %}
{% macro genDecorator(decorators) %}
{%- for decorator in decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([
{%- for param in decorator.params -%}'{{ param }}'{%- if loop.last %}{% else %}, {% endif %}{%- endfor -%}
{%- if decorator.name == 'preCheck' or decorator.name == 'preUpdate' -%}
{%- for param in decorator.params -%}{{param.type}}Util{{param.behave | capitalize}}.{{param.name}}{%- if loop.last %}{% else %}, {% endif %}{%- endfor -%}
{%- else -%}
{%- for param in decorator.params -%}'{{ param }}'{%- if loop.last %}{% else %}, {% endif %}{%- endfor -%}
{%- endif -%}
])
{%- endfor -%}
{% endmacro %}
......@@ -48,10 +52,10 @@ import { {% for s, item2 in item1 %}{{s | capitalize}}Service{%- if loop.last %}
{# 生成函数体 #}
{% macro genMain(mains) %}
{%- for main in mains %}
const {{main.type}}{{main.service|capitalize}}{{main.function|capitalize}}Result = await {{main.service}}Service.{{main.function}}(
{%- for param in main.params %}
{{param}}{% if loop.last %}{% else %},{% endif %}
{%- endfor %}
const {{main.type}}{{main.service|capitalize}}{{main.function|capitalize}}Result{{loop.index}} = await {{main.service}}Service.{{main.function}}(
{%- for param in main.params -%}
{% if param.type == 'var' %}{{param.value}}{% else %}'{{param.value}}'{% endif %}{% if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
)
{%- endfor -%}
{%- endmacro %}
......@@ -61,7 +65,7 @@ import { {% for s, item2 in item1 %}{{s | capitalize}}Service{%- if loop.last %}
return resultsModel.success({
{%- for main in mains -%}
{% if main.return %}
...{{main.type}}{{main.service|capitalize}}{{main.function|capitalize}}Result{% if loop.last %}{% else %},{% endif %}
...{{main.type}}{{main.service|capitalize}}{{main.function|capitalize}}Result{{loop.index}}{% if loop.last %}{% else %},{% endif %}
{%- endif -%}
{%- endfor %}
})
......
/** @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'
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
import { TaskService } from '../../service'
export default class Task {
/**
* 任务列表
*
*/
@checkParams(['activityId'])
@registeInfos(['vipInfo'])
@commonDecorator.checkParams(['activityId'])
@commonDecorator.registeInfos(['vipInfo'])
@commonDecorator.preCheck([commonUtilCheck.checkActivityTime])
@commonDecorator.preUpdate([commonUtilUpdate.updateVip, commonUtilUpdate.updateSignTask, commonUtilUpdate.updateOrderGoods])
@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]
{ activityInfo, userInfo, vipInfo }: IControllerInfos,
[taskService]: [TaskService]
) {
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)
}
const commonTaskInittaskResult1 = await taskService.initTask('member', '加入会员', activityInfo, userInfo)
const commonTaskInittaskResult2 = await taskService.initTask('follow', '关注店铺', activityInfo, userInfo)
return resultsModel.success({
...commonTaskInittaskResult1,
...commonTaskInittaskResult2
})
return resultsModel.success(listWithCollectStatus)
}
}
/** @format */
import commonDecorator, { services } from '../../decorator/common'
import commonUtilCheck from '../../utils/common/check'
import commonUtilUpdate from '../../utils/common/update'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
export interface IVipParams {
activityId: string
callbackUrl?: string
inviteId?: string // 需要助力回调时请求该接口
}
interface IRankList {
userNick: string
avatar: string
score: any
rank: number
}
export interface IRankResult {
rank: number
userNick: string
avatar: string
score: number
list: IRankList[]
}
export default class User {
/**
* 获取会员信息
......@@ -31,48 +13,30 @@ export default class User {
@commonDecorator.registeInfos(['session'])
@services([UserService])
async getVipInfo(
context: IContext<IVipParams>,
context: IContext<IParams>,
{ activityInfo, userInfo, session }: IControllerInfos,
[userService]: [UserService]
): Promise<IResult<IVipInfo>> {
const commonUserGetshopvipResult = await userService.getShopVip(
context,
session,
activityUserNick
)
) {
const commonUserGetshopvipResult1 = await userService.getShopVip(context, session)
return resultsModel.success({
...commonUserGetshopvipResult
...commonUserGetshopvipResult1
})
}
/**
* 获取排行榜
*/
@commonDecorator.checkParams(['activityId', 'key', 'timeKey', 'limit'])
@services([UserService])
async getRankList(
context: IContext<{
activityId: string
key: string // 排序的key值 如 score
timeKey: string // 排序时间的key值 如:updateScoreTime
limit: number
}>,
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[userService]: [UserService]
) {
const commonUserGetmyrankinfoResult = await userService.getMyRankInfo(
context.data.key,
context.data.timeKey,
userInfo
)
const commonUserGetrankResult = await userService.getRank(
context.data.key,
context.data.timeKey,
context.data.limit
)
const commonUserGetmyrankinfoResult1 = await userService.getMyRankInfo(context.data.key, context.data.timeKey, userInfo)
const commonUserGetrankResult2 = await userService.getRank(context.data.key, context.data.timeKey, context.data.limit)
return resultsModel.success({
...commonUserGetmyrankinfoResult,
...commonUserGetrankResult
...commonUserGetmyrankinfoResult1,
...commonUserGetrankResult2
})
}
}
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