Commit baf6d241 authored by maggie's avatar maggie

save

parent 13e4acfb
......@@ -19,8 +19,19 @@
]
}
],
"main": [],
"return": []
"main": [
{
"type": "common",
"service": "user",
"function": "getShopVip",
"params": [
"context",
"session",
"activityUserNick"
],
"return": true
}
]
},
"getRankList": {
"decorators": [
......@@ -35,8 +46,30 @@
]
}
],
"main": [],
"return": []
"main": [
{
"type": "common",
"service": "user",
"function": "getMyRankInfo",
"params": [
"context.data.key",
"context.data.timeKey",
"userInfo"
],
"return": true
},
{
"type": "common",
"service": "user",
"function": "getRank",
"params": [
"context.data.key",
"context.data.timeKey",
"context.data.limit"
],
"return": true
}
]
}
},
"task": {
......
......@@ -4,35 +4,48 @@
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 // 需要助力回调时请求该接口
}
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>,
{ session, activityUserNick }: IControllerInfos
{ session, activityUserNick }: IControllerInfos,
{{-macro.genServicesParams(model.getVipInfo.main)}}
): Promise<IResult<IVipInfo>> {
const { callbackUrl } = context.data
// 拼接回调参数
const result = await getShopVip(context, session, callbackUrl || formatVipCbUrl(context), activityUserNick)
{{-macro.genMain(model.getVipInfo.main)}}
return resultsModel.success(result)
{{-macro.genReturn(model.getVipInfo.main)}}
}
/**
* 获取排行榜
*/
{{-macro.genDecorator(model.getRankList.decorators)}}
@services([UserService])
{{-macro.genServicesDecorator(model.getRankList.main)}}
async getRankList(
context: IContext<{
activityId: string
......@@ -41,22 +54,10 @@ export default class User {
limit: number
}>,
{ userInfo }: IControllerInfos,
[userService]: [UserService]
{{-macro.genServicesParams(model.getRankList.main)}}
) {
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)
{{-macro.genMain(model.getRankList.main)}}
return resultsModel.success({
userNick,
avatar,
rank,
score: userInfo[key],
list
})
{{-macro.genReturn(model.getRankList.main)}}
}
}
{# 生成控制器引用的服务 #}
{% macro genControllerService(controller)%}
{% endmacro %}
{# 生成装饰器 #}
{% 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
{% endmacro %}
{# 生成services装饰器 #}
{% macro genServicesDecorator(mains) %}
@services([
{%- for service, main in mains|groupby("service") -%}
{{ service | capitalize }}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
])
{%- endmacro %}
{# 生成services参数 #}
{% macro genServicesParams(mains) %}
[
{%- for service, main in mains|groupby("service") -%}
{{ service }}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
]: [
{%- for service, main in mains|groupby("service") -%}
{{ service | capitalize }}Service{%- if loop.last %}{% else %}, {% endif %}
{%- endfor -%}
]
{%- endmacro %}
{# 生成函数体 #}
{% 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 %}
)
{%- endfor -%}
{%- endmacro %}
{# 生成return结果 #}
{% macro genReturn(mains) %}
return resultsModel.success({
{%- for main in mains -%}
{% if main.return %}
...{{main.type}}{{main.service|capitalize}}{{main.function|capitalize}}Result{% if loop.last %}{% else %},{% endif %}
{%- endif -%}
{%- endfor %}
})
{%- endmacro%}
\ No newline at end of file
......@@ -2,29 +2,47 @@
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 // 需要助力回调时请求该接口
}
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 {
/**
* 获取会员信息
*/
@commonDecorator.checkParams(['activityId'])
@commonDecorator.registeInfos(['session'])
@services([])
@services([UserService])
async getVipInfo(
context: IContext<IVipParams>,
{ session, activityUserNick }: IControllerInfos
{ session, activityUserNick }: IControllerInfos,
[userService]: [UserService]
): Promise<IResult<IVipInfo>> {
const { callbackUrl } = context.data
// 拼接回调参数
const result = await getShopVip(context, session, callbackUrl || formatVipCbUrl(context), activityUserNick)
return resultsModel.success(result)
const commonUserGetshopvipResult = await userService.getShopVip(
context,
session,
activityUserNick
)
return resultsModel.success({
...commonUserGetshopvipResult
})
}
/**
......@@ -42,20 +60,19 @@ export default class User {
{ 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)
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
)
return resultsModel.success({
userNick,
avatar,
rank,
score: userInfo[key],
list
...commonUserGetmyrankinfoResult,
...commonUserGetrankResult
})
}
}
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