Commit baf6d241 authored by maggie's avatar maggie

save

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