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
4add8c34
Commit
4add8c34
authored
Dec 08, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
助力流程
parent
aa81cb1c
Changes
20
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
40 additions
and
571 deletions
+40
-571
constants.ts
v2.0/src/constants.ts
+0
-24
card.controller.ts
v2.0/src/controller/card.controller.ts
+0
-116
share.controller.ts
v2.0/src/controller/share.controller.ts
+2
-2
customUser.ts
v2.0/src/customUser.ts
+3
-12
index.ts
v2.0/src/index.ts
+1
-10
card.service.ts
v2.0/src/service/common/card.service.ts
+0
-272
index.ts
v2.0/src/service/common/index.ts
+2
-5
stat.service.ts
v2.0/src/service/common/stat.service.ts
+4
-10
user.service.ts
v2.0/src/service/common/user.service.ts
+2
-7
activityConfig.d.ts
v2.0/src/typings/activityConfig.d.ts
+0
-8
awards.d.ts
v2.0/src/typings/awards.d.ts
+0
-1
user.d.ts
v2.0/src/typings/user.d.ts
+0
-9
checkCardGameTimes.ts
v2.0/src/utils/common/check/checkCardGameTimes.ts
+0
-13
checkHelpRecord.ts
v2.0/src/utils/common/check/checkHelpRecord.ts
+7
-12
checkInviteId.ts
v2.0/src/utils/common/check/checkInviteId.ts
+7
-1
checkInviteUserCard.ts
v2.0/src/utils/common/check/checkInviteUserCard.ts
+0
-22
index.ts
v2.0/src/utils/common/check/index.ts
+2
-8
index.ts
v2.0/src/utils/common/update/index.ts
+3
-5
updateUserInfo.ts
v2.0/src/utils/common/update/updateUserInfo.ts
+7
-21
card.ts
v2.0/src/utils/custom/card.ts
+0
-13
No files found.
v2.0/src/constants.ts
View file @
4add8c34
...
@@ -108,30 +108,6 @@ export enum STAT_TYPE {
...
@@ -108,30 +108,6 @@ export enum STAT_TYPE {
INITE_SUCCESS
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
JOIN_NEED_TIMES
=
1
...
...
v2.0/src/controller/card.controller.ts
deleted
100644 → 0
View file @
aa81cb1c
/** @format */
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
checkCardGameTimes
from
'../utils/common/check/checkCardGameTimes'
import
{
reduceCardGameTimes
,
updateUserInfo
}
from
'../utils/common/update'
export
interface
ISumitGameControllerInfos
extends
IControllerInfos
{
joinInfo
:
IJoinRecord
}
export
default
class
Card
{
@
checkParams
([
'activityId'
])
@
services
([
CommonCardService
,
CommonAwardsService
])
async
getCollectCardInfo
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
cardService
]:
[
CommonCardService
,
CommonAwardsService
]
)
{
const
{
activityId
}
=
context
.
data
const
{
joinedTimes
,
gameTimes
,
gameTimesEverday
}
=
userInfo
const
myCardInfo
=
cardService
.
getMyCardInfo
(
userInfo
)
const
joinedTimesPrizeList
=
await
cardService
.
getCardPrizeList
(
activityId
,
PRIZE_DATA_TYPE
.
JOIN_TIMES
,
'needTimes'
,
joinedTimes
)
const
collectedCardTypePrizeList
=
await
cardService
.
getCardPrizeList
(
activityId
,
PRIZE_DATA_TYPE
.
CARD_TYPE_AWARD
,
'needCards'
,
myCardInfo
.
cardTypeCollectedCount
)
const
today
=
getToday
()
return
resultsModel
.
success
({
joinedTimes
,
gameTimes
:
gameTimes
+
(
gameTimesEverday
?.[
today
]
||
0
),
giftCardStatus
:
GIFT_CARD_STATUS
,
taskOpenStatus
:
TASK_OPEN_STATUS
,
...
myCardInfo
,
joinedTimesPrizeList
,
collectedCardTypePrizeList
})
}
@
checkParams
([
'activityId'
])
@
services
([
CommonCardService
])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkCardGameTimes
])
@
preUpdate
([
reduceCardGameTimes
(
JOIN_NEED_TIMES
)])
async
doJoin
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
cardService
]:
[
CommonCardService
])
{
const
{
activityId
}
=
context
.
data
const
cardResult
=
await
cardService
.
collectCard
(
activityId
,
userInfo
)
await
cardService
.
addCollectRecord
(
userInfo
,
cardResult
)
return
resultsModel
.
success
(
cardResult
)
}
// 获取中奖轮播
@
checkParams
([
'activityId'
])
@
services
([
CommonCardService
,
CommonAwardsService
])
async
getAwardsCarouselList
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
[
cardService
,
awardsService
]:
[
CommonCardService
,
CommonAwardsService
]
)
{
const
{
activityId
}
=
context
.
data
const
list
=
await
cardService
.
getAwardsCarouselList
(
activityId
)
return
resultsModel
.
success
({
list
})
}
// 我的卡牌详情
@
checkParams
([
'activityId'
])
@
services
([
CommonCardService
,
CommonAwardsService
])
async
getMyCardsInfo
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
cardService
]:
[
CommonCardService
])
{
const
{
activityId
}
=
context
.
data
const
list
=
await
cardService
.
getMyCardsInfo
(
activityId
,
userInfo
)
return
resultsModel
.
success
({
list
})
}
// 获取好友赠送卡片
@
checkParams
([
'activityId'
,
'type'
,
'inviteId'
])
@
services
([
CommonCardService
,
CommonAwardsService
])
@
preCheck
([
checkActivityTime
,
checkInviteId
,
checkInviteUserCard
])
async
getGiftCard
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
cardService
]:
[
CommonCardService
],
{
inviteUserInfo
}:
IPreCheckData
)
{
const
{
activityId
,
type
}
=
context
.
data
const
giftResult
=
await
cardService
.
getGiftCard
(
activityId
,
type
,
userInfo
,
inviteUserInfo
)
return
resultsModel
.
success
(
giftResult
)
}
}
v2.0/src/controller/share.controller.ts
View file @
4add8c34
...
@@ -25,7 +25,7 @@ export default class Share {
...
@@ -25,7 +25,7 @@ export default class Share {
@
registeInfos
([
'vipInfo'
])
@
registeInfos
([
'vipInfo'
])
@
services
([
CommonTaskService
,
CommonStatService
])
@
services
([
CommonTaskService
,
CommonStatService
])
@
preCheck
([
checkActivityTime
,
checkInviteId
,
checkNewVip
,
checkHelpRecord
])
@
preCheck
([
checkActivityTime
,
checkInviteId
,
checkNewVip
,
checkHelpRecord
])
@
preUpdate
([
updateVip
])
@
preUpdate
([
updateVip
,
updateHelpRecord
])
async
doHelp
(
async
doHelp
(
context
:
IContext
<
IParams
>
,
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
...
@@ -34,7 +34,7 @@ export default class Share {
...
@@ -34,7 +34,7 @@ export default class Share {
)
{
)
{
const
result
=
await
taskService
.
completeTask
(
'invites'
,
activityInfo
,
inviteUserInfo
)
const
result
=
await
taskService
.
completeTask
(
'invites'
,
activityInfo
,
inviteUserInfo
)
await
statService
.
addStat
(
STAT_TYPE
.
INITE_SUCCESS
,
userInfo
)
statService
.
addStat
(
STAT_TYPE
.
INITE_SUCCESS
,
userInfo
)
return
resultsModel
.
success
(
result
)
return
resultsModel
.
success
(
result
)
}
}
...
...
v2.0/src/customUser.ts
View file @
4add8c34
/** @format */
/** @format */
import
{
FREE_TYPE
}
from
'./constants'
import
{
getToday
}
from
'./utils'
import
{
getToday
}
from
'./utils'
// login初始化用户信息
// login初始化用户信息
export
const
initCustomUserWhenLogin
=
(
context
:
IContext
<
IParams
>
,
activityInfo
:
IActivityInfo
):
ICustomUserInfo
=>
{
export
const
initCustomUserWhenLogin
=
(
context
:
IContext
<
IParams
>
,
activityInfo
:
IActivityInfo
):
ICustomUserInfo
=>
{
const
{
freeTimes
,
freeType
}
=
activityInfo
?.
collectCardConfig
||
{}
return
{
return
{
gameTimes
:
freeType
===
FREE_TYPE
.
FOERVER
?
freeTimes
:
0
,
gameTimes
:
0
gameTimesEverday
:
{
[
getToday
()]:
freeType
===
FREE_TYPE
.
EVERY_DAY
?
freeTimes
:
0
},
joinedTimes
:
0
,
cardsCollectedCount
:
0
,
cardInfo
:
{}
}
}
}
}
...
@@ -22,7 +14,6 @@ export const updateUserWhenLogin = (
...
@@ -22,7 +14,6 @@ export const updateUserWhenLogin = (
activityInfo
:
IActivityInfo
,
activityInfo
:
IActivityInfo
,
userInfo
:
IUserInfo
userInfo
:
IUserInfo
):
IUpdateQuery
=>
{
):
IUpdateQuery
=>
{
const
{
freeTimes
,
freeType
}
=
activityInfo
?.
collectCardConfig
||
{}
const
today
=
getToday
()
const
today
=
getToday
()
let
projection
:
IUpdateQuery
=
{
let
projection
:
IUpdateQuery
=
{
...
@@ -31,8 +22,8 @@ export const updateUserWhenLogin = (
...
@@ -31,8 +22,8 @@ export const updateUserWhenLogin = (
const
firstLoginToday
=
!
userInfo
?.
login
?.[
today
]
const
firstLoginToday
=
!
userInfo
?.
login
?.[
today
]
if
(
firstLoginToday
&&
freeType
===
FREE_TYPE
.
EVERY_DAY
)
{
if
(
firstLoginToday
)
{
projection
.
$inc
[
`gameTimesEverday.
${
today
}
`
]
=
freeTimes
}
}
return
projection
return
projection
}
}
v2.0/src/index.ts
View file @
4add8c34
...
@@ -17,9 +17,6 @@ import CustomTest1Controller from './controller/custom/test1.controller'
...
@@ -17,9 +17,6 @@ import CustomTest1Controller from './controller/custom/test1.controller'
const
CustomTest1ControllerInstance
=
new
CustomTest1Controller
()
const
CustomTest1ControllerInstance
=
new
CustomTest1Controller
()
import
CustomTest2Controller
from
'./controller/custom/test2.controller'
import
CustomTest2Controller
from
'./controller/custom/test2.controller'
const
CustomTest2ControllerInstance
=
new
CustomTest2Controller
()
const
CustomTest2ControllerInstance
=
new
CustomTest2Controller
()
import
CommonCardController
from
'./controller/card.controller'
const
{
getAwardsCarouselList
,
getCollectCardInfo
,
getGiftCard
,
getMyCardsInfo
,
doJoin
}
=
new
CommonCardController
()
export
default
{
export
default
{
getVipInfo
:
CommonUserControllerInstance
.
getVipInfo
,
getVipInfo
:
CommonUserControllerInstance
.
getVipInfo
,
...
@@ -41,11 +38,5 @@ export default {
...
@@ -41,11 +38,5 @@ export default {
testAddStat
:
CustomTest1ControllerInstance
.
testAddStat
,
testAddStat
:
CustomTest1ControllerInstance
.
testAddStat
,
testGetStats
:
CustomTest1ControllerInstance
.
testGetStats
,
testGetStats
:
CustomTest1ControllerInstance
.
testGetStats
,
test2addStat
:
CustomTest2ControllerInstance
.
test2addStat
,
test2addStat
:
CustomTest2ControllerInstance
.
test2addStat
,
test2getStats
:
CustomTest2ControllerInstance
.
test2getStats
,
test2getStats
:
CustomTest2ControllerInstance
.
test2getStats
// 卡牌类
getAwardsCarouselList
,
getCollectCardInfo
,
getGiftCard
,
getMyCardsInfo
,
doJoin
}
}
v2.0/src/service/common/card.service.ts
deleted
100644 → 0
View file @
aa81cb1c
/**
* 基本信息
*
* @format
*/
import
{
BaseDao
,
resultsModel
,
TBAPIS
}
from
'../../sdk'
import
{
JOIN_DB_NAME
}
from
'../../db'
import
{
ACTIVITY_STATUS
,
CARD_PRIZE_STATUS
,
PRIZE_DATA_TYPE
,
PRIZE_TYPE
}
from
'../../constants'
import
{
getToday
,
logger
}
from
'../../utils'
import
UserService
from
'./user.service'
import
AwardService
from
'./awards.service'
import
{
CODE_TYPES
}
from
'../../errorCode'
import
{
uniq
}
from
'lodash'
import
{
setCardPrizeStatus
}
from
'../../utils/custom/card'
export
default
class
CardService
extends
UserService
{
context
:
IContext
<
IParams
>
joindao
:
IBaseDao
awardService
:
AwardService
constructor
(
context
:
IContext
<
IParams
>
)
{
super
(
context
)
this
.
joindao
=
new
BaseDao
(
context
,
JOIN_DB_NAME
)
this
.
awardService
=
new
AwardService
(
context
)
}
// 集卡
async
collectCard
(
activityId
:
string
,
userInfo
:
IUserInfo
)
{
const
cardPool
=
await
this
.
awardService
.
getPrizeConfig
({
activityId
,
prizeDataType
:
PRIZE_DATA_TYPE
.
CARD
})
const
card
=
await
this
.
getCard
(
cardPool
)
const
{
cardType
,
_id
,
image
,
name
,
type
}
=
card
if
(
type
===
PRIZE_TYPE
.
THANKS
)
{
await
this
.
updateUser
(
userInfo
.
_id
,
{
$inc
:
{
joinedTimes
:
1
}
})
return
{
type
:
PRIZE_TYPE
.
THANKS
,
name
:
'谢谢参与'
}
}
const
reduceResult
=
await
this
.
awardService
.
reduceStock
(
_id
)
if
((
reduceResult
as
ICodeType
)?.
code
)
return
CODE_TYPES
.
ERROR_NO_STOCK
userInfo
.
cardInfo
=
userInfo
.
cardInfo
||
{}
userInfo
.
cardInfo
[
cardType
]
=
(
userInfo
.
cardInfo
?.[
cardType
]
||
0
)
+
1
const
updateResult
=
await
this
.
updateUser
(
userInfo
.
_id
,
{
$inc
:
{
joinedTimes
:
1
,
[
`cardInfo.
${
cardType
}
`
]:
1
,
cardsCollectedCount
:
1
}
})
if
(
updateResult
!==
1
)
return
CODE_TYPES
.
SYSTEM_ERROR
const
myCardInfo
=
this
.
getMyCardInfo
(
userInfo
,
cardType
,
cardPool
)
const
collectedCardTypePrizeList
=
await
this
.
getCardPrizeList
(
activityId
,
PRIZE_DATA_TYPE
.
CARD_TYPE_AWARD
,
'needCards'
,
myCardInfo
.
cardTypeCollectedCount
)
return
{
cardType
,
image
,
name
,
type
,
...
myCardInfo
,
isNewCard
:
userInfo
?.
cardInfo
?.[
cardType
]
===
1
,
drawLotteryStatus
:
collectedCardTypePrizeList
.
find
(
v
=>
v
.
needCardTypes
===
myCardInfo
.
cardTypeCollectedCount
)?.
status
||
CARD_PRIZE_STATUS
.
LOCK
}
}
getMyCardInfo
(
userInfo
:
IUserInfo
,
cardType
?:
number
,
cardPool
?:
IActivityPrize
[])
{
const
{
cardInfo
=
{}
}
=
userInfo
// 该卡片收集数量
const
currCardCollectedCount
=
cardType
?
cardInfo
?.[
cardType
]
||
0
:
undefined
// 已收集卡片的总数量
const
cardQuantityCollectedCount
=
Object
.
values
(
cardInfo
).
reduce
((
total
,
count
)
=>
total
+
count
,
0
)
// 已收集卡片类型
const
cardTypeCollectedCount
=
Object
.
keys
(
cardInfo
).
length
// 活动配置的卡片类型
const
cardTypeConfigCount
=
cardPool
?
cardPool
.
filter
(
v
=>
v
.
type
===
PRIZE_TYPE
.
CARD
).
length
:
undefined
return
{
currCardCollectedCount
,
cardQuantityCollectedCount
,
cardTypeCollectedCount
,
cardTypeConfigCount
,
// 未收集的卡片类型
restCardTypeCount
:
cardPool
?
cardTypeConfigCount
-
cardTypeCollectedCount
:
undefined
}
}
async
addCollectRecord
(
userInfo
:
IUserInfo
,
cardResult
:
object
)
{
const
{
openId
}
=
this
.
context
const
{
activityId
}
=
this
.
context
.
data
const
{
userNick
}
=
userInfo
const
recordId
=
await
this
.
joindao
.
insertOne
({
activityId
,
userNick
,
openId
,
...
cardResult
,
createTime
:
Date
.
now
(),
createDay
:
getToday
()
})
return
{
recordId
}
}
// 获取卡片
async
getCard
(
cardPool
:
IActivityPrize
[])
{
let
card
=
await
this
.
awardService
.
getPrizeByProbability
(
cardPool
)
const
thanksPrize
=
cardPool
.
find
(
v
=>
v
.
type
===
PRIZE_TYPE
.
THANKS
)
||
{
type
:
PRIZE_TYPE
.
THANKS
,
prizeDataType
:
PRIZE_DATA_TYPE
.
CARD
,
name
:
'谢谢参与'
}
!
card
&&
(
card
=
thanksPrize
)
return
card
}
async
getCardPrizeList
(
activityId
:
string
,
prizeDataType
:
number
,
needKey
:
string
,
userCount
:
number
)
{
const
{
openId
}
=
this
.
context
const
joinedTimesPrizePool
=
await
this
.
awardService
.
getPrizeConfig
(
{
activityId
,
prizeDataType
},
{
projection
:
{
type
:
1
,
image
:
1
,
prizeDataType
:
1
,
name
:
1
,
[
needKey
]:
1
}
}
)
// 抽奖次数奖池分类 从小到大排列
const
category
=
uniq
(
joinedTimesPrizePool
.
map
(
v
=>
+
v
[
needKey
])).
sort
((
a
,
b
)
=>
a
-
b
)
const
prizeMapper
=
category
.
reduce
((
prev
,
curr
)
=>
{
return
{
...
prev
,
[
`
${
curr
}
`
]:
joinedTimesPrizePool
.
filter
(
v
=>
v
[
needKey
]
===
curr
)
}
},
{})
const
awardList
=
await
this
.
awardService
.
getAwardsInfoList
(
{
activityId
,
openId
,
prizeDataType
},
{
projection
:
{
type
:
1
,
image
:
1
,
prizeDataType
:
1
,
name
:
1
}
}
)
const
prizeList
=
category
.
map
(
key
=>
{
return
{
[
needKey
]:
key
,
status
:
setCardPrizeStatus
(
userCount
,
key
,
awardList
),
prizeList
:
prizeMapper
[
key
]
}
})
return
prizeList
}
async
getAwardsCarouselList
(
activityId
:
string
,
limit
:
number
=
30
)
{
const
list
=
await
this
.
awardService
.
getAwardsInfoList
(
{
activityId
,
prizeDataType
:
{
$in
:
[
PRIZE_DATA_TYPE
.
CARD_TYPE_AWARD
,
PRIZE_DATA_TYPE
.
JOIN_TIMES
]
}
},
{
sort
:
{
createTime
:
1
},
projection
:
{
name
:
1
,
image
:
1
,
type
:
1
,
prizeDataType
:
1
,
avatar
:
1
,
userNick
:
1
},
limit
}
)
return
list
}
async
getMyCardsInfo
(
activityId
:
string
,
userInfo
:
IUserInfo
)
{
const
{
cardInfo
=
{}
}
=
userInfo
const
cardPool
=
await
this
.
awardService
.
getPrizeConfig
(
{
activityId
,
prizeDataType
:
PRIZE_DATA_TYPE
.
CARD
},
{
projection
:
{
name
:
1
,
image
:
1
,
cardType
:
1
}
}
)
return
cardPool
.
map
(
v
=>
{
const
{
name
,
image
,
cardType
}
=
v
return
{
type
:
cardType
,
name
,
image
,
count
:
cardInfo
[
cardType
]
||
0
}
})
}
async
getGiftCard
(
activityId
:
string
,
type
:
number
,
userInfo
:
IUserInfo
,
inviteUserInfo
:
IUserInfo
)
{
// 扣除邀请者的对应卡牌
const
reduceResult
=
await
this
.
userdao
.
update
(
{
_id
:
inviteUserInfo
.
_id
,
$where
:
`this.cardInfo.
${
type
}
>= 1`
},
{
$inc
:
{
[
`cardInfo.
${
type
}
`
]:
-
1
}
}
)
if
(
!
reduceResult
)
return
CODE_TYPES
.
SYSTEM_ERROR
// 增加受赠者的卡牌
const
addResult
=
await
this
.
updateUser
(
userInfo
.
_id
,
{
$inc
:
{
[
`cardInfo.
${
type
}
`
]:
-
1
}
})
if
(
!
addResult
)
return
CODE_TYPES
.
SYSTEM_ERROR
const
cardInfo
=
(
await
this
.
awardService
.
getPrizeConfig
({
activityId
,
prizeDataType
:
PRIZE_DATA_TYPE
.
CARD
,
cardType
:
+
type
})?.[
0
])
||
{}
const
{
name
,
image
}
=
cardInfo
return
{
name
,
image
,
type
}
}
}
v2.0/src/service/common/index.ts
View file @
4add8c34
...
@@ -7,7 +7,6 @@ import CommonAwardsService from './awards.service'
...
@@ -7,7 +7,6 @@ import CommonAwardsService from './awards.service'
import
CommonTaskService
from
'./task.service'
import
CommonTaskService
from
'./task.service'
import
CommonStatService
from
'./stat.service'
import
CommonStatService
from
'./stat.service'
import
CommonGameService
from
'./game.service'
import
CommonGameService
from
'./game.service'
import
CommonCardService
from
'./card.service'
const
common
=
{
const
common
=
{
CommonAccessService
,
CommonAccessService
,
...
@@ -16,8 +15,7 @@ const common = {
...
@@ -16,8 +15,7 @@ const common = {
CommonAwardsService
,
CommonAwardsService
,
CommonTaskService
,
CommonTaskService
,
CommonStatService
,
CommonStatService
,
CommonGameService
,
CommonGameService
CommonCardService
}
}
export
default
common
export
default
common
...
@@ -29,6 +27,5 @@ export {
...
@@ -29,6 +27,5 @@ export {
CommonAwardsService
,
CommonAwardsService
,
CommonTaskService
,
CommonTaskService
,
CommonStatService
,
CommonStatService
,
CommonGameService
,
CommonGameService
CommonCardService
}
}
v2.0/src/service/common/stat.service.ts
View file @
4add8c34
...
@@ -72,21 +72,15 @@ export default class StatService {
...
@@ -72,21 +72,15 @@ export default class StatService {
// 新增PV
// 新增PV
// const newPV = await this.userdao.count({ activityId, createDay: day })
// const newPV = await this.userdao.count({ activityId, createDay: day })
// 抽卡PV
// 新增UV(通过邀请)
const
joinPV
=
await
this
.
joindao
.
count
({
activityId
,
createDay
:
day
})
const
newUVFromInviteUV
=
(
await
this
.
accessdao
.
aggregate
([
// 抽卡UV
{
$match
:
{
activityId
,
createDay
:
day
,
inviteId
:
{
$exists
:
true
}
}
},
const
joinUV
=
(
await
this
.
joindao
.
aggregate
([
{
$match
:
{
activityId
,
createDay
:
day
}
},
{
$project
:
{
openId
:
true
}
},
{
$project
:
{
openId
:
true
}
},
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
])
])
).
length
).
length
// 新增UV(通过邀请)
const
newUVFromInviteUV
=
await
this
.
userdao
.
count
({
activityId
,
createDay
:
day
,
inviteId
:
{
$exists
:
true
}
})
// 已入会(老会员)PV
// 已入会(老会员)PV
const
vipPV
=
await
this
.
accessdao
.
count
({
const
vipPV
=
await
this
.
accessdao
.
count
({
activityId
,
activityId
,
...
...
v2.0/src/service/common/user.service.ts
View file @
4add8c34
...
@@ -64,7 +64,7 @@ class UserService extends BaseService {
...
@@ -64,7 +64,7 @@ class UserService extends BaseService {
*/
*/
async
initUserData
(
vipInfo
:
IVipInfo
,
activityInfo
:
IActivityInfo
,
customUserInfo
:
ICustomUserInfo
)
{
async
initUserData
(
vipInfo
:
IVipInfo
,
activityInfo
:
IActivityInfo
,
customUserInfo
:
ICustomUserInfo
)
{
const
{
openId
,
data
}
=
this
.
context
const
{
openId
,
data
}
=
this
.
context
const
{
activityId
,
isFollow
,
avatar
,
inviteId
,
userNick
}
=
data
const
{
activityId
,
isFollow
,
avatar
,
userNick
}
=
data
const
today
=
getToday
()
const
today
=
getToday
()
console
.
log
(
`----------
${
today
}
----------`
,
today
)
console
.
log
(
`----------
${
today
}
----------`
,
today
)
const
{
tasks
}
=
activityInfo
const
{
tasks
}
=
activityInfo
...
@@ -72,13 +72,8 @@ class UserService extends BaseService {
...
@@ -72,13 +72,8 @@ class UserService extends BaseService {
const
user
:
ICommonUserInfo
=
{
const
user
:
ICommonUserInfo
=
{
activityId
,
activityId
,
avatar
,
avatar
,
inviteId
,
userNick
,
userNick
,
openId
,
openId
,
// gameTimes: 0,
// totalScore: 0,
// maxScore: 0,
// 待领取次数初始化, 根据需自定义添加
remainTimes
:
{
remainTimes
:
{
follow
:
isFollow
?
follow
.
value
:
0
,
follow
:
isFollow
?
follow
.
value
:
0
,
member
:
vipInfo
.
isVip
?
member
.
value
:
0
,
member
:
vipInfo
.
isVip
?
member
.
value
:
0
,
...
@@ -120,7 +115,7 @@ class UserService extends BaseService {
...
@@ -120,7 +115,7 @@ class UserService extends BaseService {
user
.
taskInfo
[
today
].
member
=
[{
createTime
:
Date
.
now
()
}]
user
.
taskInfo
[
today
].
member
=
[{
createTime
:
Date
.
now
()
}]
}
}
await
this
.
userdao
.
insertOne
({
await
this
.
userdao
.
insertOne
<
IUserInfo
>
({
...
user
,
...
user
,
...
customUserInfo
...
customUserInfo
})
})
...
...
v2.0/src/typings/activityConfig.d.ts
View file @
4add8c34
...
@@ -3,14 +3,6 @@
...
@@ -3,14 +3,6 @@
type
IActivityInfo
=
ICommonActivityInfo
&
ICustomActivityInfo
type
IActivityInfo
=
ICommonActivityInfo
&
ICustomActivityInfo
interface
ICustomActivityInfo
{
interface
ICustomActivityInfo
{
collectCardConfig
:
{
freeTimes
:
number
freeType
:
number
joinLimit
:
number
}
shareImage
:
string
shareTitle
:
string
shareSubtitle
:
string
}
}
interface
ICommonActivityInfo
{
interface
ICommonActivityInfo
{
_id
?:
string
_id
?:
string
...
...
v2.0/src/typings/awards.d.ts
View file @
4add8c34
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
type
IAwards
=
ICommonAwards
&
ICustomAwards
type
IAwards
=
ICommonAwards
&
ICustomAwards
interface
ICustomAwards
{
interface
ICustomAwards
{
needTimes
?:
number
}
}
interface
ICommonAwards
{
interface
ICommonAwards
{
_id
?:
string
_id
?:
string
...
...
v2.0/src/typings/user.d.ts
View file @
4add8c34
...
@@ -7,15 +7,6 @@ interface ICustomUserInfo {
...
@@ -7,15 +7,6 @@ interface ICustomUserInfo {
maxScore
?:
number
maxScore
?:
number
totalScore
?:
number
totalScore
?:
number
updateScoreTime
?:
number
updateScoreTime
?:
number
// 集卡
joinedTimes
?:
number
gameTimesEverday
?:
{
[
key
:
string
]:
number
}
cardsCollectedCount
?:
number
cardInfo
:
{
[
key
:
string
]:
number
}
}
}
interface
ICommonUserInfo
{
interface
ICommonUserInfo
{
...
...
v2.0/src/utils/common/check/checkCardGameTimes.ts
deleted
100644 → 0
View file @
aa81cb1c
/** @format */
import
{
resultsModel
}
from
'../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
getToday
}
from
'../getToday'
export
default
async
function
checkCardGameTimes
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
)
{
const
{
gameTimes
,
gameTimesEverday
}
=
userInfo
const
today
=
getToday
()
if
(
!
gameTimesEverday
?.[
today
]
&&
!
gameTimes
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_NO_GAME_TIMES
)
}
}
v2.0/src/utils/common/check/checkHelpRecord.ts
View file @
4add8c34
...
@@ -14,18 +14,13 @@ import { STAT_TYPE } from '../../../constants'
...
@@ -14,18 +14,13 @@ import { STAT_TYPE } from '../../../constants'
* @param {IContext<{ activityId: string; inviteId: string }>} context
* @param {IContext<{ activityId: string; inviteId: string }>} context
* @return {*}
* @return {*}
*/
*/
export
default
async
function
checkHelpRecord
(
context
:
IContext
<
{
activityId
:
string
;
inviteId
:
string
}
>
)
{
export
default
async
function
checkHelpRecord
(
con
st
{
con
text
:
IContext
<
{
activityId
:
string
;
inviteId
:
string
}
>
,
openId
,
{
userInfo
}:
IControllerInfos
data
:
{
activityId
,
inviteId
}
)
{
}
=
context
const
{
inviteId
}
=
userInfo
// 邀请成功有该用户信息
// 邀请成功有该用户信息
const
userInviteSuccessCount
=
await
dbCount
(
context
,
STAT_DB_NAME
,
{
if
(
inviteId
)
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_AREADY_INVITE_SUCCESS
)
activityId
,
openId
,
type
:
STAT_TYPE
.
INITE_SUCCESS
})
if
(
userInviteSuccessCount
)
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_AREADY_INVITE_SUCCESS
)
return
{
userInviteSuccessCount
}
return
{
inviteId
}
}
}
v2.0/src/utils/common/check/checkInviteId.ts
View file @
4add8c34
...
@@ -4,6 +4,7 @@ import { resultsModel } from '../../../sdk'
...
@@ -4,6 +4,7 @@ import { resultsModel } from '../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
dbFindOne
}
from
'../../common/mongodb'
import
{
dbFindOne
}
from
'../../common/mongodb'
import
{
USER_DB_NAME
}
from
'../../../db'
import
{
USER_DB_NAME
}
from
'../../../db'
import
{
getTodayCompleteTask
}
from
'../task'
/**
/**
* 检查inviteId是否合法 返回邀请人的用户信息
* 检查inviteId是否合法 返回邀请人的用户信息
...
@@ -12,7 +13,10 @@ import { USER_DB_NAME } from '../../../db'
...
@@ -12,7 +13,10 @@ import { USER_DB_NAME } from '../../../db'
* @param {IContext<{ activityId: string; inviteId: string }>} context
* @param {IContext<{ activityId: string; inviteId: string }>} context
* @return {*}
* @return {*}
*/
*/
export
default
async
function
checkInviteId
(
context
:
IContext
<
{
activityId
:
string
;
inviteId
:
string
}
>
)
{
export
default
async
function
checkInviteId
(
context
:
IContext
<
{
activityId
:
string
;
inviteId
:
string
}
>
,
{}:
IControllerInfos
)
{
const
{
const
{
openId
,
openId
,
data
:
{
activityId
,
inviteId
}
data
:
{
activityId
,
inviteId
}
...
@@ -30,6 +34,8 @@ export default async function checkInviteId(context: IContext<{ activityId: stri
...
@@ -30,6 +34,8 @@ export default async function checkInviteId(context: IContext<{ activityId: stri
// inviteId的用户信息查询不到, 则inviteId无效
// inviteId的用户信息查询不到, 则inviteId无效
if
(
!
inviteUserInfo
)
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_INVALID_INVITE_ID
)
if
(
!
inviteUserInfo
)
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_INVALID_INVITE_ID
)
const
{
todayCompleteTimes
}
=
getTodayCompleteTask
(
'invites'
,
inviteUserInfo
)
return
{
return
{
inviteUserInfo
inviteUserInfo
}
}
...
...
v2.0/src/utils/common/check/checkInviteUserCard.ts
deleted
100644 → 0
View file @
aa81cb1c
/** @format */
import
{
resultsModel
}
from
'../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
isBoolean
}
from
'lodash'
export
default
async
function
checkInviteUserCard
(
context
:
IContext
<
{
type
:
number
;
activityId
:
string
;
inviteId
:
string
}
>
,
{}:
IControllerInfos
,
[],
{
inviteUserInfo
}:
IPreCheckData
):
Promise
<
IPreCheckResult
>
{
const
{
type
}
=
context
.
data
if
(
!
inviteUserInfo
)
{
console
.
error
(
`checkInviteUserCard必须搭配 checkInviteId使用`
)
}
const
{
cardInfo
=
{}
}
=
inviteUserInfo
if
(
!
cardInfo
?.
type
)
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
'邀请者该卡片不足'
)
}
v2.0/src/utils/common/check/index.ts
View file @
4add8c34
...
@@ -12,8 +12,6 @@ import checkVip from './checkVip'
...
@@ -12,8 +12,6 @@ import checkVip from './checkVip'
import
checkUserInfo
,
{
checkGameTimes
}
from
'./checkUserInfo'
import
checkUserInfo
,
{
checkGameTimes
}
from
'./checkUserInfo'
import
checkJoinId
from
'./checkJoinId'
import
checkJoinId
from
'./checkJoinId'
import
checkOpenPrizeStatus
from
'./checkOpenPrizeStatus'
import
checkOpenPrizeStatus
from
'./checkOpenPrizeStatus'
import
checkInviteUserCard
from
'./checkInviteUserCard'
import
checkCardGameTimes
from
'./checkCardGameTimes'
const
check
=
{
const
check
=
{
checkActivityTime
,
checkActivityTime
,
...
@@ -31,9 +29,7 @@ const check = {
...
@@ -31,9 +29,7 @@ const check = {
checkUserInfo
,
checkUserInfo
,
checkJoinId
,
checkJoinId
,
checkGameTimes
,
checkGameTimes
,
checkOpenPrizeStatus
,
checkOpenPrizeStatus
checkInviteUserCard
,
checkCardGameTimes
}
}
export
default
check
export
default
check
...
@@ -54,7 +50,5 @@ export {
...
@@ -54,7 +50,5 @@ export {
checkUserInfo
,
checkUserInfo
,
checkJoinId
,
checkJoinId
,
checkGameTimes
,
checkGameTimes
,
checkOpenPrizeStatus
,
checkOpenPrizeStatus
checkInviteUserCard
,
checkCardGameTimes
}
}
v2.0/src/utils/common/update/index.ts
View file @
4add8c34
...
@@ -3,7 +3,7 @@ import updateVip from './updateVip'
...
@@ -3,7 +3,7 @@ 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
,
{
reduceGameTimes
,
reduceCardGameTimes
}
from
'./updateUserInfo'
import
updateUserInfo
,
{
reduceGameTimes
}
from
'./updateUserInfo'
const
update
=
{
const
update
=
{
updateVip
,
updateVip
,
...
@@ -11,8 +11,7 @@ const update = {
...
@@ -11,8 +11,7 @@ const update = {
updateOrderGoods
,
updateOrderGoods
,
updateFirstLoginToday
,
updateFirstLoginToday
,
updateUserInfo
,
updateUserInfo
,
reduceGameTimes
,
reduceGameTimes
reduceCardGameTimes
}
}
export
default
update
export
default
update
...
@@ -23,6 +22,5 @@ export {
...
@@ -23,6 +22,5 @@ export {
updateOrderGoods
,
updateOrderGoods
,
updateFirstLoginToday
,
updateFirstLoginToday
,
updateUserInfo
,
updateUserInfo
,
reduceGameTimes
,
reduceGameTimes
reduceCardGameTimes
}
}
v2.0/src/utils/common/update/updateUserInfo.ts
View file @
4add8c34
...
@@ -20,26 +20,12 @@ export function reduceGameTimes(needGameTimes: number) {
...
@@ -20,26 +20,12 @@ export function reduceGameTimes(needGameTimes: number) {
})
})
}
}
export
function
reduceCardGameTimes
(
needGameTimes
:
number
)
{
export
function
updateHelpRecord
()
{
return
async
function
(
return
updateUserInfo
({
context
:
IContext
<
IParams
>
,
$where
:
`!!this.inviteId`
,
{
userInfo
}:
IControllerInfos
$set
:
{
):
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/custom/card.ts
deleted
100644 → 0
View file @
aa81cb1c
/** @format */
import
{
CARD_PRIZE_STATUS
}
from
'../../constants'
export
function
setCardPrizeStatus
(
joinedTimes
:
number
,
needTimes
:
number
,
joinedTimesAwardList
:
IAwards
[])
{
if
(
joinedTimes
<
needTimes
)
return
CARD_PRIZE_STATUS
.
LOCK
if
(
joinedTimes
>=
needTimes
&&
!
joinedTimesAwardList
.
some
(
v
=>
v
.
needTimes
===
needTimes
))
return
CARD_PRIZE_STATUS
.
UN_LOCK
if
(
joinedTimes
>=
needTimes
&&
joinedTimesAwardList
.
some
(
v
=>
v
.
needTimes
===
needTimes
))
return
CARD_PRIZE_STATUS
.
SUCCESS
}
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