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
3609b20c
Commit
3609b20c
authored
Jan 22, 2021
by
王波
Committed by
qinhaitao
Jan 22, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化修改
parent
d30d2d07
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
138 additions
and
125 deletions
+138
-125
growShare.controller.ts
v2.0/src/controller/growShare.controller.ts
+1
-1
growTask.controller.ts
v2.0/src/controller/growTask.controller.ts
+2
-2
db.ts
v2.0/src/db.ts
+1
-0
growTask.service.ts
v2.0/src/service/common/growTask.service.ts
+35
-9
task.service.ts
v2.0/src/service/common/task.service.ts
+1
-1
awards.d.ts
v2.0/src/typings/awards.d.ts
+1
-2
task.ts
v2.0/src/utils/common/task.ts
+57
-15
index.ts
v2.0/src/utils/common/update/index.ts
+0
-2
updateGrowOrderGoods.ts
v2.0/src/utils/common/update/updateGrowOrderGoods.ts
+40
-93
No files found.
v2.0/src/controller/growShare.controller.ts
View file @
3609b20c
...
...
@@ -2,7 +2,7 @@
import
{
services
,
preCheck
,
registeInfos
,
preUpdate
,
checkParams
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
Common
UserService
,
CommonStatService
,
CommonTask
Service
,
CommonGrowTaskService
}
from
'../service/common'
import
{
Common
Stat
Service
,
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'
...
...
v2.0/src/controller/growTask.controller.ts
View file @
3609b20c
...
...
@@ -25,11 +25,11 @@ export default class Task {
@
preUpdate
([
updateVip
,
updateSignGrowTask
,
updateGrowOrderGoods
])
async
getTaskList
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
{
userInfo
,
activityInfo
,
task
}:
IControllerInfos
,
[
growTaskService
]:
[
CommonGrowTaskService
]
):
Promise
<
IResult
<
{
list
:
ITaskInfo
[]
}
>>
{
// 读取B端 tasks字段配置自动生成任务列表
const
result
=
await
growTaskService
.
initTaskList
(
userInfo
,
activityInfo
)
const
result
=
await
growTaskService
.
initTaskList
(
userInfo
,
activityInfo
,
task
)
return
resultsModel
.
success
({
...
result
...
...
v2.0/src/db.ts
View file @
3609b20c
...
...
@@ -22,3 +22,4 @@ export const PRIZE_CONFIG_DB_NAME = 'b_prize_config'
export
const
ACTIVITY_CONFIG_DB_NAME
=
'b_activity_config'
export
const
OEDER_DB_NAME
=
'c_user_order'
v2.0/src/service/common/growTask.service.ts
View file @
3609b20c
...
...
@@ -7,7 +7,13 @@
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
{
getTotalCompleteTask
,
setGrowTaskStatus
,
updateTaskInfo
,
getTodayCompleteGrowTask
,
getOrderCount
}
from
'../../utils/common/task'
import
{
CODE_TYPES
}
from
'../../errorCode'
export
interface
ITaskInfo
{
...
...
@@ -29,11 +35,16 @@ export default class TaskService extends UserService {
}
// 根据活动tasks字段渲染任务
async
initTaskList
(
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
)
{
async
initTaskList
(
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
,
task
:
ITask
)
{
let
list
=
[]
const
keyList
=
Object
.
keys
(
activityInfo
?.
tasks
||
{})
for
(
let
index
=
0
;
index
<
keyList
.
length
;
index
++
)
{
// @ts-ignore
const
taskType
:
ITaskType
=
keyList
[
index
]
list
.
push
(
await
this
.
initTask
(
task
,
taskType
,
activityInfo
?.
tasks
?.[
taskType
]?.
title
,
userInfo
,
activityInfo
))
}
return
{
list
:
Object
.
keys
(
activityInfo
?.
tasks
||
{}).
map
((
task
:
ITaskType
)
=>
{
return
this
.
initTask
(
task
,
activityInfo
?.
tasks
?.[
task
]?.
title
,
userInfo
,
activityInfo
)
})
list
}
}
/**
...
...
@@ -46,14 +57,29 @@ export default class TaskService extends UserService {
* @return {ITaskInfo} {ITaskInfo} 任务信息
* @memberof TaskService
*/
initTask
(
taskType
:
ITaskType
,
title
:
string
,
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
):
ITaskInfo
{
async
initTask
(
task
:
ITask
,
taskType
:
ITaskType
,
title
:
string
,
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
):
Promise
<
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
)
let
{
todayCompleteTimes
}
=
getTodayCompleteGrowTask
(
taskType
,
task
)
let
{
completeTimes
}
=
getTotalCompleteTask
(
taskType
,
userInfo
)
if
(
taskType
===
'orderGoods'
)
{
//如果是下单任务,需要单独去根据订单类型去订单表获取下单列表
todayCompleteTimes
=
completeTimes
=
await
getOrderCount
(
this
.
context
,
userInfo
.
openId
,
activityInfo
.
_id
,
taskRateType
)
}
return
{
taskType
,
...
...
@@ -65,7 +91,7 @@ export default class TaskService extends UserService {
url
:
taskType
===
'member'
?
generateVipUrl
(
formatVipCbUrl
(
this
.
context
))
:
link
,
todayCompleteTimes
,
completeTimes
,
status
:
set
TaskStatus
(
userInfo
,
taskType
,
taskRateType
,
t
imes
),
status
:
set
GrowTaskStatus
(
userInfo
,
taskType
,
taskRateType
,
times
,
todayCompleteTimes
,
completeT
imes
),
waitReceive
:
remainTimes
?.[
taskType
]
}
}
...
...
v2.0/src/service/common/task.service.ts
View file @
3609b20c
...
...
@@ -37,7 +37,7 @@ export default class TaskService extends UserService {
}
}
/**
* 根据任务类型初始化 b端 tasks字段必须有相应的配置
* 根据任务类型初始化 b端 tasks字段必须有相应的配置
TODO
*
* @param {ITaskType} taskType 任务类型
* @param {string} title 任务标题
...
...
v2.0/src/typings/awards.d.ts
View file @
3609b20c
...
...
@@ -2,8 +2,7 @@
type
IAwards
=
ICommonAwards
&
ICustomAwards
interface
ICustomAwards
{
}
interface
ICustomAwards
{}
interface
ICommonAwards
{
_id
?:
string
id
?:
string
...
...
v2.0/src/utils/common/task.ts
View file @
3609b20c
...
...
@@ -2,7 +2,7 @@
import
{
getToday
}
from
'./getToday'
import
{
TASK_STATUS
,
TASK_RATE_TYPE
}
from
'../../constants'
import
{
TASK_DB_NAME
}
from
'../../db'
import
{
TASK_DB_NAME
,
OEDER_DB_NAME
}
from
'../../db'
import
{
BaseDao
}
from
'../../sdk'
import
Task
from
'../../controller/task.controller'
...
...
@@ -176,21 +176,63 @@ export async function updateTaskInfo(context: IContext<IParams>, _id: string, ta
}
/**
*
增加每日任务每日任务,适用于普通
每日任务
*
更新每日任务,适用于购买商品
每日任务
* @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
}
}
)
export
async
function
getOrderCount
(
context
:
IContext
<
IParams
>
,
openId
:
string
,
activityId
:
string
,
taskRateType
:
number
)
{
let
orderdao
:
IBaseDao
=
new
BaseDao
(
context
,
OEDER_DB_NAME
)
const
project
=
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
?
{
openId
,
activityId
,
createDay
:
getToday
()
}
:
{
openId
,
activityId
}
return
await
orderdao
.
count
(
project
)
}
/**
*
* 根据用户和任务完成情况,设置任务状态
*
* @param {IUserInfo} useInfo
* @param {string} taskType
* @param {number} taskRateType
* @param {number} [limitTimesEverday] 每天限制次数 任务频率为每天的时候必填
* @return {taskTatus} 1未完成 2 待领取 3 已完成
* @memberof TaskService
*/
export
function
setGrowTaskStatus
(
userInfo
:
IUserInfo
,
taskType
:
string
,
taskRateType
:
number
,
limitTimesEveryday
:
number
=
1
,
todayCompleteTimes
:
number
,
completeTimes
:
number
):
number
{
const
waitReceive
=
userInfo
?.
remainTimes
?.[
taskType
]
||
0
if
(
waitReceive
)
return
TASK_STATUS
.
WAIT_RECEIVE
switch
(
taskRateType
)
{
case
TASK_RATE_TYPE
.
FOREVER
:
return
completeTimes
>=
limitTimesEveryday
?
TASK_STATUS
.
DONE
:
TASK_STATUS
.
WAIT_DO
break
case
TASK_RATE_TYPE
.
EVERYDAY
:
return
todayCompleteTimes
>=
limitTimesEveryday
?
TASK_STATUS
.
DONE
:
TASK_STATUS
.
WAIT_DO
break
case
TASK_RATE_TYPE
.
NOLIMIT
:
return
TASK_STATUS
.
WAIT_DO
break
}
}
v2.0/src/utils/common/update/index.ts
View file @
3609b20c
...
...
@@ -7,8 +7,6 @@ import updateUserInfo, { reduceGameTimes, updateHelpRecord } from './updateUserI
import
updateSignGrowTask
from
'./updateSignGrowTask'
import
updateGrowOrderGoods
from
'./updateGrowOrderGoods'
const
update
=
{
updateVip
,
updateSignTask
,
...
...
v2.0/src/utils/common/update/updateGrowOrderGoods.ts
View file @
3609b20c
/** @format */
import
{
getToday
}
from
'../getToday'
import
{
getTotalCompleteTask
,
getTodayCompleteGrowTask
,
updateGoodsTaskInfo
}
from
'../task'
import
{
TASK_RATE_TYPE
}
from
'../../../constants'
import
{
getUserOrderlist
}
from
'../getUserOrderlist'
import
{
OEDER_DB_NAME
}
from
'../../../db'
import
{
resultsModel
}
from
'../../../sdk'
import
{
BaseDao
}
from
'../../../sdk'
import
{
CODE_TYPES
}
from
'../../../errorCode'
import
{
formatDate
}
from
'../date'
export
default
async
function
updateOrderGoods
(
export
default
async
function
update
Grow
OrderGoods
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
,
task
}:
IControllerInfos
{
userInfo
,
activityInfo
}:
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
)
let
orderdao
:
IBaseDao
=
new
BaseDao
(
context
,
OEDER_DB_NAME
)
const
orderList
=
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
?
await
orderdao
.
find
({
openId
:
userInfo
.
openId
,
activityId
:
userInfo
.
activityId
,
createDay
:
getToday
})
:
await
orderdao
.
find
({
openId
:
userInfo
.
openId
,
activityId
:
userInfo
.
activityId
})
const
completeTimes
=
orderList
?.
length
||
0
if
(
!
activityInfo
?.
tasks
?.[
taskType
])
return
{}
//
永久
任务且已完成
if
(
taskRateType
===
TASK_RATE_TYPE
.
FOREVER
&&
completeTimes
>=
times
)
{
//
每日任务或者是永久任务的
任务且已完成
if
(
taskRateType
!==
TASK_RATE_TYPE
.
NOLIMIT
&&
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
startTime
=
Date
.
now
()
if
(
taskRateType
===
TASK_RATE_TYPE
.
EVERYDAY
)
{
let
TodayTime
=
formatDate
(
today
).
getTimestamp
()
startTime
=
TodayTime
>
userInfo
.
createTime
?
TodayTime
:
userInfo
.
createTime
}
else
{
startTime
=
userInfo
.
createTime
||
activityInfo
?.
startTime
||
Date
.
now
()
}
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
...
...
@@ -113,33 +59,34 @@ async function getEverydayGoods(context: IContext<IParams>, taskType: string, it
},
$set
:
{}
}
let
targetOrders
=
task
?.
taskInfo
?.[
today
]?.[
taskType
]
||
[]
let
targetLength
=
targetOrders
.
length
//筛选符合任务的订单并添加到下单表
let
targetOrders
=
[]
orderResult
.
forEach
(
v
=>
{
// @ts-ignore
// 商品订单包含目标商品 且orderId为新订单
if
(
itemIdsArr
.
includes
(
v
.
itemId
)
&&
!
task
?.
taskInfo
.
some
(
order
=>
order
.
orderId
===
v
.
orderId
))
{
if
(
targetOrders
.
length
>=
times
)
{
if
(
itemIdsArr
.
includes
(
v
.
itemId
)
&&
!
orderList
.
some
(
order
=>
order
.
orderId
===
v
.
orderId
))
{
if
(
targetOrders
.
length
+
completeTimes
>=
times
)
{
return
}
projection
.
$inc
[
`remainTimes.
${
taskType
}
`
]
+=
+
value
targetOrders
.
push
({
openId
:
userInfo
.
openId
,
activityId
:
activityInfo
.
_id
,
itemId
:
v
.
itemId
,
orderId
:
v
.
orderId
,
payTime
:
v
.
payTime
,
tId
:
v
.
tId
,
createTime
:
Date
.
now
()
createTime
:
Date
.
now
(),
createDay
:
today
})
}
})
if
(
targetOrders
?.
length
&&
targetLength
!==
targetOrders
?.
length
)
{
const
result
=
await
updateGoodsTaskInfo
(
context
,
today
,
taskType
,
targetOrders
)
if
(
result
!==
1
)
{
if
(
targetOrders
?.
length
)
{
const
result
=
await
orderdao
.
insertMany
(
targetOrders
)
if
(
!
result
||
result
.
length
===
0
)
{
// @ts-ignore
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
'订单任务更新失败'
)
}
projection
.
$inc
[
`remainTimes.
${
taskType
}
`
]
=
result
.
length
*
value
}
return
projection
...
...
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