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
3d277a1e
Commit
3d277a1e
authored
Nov 04, 2020
by
maggie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改装饰器导出方式
parent
ea02b5a8
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
282 additions
and
17 deletions
+282
-17
awards.controller.njk
...Server/templates/controllers/common/awards.controller.njk
+1
-0
awards.controller.ts
v2.0/src/controller/awards.controller.ts
+2
-2
awards.controller.ts
v2.0/src/controller/common/awards.controller.ts
+213
-0
login.controller.ts
v2.0/src/controller/login.controller.ts
+2
-2
share.controller.ts
v2.0/src/controller/share.controller.ts
+1
-1
checkParams.ts
v2.0/src/decorator/common/checkParams.ts
+3
-1
index.ts
v2.0/src/decorator/common/index.ts
+9
-5
noCatch.ts
v2.0/src/decorator/common/noCatch.ts
+3
-1
noCheckUser.ts
v2.0/src/decorator/common/noCheckUser.ts
+3
-1
preCheck.ts
v2.0/src/decorator/common/preCheck.ts
+3
-1
registeInfos.ts
v2.0/src/decorator/common/registeInfos.ts
+3
-1
services.ts
v2.0/src/decorator/common/services.ts
+3
-1
update.ts
v2.0/src/decorator/common/update.ts
+3
-1
index.ts
v2.0/src/utils/common/check/index.ts
+17
-0
index.ts
v2.0/src/utils/common/index.ts
+9
-0
index.ts
v2.0/src/utils/common/update/index.ts
+7
-0
No files found.
v2.0/compileServer/templates/controllers/common/awards.controller.njk
View file @
3d277a1e
/** @format */
import commonDecorator, { services } from '../../decorator/common'
import commonUtil from '../../utils/common'
import { resultsModel } from '../../sdk'
import { AwardsService } from '../../service'
import { PRIZE_TYPE, DRAW_STATUS, CODE_TYPES } from '../../constants'
...
...
v2.0/src/controller/awards.controller.ts
View file @
3d277a1e
/** @format */
import
{
services
,
checkParam
s
}
from
'../decorator/common'
import
{
checkParams
,
service
s
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
AwardsService
}
from
'../service'
import
{
PRIZE_TYPE
,
DRAW_STATUS
,
CODE_TYPES
}
from
'../constants'
import
{
getToday
}
from
'../utils/'
import
{
CodeType
}
from
'taobao-mini-sdk/lib/utils/codetypes'
import
{
preCheck
}
from
'../decorator/common/preCheck'
import
preCheck
from
'../decorator/common/preCheck'
import
{
checkActivityTime
}
from
'../utils/common/check/checkActivityTime'
export
interface
IPrizeListParams
{
...
...
v2.0/src/controller/common/awards.controller.ts
0 → 100644
View file @
3d277a1e
/** @format */
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
commonUtil
from
'../../utils/common'
import
{
resultsModel
}
from
'../../sdk'
import
{
AwardsService
}
from
'../../service'
import
{
PRIZE_TYPE
,
DRAW_STATUS
,
CODE_TYPES
}
from
'../../constants'
import
{
getToday
}
from
'../../utils/'
import
{
CodeType
}
from
'taobao-mini-sdk/lib/utils/codetypes'
import
{
preCheck
}
from
'../../decorator/common/preCheck'
import
{
checkActivityTime
}
from
'../../utils/common/check/checkActivityTime'
export
interface
IPrizeListParams
{
activityId
:
string
}
export
interface
IReceiveOjectParams
{
activityId
:
string
id
:
string
name
:
string
phone
:
string
province
:
string
city
:
string
area
:
string
addressDetail
:
string
streetName
:
string
}
export
interface
IReceiveEnameParams
{
activityId
:
string
id
:
string
}
export
default
class
AwardsController
{
/**
* 我的奖品列表
*/
@
commonDecorator
.
checkParams
([
'activityId'
,])
@
commonDecorator
.
registeInfos
([
'activityInfo'
,])
@
services
([
AwardsService
])
async
getMyPrizeList
(
context
:
IContext
<
IPrizeListParams
>
,
[
awardSer
]:
[
AwardsService
]
):
Promise
<
IResult
<
{
list
:
IAwards
[]
}
>>
{
const
{
openId
,
data
:
{
activityId
}
}
=
context
const
{
awardReceiveExpiredTime
}
=
activityInfo
const
myPrizeList
=
await
awardSer
.
getAwardsInfoList
(
{
openId
,
activityId
,
type
:
{
$ne
:
PRIZE_TYPE
.
THANKS
}
},
{
projection
:
{
_id
:
1
,
name
:
1
,
image
:
1
,
type
:
1
,
drawStatus
:
1
,
shipStatus
:
1
,
receiveName
:
1
,
phone
:
1
,
address
:
1
,
provice
:
1
,
city
:
1
,
area
:
1
,
remark
:
1
,
useUrk
:
1
,
shipCompany
:
1
,
shipNum
:
1
},
sort
:
{
createTime
:
-
1
}
}
)
return
resultsModel
.
success
({
list
:
awardSer
.
formateMyPrizeList
(
myPrizeList
,
awardReceiveExpiredTime
)
})
}
/**
* 领取实物
*/
@
checkParams
([
'activityId'
,
'id'
,
'name'
,
'phone'
,
'province'
,
'city'
,
'area'
,
'addressDetail'
,
'streetName'
])
@
services
([
AwardsService
])
async
receiveObjectPrize
(
context
:
IContext
<
IReceiveOjectParams
>
,
{
activityInfo
}:
IControllerInfos
,
[
awardSer
]:
[
AwardsService
]
):
Promise
<
IResult
<
boolean
>>
{
let
{
province
,
city
,
area
,
streetName
,
addressDetail
,
id
,
name
,
phone
,
activityId
}
=
context
.
data
// 若有过期时间,且已过期
let
{
awardReceiveExpiredTime
}
=
activityInfo
if
(
awardReceiveExpiredTime
&&
Date
.
now
()
>
awardReceiveExpiredTime
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_PRIZE_EXPIRED
)
}
let
result
=
await
awardSer
.
recieveObjectPrize
(
id
,
{
activityId
,
province
,
city
,
area
,
streetName
,
addressDetail
,
name
,
phone
})
if
((
result
as
CodeType
).
code
)
{
return
resultsModel
.
error
(
result
as
CodeType
)
}
return
resultsModel
.
success
(
result
as
true
)
}
/**
* 权益重新领取
*/
@
checkParams
([
'activityId'
,
'id'
])
@
services
([
AwardsService
])
async
receiveEnamePrize
(
context
:
IContext
<
IReceiveEnameParams
>
,
{},
[
awardSer
]:
[
AwardsService
])
{
let
{
id
,
activityId
}
=
context
.
data
let
result
=
await
awardSer
.
recieveEnamePrize
(
id
,
activityId
)
if
((
result
as
CodeType
).
code
)
{
return
resultsModel
.
error
(
result
as
CodeType
)
}
if
((
result
as
IAwards
).
remark
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
(
result
as
IAwards
).
remark
)
}
return
resultsModel
.
success
(
result
)
}
/**
* 概率抽奖
*/
@
checkParams
([
'activityId'
,
'prizeDataType'
])
@
services
([
AwardsService
])
@
preCheck
([
checkActivityTime
])
async
drawLotteryPrize
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
awardSer
]:
[
AwardsService
])
{
const
{
openId
}
=
context
const
{
activityId
,
prizeDataType
}
=
context
.
data
// 获取奖池配置
const
prizesPool
=
await
awardSer
.
getPrizeConfig
({
activityId
,
// 根据需求配置筛选条件
prizeDataType
})
const
thanksPrize
=
prizesPool
.
find
(
v
=>
v
.
type
===
PRIZE_TYPE
.
THANKS
)
||
{
type
:
PRIZE_TYPE
.
THANKS
,
prizeDataType
,
name
:
'谢谢参与'
}
// 根据概率获取
let
prize
=
await
awardSer
.
getPrizeByProbability
(
prizesPool
)
// 未找到奖品,降级到谢谢参与
if
(
!
prize
)
{
prize
=
thanksPrize
}
let
reduceResult
:
ICodeType
|
number
=
1
// 不是积分奖品, 检查是否扣库存
if
(
prize
.
type
!==
PRIZE_TYPE
.
CREDITS
&&
prize
.
type
!==
PRIZE_TYPE
.
THANKS
)
{
reduceResult
=
await
awardSer
.
reduceStock
(
prize
.
_id
)
}
// 扣库存失败降级到谢谢参与
if
((
reduceResult
as
ICodeType
)?.
code
||
!
reduceResult
)
{
prize
=
thanksPrize
}
const
{
type
,
_id
,
ename
,
image
,
name
,
useUrl
}
=
prize
const
{
userNick
}
=
userInfo
let
record
=
{
openId
,
prizeId
:
_id
,
activityId
,
drawStatus
:
DRAW_STATUS
.
WAITAWARD
,
prizeDataType
,
remark
:
''
,
useUrl
,
type
,
ename
,
name
,
image
,
userNick
,
createDay
:
getToday
()
}
// 奖品信息 insert c_awards表
const
result
=
await
awardSer
.
addAward
(
record
)
return
resultsModel
.
success
({
id
:
result
,
type
,
name
,
image
})
}
}
\ No newline at end of file
v2.0/src/controller/login.controller.ts
View file @
3d277a1e
...
...
@@ -3,9 +3,9 @@
import
{
services
,
checkParams
,
registeInfos
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
UserService
,
AccessService
}
from
'../service'
import
{
preCheck
}
from
'../decorator/common/preCheck'
import
preCheck
from
'../decorator/common/preCheck'
import
{
checkActivityTime
}
from
'../utils/common/check/checkActivityTime'
import
{
noCheckUser
}
from
'../decorator/common/noCheckUser'
import
noCheckUser
from
'../decorator/common/noCheckUser'
export
interface
ILoginParams
{
activityId
:
string
...
...
v2.0/src/controller/share.controller.ts
View file @
3d277a1e
...
...
@@ -10,7 +10,7 @@ import { checkInviteId } from '../utils/common/check/checkInviteId'
import
{
checkHelpRecord
}
from
'../utils/common/check/checkHelpRecord'
import
{
checkNewVip
}
from
'../utils/common/check/checkNewVip'
import
{
CODE_TYPES
}
from
'../errorCode'
import
{
update
}
from
'../decorator/common/update'
import
update
from
'../decorator/common/update'
import
{
updateVip
}
from
'../utils/common/update/updateVip'
export
interface
IdoHelpInfos
extends
IControllerInfos
{
inviteUserInfo
:
IUserInfo
...
...
v2.0/src/decorator/common/checkParams.ts
View file @
3d277a1e
...
...
@@ -3,7 +3,7 @@ import { resultsModel } from '../../sdk'
import
{
CODE_TYPES
}
from
'../../constants'
import
{
logFn
}
from
'../../utils'
// 检验参数是否存在
export
const
checkParams
=
(
params
:
string
[])
=>
{
const
checkParams
=
(
params
:
string
[])
=>
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
...
...
@@ -21,3 +21,5 @@ export const checkParams = (params: string[]) => {
}
}
}
export
default
checkParams
v2.0/src/decorator/common/index.ts
View file @
3d277a1e
/** @format */
export
*
from
'./checkParams'
export
*
from
'./services'
export
*
from
'./noCatch'
export
*
from
'./registeInfos'
export
*
from
'./preCheck'
import
services
from
'./services'
import
noCatch
from
'./noCatch'
import
checkParams
from
'./checkParams'
import
preCheck
from
'./preCheck'
import
registeInfos
from
'./registeInfos'
import
noCheckUser
from
'./noCheckUser'
import
update
from
'./update'
export
{
services
,
noCatch
,
checkParams
,
preCheck
,
registeInfos
,
noCheckUser
,
update
}
v2.0/src/decorator/common/noCatch.ts
View file @
3d277a1e
/** @format */
export
const
noCatch
=
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
=>
{
const
noCatch
=
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
=>
{
const
method
=
descriptor
.
value
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
const
[
context
,
otherArgs
=
{}]
=
args
return
method
.
apply
(
this
,
[
context
,
{
...
otherArgs
,
noCatch
:
true
}])
}
}
export
default
noCatch
v2.0/src/decorator/common/noCheckUser.ts
View file @
3d277a1e
/** @format */
export
const
noCheckUser
=
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
=>
{
const
noCheckUser
=
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
=>
{
const
method
=
descriptor
.
value
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
const
[
context
,
otherArgs
=
{}]
=
args
return
method
.
apply
(
this
,
[
context
,
{
...
otherArgs
,
noCheckUser
:
true
}])
}
}
export
default
noCheckUser
v2.0/src/decorator/common/preCheck.ts
View file @
3d277a1e
/** @format */
// 检验参数是否存在
export
const
preCheck
=
(
checks
:
IFunction
[])
=>
{
const
preCheck
=
(
checks
:
IFunction
[])
=>
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
...
...
@@ -23,3 +23,5 @@ export const preCheck = (checks: IFunction[]) => {
}
}
}
export
default
preCheck
v2.0/src/decorator/common/registeInfos.ts
View file @
3d277a1e
...
...
@@ -44,7 +44,7 @@ async function initBaseInfo(context: IContext<IParams>, baseInfos: ICheckControl
return
baseInfos
}
export
const
registeInfos
=
(
needInfos
:
IInfo
[])
=>
{
const
registeInfos
=
(
needInfos
:
IInfo
[])
=>
{
return
function
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
...
...
@@ -58,3 +58,5 @@ export const registeInfos = (needInfos: IInfo[]) => {
}
}
}
export
default
registeInfos
v2.0/src/decorator/common/services.ts
View file @
3d277a1e
...
...
@@ -31,7 +31,7 @@ async function formatBaseInfos(context: IContext<IParams>, baseInfos: ICheckCont
}
// 注入服务
export
const
services
=
(
services
:
Constructor
[])
=>
{
const
services
=
(
services
:
Constructor
[])
=>
{
return
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
=>
{
const
method
=
descriptor
.
value
...
...
@@ -57,3 +57,5 @@ export const services = (services: Constructor[]) => {
}
}
}
export
default
services
v2.0/src/decorator/common/update.ts
View file @
3d277a1e
/** @format */
// 检验参数是否存在
export
const
update
=
(
checks
:
IFunction
[])
=>
{
const
update
=
(
checks
:
IFunction
[])
=>
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
...
...
@@ -23,3 +23,5 @@ export const update = (checks: IFunction[]) => {
}
}
}
export
default
update
v2.0/src/utils/common/check/index.ts
0 → 100644
View file @
3d277a1e
/** @format */
import
{
checkActivityTime
}
from
'./checkActivityTime'
import
{
checkHelpRecord
}
from
'./checkHelpRecord'
import
{
checkInviteId
}
from
'./checkInviteId'
import
{
checkNewVip
}
from
'./checkNewVip'
import
{
checkTaskLimit
}
from
'./checkTaskLimit'
import
{
checkVip
}
from
'./checkVip'
export
default
{
checkActivityTime
,
checkHelpRecord
,
checkInviteId
,
checkNewVip
,
checkTaskLimit
,
checkVip
}
v2.0/src/utils/common/index.ts
0 → 100644
View file @
3d277a1e
/** @format */
import
*
as
check
from
'./check'
import
*
as
update
from
'./update'
export
default
{
check
,
update
}
v2.0/src/utils/common/update/index.ts
0 → 100644
View file @
3d277a1e
/** @format */
import
{
updateVip
}
from
'./updateVip'
export
default
{
updateVip
}
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