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
2dbe42a1
Commit
2dbe42a1
authored
Dec 02, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
接口数据
parent
0bd83d36
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
136 additions
and
56 deletions
+136
-56
constants.ts
v2.0/src/constants.ts
+18
-0
card.controller.ts
v2.0/src/controller/card.controller.ts
+12
-20
customUser.ts
v2.0/src/customUser.ts
+35
-7
awards.service.ts
v2.0/src/service/common/awards.service.ts
+2
-1
user.service.ts
v2.0/src/service/common/user.service.ts
+7
-6
awards.d.ts
v2.0/src/typings/awards.d.ts
+1
-0
user.d.ts
v2.0/src/typings/user.d.ts
+3
-0
checkCardGameTimes.ts
v2.0/src/utils/common/check/checkCardGameTimes.ts
+13
-0
index.ts
v2.0/src/utils/common/check/index.ts
+6
-2
initCustomUser.ts
v2.0/src/utils/common/initCustomUser.ts
+0
-12
index.ts
v2.0/src/utils/common/update/index.ts
+12
-3
updateUserInfo.ts
v2.0/src/utils/common/update/updateUserInfo.ts
+27
-3
index.ts
v2.0/src/utils/index.ts
+0
-2
No files found.
v2.0/src/constants.ts
View file @
2dbe42a1
...
...
@@ -108,12 +108,30 @@ export enum STAT_TYPE {
INITE_SUCCESS
}
// 集卡阶梯奖励状态
export
enum
CARD_PRIZE_STATUS
{
LOCK
=
1
,
UN_LOCK
,
SUCCESS
}
// 免费次数赠送类型
export
enum
FREE_TYPE
{
FOERVER
=
1
,
EVERY_DAY
=
2
}
export
enum
FEATURE_OPEN_STATUS
{
CLOSE
=
1
,
OPEN
=
2
}
export
const
GIFT_CARD_STATUS
=
FEATURE_OPEN_STATUS
.
OPEN
export
const
TASK_OPEN_STATUS
=
FEATURE_OPEN_STATUS
.
OPEN
export
const
JOIN_NEED_TIMES
=
1
export
const
appId
=
'${需要补充}'
// 商铺id 拼接vip链接用
...
...
v2.0/src/controller/card.controller.ts
View file @
2dbe42a1
/** @format */
import
{
PRIZE_DATA_TYPE
}
from
'../constants'
import
{
GIFT_CARD_STATUS
,
JOIN_NEED_TIMES
,
PRIZE_DATA_TYPE
,
TASK_OPEN_STATUS
}
from
'../constants'
import
{
services
,
checkParams
,
preCheck
,
preUpdate
}
from
'../decorator/common'
import
{
CODE_TYPES
}
from
'../errorCode'
import
{
resultsModel
}
from
'../sdk'
import
{
CommonCardService
,
CommonAwardsService
}
from
'../service/common'
import
{
getToday
}
from
'../utils'
import
{
checkActivityTime
,
checkUserInfo
,
checkVip
,
checkInviteId
,
checkInviteUserCard
}
from
'../utils/common/check'
import
{
updateUserInfo
}
from
'../utils/common/update'
import
checkCardGameTimes
from
'../utils/common/check/checkCardGameTimes'
import
{
reduceCardGameTimes
,
updateUserInfo
}
from
'../utils/common/update'
export
interface
ISumitGameControllerInfos
extends
IControllerInfos
{
joinInfo
:
IJoinRecord
...
...
@@ -21,7 +23,7 @@ export default class Card {
[
cardService
]:
[
CommonCardService
,
CommonAwardsService
]
)
{
const
{
activityId
}
=
context
.
data
const
{
joinedTimes
,
gameTimes
}
=
userInfo
const
{
joinedTimes
,
gameTimes
,
gameTimesEverday
}
=
userInfo
const
myCardInfo
=
cardService
.
getMyCardInfo
(
userInfo
)
...
...
@@ -39,9 +41,13 @@ export default class Card {
myCardInfo
.
cardTypeCollectedCount
)
const
today
=
getToday
()
return
resultsModel
.
success
({
joinedTimes
,
gameTimes
,
gameTimes
:
gameTimes
+
(
gameTimesEverday
?.[
today
]
||
0
),
giftCardStatus
:
GIFT_CARD_STATUS
,
taskOpenStatus
:
TASK_OPEN_STATUS
,
...
myCardInfo
,
joinedTimesPrizeList
,
collectedCardTypePrizeList
...
...
@@ -50,22 +56,8 @@ export default class Card {
@
checkParams
([
'activityId'
])
@
services
([
CommonCardService
])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkUserInfo
(
{
gameTimes
:
{
$gte
:
1
}
},
CODE_TYPES
.
ERROR_NO_GAME_TIMES
)
])
@
preUpdate
([
updateUserInfo
({
$where
:
`this.gameTimes >= 1`
,
$inc
:
{
gameTimes
:
-
1
}
})
])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkCardGameTimes
])
@
preUpdate
([
reduceCardGameTimes
(
JOIN_NEED_TIMES
)])
async
doJoin
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
cardService
]:
[
CommonCardService
])
{
const
{
activityId
}
=
context
.
data
...
...
v2.0/src/customUser.ts
View file @
2dbe42a1
/** @format */
export
const
customInitUserInfo
:
ICustomUserInfo
=
{
gameTimes
:
0
,
// maxScore: 0,
// totalScore: 0,
import
{
FREE_TYPE
}
from
'./constants'
import
{
getToday
}
from
'./utils'
// login初始化用户信息
export
const
initCustomUserWhenLogin
=
(
context
:
IContext
<
IParams
>
,
activityInfo
:
IActivityInfo
):
ICustomUserInfo
=>
{
const
{
freeTimes
,
freeType
}
=
activityInfo
?.
collectCardConfig
||
{}
return
{
gameTimes
:
freeType
===
FREE_TYPE
.
FOERVER
?
freeTimes
:
0
,
gameTimesEverday
:
{
[
getToday
()]:
freeType
===
FREE_TYPE
.
EVERY_DAY
?
freeTimes
:
0
},
joinedTimes
:
0
,
cardsCollectedCount
:
0
,
cardInfo
:
{}
}
}
export
const
updateUserWhenLogin
=
(
context
:
IContext
<
IParams
>
,
activityInfo
:
IActivityInfo
,
userInfo
:
IUserInfo
):
IUpdateQuery
=>
{
const
{
freeTimes
,
freeType
}
=
activityInfo
?.
collectCardConfig
||
{}
const
today
=
getToday
()
let
projection
:
IUpdateQuery
=
{
$inc
:
{}
}
const
firstLoginToday
=
!
userInfo
?.
login
?.[
today
]
if
(
firstLoginToday
&&
freeType
===
FREE_TYPE
.
EVERY_DAY
)
{
projection
.
$inc
[
`gameTimesEverday.
${
today
}
`
]
=
freeTimes
}
return
projection
}
v2.0/src/service/common/awards.service.ts
View file @
2dbe42a1
...
...
@@ -254,7 +254,7 @@ export default class AwardsService extends UserService {
prize
=
thanksPrize
}
const
{
type
,
_id
,
ename
,
image
,
name
,
useUrl
}
=
prize
const
{
type
,
_id
,
ename
,
image
,
name
,
useUrl
,
credits
}
=
prize
const
{
userNick
}
=
userInfo
let
record
=
{
...
...
@@ -269,6 +269,7 @@ export default class AwardsService extends UserService {
ename
,
name
,
image
,
credits
:
+
credits
,
userNick
,
createDay
:
getToday
()
}
...
...
v2.0/src/service/common/user.service.ts
View file @
2dbe42a1
...
...
@@ -7,13 +7,14 @@
import
{
BaseDao
}
from
'../../sdk'
import
BaseService
from
'./base.service'
import
{
USER_DB_NAME
}
from
'../../db'
import
{
customInitUserInfo
}
from
'../../customUser'
import
{
getToday
,
formatUpdateUserProjection
,
initCustomUser
}
from
'../../utils'
import
{
initCustomUserWhenLogin
,
updateUserWhenLogin
}
from
'../../customUser'
import
{
getToday
,
formatUpdateUserProjection
}
from
'../../utils'
import
{
isNewVip
}
from
'../../utils/common/userUpdate'
import
{
formatUserNick
,
formatUpdatedDataByProjection
}
from
'../../utils/common/format'
import
{
setNewFollowUserData
,
setNewVipUserData
}
from
'../../utils/common/userUpdate'
import
{
getShopVip
,
formatVipCbUrl
}
from
'../../utils/common/vip'
import
{
get
}
from
'mpath'
import
{
merge
}
from
'lodash'
class
UserService
extends
BaseService
{
userdao
:
IBaseDao
...
...
@@ -45,7 +46,7 @@ class UserService extends BaseService {
async
doLogin
(
userInfo
:
IUserInfo
,
vipInfo
:
IVipInfo
,
activityInfo
:
IActivityInfo
)
{
if
(
!
userInfo
)
{
const
customUserInfo
=
initCustomUser
(
this
.
context
,
activityInfo
,
customInitUser
Info
)
const
customUserInfo
=
initCustomUser
WhenLogin
(
this
.
context
,
activity
Info
)
userInfo
=
await
this
.
initUserData
(
vipInfo
,
activityInfo
,
customUserInfo
)
}
else
{
userInfo
=
await
this
.
updateUserData
(
vipInfo
,
userInfo
,
activityInfo
)
...
...
@@ -135,7 +136,7 @@ class UserService extends BaseService {
const
{
isFollow
}
=
data
const
today
=
getToday
()
let
projection
=
{
let
projection
:
IUpdateQuery
=
{
$set
:
{
updateTime
:
Date
.
now
()
},
...
...
@@ -153,7 +154,6 @@ class UserService extends BaseService {
const
followBefore
=
userInfo
.
follow
.
flag
const
followNow
=
isFollow
if
(
!
followBefore
&&
followNow
&&
!
userInfo
.
follow
.
newFollow
)
{
// @ts-ignore
projection
.
$set
.
follow
=
setNewFollowUserData
(
userInfo
.
follow
)
projection
.
$push
[
`taskInfo.
${
today
}
.follow`
]
=
{
createTime
:
Date
.
now
()
}
projection
.
$inc
[
`remainTimes.follow`
]
=
follow
.
value
...
...
@@ -162,12 +162,13 @@ class UserService extends BaseService {
// 之前进入活动非会员,现在进入会员,则视为新会员用户
const
newVip
=
isNewVip
(
userInfo
,
vipInfo
)
if
(
newVip
)
{
// @ts-ignore
projection
.
$set
.
member
=
setNewVipUserData
(
userInfo
.
member
)
projection
.
$push
[
`taskInfo.
${
today
}
.member`
]
=
{
createTime
:
Date
.
now
()
}
projection
.
$inc
[
`remainTimes.member`
]
=
member
.
value
}
projection
=
merge
({},
projection
,
updateUserWhenLogin
(
this
.
context
,
activityInfo
,
userInfo
))
await
this
.
updateUser
(
userInfo
.
_id
,
projection
)
return
formatUpdatedDataByProjection
(
userInfo
,
projection
)
...
...
v2.0/src/typings/awards.d.ts
View file @
2dbe42a1
...
...
@@ -26,6 +26,7 @@ interface ICommonAwards {
area
?:
string
receiveTime
?:
number
shipStatus
?:
number
credtis
?:
number
shipCompany
?:
string
shipNum
?:
string
|
number
remark
:
string
...
...
v2.0/src/typings/user.d.ts
View file @
2dbe42a1
...
...
@@ -9,6 +9,9 @@ interface ICustomUserInfo {
updateScoreTime
?:
number
// 集卡
joinedTimes
?:
number
gameTimesEverday
?:
{
[
key
:
string
]:
number
}
cardsCollectedCount
?:
number
cardInfo
:
{
[
key
:
string
]:
number
...
...
v2.0/src/utils/common/check/checkCardGameTimes.ts
0 → 100644
View file @
2dbe42a1
/** @format */
import
{
resultsModel
}
from
'../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
getToday
}
from
'../getToday'
export
default
async
function
checkCardGameTimes
(
context
:
IContext
<
IParams
>
,
{
vipInfo
,
userInfo
}:
IControllerInfos
)
{
const
{
gameTimes
,
gameTimesEverday
}
=
userInfo
const
today
=
getToday
()
if
(
!
gameTimesEverday
?.[
today
]
&&
!
gameTimes
)
{
return
CODE_TYPES
.
ERROR_NO_GAME_TIMES
}
}
v2.0/src/utils/common/check/index.ts
View file @
2dbe42a1
...
...
@@ -13,6 +13,8 @@ import checkUserInfo, { checkGameTimes } from './checkUserInfo'
import
checkJoinId
from
'./checkJoinId'
import
checkOpenPrizeStatus
from
'./checkOpenPrizeStatus'
import
checkInviteUserCard
from
'./checkInviteUserCard'
import
checkCardGameTimes
from
'./checkCardGameTimes'
const
check
=
{
checkActivityTime
,
checkExchangeCreditsTask
,
...
...
@@ -30,7 +32,8 @@ const check = {
checkJoinId
,
checkGameTimes
,
checkOpenPrizeStatus
,
checkInviteUserCard
checkInviteUserCard
,
checkCardGameTimes
}
export
default
check
...
...
@@ -52,5 +55,6 @@ export {
checkJoinId
,
checkGameTimes
,
checkOpenPrizeStatus
,
checkInviteUserCard
checkInviteUserCard
,
checkCardGameTimes
}
v2.0/src/utils/common/initCustomUser.ts
deleted
100644 → 0
View file @
0bd83d36
/** @format */
export
const
initCustomUser
=
(
context
:
IContext
<
IParams
>
,
activityInfo
:
IActivityInfo
,
customUserInfo
:
ICustomUserInfo
)
=>
{
return
{
...
customUserInfo
,
gameTimes
:
activityInfo
?.
collectCardConfig
?.
freeTimes
||
0
}
}
v2.0/src/utils/common/update/index.ts
View file @
2dbe42a1
...
...
@@ -3,7 +3,7 @@ import updateVip from './updateVip'
import
updateSignTask
from
'./updateSignTask'
import
updateOrderGoods
from
'./updateOrderGoods'
import
updateFirstLoginToday
from
'./updateFirstLoginToday'
import
updateUserInfo
,
{
reduceGameTimes
}
from
'./updateUserInfo'
import
updateUserInfo
,
{
reduceGameTimes
,
reduceCardGameTimes
}
from
'./updateUserInfo'
const
update
=
{
updateVip
,
...
...
@@ -11,9 +11,18 @@ const update = {
updateOrderGoods
,
updateFirstLoginToday
,
updateUserInfo
,
reduceGameTimes
reduceGameTimes
,
reduceCardGameTimes
}
export
default
update
export
{
updateVip
,
updateSignTask
,
updateOrderGoods
,
updateFirstLoginToday
,
updateUserInfo
,
reduceGameTimes
}
export
{
updateVip
,
updateSignTask
,
updateOrderGoods
,
updateFirstLoginToday
,
updateUserInfo
,
reduceGameTimes
,
reduceCardGameTimes
}
v2.0/src/utils/common/update/updateUserInfo.ts
View file @
2dbe42a1
...
...
@@ -13,9 +13,33 @@ export default function updateUserInfo(update?: IPreUpdateQuery) {
}
}
export
function
reduceGameTimes
(
g
ameTimes
:
number
)
{
export
function
reduceGameTimes
(
needG
ameTimes
:
number
)
{
return
updateUserInfo
({
$where
:
`this.gameTimes >=
${
g
ameTimes
}
`
,
$inc
:
{
gameTimes
:
-
g
ameTimes
}
$where
:
`this.gameTimes >=
${
needG
ameTimes
}
`
,
$inc
:
{
gameTimes
:
-
needG
ameTimes
}
})
}
export
function
reduceCardGameTimes
(
needGameTimes
:
number
)
{
return
async
function
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
):
Promise
<
IPreUpdateQuery
|
undefined
>
{
if
(
!
userInfo
)
return
{}
let
projection
:
IPreUpdateQuery
=
{
$inc
:
{}
}
const
today
=
getToday
()
const
{
gameTimes
,
gameTimesEverday
}
=
userInfo
if
(
gameTimesEverday
?.[
today
])
{
projection
.
$inc
[
`gameTimesEverday.
${
today
}
`
]
=
-
needGameTimes
projection
.
$where
[
`this.gameTimesEverday.
${
today
}
>=
${
needGameTimes
}
`
]
=
-
needGameTimes
return
projection
}
if
(
gameTimes
)
{
projection
.
$inc
[
`gameTimes`
]
=
-
needGameTimes
projection
.
$where
[
`this.gameTimes >=
${
needGameTimes
}
`
]
=
-
needGameTimes
return
projection
}
}
}
v2.0/src/utils/index.ts
View file @
2dbe42a1
...
...
@@ -27,5 +27,3 @@ export * from './common/userUpdate'
export
*
from
'./common/format'
export
*
from
'./common/doHandler'
export
*
from
'./common/initCustomUser'
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