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
94369362
Commit
94369362
authored
Nov 05, 2020
by
maggie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save
parent
66c67294
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
154 additions
and
6 deletions
+154
-6
config.json
v2.0/compileServer/config.json
+2
-1
generate.js
v2.0/compileServer/generate.js
+19
-1
user.controller.njk
...leServer/templates/controllers/common/user.controller.njk
+1
-1
macro.njk
v2.0/compileServer/templates/macro.njk
+5
-2
task.controller.ts
v2.0/src/controller/common/task.controller.ts
+122
-0
user.controller.ts
v2.0/src/controller/common/user.controller.ts
+5
-1
No files found.
v2.0/compileServer/config.json
View file @
94369362
...
...
@@ -98,7 +98,8 @@
}
]
}
]
],
"main"
:
[]
}
}
}
...
...
v2.0/compileServer/generate.js
View file @
94369362
...
...
@@ -5,6 +5,23 @@ const config = require('./config.json')
const
serverTemplatePath
=
'templates'
const
run
=
async
(
gulp
,
nunjucksRender
,
rename
,
nunjucksRenderConfig
)
=>
{
//生成控制器service
const
controllerServices
=
{
common
:
{},
custom
:
{}
}
//通用控制器
for
(
let
commonController
in
config
.
controllers
.
common
)
{
controllerServices
.
common
[
commonController
]
=
{}
for
(
let
fn
in
config
.
controllers
.
common
[
commonController
])
{
for
(
let
main
of
config
.
controllers
.
common
[
commonController
][
fn
].
main
)
{
if
(
!
controllerServices
.
common
[
commonController
][
main
.
type
])
{
controllerServices
.
common
[
commonController
][
main
.
type
]
=
{}
}
controllerServices
.
common
[
commonController
][
main
.
type
][
main
.
service
]
=
true
}
}
}
//编译controller.common
for
(
let
commonController
in
config
.
controllers
.
common
)
{
await
gulp
...
...
@@ -13,7 +30,8 @@ const run = async (gulp, nunjucksRender, rename, nunjucksRenderConfig) => {
nunjucksRender
({
...
nunjucksRenderConfig
,
data
:
{
model
:
config
.
controllers
.
common
[
commonController
]
model
:
config
.
controllers
.
common
[
commonController
],
service
:
controllerServices
.
common
[
commonController
]
}
})
)
...
...
v2.0/compileServer/templates/controllers/common/user.controller.njk
View file @
94369362
...
...
@@ -3,7 +3,7 @@
import commonDecorator, { services } from '../../decorator/common'
import { resultsModel } from '../../sdk'
import { UserService } from '../../service'
{{-macro.genControllerService(service)}}
export interface IVipParams {
activityId: string
...
...
v2.0/compileServer/templates/macro.njk
View file @
94369362
{# 生成控制器引用的服务 #}
{% macro genControllerService(controller)%}
{% macro genControllerService(service)%}
{%- for type, item1 in service %}
import { {% for s, item2 in item1 %}{{s | capitalize}}Service{%- if loop.last %}{% else %}, {% endif %}{% endfor %} } from '../../service'
{%- endfor -%}
{% endmacro %}
{# 生成装饰器 #}
{% macro genDecorator(decorators) %}
{%- for decorator in decorators %}
...
...
v2.0/src/controller/common/task.controller.ts
0 → 100644
View file @
94369362
/** @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
View file @
94369362
...
...
@@ -35,7 +35,11 @@ export default class User {
{
session
,
activityUserNick
}:
IControllerInfos
,
[
userService
]:
[
UserService
]
):
Promise
<
IResult
<
IVipInfo
>>
{
const
commonUserGetshopvipResult
=
await
userService
.
getShopVip
(
context
,
session
,
activityUserNick
)
const
commonUserGetshopvipResult
=
await
userService
.
getShopVip
(
context
,
session
,
activityUserNick
)
return
resultsModel
.
success
({
...
commonUserGetshopvipResult
})
...
...
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