Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinhaitao
taobao-mini-template
Commits
ff0eace9
Commit
ff0eace9
authored
Nov 04, 2020
by
maggie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置模板宏
parent
d0b32ac5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
414 additions
and
34 deletions
+414
-34
config.json
v2.0/compileServer/config.json
+27
-24
awards.controller.njk
...Server/templates/controllers/common/awards.controller.njk
+8
-3
task.controller.njk
...leServer/templates/controllers/common/task.controller.njk
+122
-0
user.controller.njk
...leServer/templates/controllers/common/user.controller.njk
+62
-0
macro.njk
v2.0/compileServer/templates/macro.njk
+7
-0
awards.controller.ts
v2.0/src/controller/common/awards.controller.ts
+5
-4
task.controller.ts
v2.0/src/controller/common/task.controller.ts
+122
-0
user.controller.ts
v2.0/src/controller/common/user.controller.ts
+61
-0
user.controller.ts
v2.0/src/controller/user.controller.ts
+0
-3
No files found.
v2.0/compileServer/config.json
View file @
ff0eace9
{
{
"controllers"
:
{
"controllers"
:
{
"common"
:
{
"common"
:
{
"
awards
"
:
{
"
user
"
:
{
"get
MyPrizeList
"
:
{
"get
VipInfo
"
:
{
"decorators"
:
[
"decorators"
:
[
{
{
"type"
:
"common"
,
"type"
:
"common"
,
...
@@ -15,32 +15,45 @@
...
@@ -15,32 +15,45 @@
"type"
:
"common"
,
"type"
:
"common"
,
"name"
:
"registeInfos"
,
"name"
:
"registeInfos"
,
"params"
:
[
"params"
:
[
"
activityInfo
"
"
session
"
]
]
}
}
]
],
"main"
:
[],
"return"
:
[]
},
},
"
receiveObjectPrize
"
:
{
"
getRankList
"
:
{
"decorators"
:
[
"decorators"
:
[
{
{
"type"
:
"common"
,
"type"
:
"common"
,
"name"
:
"checkParams"
,
"name"
:
"checkParams"
,
"params"
:
[
"params"
:
[
"activityId"
,
"activityId"
,
"id"
,
"key"
,
"name"
,
"timeKey"
,
"phone"
,
"limit"
"province"
,
]
"city"
,
}
"addressDetail"
,
],
"streetName"
"main"
:
[],
"return"
:
[]
}
},
"task"
:
{
"getTaskList"
:
{
"decorators"
:
[
{
"type"
:
"common"
,
"name"
:
"checkParams"
,
"params"
:
[
"activityId"
]
]
},
},
{
{
"type"
:
"common"
,
"type"
:
"common"
,
"name"
:
"registeInfos"
,
"name"
:
"registeInfos"
,
"params"
:
[
"params"
:
[
"
activity
Info"
"
vip
Info"
]
]
},
},
{
{
...
@@ -48,17 +61,7 @@
...
@@ -48,17 +61,7 @@
"name"
:
"preCheck"
,
"name"
:
"preCheck"
,
"params"
:
[
"params"
:
[
{
{
"type"
:
"common"
,
"type"
:
"common"
"behave"
:
"check"
,
"name"
:
"checkAwardReceiveExpired"
},
{
"type"
:
"common"
,
"behave"
:
"check"
,
"name"
:
"checkReceivePrize"
,
"params"
:
{
"prizeType"
:
5
}
}
}
]
]
}
}
...
...
v2.0/compileServer/templates/controllers/common/awards.controller.njk
View file @
ff0eace9
...
@@ -40,6 +40,7 @@ export default class AwardsController {
...
@@ -40,6 +40,7 @@ export default class AwardsController {
@services([AwardsService])
@services([AwardsService])
async getMyPrizeList(
async getMyPrizeList(
context: IContext<IPrizeListParams>,
context: IContext<IPrizeListParams>,
{ activityInfo, vipInfo },
[awardSer]: [AwardsService]
[awardSer]: [AwardsService]
): Promise<IResult<{ list: IAwards[] }>> {
): Promise<IResult<{ list: IAwards[] }>> {
const {
const {
...
@@ -88,11 +89,13 @@ export default class AwardsController {
...
@@ -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])
@services([AwardsService])
async receiveObjectPrize(
async receiveObjectPrize(
context: IContext<IReceiveOjectParams>,
context: IContext<IReceiveOjectParams>,
{ activityInfo }: IControllerInfos,
{ activityInfo
, vipInfo
}: IControllerInfos,
[awardSer]: [AwardsService]
[awardSer]: [AwardsService]
): Promise<IResult<boolean>> {
): Promise<IResult<boolean>> {
let { province, city, area, streetName, addressDetail, id, name, phone, activityId } = context.data
let { province, city, area, streetName, addressDetail, id, name, phone, activityId } = context.data
...
@@ -123,7 +126,9 @@ export default class AwardsController {
...
@@ -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])
@services([AwardsService])
async receiveEnamePrize(context: IContext<IReceiveEnameParams>, {}, [awardSer]: [AwardsService]) {
async receiveEnamePrize(context: IContext<IReceiveEnameParams>, {}, [awardSer]: [AwardsService]) {
let { id, activityId } = context.data
let { id, activityId } = context.data
...
...
v2.0/compileServer/templates/controllers/common/task.controller.njk
0 → 100644
View file @
ff0eace9
/** @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)
}
}
v2.0/compileServer/templates/controllers/common/user.controller.njk
0 → 100644
View file @
ff0eace9
/** @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
})
}
}
v2.0/compileServer/templates/macro.njk
0 → 100644
View file @
ff0eace9
{% 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
v2.0/src/controller/common/awards.controller.ts
View file @
ff0eace9
...
@@ -39,7 +39,7 @@ export default class AwardsController {
...
@@ -39,7 +39,7 @@ export default class AwardsController {
@
services
([
AwardsService
])
@
services
([
AwardsService
])
async
getMyPrizeList
(
async
getMyPrizeList
(
context
:
IContext
<
IPrizeListParams
>
,
context
:
IContext
<
IPrizeListParams
>
,
{
activityInfo
},
{
activityInfo
,
vipInfo
},
[
awardSer
]:
[
AwardsService
]
[
awardSer
]:
[
AwardsService
]
):
Promise
<
IResult
<
{
list
:
IAwards
[]
}
>>
{
):
Promise
<
IResult
<
{
list
:
IAwards
[]
}
>>
{
const
{
const
{
...
@@ -88,11 +88,13 @@ export default class AwardsController {
...
@@ -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
])
@
services
([
AwardsService
])
async
receiveObjectPrize
(
async
receiveObjectPrize
(
context
:
IContext
<
IReceiveOjectParams
>
,
context
:
IContext
<
IReceiveOjectParams
>
,
{
activityInfo
}:
IControllerInfos
,
{
activityInfo
,
vipInfo
}:
IControllerInfos
,
[
awardSer
]:
[
AwardsService
]
[
awardSer
]:
[
AwardsService
]
):
Promise
<
IResult
<
boolean
>>
{
):
Promise
<
IResult
<
boolean
>>
{
let
{
province
,
city
,
area
,
streetName
,
addressDetail
,
id
,
name
,
phone
,
activityId
}
=
context
.
data
let
{
province
,
city
,
area
,
streetName
,
addressDetail
,
id
,
name
,
phone
,
activityId
}
=
context
.
data
...
@@ -123,7 +125,6 @@ export default class AwardsController {
...
@@ -123,7 +125,6 @@ export default class AwardsController {
/**
/**
* 权益重新领取
* 权益重新领取
*/
*/
@
checkParams
([
'activityId'
,
'id'
])
@
services
([
AwardsService
])
@
services
([
AwardsService
])
async
receiveEnamePrize
(
context
:
IContext
<
IReceiveEnameParams
>
,
{},
[
awardSer
]:
[
AwardsService
])
{
async
receiveEnamePrize
(
context
:
IContext
<
IReceiveEnameParams
>
,
{},
[
awardSer
]:
[
AwardsService
])
{
let
{
id
,
activityId
}
=
context
.
data
let
{
id
,
activityId
}
=
context
.
data
...
...
v2.0/src/controller/common/task.controller.ts
0 → 100644
View file @
ff0eace9
/** @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
)
}
}
v2.0/src/controller/common/user.controller.ts
0 → 100644
View file @
ff0eace9
/** @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
})
}
}
v2.0/src/controller/user.controller.ts
View file @
ff0eace9
...
@@ -14,9 +14,6 @@ export default class User {
...
@@ -14,9 +14,6 @@ export default class User {
/**
/**
* 获取会员信息
* 获取会员信息
*/
*/
@
checkParams
([
'activityId'
])
@
registeInfos
([
'session'
])
@
services
([])
async
getVipInfo
(
async
getVipInfo
(
context
:
IContext
<
IVipParams
>
,
context
:
IContext
<
IVipParams
>
,
{
session
,
activityUserNick
}:
IControllerInfos
{
session
,
activityUserNick
}:
IControllerInfos
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment