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
811ef1b2
Commit
811ef1b2
authored
Nov 05, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
增加 await
parent
03c6bb44
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
53 additions
and
16 deletions
+53
-16
game.controller.ts
v2.0/src/controller/game.controller.ts
+9
-4
task.controller.ts
v2.0/src/controller/task.controller.ts
+2
-2
preUpdate.ts
v2.0/src/decorator/common/preUpdate.ts
+1
-1
index.ts
v2.0/src/index.ts
+4
-1
task.service.ts
v2.0/src/service/task.service.ts
+5
-4
user.service.ts
v2.0/src/service/user.service.ts
+2
-2
index.ts
v2.0/src/utils/common/update/index.ts
+4
-2
updateFirstLogin.ts
v2.0/src/utils/common/update/updateFirstLogin.ts
+26
-0
No files found.
v2.0/src/controller/game.controller.ts
View file @
811ef1b2
/** @format */
/** @format */
import
{
services
,
checkParams
,
registeInfos
}
from
'../decorator/common'
import
{
services
,
checkParams
,
preUpdate
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
resultsModel
}
from
'../sdk'
import
{
UserService
,
AccessService
}
from
'../service'
import
{
UserService
}
from
'../service'
export
default
class
User
{
export
default
class
User
{
/**
/**
* 获取游戏信息
* 获取游戏信息
*
* needKeys 根据需求自取字段 格式: { gameTimes: 1}
*/
*/
@
checkParams
([
'activityId'
,
'needKeys'
])
@
checkParams
([
'activityId'
,
'needKeys'
])
@
services
([
UserService
,
AccessService
])
@
services
([
UserService
])
async
getGameInfo
(
async
getGameInfo
(
context
:
IContext
<
IParams
>
,
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
[
userService
,
accessService
]:
[
UserService
,
Access
Service
]
[
userService
]:
[
User
Service
]
)
{
)
{
const
{
needKeys
}
=
context
.
data
const
{
needKeys
}
=
context
.
data
const
gameInfoResult
=
await
userService
.
getUserInfo
(
needKeys
)
const
gameInfoResult
=
await
userService
.
getUserInfo
(
needKeys
)
return
resultsModel
.
success
({
...
gameInfoResult
})
}
}
}
}
v2.0/src/controller/task.controller.ts
View file @
811ef1b2
...
@@ -23,7 +23,7 @@ export default class Task {
...
@@ -23,7 +23,7 @@ export default class Task {
[
taskService
]:
[
TaskService
]
[
taskService
]:
[
TaskService
]
):
Promise
<
IResult
<
{
list
:
ITaskInfo
[]
}
>>
{
):
Promise
<
IResult
<
{
list
:
ITaskInfo
[]
}
>>
{
// 读取B端 tasks字段配置自动生成任务列表
// 读取B端 tasks字段配置自动生成任务列表
const
result
=
taskService
.
initTaskList
(
userInfo
,
activityInfo
)
const
result
=
await
taskService
.
initTaskList
(
userInfo
,
activityInfo
)
return
resultsModel
.
success
({
return
resultsModel
.
success
({
...
result
...
result
...
@@ -88,7 +88,7 @@ export default class Task {
...
@@ -88,7 +88,7 @@ export default class Task {
const
list
=
await
baseService
.
getItemListByIds
(
itemIds
,
session
)
const
list
=
await
baseService
.
getItemListByIds
(
itemIds
,
session
)
const
listWithCollectStatus
=
taskService
.
getItemListWithCollectStatus
(
list
,
userInfo
)
const
listWithCollectStatus
=
await
taskService
.
getItemListWithCollectStatus
(
list
,
userInfo
)
return
resultsModel
.
success
(
listWithCollectStatus
)
return
resultsModel
.
success
(
listWithCollectStatus
)
}
}
...
...
v2.0/src/decorator/common/preUpdate.ts
View file @
811ef1b2
/** @format */
/** @format */
import
{
is
Array
,
isEmpty
,
isObject
,
merge
}
from
'lodash'
import
{
is
Empty
,
merge
}
from
'lodash'
import
{
UserService
}
from
'../../service'
import
{
UserService
}
from
'../../service'
import
{
recordErrorLog
}
from
'../../utils/common/logger'
import
{
recordErrorLog
}
from
'../../utils/common/logger'
import
{
resultsModel
}
from
'../../sdk'
import
{
resultsModel
}
from
'../../sdk'
...
...
v2.0/src/index.ts
View file @
811ef1b2
...
@@ -7,10 +7,12 @@ import AwardsController from './controller/awards.controller'
...
@@ -7,10 +7,12 @@ import AwardsController from './controller/awards.controller'
import
ShareController
from
'./controller/share.controller'
import
ShareController
from
'./controller/share.controller'
import
StatController
from
'./controller/stat.controller'
import
StatController
from
'./controller/stat.controller'
import
LoginController
from
'./controller/login.controller'
import
LoginController
from
'./controller/login.controller'
import
GameController
from
'./controller/game.controller'
const
{
getVipInfo
,
getRankList
}
=
new
UserController
()
const
{
getVipInfo
,
getRankList
}
=
new
UserController
()
const
{
login
}
=
new
LoginController
()
const
{
login
}
=
new
LoginController
()
const
{
getGameInfo
}
=
new
GameController
()
const
{
const
{
getTaskList
,
getTaskList
,
receiveTaskRewards
,
receiveTaskRewards
,
...
@@ -39,5 +41,6 @@ export default {
...
@@ -39,5 +41,6 @@ export default {
doHelp
,
doHelp
,
getStats
,
getStats
,
addStat
,
addStat
,
getRankList
getRankList
,
getGameInfo
}
}
v2.0/src/service/task.service.ts
View file @
811ef1b2
...
@@ -29,7 +29,7 @@ export default class TaskService extends UserService {
...
@@ -29,7 +29,7 @@ export default class TaskService extends UserService {
}
}
// 根据活动tasks字段渲染任务
// 根据活动tasks字段渲染任务
initTaskList
(
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
)
{
async
initTaskList
(
userInfo
:
IUserInfo
,
activityInfo
:
IActivityInfo
)
{
return
{
return
{
list
:
Object
.
keys
(
activityInfo
?.
tasks
||
{}).
map
((
task
:
ITaskType
)
=>
{
list
:
Object
.
keys
(
activityInfo
?.
tasks
||
{}).
map
((
task
:
ITaskType
)
=>
{
return
this
.
initTask
(
task
,
activityInfo
?.
tasks
?.[
task
]?.
title
,
userInfo
,
activityInfo
)
return
this
.
initTask
(
task
,
activityInfo
?.
tasks
?.[
task
]?.
title
,
userInfo
,
activityInfo
)
...
@@ -115,7 +115,8 @@ export default class TaskService extends UserService {
...
@@ -115,7 +115,8 @@ export default class TaskService extends UserService {
async
completeTask
(
async
completeTask
(
taskType
:
ITaskType
,
taskType
:
ITaskType
,
activityInfo
:
IActivityInfo
,
activityInfo
:
IActivityInfo
,
userInfo
:
IUserInfo
userInfo
:
IUserInfo
,
customRecord
:
Object
=
{}
):
Promise
<
boolean
|
ICodeType
>
{
):
Promise
<
boolean
|
ICodeType
>
{
const
today
=
getToday
()
const
today
=
getToday
()
const
rewards
=
activityInfo
?.
tasks
?.[
taskType
]?.
value
||
0
const
rewards
=
activityInfo
?.
tasks
?.[
taskType
]?.
value
||
0
...
@@ -124,7 +125,7 @@ export default class TaskService extends UserService {
...
@@ -124,7 +125,7 @@ export default class TaskService extends UserService {
data
:
{
itemId
}
data
:
{
itemId
}
}
=
this
.
context
}
=
this
.
context
const
record
=
{
itemId
,
openId
:
taskType
===
'invites'
?
openId
:
undefined
}
const
record
=
{
itemId
,
openId
:
taskType
===
'invites'
?
openId
:
undefined
,
...
customRecord
}
const
result
=
await
this
.
updateUser
(
userInfo
.
_id
,
{
const
result
=
await
this
.
updateUser
(
userInfo
.
_id
,
{
$inc
:
{
$inc
:
{
[
`remainTimes.
${
taskType
}
`
]:
rewards
[
`remainTimes.
${
taskType
}
`
]:
rewards
...
@@ -196,7 +197,7 @@ export default class TaskService extends UserService {
...
@@ -196,7 +197,7 @@ export default class TaskService extends UserService {
return
projection
return
projection
}
}
getItemListWithCollectStatus
(
list
:
ITaoBaoItems
[],
userInfo
:
IUserInfo
)
{
async
getItemListWithCollectStatus
(
list
:
ITaoBaoItems
[],
userInfo
:
IUserInfo
)
{
const
{
taskInfo
}
=
getTotalCompleteTask
(
'collectGoods'
,
userInfo
)
const
{
taskInfo
}
=
getTotalCompleteTask
(
'collectGoods'
,
userInfo
)
return
list
.
map
(
v
=>
{
return
list
.
map
(
v
=>
{
...
...
v2.0/src/service/user.service.ts
View file @
811ef1b2
...
@@ -21,10 +21,10 @@ class UserService extends BaseService {
...
@@ -21,10 +21,10 @@ class UserService extends BaseService {
* @desc 获取当前打开活动的用户详情
* @desc 获取当前打开活动的用户详情
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
* @returns 若用户不存在,返回null; 用户存在,返回用户信息(object对象)
*/
*/
async
getUserInfo
(
projection
:
IFindProjection
=
{})
{
async
getUserInfo
(
projection
=
{})
{
let
{
openId
,
data
}
=
this
.
context
let
{
openId
,
data
}
=
this
.
context
let
{
activityId
}
=
data
let
{
activityId
}
=
data
return
await
this
.
userdao
.
findOne
<
IUserInfo
>
({
openId
,
activityId
},
projection
)
return
await
this
.
userdao
.
findOne
<
IUserInfo
>
({
openId
,
activityId
},
{
projection
}
)
}
}
/**
/**
...
...
v2.0/src/utils/common/update/index.ts
View file @
811ef1b2
...
@@ -2,13 +2,15 @@
...
@@ -2,13 +2,15 @@
import
updateVip
from
'./updateVip'
import
updateVip
from
'./updateVip'
import
updateSignTask
from
'./updateSignTask'
import
updateSignTask
from
'./updateSignTask'
import
updateOrderGoods
from
'./updateOrderGoods'
import
updateOrderGoods
from
'./updateOrderGoods'
import
updateFirstLogin
from
'./updateFirstLogin'
const
update
=
{
const
update
=
{
updateVip
,
updateVip
,
updateSignTask
,
updateSignTask
,
updateOrderGoods
updateOrderGoods
,
updateFirstLogin
}
}
export
default
update
export
default
update
export
{
updateVip
,
updateSignTask
,
updateOrderGoods
}
export
{
updateVip
,
updateSignTask
,
updateOrderGoods
,
updateFirstLogin
}
v2.0/src/utils/common/update/updateFirstLogin.ts
0 → 100644
View file @
811ef1b2
/** @format */
import
{
getToday
}
from
'../getToday'
import
{
isNewVip
,
setNewVipUserData
}
from
'../userUpdate'
export
default
async
function
updateFirstLogin
(
context
:
IContext
<
IParams
>
,
{
vipInfo
,
userInfo
,
activityInfo
}:
IControllerInfos
):
Promise
<
IPreUpdateQuery
>
{
let
{
member
}
=
userInfo
const
memberReWards
=
activityInfo
?.
tasks
?.
member
?.
value
return
isNewVip
(
userInfo
,
vipInfo
)
?
{
$set
:
{
member
:
setNewVipUserData
(
member
)
},
$inc
:
{
'remainTimes.member'
:
+
memberReWards
},
$push
:
{
[
`taskInfo.
${
getToday
()}
.member`
]:
{
creatTime
:
Date
.
now
()
}
}
}
:
{}
}
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