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
d2ff6879
Commit
d2ff6879
authored
Nov 12, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
游戏数据
parent
8ac9ef94
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
80 additions
and
34 deletions
+80
-34
.DS_Store
.DS_Store
+0
-0
config.json
v2.0/compileServer/config.json
+8
-1
formatConfg.js
v2.0/compileServer/utils/formatConfg.js
+2
-8
game.controller.ts
v2.0/src/controller/game.controller.ts
+4
-9
task.controller.ts
v2.0/src/controller/task.controller.ts
+1
-1
user.controller.ts
v2.0/src/controller/user.controller.ts
+2
-2
checkParams.ts
v2.0/src/decorator/common/checkParams.ts
+16
-5
noCatch.ts
v2.0/src/decorator/common/noCatch.ts
+9
-0
noCheckUser.ts
v2.0/src/decorator/common/noCheckUser.ts
+10
-0
preCheck.ts
v2.0/src/decorator/common/preCheck.ts
+7
-1
preUpdate.ts
v2.0/src/decorator/common/preUpdate.ts
+1
-1
checkUserInfo.ts
v2.0/src/utils/common/check/checkUserInfo.ts
+4
-0
index.ts
v2.0/src/utils/common/check/index.ts
+5
-3
index.ts
v2.0/src/utils/common/update/index.ts
+4
-3
updateUserInfo.ts
v2.0/src/utils/common/update/updateUserInfo.ts
+7
-0
No files found.
.DS_Store
View file @
d2ff6879
No preview for this file type
v2.0/compileServer/config.json
View file @
d2ff6879
...
@@ -155,7 +155,8 @@
...
@@ -155,7 +155,8 @@
{
{
"type"
:
"common"
,
"type"
:
"common"
,
"behave"
:
"check"
,
"behave"
:
"check"
,
"name"
:
"checkActivityTime"
"name"
:
"checkActivityTime"
,
},
},
{
{
"type"
:
"common"
,
"type"
:
"common"
,
...
@@ -166,6 +167,12 @@
...
@@ -166,6 +167,12 @@
"type"
:
"common"
,
"type"
:
"common"
,
"behave"
:
"check"
,
"behave"
:
"check"
,
"name"
:
"checkExchangeCreditsTask"
"name"
:
"checkExchangeCreditsTask"
},
{
"type"
:
"common"
,
"behave"
:
"check"
,
"name"
:
"checkUserInfo"
,
"params"
:
3
}
}
]
]
}
}
...
...
v2.0/compileServer/utils/formatConfg.js
View file @
d2ff6879
...
@@ -10,10 +10,7 @@ function getDecorators(controller, decoratorType) {
...
@@ -10,10 +10,7 @@ function getDecorators(controller, decoratorType) {
function
getPreChecks
(
controller
,
checkType
)
{
function
getPreChecks
(
controller
,
checkType
)
{
checkType
=
checkType
||
'common'
checkType
=
checkType
||
'common'
let
decorators
=
[]
let
decorators
=
[]
decorators
=
[...
decorators
,
...
Object
.
values
(
controller
).
map
(
v
=>
v
.
decorators
)].
reduce
(
decorators
=
[...
decorators
,
...
Object
.
values
(
controller
).
map
(
v
=>
v
.
decorators
)].
flat
()
(
r
,
item
)
=>
r
.
concat
(
item
),
[]
)
const
preChecks
=
[...
decorators
.
filter
(
v
=>
v
.
type
===
'common'
&&
v
.
name
===
'preCheck'
).
map
(
v
=>
v
.
params
)].
flat
()
const
preChecks
=
[...
decorators
.
filter
(
v
=>
v
.
type
===
'common'
&&
v
.
name
===
'preCheck'
).
map
(
v
=>
v
.
params
)].
flat
()
return
[...
new
Set
(
preChecks
.
filter
(
v
=>
v
.
type
===
checkType
&&
v
.
behave
===
'check'
).
map
(
v
=>
v
.
name
))]
return
[...
new
Set
(
preChecks
.
filter
(
v
=>
v
.
type
===
checkType
&&
v
.
behave
===
'check'
).
map
(
v
=>
v
.
name
))]
...
@@ -22,10 +19,7 @@ function getPreChecks(controller, checkType) {
...
@@ -22,10 +19,7 @@ function getPreChecks(controller, checkType) {
function
getPreUpdates
(
controller
,
updateType
)
{
function
getPreUpdates
(
controller
,
updateType
)
{
updateType
=
updateType
||
'common'
updateType
=
updateType
||
'common'
let
decorators
=
[]
let
decorators
=
[]
decorators
=
[...
decorators
,
...
Object
.
values
(
controller
).
map
(
v
=>
v
.
decorators
)].
reduce
(
decorators
=
[...
decorators
,
...
Object
.
values
(
controller
).
map
(
v
=>
v
.
decorators
)].
flat
()
(
r
,
item
)
=>
r
.
concat
(
item
),
[]
)
const
preUpdates
=
[
const
preUpdates
=
[
...
decorators
.
filter
(
v
=>
v
.
type
===
'common'
&&
v
.
name
===
'preUpdate'
).
map
(
v
=>
v
.
params
)
...
decorators
.
filter
(
v
=>
v
.
type
===
'common'
&&
v
.
name
===
'preUpdate'
).
map
(
v
=>
v
.
params
)
].
flat
()
].
flat
()
...
...
v2.0/src/controller/game.controller.ts
View file @
d2ff6879
...
@@ -3,8 +3,8 @@
...
@@ -3,8 +3,8 @@
import
{
services
,
checkParams
,
preCheck
,
preUpdate
}
from
'../decorator/common'
import
{
services
,
checkParams
,
preCheck
,
preUpdate
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
resultsModel
}
from
'../sdk'
import
{
CommonUserService
,
CommonGameService
}
from
'../service/common'
import
{
CommonUserService
,
CommonGameService
}
from
'../service/common'
import
{
checkActivityTime
,
checkJoinId
,
checkUserInfo
,
checkVip
}
from
'../utils/common/check'
import
{
checkActivityTime
,
checkJoinId
,
checkUserInfo
,
checkVip
,
checkGameTimes
}
from
'../utils/common/check'
import
{
updateUserInfo
}
from
'../utils/common/update'
import
{
updateUserInfo
,
reduceGameTimes
}
from
'../utils/common/update'
export
interface
ISumitGameControllerInfos
extends
IControllerInfos
{
export
interface
ISumitGameControllerInfos
extends
IControllerInfos
{
joinInfo
:
IJoinRecord
joinInfo
:
IJoinRecord
...
@@ -32,13 +32,8 @@ export default class Game {
...
@@ -32,13 +32,8 @@ export default class Game {
@
checkParams
([
'activityId'
])
@
checkParams
([
'activityId'
])
@
services
([
CommonGameService
])
@
services
([
CommonGameService
])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkUserInfo
({
gameTimes
:
{
$gte
:
3
}
},
'游戏次数不足,做点任务吧'
)])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkGameTimes
(
3
)])
@
preUpdate
([
@
preUpdate
([
reduceGameTimes
(
3
)])
updateUserInfo
({
$where
:
'this.gameTimes>3'
,
$inc
:
{
gameTimes
:
-
3
}
})
])
async
startGame
(
async
startGame
(
context
:
IContext
<
IParams
>
,
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
...
...
v2.0/src/controller/task.controller.ts
View file @
d2ff6879
...
@@ -42,7 +42,7 @@ export default class Task {
...
@@ -42,7 +42,7 @@ export default class Task {
* 商品相关任务 需要传itemId参数
* 商品相关任务 需要传itemId参数
* 积分兑换任务 需要传credits参数
* 积分兑换任务 需要传credits参数
*/
*/
@
checkParams
([
'activityId'
,
'taskType'
])
@
checkParams
([
'activityId'
,
'taskType'
,
'itemId?'
,
'credits?'
])
@
registeInfos
([
'session'
])
@
registeInfos
([
'session'
])
@
services
([
CommonTaskService
])
@
services
([
CommonTaskService
])
@
preCheck
([
checkActivityTime
,
checkTaskLimit
,
checkExchangeCreditsTask
])
@
preCheck
([
checkActivityTime
,
checkTaskLimit
,
checkExchangeCreditsTask
])
...
...
v2.0/src/controller/user.controller.ts
View file @
d2ff6879
...
@@ -38,10 +38,10 @@ export default class User {
...
@@ -38,10 +38,10 @@ export default class User {
/**
/**
* 获取排行榜
* 获取排行榜
*/
*/
@
checkParams
([
'activityId'
,
'key
'
,
'timeKey
'
])
@
checkParams
([
'activityId'
,
'key
?'
,
'timeKey?'
,
'limit?
'
])
@
services
([
CommonUserService
])
@
services
([
CommonUserService
])
async
getRankList
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
userService
]:
[
CommonUserService
])
{
async
getRankList
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
userService
]:
[
CommonUserService
])
{
const
{
key
,
timeKey
,
limit
=
200
}
=
context
.
data
const
{
key
=
'score'
,
timeKey
=
'updateScoreTime'
,
limit
=
200
}
=
context
.
data
const
rankInfo
=
await
userService
.
getMyRankInfo
(
key
,
timeKey
,
userInfo
)
const
rankInfo
=
await
userService
.
getMyRankInfo
(
key
,
timeKey
,
userInfo
)
...
...
v2.0/src/decorator/common/checkParams.ts
View file @
d2ff6879
...
@@ -2,14 +2,25 @@
...
@@ -2,14 +2,25 @@
import
{
resultsModel
}
from
'../../sdk'
import
{
resultsModel
}
from
'../../sdk'
import
{
CODE_TYPES
}
from
'../../constants'
import
{
CODE_TYPES
}
from
'../../constants'
import
{
logFn
}
from
'../../utils'
import
{
logFn
}
from
'../../utils'
// 检验参数是否存在
export
default
function
checkParams
(
params
:
string
[])
{
/**
* 检查接口参数
*
* @checkParams(['activityId', 'itemId?'])
*
* itemId? 问号结尾为可选参数 不做校验
*
* @export
* @param {string[]} params 参数列表
* @return {*}
*/
export
default
function
checkParams
(
params
:
string
[]):
IFunction
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
const
method
=
descriptor
.
value
descriptor
.
value
=
function
(...
args
:
any
[])
{
descriptor
.
value
=
function
(...
args
:
any
[])
{
const
[
context
,
otherArgs
=
{}]
=
args
const
[
context
,
otherArgs
=
{}
,
services
=
[],
preCheckData
=
{}
]
=
args
const
dataKeys
=
Object
.
keys
(
context
.
data
)
const
dataKeys
=
Object
.
keys
(
context
.
data
)
.
filter
(
v
=>
!
v
.
endsWith
(
'?'
))
for
(
let
i
=
0
;
i
<
params
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
params
.
length
;
i
++
)
{
const
param
=
params
[
i
]
const
param
=
params
[
i
]
if
(
!
dataKeys
.
includes
(
param
)
||
context
.
data
?.[
param
]
===
''
)
{
if
(
!
dataKeys
.
includes
(
param
)
||
context
.
data
?.[
param
]
===
''
)
{
...
@@ -17,7 +28,7 @@ export default function checkParams(params: string[]) {
...
@@ -17,7 +28,7 @@ export default function checkParams(params: string[]) {
return
resultsModel
.
error
(
CODE_TYPES
.
PARAMS_ERROR
,
`缺少
${
param
}
参数`
)
return
resultsModel
.
error
(
CODE_TYPES
.
PARAMS_ERROR
,
`缺少
${
param
}
参数`
)
}
}
}
}
return
method
.
apply
(
target
,
[
context
,
{
...
otherArgs
}])
return
method
.
apply
(
target
,
[
context
,
{
...
otherArgs
}
,
services
,
preCheckData
])
}
}
}
}
}
}
v2.0/src/decorator/common/noCatch.ts
View file @
d2ff6879
/** @format */
/** @format */
/**
*
* 默认接口最外层会tryCatch 某些特殊接口需要自定义tryCatch 可以使用该装饰器
*
* @export
* @param {*} target
* @param {string} name
* @param {PropertyDescriptor} descriptor
*/
export
default
function
noCatch
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
export
default
function
noCatch
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
const
method
=
descriptor
.
value
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
...
...
v2.0/src/decorator/common/noCheckUser.ts
View file @
d2ff6879
/** @format */
/** @format */
/**
*
* 默认所用接口都会校验活动信息和用户信息
* 不需要检查用户信息的使用noCheckUser装饰器 如:login getActivityBaseInfoById
*
* @export
* @param {*} target
* @param {string} name
* @param {PropertyDescriptor} descriptor
*/
export
default
function
noCheckUser
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
export
default
function
noCheckUser
(
target
:
any
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
const
method
=
descriptor
.
value
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
...
...
v2.0/src/decorator/common/preCheck.ts
View file @
d2ff6879
/** @format */
/** @format */
// 检验参数是否存在
/**
* 前置检查
*
* @export
* @param {IFunction[]} checks
* @return {*}
*/
export
default
function
preCheck
(
checks
:
IFunction
[])
{
export
default
function
preCheck
(
checks
:
IFunction
[])
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
const
method
=
descriptor
.
value
...
...
v2.0/src/decorator/common/preUpdate.ts
View file @
d2ff6879
...
@@ -8,7 +8,7 @@ import { formatUpdatedDataByProjection, formatUpdateUserProjection } from '../..
...
@@ -8,7 +8,7 @@ import { formatUpdatedDataByProjection, formatUpdateUserProjection } from '../..
import
{
dbUpdate
}
from
'../../utils/common/mongodb'
import
{
dbUpdate
}
from
'../../utils/common/mongodb'
import
{
USER_DB_NAME
}
from
'../../db'
import
{
USER_DB_NAME
}
from
'../../db'
//
检验参数是否存在
//
前置更新
export
default
function
preUpdate
(
checks
:
IFunction
[])
{
export
default
function
preUpdate
(
checks
:
IFunction
[])
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
return
function
(
target
:
Object
,
name
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
method
=
descriptor
.
value
const
method
=
descriptor
.
value
...
...
v2.0/src/utils/common/check/checkUserInfo.ts
View file @
d2ff6879
...
@@ -31,6 +31,10 @@ export default function checkUserInfo(gameLimit: IGameLimit, errorMsg: string) {
...
@@ -31,6 +31,10 @@ export default function checkUserInfo(gameLimit: IGameLimit, errorMsg: string) {
}
}
}
}
export
function
checkGameTimes
(
count
:
number
)
{
return
checkUserInfo
({
gameTimes
:
{
$gte
:
count
}
},
'游戏次数不足'
)
}
function
validateData
(
data
:
any
=
{},
condition
:
IGameLimit
)
{
function
validateData
(
data
:
any
=
{},
condition
:
IGameLimit
)
{
let
allValid
=
true
let
allValid
=
true
Object
.
keys
(
condition
).
forEach
(
key
=>
{
Object
.
keys
(
condition
).
forEach
(
key
=>
{
...
...
v2.0/src/utils/common/check/index.ts
View file @
d2ff6879
...
@@ -9,7 +9,7 @@ import checkRemainTimes from './checkRemainTimes'
...
@@ -9,7 +9,7 @@ import checkRemainTimes from './checkRemainTimes'
import
checkTaskLimit
from
'./checkTaskLimit'
import
checkTaskLimit
from
'./checkTaskLimit'
import
checkValidPrize
,
{
checkValidEnamePrize
,
checkValidObjectPrize
}
from
'./checkValidPrize'
import
checkValidPrize
,
{
checkValidEnamePrize
,
checkValidObjectPrize
}
from
'./checkValidPrize'
import
checkVip
from
'./checkVip'
import
checkVip
from
'./checkVip'
import
checkUserInfo
from
'./checkUserInfo'
import
checkUserInfo
,
{
checkGameTimes
}
from
'./checkUserInfo'
import
checkJoinId
from
'./checkJoinId'
import
checkJoinId
from
'./checkJoinId'
const
check
=
{
const
check
=
{
...
@@ -26,7 +26,8 @@ const check = {
...
@@ -26,7 +26,8 @@ const check = {
checkValidObjectPrize
,
checkValidObjectPrize
,
checkVip
,
checkVip
,
checkUserInfo
,
checkUserInfo
,
checkJoinId
checkJoinId
,
checkGameTimes
}
}
export
default
check
export
default
check
...
@@ -45,5 +46,6 @@ export {
...
@@ -45,5 +46,6 @@ export {
checkValidObjectPrize
,
checkValidObjectPrize
,
checkVip
,
checkVip
,
checkUserInfo
,
checkUserInfo
,
checkJoinId
checkJoinId
,
checkGameTimes
}
}
v2.0/src/utils/common/update/index.ts
View file @
d2ff6879
...
@@ -3,16 +3,17 @@ import updateVip from './updateVip'
...
@@ -3,16 +3,17 @@ import updateVip from './updateVip'
import
updateSignTask
from
'./updateSignTask'
import
updateSignTask
from
'./updateSignTask'
import
updateOrderGoods
from
'./updateOrderGoods'
import
updateOrderGoods
from
'./updateOrderGoods'
import
updateFirstLoginToday
from
'./updateFirstLoginToday'
import
updateFirstLoginToday
from
'./updateFirstLoginToday'
import
updateUserInfo
from
'./updateUserInfo'
import
updateUserInfo
,
{
reduceGameTimes
}
from
'./updateUserInfo'
const
update
=
{
const
update
=
{
updateVip
,
updateVip
,
updateSignTask
,
updateSignTask
,
updateOrderGoods
,
updateOrderGoods
,
updateFirstLoginToday
,
updateFirstLoginToday
,
updateUserInfo
updateUserInfo
,
reduceGameTimes
}
}
export
default
update
export
default
update
export
{
updateVip
,
updateSignTask
,
updateOrderGoods
,
updateFirstLoginToday
,
updateUserInfo
}
export
{
updateVip
,
updateSignTask
,
updateOrderGoods
,
updateFirstLoginToday
,
updateUserInfo
,
reduceGameTimes
}
v2.0/src/utils/common/update/updateUserInfo.ts
View file @
d2ff6879
...
@@ -12,3 +12,10 @@ export default function updateUserInfo(update?: IPreUpdateQuery) {
...
@@ -12,3 +12,10 @@ export default function updateUserInfo(update?: IPreUpdateQuery) {
return
update
return
update
}
}
}
}
export
function
reduceGameTimes
(
gameTimes
:
number
)
{
return
updateUserInfo
({
$where
:
`this.gameTimes >=
${
gameTimes
}
`
,
$inc
:
{
gameTimes
:
-
gameTimes
}
})
}
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