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
6a697143
Commit
6a697143
authored
Jan 20, 2021
by
王波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
养成类模板提交
parent
c10278bb
Changes
15
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
1970 additions
and
8 deletions
+1970
-8
package-lock.json
v2.0/package-lock.json
+1286
-0
growShare.controller.ts
v2.0/src/controller/growShare.controller.ts
+34
-0
growTask.controller.ts
v2.0/src/controller/growTask.controller.ts
+101
-0
db.ts
v2.0/src/db.ts
+3
-0
registeInfos.ts
v2.0/src/decorator/common/registeInfos.ts
+8
-2
growTask.service.ts
v2.0/src/service/common/growTask.service.ts
+184
-0
index.ts
v2.0/src/service/common/index.ts
+6
-2
index.d.ts
v2.0/src/typings/index.d.ts
+10
-0
checkGrowTaskLimit.ts
v2.0/src/utils/common/check/checkGrowTaskLimit.ts
+53
-0
index.ts
v2.0/src/utils/common/check/index.ts
+5
-2
task.ts
v2.0/src/utils/common/task.ts
+97
-0
index.ts
v2.0/src/utils/common/update/index.ts
+10
-2
updateGrowOrderGoods.ts
v2.0/src/utils/common/update/updateGrowOrderGoods.ts
+146
-0
updateSignGrowTask.ts
v2.0/src/utils/common/update/updateSignGrowTask.ts
+25
-0
index.ts
v2.0/src/utils/index.ts
+2
-0
No files found.
v2.0/package-lock.json
0 → 100644
View file @
6a697143
This diff is collapsed.
Click to expand it.
v2.0/src/controller/growShare.controller.ts
0 → 100644
View file @
6a697143
/** @format */
import
{
services
,
preCheck
,
registeInfos
,
preUpdate
,
checkParams
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
CommonUserService
,
CommonStatService
,
CommonTaskService
,
CommonGrowTaskService
}
from
'../service/common'
import
{
STAT_TYPE
}
from
'../constants'
import
{
checkActivityTime
,
checkInviteId
,
checkHelpRecord
,
checkNewVip
}
from
'../utils/common/check'
import
{
updateHelpRecord
,
updateVip
}
from
'../utils/common/update'
import
{
getTask
}
from
'../utils'
export
default
class
Share
{
/**
* 完成分享
*/
@
checkParams
([
'activityId'
,
'inviteId'
])
@
registeInfos
([
'vipInfo'
])
@
services
([
CommonGrowTaskService
,
CommonStatService
])
@
preCheck
([
checkActivityTime
,
checkInviteId
,
checkNewVip
,
checkHelpRecord
])
@
preUpdate
([
updateVip
,
updateHelpRecord
])
async
doHelp
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
[
growTaskService
,
statService
]:
[
CommonGrowTaskService
,
CommonStatService
],
{
inviteUserInfo
}:
IPreCheckData
)
{
// 如果邀请任务是每日的,则需要请求每日任务信息
const
task
=
await
getTask
(
context
,
inviteUserInfo
.
openId
)
const
result
=
await
growTaskService
.
completeTask
(
'invites'
,
activityInfo
,
inviteUserInfo
,
task
)
statService
.
addStat
(
STAT_TYPE
.
INITE_SUCCESS
,
userInfo
)
return
resultsModel
.
success
(
result
)
}
}
v2.0/src/controller/growTask.controller.ts
0 → 100644
View file @
6a697143
/** @format */
import
{
checkParams
,
services
,
registeInfos
,
preCheck
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
CommonGrowTaskService
,
CommonBaseService
}
from
'../service/common'
import
{
ITaskInfo
}
from
'../service/common/task.service'
import
{
checkActivityTime
,
checkGrowTaskLimit
,
checkExchangeCreditsTask
,
checkRemainTimes
,
checkInviteId
}
from
'../utils/common/check'
import
{
preUpdate
}
from
'../decorator/common'
import
{
updateVip
,
updateSignGrowTask
,
updateGrowOrderGoods
}
from
'../utils/common/update'
export
default
class
Task
{
/**
* 任务列表
*/
@
checkParams
([
'activityId'
])
@
registeInfos
([
'vipInfo'
,
'task'
])
@
services
([
CommonGrowTaskService
])
@
preCheck
([
checkActivityTime
])
@
preUpdate
([
updateVip
,
updateSignGrowTask
,
updateGrowOrderGoods
])
async
getTaskList
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
[
growTaskService
]:
[
CommonGrowTaskService
]
):
Promise
<
IResult
<
{
list
:
ITaskInfo
[]
}
>>
{
// 读取B端 tasks字段配置自动生成任务列表
const
result
=
await
growTaskService
.
initTaskList
(
userInfo
,
activityInfo
)
return
resultsModel
.
success
({
...
result
})
}
/**
* 完成任务
*
* 商品相关任务 需要传itemId参数
* 积分兑换任务 需要传credits参数
*/
@
checkParams
([
'activityId'
,
'taskType'
,
'itemId?'
,
'credits?'
])
@
registeInfos
([
'session'
,
'task'
])
@
services
([
CommonGrowTaskService
])
@
preCheck
([
checkActivityTime
,
checkGrowTaskLimit
,
checkExchangeCreditsTask
])
async
doCompleteTask
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
,
task
}:
IControllerInfos
,
[
growTaskService
]:
[
CommonGrowTaskService
]
)
{
const
{
taskType
}
=
context
.
data
// 更新user表
const
result
=
await
growTaskService
.
completeTask
(
taskType
,
activityInfo
,
userInfo
,
task
)
return
resultsModel
.
success
(
result
)
}
/**
* 领取任务奖励
* 领取的奖励增加的key值 如: gameTimes 前端传入
*/
@
checkParams
([
'activityId'
,
'taskType'
,
'rewardsKey'
])
@
services
([
CommonGrowTaskService
])
@
preCheck
([
checkActivityTime
,
checkRemainTimes
])
async
receiveTaskRewards
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
growTaskService
]:
[
CommonGrowTaskService
]
):
Promise
<
IResult
<
{
rewards
:
number
}
>>
{
const
{
rewardsKey
}
=
context
.
data
const
{
taskType
}
=
context
.
data
const
rewardsResult
=
await
growTaskService
.
receiveTaskRewards
(
taskType
,
rewardsKey
,
userInfo
)
return
resultsModel
.
success
(
rewardsResult
)
}
/**
* 获取收藏商品列表
*/
@
checkParams
([
'activityId'
,
'itemIds'
])
@
registeInfos
([
'session'
])
@
services
([
CommonBaseService
,
CommonGrowTaskService
])
async
getCollectGoodsList
(
context
:
IContext
<
IParams
>
,
{
session
,
userInfo
}:
IControllerInfos
,
[
commonBaseService
,
growTaskService
]:
[
CommonBaseService
,
CommonGrowTaskService
]
)
{
const
{
itemIds
}
=
context
.
data
const
list
=
await
commonBaseService
.
getItemListByIds
(
itemIds
,
session
)
const
listWithCollectStatus
=
await
growTaskService
.
getItemListWithCollectStatus
(
list
,
userInfo
)
return
resultsModel
.
success
(
listWithCollectStatus
)
}
}
v2.0/src/db.ts
View file @
6a697143
...
...
@@ -10,6 +10,8 @@ export const JOIN_DB_NAME = 'c_user_join'
export
const
SIGN_DB_NAME
=
'c_user_sign'
export
const
TASK_DB_NAME
=
'c_user_tasks'
export
const
STAT_DB_NAME
=
'c_stats'
export
const
ERROR_LOG_DB_NAME
=
'error_log'
...
...
@@ -19,3 +21,4 @@ export const SELLER_INFO_DB_NAME = 'a_seller_info'
export
const
PRIZE_CONFIG_DB_NAME
=
'b_prize_config'
export
const
ACTIVITY_CONFIG_DB_NAME
=
'b_activity_config'
v2.0/src/decorator/common/registeInfos.ts
View file @
6a697143
/** @format */
import
{
CommonUserService
,
CommonBaseService
}
from
'../../service/common'
import
{
getSellerSession
,
getUserOrderlist
}
from
'../../utils'
import
{
getSellerSession
,
getUserOrderlist
,
getTask
}
from
'../../utils'
import
{
formatVipCbUrl
,
getShopVip
}
from
'../../utils/common/vip'
import
{
CODE_TYPES
}
from
'../../errorCode'
import
{
resultsModel
,
TBAPIS
}
from
'../../sdk'
export
type
IInfo
=
'session'
|
'vipInfo'
|
'taobaoOrderist'
|
'credits'
export
type
IInfo
=
'session'
|
'vipInfo'
|
'taobaoOrderist'
|
'credits'
|
'task'
async
function
initBaseInfo
(
context
:
IContext
<
IParams
>
,
baseInfos
:
ICheckControllerInfos
,
needInfos
:
IInfo
[])
{
const
handler
=
context
?.
cloud
?.
dataspace
?.
context
?.
handler
...
...
@@ -54,6 +54,12 @@ async function initBaseInfo(context: IContext<IParams>, baseInfos: ICheckControl
baseInfos
.
credits
=
credits
}
if
(
needInfos
.
includes
(
'task'
)
&&
!
baseInfos
.
credits
)
{
const
task
=
await
getTask
(
context
)
if
(
!
task
.
_id
)
return
CODE_TYPES
.
ERROR_UPDATE_RETRY
baseInfos
.
task
=
task
}
return
baseInfos
}
...
...
v2.0/src/service/common/growTask.service.ts
0 → 100644
View file @
6a697143
/**
* 任务相关方法
*
* @format
*/
import
UserService
from
'./user.service'
import
{
getToday
,
getUserOrderlist
,
generateVipUrl
,
formatVipCbUrl
,
setNewFollowUserData
}
from
'../../utils'
import
{
TASK_RATE_TYPE
,
TASK_STATUS
}
from
'../../constants'
import
{
getTodayCompleteTask
,
getTotalCompleteTask
,
setTaskStatus
,
updateTaskInfo
}
from
'../../utils/common/task'
import
{
CODE_TYPES
}
from
'../../errorCode'
export
interface
ITaskInfo
{
taskType
?:
string
// 任务类型
url
?:
string
// 链接地址
rewards
:
number
// 任务奖励
itemIds
?:
string
// 商品配置ids 商品相关任务返回
todayCompleteTimes
?:
number
// 今日完成次数
completeTimes
?:
number
// 总共完成次数
taskRateType
:
number
// 任务频率
times
?:
number
// 任务每日限制次数
waitReceive
?:
number
// 待领取次数
title
:
string
// 任务文案
status
:
number
// 任务状态 1未完成 2 待领取 3 已完成
}
export
default
class
TaskService
extends
UserService
{
constructor
(
context
:
IContext
<
IParams
>
)
{
super
(
context
)
}
// 根据活动tasks字段渲染任务
async
initTaskList
(
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
)
{
return
{
list
:
Object
.
keys
(
activityInfo
?.
tasks
||
{}).
map
((
task
:
ITaskType
)
=>
{
return
this
.
initTask
(
task
,
activityInfo
?.
tasks
?.[
task
]?.
title
,
userInfo
,
activityInfo
)
})
}
}
/**
* 根据任务类型初始化 b端 tasks字段必须有相应的配置
*
* @param {ITaskType} taskType 任务类型
* @param {string} title 任务标题
* @param {IActivityInfo} activityInfo 任务配置
* @param {IUserInfo} userInfo 用户信息
* @return {ITaskInfo} {ITaskInfo} 任务信息
* @memberof TaskService
*/
initTask
(
taskType
:
ITaskType
,
title
:
string
,
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
):
ITaskInfo
{
if
(
!
activityInfo
?.
tasks
?.[
taskType
])
{
console
.
error
(
`活动缺少
${
taskType
}
任务配置项`
)
}
const
{
value
,
itemIds
=
''
,
taskRateType
,
times
=
1
,
link
=
''
}
=
activityInfo
?.
tasks
?.[
taskType
]
||
{}
const
{
remainTimes
}
=
userInfo
const
{
todayCompleteTimes
}
=
getTodayCompleteTask
(
taskType
,
userInfo
)
const
{
completeTimes
}
=
getTotalCompleteTask
(
taskType
,
userInfo
)
return
{
taskType
,
title
,
itemIds
,
rewards
:
value
,
taskRateType
,
times
,
url
:
taskType
===
'member'
?
generateVipUrl
(
formatVipCbUrl
(
this
.
context
))
:
link
,
todayCompleteTimes
,
completeTimes
,
status
:
setTaskStatus
(
userInfo
,
taskType
,
taskRateType
,
times
),
waitReceive
:
remainTimes
?.[
taskType
]
}
}
/**
*
* 领取任务奖励
*
* @param {ITaskType} taskType
* @param {string} awardsTargetKey
* @param {IUserInfo} userInfo
* @return {number} rewards
* @memberof TaskService
*/
async
receiveTaskRewards
(
taskType
:
ITaskType
,
awardsTargetKey
:
string
,
userInfo
:
IUserInfo
):
Promise
<
{
rewards
:
number
}
>
{
const
waitReceiveTimes
=
userInfo
?.
remainTimes
?.[
taskType
]
await
this
.
updateUser
(
userInfo
.
_id
,
{
$set
:
{
[
`remainTimes.
${
taskType
}
`
]:
0
},
$inc
:
{
[
awardsTargetKey
]:
waitReceiveTimes
}
})
return
{
rewards
:
waitReceiveTimes
}
}
/**
*根据任务类型更新任务待领取次数和任务记录
*
* @param {string} taskType
* @param {number} activityInfo
* @param {IActivityInfo} userInfo
* @returns {boolean}
* @memberof TaskService
*/
async
completeTask
(
taskType
:
ITaskType
,
activityInfo
:
IActivityInfo
,
userInfo
:
IUserInfo
,
task
:
ITask
=
{},
customRecord
:
Object
=
{}
)
{
const
today
=
getToday
()
const
rewards
=
activityInfo
?.
tasks
?.[
taskType
]?.
value
||
0
const
{
tasks
}
=
activityInfo
const
{
[
taskType
]:
{
taskRateType
}
}
=
tasks
const
{
openId
,
data
:
{
itemId
}
}
=
this
.
context
const
record
=
{
itemId
,
openId
:
taskType
===
'invites'
?
openId
:
undefined
,
createTime
:
Date
.
now
(),
...
customRecord
}
if
(
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
)
{
//如果是每日任务,则更新每日任务表
const
result
=
await
updateTaskInfo
(
this
.
context
,
task
.
_id
,
taskType
,
record
)
if
(
result
===
1
)
{
const
updateResult
=
await
this
.
updateUser
(
userInfo
.
_id
,
{
$inc
:
{
[
`remainTimes.
${
taskType
}
`
]:
+
rewards
}
})
return
updateResult
===
1
?
{
ok
:
1
}
:
CODE_TYPES
.
ERROR_DO_TASK
}
return
CODE_TYPES
.
ERROR_DO_TASK
}
else
{
//永久任务就更新永久任务表
let
updateQuery
:
IUpdateQuery
=
{
$inc
:
{
[
`remainTimes.
${
taskType
}
`
]:
+
rewards
},
$push
:
{
[
`taskInfo.
${
today
}
.
${
taskType
}
`
]:
{
...
record
,
createTime
:
Date
.
now
()
}
}
}
if
(
taskType
===
'follow'
)
{
updateQuery
.
$set
=
{
follow
:
setNewFollowUserData
(
userInfo
.
follow
)
}
}
const
result
=
await
this
.
updateUser
(
userInfo
.
_id
,
updateQuery
)
return
result
===
1
?
{
ok
:
1
}
:
CODE_TYPES
.
ERROR_DO_TASK
}
}
async
getItemListWithCollectStatus
(
list
:
{
list
:
ITaoBaoItems
[]
},
userInfo
:
IUserInfo
)
{
const
{
taskInfo
}
=
getTotalCompleteTask
(
'collectGoods'
,
userInfo
)
return
{
list
:
list
.
list
.
map
(
v
=>
{
return
{
...
v
,
// 完成列表是否含有itemId
collected
:
taskInfo
.
some
(
completeItem
=>
completeItem
.
itemId
===
v
.
itemId
)
}
})
}
}
}
v2.0/src/service/common/index.ts
View file @
6a697143
...
...
@@ -8,6 +8,8 @@ import CommonTaskService from './task.service'
import
CommonStatService
from
'./stat.service'
import
CommonGameService
from
'./game.service'
import
CommonSignService
from
'./sign.service'
import
CommonGrowTaskService
from
'./growTask.service'
const
common
=
{
CommonAccessService
,
...
...
@@ -17,7 +19,8 @@ const common = {
CommonTaskService
,
CommonStatService
,
CommonGameService
,
CommonSignService
CommonSignService
,
CommonGrowTaskService
}
export
default
common
...
...
@@ -30,5 +33,6 @@ export {
CommonTaskService
,
CommonStatService
,
CommonGameService
,
CommonSignService
CommonSignService
,
CommonGrowTaskService
}
v2.0/src/typings/index.d.ts
View file @
6a697143
...
...
@@ -30,6 +30,7 @@ interface IControllerInfos {
session
?:
string
credits
?:
number
taobaoOrderist
?:
ITaoBaoOrders
[]
task
:
ITask
}
interface
ICheckControllerInfos
extends
IControllerInfos
{
...
...
@@ -51,6 +52,15 @@ interface IVipInfo {
url
?:
string
}
interface
ITask
{
_id
?:
string
openId
?:
string
activityId
?:
string
taskInfo
?:
any
createDay
?:
string
createTime
?:
number
}
type
IFunction
=
(...
args
:
any
[])
=>
any
type
ValueOf
<
T
>
=
T
extends
any
[]
?
T
[
number
]
:
T
[
keyof
T
]
v2.0/src/utils/common/check/checkGrowTaskLimit.ts
0 → 100644
View file @
6a697143
/** @format */
import
{
resultsModel
}
from
'../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
getTotalCompleteTask
,
getTodayCompleteGrowTask
}
from
'../task'
import
{
TASK_RATE_TYPE
}
from
'../../../constants'
export
default
async
function
checkTaskLimit
(
context
:
IContext
<
{
activityId
:
string
;
taskType
:
ITaskType
;
itemId
?:
string
}
>
,
{
userInfo
,
activityInfo
,
task
}:
IControllerInfos
)
{
const
{
taskType
,
itemId
}
=
context
.
data
const
{
itemIds
}
=
activityInfo
?.
tasks
?.[
taskType
]
||
{}
if
(
!
taskType
)
{
console
.
error
(
'使用checkTaskLimit, 云函数必须传入taskType参数'
)
return
}
if
(
!
activityInfo
?.
tasks
?.[
taskType
])
{
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
`该活动缺少
${
taskType
}
配置项`
)
}
if
(
itemId
&&
!
itemIds
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
`该任务缺少商品配置项`
)
}
// B端配置商品ids不匹配正确
if
(
itemId
&&
itemIds
)
{
const
itemIdArray
:
number
[]
=
Array
.
isArray
(
itemIds
)
?
itemIds
:
itemIds
.
split
(
','
).
map
(
v
=>
+
v
)
if
(
!
itemIdArray
.
includes
(
+
itemId
))
return
resultsModel
.
error
(
CODE_TYPES
.
PARAMS_ERROR
,
'商品id不匹配'
)
}
const
{
taskRateType
,
times
=
1
}
=
activityInfo
?.
tasks
?.[
taskType
]
// 永久任务已经完成
const
{
completeTimes
}
=
getTotalCompleteTask
(
taskType
,
userInfo
)
const
hasComplete
=
completeTimes
>=
times
&&
taskRateType
===
TASK_RATE_TYPE
.
FOREVER
if
(
hasComplete
)
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_TASK_LIMIT
,
`该任务已完成,去看看其它任务吧~`
)
// 每日任务今天已经完成
const
{
todayCompleteTimes
,
todayTaskInfo
}
=
getTodayCompleteGrowTask
(
taskType
,
task
)
const
hasCompleteToday
=
times
&&
todayCompleteTimes
===
times
&&
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
if
(
hasCompleteToday
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_TASK_LIMIT
,
`该任务今天已完成,明天再来吧~`
)
}
// 今日任务该商品已经完成
const
itemHasCompleteToday
=
todayTaskInfo
.
find
(
v
=>
v
.
itemId
&&
v
.
itemId
===
itemId
)
&&
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
if
(
itemHasCompleteToday
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
PARAMS_ERROR
,
'今日该商品任务已完成'
)
}
}
v2.0/src/utils/common/check/index.ts
View file @
6a697143
...
...
@@ -13,6 +13,7 @@ import checkUserInfo, { checkGameTimes } from './checkUserInfo'
import
checkJoinId
from
'./checkJoinId'
import
checkOpenPrizeStatus
from
'./checkOpenPrizeStatus'
import
checkSign
from
'./checkSign'
import
checkGrowTaskLimit
from
'./checkGrowTaskLimit'
const
check
=
{
checkActivityTime
,
...
...
@@ -31,7 +32,8 @@ const check = {
checkJoinId
,
checkGameTimes
,
checkOpenPrizeStatus
,
checkSign
checkSign
,
checkGrowTaskLimit
}
export
default
check
...
...
@@ -53,5 +55,6 @@ export {
checkJoinId
,
checkGameTimes
,
checkOpenPrizeStatus
,
checkSign
checkSign
,
checkGrowTaskLimit
}
v2.0/src/utils/common/task.ts
View file @
6a697143
...
...
@@ -2,6 +2,9 @@
import
{
getToday
}
from
'./getToday'
import
{
TASK_STATUS
,
TASK_RATE_TYPE
}
from
'../../constants'
import
{
TASK_DB_NAME
}
from
'../../db'
import
{
BaseDao
}
from
'../../sdk'
import
Task
from
'../../controller/task.controller'
/**
* 根据任务类型获取任务完成情况
...
...
@@ -97,3 +100,97 @@ export function setTaskStatus(
break
}
}
/**
* 获取用户任务参与信息
* @param context
* @param openId
* @param activityId
*/
export
const
getTask
=
async
(
context
:
IContext
<
IParams
>
,
openId
:
string
=
''
,
activityId
?:
string
):
Promise
<
ITask
>
=>
{
activityId
=
activityId
?
activityId
:
context
.
data
.
activityId
openId
=
openId
?
openId
:
context
.
openId
const
taskInfodao
:
IBaseDao
=
new
BaseDao
(
context
,
TASK_DB_NAME
)
const
createDay
=
getToday
()
//查询每日任务完成记录
const
result
:
ITask
=
await
taskInfodao
.
findOne
({
openId
,
activityId
,
createDay
})
//如果还没有今天的任务数据,则新增一条用户任务数据
if
(
!
result
)
{
const
insertObj
=
{
openId
,
activityId
,
taskInfo
:
{},
createTime
:
Date
.
now
(),
createDay
:
createDay
}
const
insertResult
=
await
taskInfodao
.
insertOne
(
insertObj
)
return
{
...
insertObj
,
_id
:
insertResult
}
}
return
result
}
/**
* 获取养成类每日任务信息
* @param taskType
* @param task
*/
export
function
getTodayCompleteGrowTask
(
taskType
:
string
,
task
:
ITask
):
{
todayCompleteTimes
:
number
todayTaskInfo
:
ITaskDetail
[]
}
{
const
today
=
getToday
()
return
{
todayCompleteTimes
:
task
?.
taskInfo
?.[
today
]?.[
taskType
]?.
length
||
0
,
todayTaskInfo
:
task
?.
taskInfo
?.[
today
]?.[
taskType
]
||
[]
}
}
/**
* 更新每日任务,适用于购买商品每日任务
* @param context
* @param activityId
*/
export
async
function
updateTaskInfo
(
context
:
IContext
<
IParams
>
,
_id
:
string
,
taskType
:
string
,
value
)
{
let
taskInfodao
:
IBaseDao
=
new
BaseDao
(
context
,
TASK_DB_NAME
)
const
today
=
getToday
()
return
await
taskInfodao
.
update
(
{
_id
},
{
$push
:
{
[
`taskInfo.
${
today
}
.
${
taskType
}
`
]:
value
}
}
)
}
/**
* 增加每日任务每日任务,适用于普通每日任务
* @param context
* @param activityId
*/
export
async
function
updateGoodsTaskInfo
(
context
:
IContext
<
IParams
>
,
_id
:
string
,
taskType
:
string
,
value
)
{
let
taskInfodao
:
IBaseDao
=
new
BaseDao
(
context
,
TASK_DB_NAME
)
const
today
=
getToday
()
return
await
taskInfodao
.
update
(
{
_id
},
{
$set
:
{
[
`taskInfo.
${
today
}
.
${
taskType
}
`
]:
value
}
}
)
}
v2.0/src/utils/common/update/index.ts
View file @
6a697143
...
...
@@ -4,6 +4,10 @@ import updateSignTask from './updateSignTask'
import
updateOrderGoods
from
'./updateOrderGoods'
import
updateFirstLoginToday
from
'./updateFirstLoginToday'
import
updateUserInfo
,
{
reduceGameTimes
,
updateHelpRecord
}
from
'./updateUserInfo'
import
updateSignGrowTask
from
'./updateSignGrowTask'
import
updateGrowOrderGoods
from
'./updateGrowOrderGoods'
const
update
=
{
updateVip
,
...
...
@@ -12,7 +16,9 @@ const update = {
updateFirstLoginToday
,
updateUserInfo
,
reduceGameTimes
,
updateHelpRecord
updateHelpRecord
,
updateSignGrowTask
,
updateGrowOrderGoods
}
export
default
update
...
...
@@ -24,5 +30,7 @@ export {
updateFirstLoginToday
,
updateUserInfo
,
reduceGameTimes
,
updateHelpRecord
updateHelpRecord
,
updateSignGrowTask
,
updateGrowOrderGoods
}
v2.0/src/utils/common/update/updateGrowOrderGoods.ts
0 → 100644
View file @
6a697143
/** @format */
import
{
getToday
}
from
'../getToday'
import
{
getTotalCompleteTask
,
getTodayCompleteGrowTask
,
updateGoodsTaskInfo
}
from
'../task'
import
{
TASK_RATE_TYPE
}
from
'../../../constants'
import
{
getUserOrderlist
}
from
'../getUserOrderlist'
import
{
resultsModel
}
from
'../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
export
default
async
function
updateOrderGoods
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
,
task
}:
IControllerInfos
):
Promise
<
IPreUpdateQuery
>
{
const
taskType
=
'orderGoods'
const
{
value
,
itemIds
,
taskRateType
,
times
}
=
activityInfo
?.
tasks
?.[
taskType
]
||
{}
const
{
completeTimes
,
taskInfo
}
=
getTotalCompleteTask
(
taskType
,
userInfo
)
const
{
todayCompleteTimes
}
=
getTodayCompleteGrowTask
(
taskType
,
task
)
if
(
!
activityInfo
?.
tasks
?.[
taskType
])
return
{}
// 永久任务且已完成
if
(
taskRateType
===
TASK_RATE_TYPE
.
FOREVER
&&
completeTimes
>=
times
)
{
return
{}
}
// 每日限制完成且完成次数达到限制
if
(
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
&&
todayCompleteTimes
>=
times
)
{
return
{}
}
return
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
?
await
getEverydayGoods
(
context
,
taskType
,
itemIds
,
task
,
times
,
value
,
userInfo
)
:
await
getOrderGoods
(
taskType
,
itemIds
,
times
,
value
,
userInfo
,
taskInfo
)
}
/**
* 更新永久订单信息
* @param taskType
* @param itemIds
* @param times
* @param value
* @param userInfo
*/
async
function
getOrderGoods
(
taskType
:
string
,
itemIds
:
string
,
times
:
number
,
value
:
number
,
userInfo
:
IUserInfo
,
taskInfo
:
ITaskDetail
[]):
Promise
<
IPreUpdateQuery
>
{
const
today
=
getToday
()
const
orderResult
=
await
getUserOrderlist
(
this
.
context
,
//@ts-ignore
userInfo
.
createTime
||
activityInfo
?.
startTime
||
Date
.
now
(),
Date
.
now
()
)
const
itemIdsArr
=
itemIds
.
split
(
','
).
map
(
v
=>
+
v
)
let
projection
=
{
$inc
:
{
[
`remainTimes.
${
taskType
}
`
]:
0
},
$set
:
{}
}
let
targetOrders
=
userInfo
?.
taskInfo
?.[
today
]?.[
taskType
]
||
[]
orderResult
.
forEach
(
v
=>
{
// @ts-ignore
// 商品订单包含目标商品 且orderId为新订单
if
(
itemIdsArr
.
includes
(
v
.
itemId
)
&&
!
taskInfo
.
some
(
order
=>
order
.
orderId
===
v
.
orderId
))
{
if
(
targetOrders
.
length
>=
times
)
{
return
}
projection
.
$inc
[
`remainTimes.
${
taskType
}
`
]
+=
+
value
targetOrders
.
push
({
itemId
:
v
.
itemId
,
orderId
:
v
.
orderId
,
payTime
:
v
.
payTime
,
tId
:
v
.
tId
,
createTime
:
Date
.
now
()
})
}
if
(
targetOrders
?.
length
)
{
projection
.
$set
[
`taskInfo.
${
today
}
.
${
taskType
}
`
]
=
targetOrders
}
})
return
projection
}
/**
* 更新每日订单信息,仅适用于下单,如果是每日确认收货,需要单独处理
* @param context
* @param taskType
* @param itemIds
* @param task
* @param times
* @param value
* @param userInfo
*/
async
function
getEverydayGoods
(
context
:
IContext
<
IParams
>
,
taskType
:
string
,
itemIds
:
string
,
task
:
ITask
,
times
:
number
,
value
:
number
,
userInfo
:
IUserInfo
):
Promise
<
IPreUpdateQuery
>
{
const
today
=
getToday
()
const
TodayTime
=
new
Date
(
today
).
getTime
()
let
startTime
=
TodayTime
>
userInfo
.
createTime
?
TodayTime
:
userInfo
.
createTime
const
orderResult
=
await
getUserOrderlist
(
context
,
//@ts-ignore
startTime
,
Date
.
now
()
)
const
itemIdsArr
=
itemIds
.
split
(
','
).
map
(
v
=>
+
v
)
let
projection
=
{
$inc
:
{
[
`remainTimes.
${
taskType
}
`
]:
0
},
$set
:
{}
}
let
targetOrders
=
task
?.
taskInfo
?.[
today
]?.[
taskType
]
||
[]
let
targetLength
=
targetOrders
.
length
orderResult
.
forEach
(
v
=>
{
// @ts-ignore
// 商品订单包含目标商品 且orderId为新订单
if
(
itemIdsArr
.
includes
(
v
.
itemId
)
&&
!
task
?.
taskInfo
.
some
(
order
=>
order
.
orderId
===
v
.
orderId
))
{
if
(
targetOrders
.
length
>=
times
)
{
return
}
projection
.
$inc
[
`remainTimes.
${
taskType
}
`
]
+=
+
value
targetOrders
.
push
({
itemId
:
v
.
itemId
,
orderId
:
v
.
orderId
,
payTime
:
v
.
payTime
,
tId
:
v
.
tId
,
createTime
:
Date
.
now
()
})
}
})
if
(
targetOrders
?.
length
&&
targetLength
!==
targetOrders
?.
length
)
{
const
result
=
await
updateGoodsTaskInfo
(
context
,
today
,
taskType
,
targetOrders
)
if
(
result
!==
1
)
{
// @ts-ignore
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
'订单任务更新失败'
)
}
}
return
projection
}
v2.0/src/utils/common/update/updateSignGrowTask.ts
0 → 100644
View file @
6a697143
/** @format */
import
{
getToday
}
from
'../getToday'
import
{
getTodayCompleteGrowTask
,
updateTaskInfo
}
from
'../task'
export
default
async
function
updateSignTask
(
context
:
IContext
<
IParams
>
,
{
activityInfo
,
task
}:
IControllerInfos
):
Promise
<
IPreUpdateQuery
|
undefined
>
{
if
(
!
activityInfo
?.
tasks
?.
sign
)
return
// 获取签到奖励
const
{
value
}
=
activityInfo
?.
tasks
?.
sign
||
{}
const
{
todayCompleteTimes
}
=
getTodayCompleteGrowTask
(
'sign'
,
task
)
if
(
todayCompleteTimes
===
0
)
{
const
result
=
await
updateTaskInfo
(
context
,
task
.
_id
,
'sign'
,
{
createTime
:
Date
.
now
()
})
return
result
===
1
?
{
$inc
:
{
'remainTimes.sign'
:
value
||
0
},
}
:
{}
}
return
{}
}
v2.0/src/utils/index.ts
View file @
6a697143
...
...
@@ -27,3 +27,5 @@ export * from './common/userUpdate'
export
*
from
'./common/format'
export
*
from
'./common/doHandler'
export
*
from
'./common/task'
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