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
b1a4368f
Commit
b1a4368f
authored
Nov 04, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor:
💡
邀请接口
parent
18fd9dc1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
3 additions
and
345 deletions
+3
-345
awards.controller.ts
v2.0/src/controller/common/awards.controller.ts
+0
-214
task.controller.ts
v2.0/src/controller/common/task.controller.ts
+0
-122
user.controller.ts
v2.0/src/controller/common/user.controller.ts
+1
-5
share.controller.ts
v2.0/src/controller/share.controller.ts
+1
-3
user.controller.ts
v2.0/src/controller/user.controller.ts
+1
-1
No files found.
v2.0/src/controller/common/awards.controller.ts
deleted
100644 → 0
View file @
18fd9dc1
/** @format */
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
commonUtil
from
'../../utils/common'
import
{
resultsModel
}
from
'../../sdk'
import
{
AwardsService
}
from
'../../service'
import
{
PRIZE_TYPE
,
DRAW_STATUS
,
CODE_TYPES
}
from
'../../constants'
import
{
getToday
}
from
'../../utils/'
import
{
CodeType
}
from
'taobao-mini-sdk/lib/utils/codetypes'
import
{
checkActivityTime
}
from
'../../utils/common/check/checkActivityTime'
export
interface
IPrizeListParams
{
activityId
:
string
}
export
interface
IReceiveOjectParams
{
activityId
:
string
id
:
string
name
:
string
phone
:
string
province
:
string
city
:
string
area
:
string
addressDetail
:
string
streetName
:
string
}
export
interface
IReceiveEnameParams
{
activityId
:
string
id
:
string
}
export
default
class
AwardsController
{
/**
* 我的奖品列表
*/
@
commonDecorator
.
checkParams
([
'activityId'
,])
@
commonDecorator
.
registeInfos
([
'activityInfo'
,])
@
services
([
AwardsService
])
async
getMyPrizeList
(
context
:
IContext
<
IPrizeListParams
>
,
{
activityInfo
,
vipInfo
},
[
awardSer
]:
[
AwardsService
]
):
Promise
<
IResult
<
{
list
:
IAwards
[]
}
>>
{
const
{
openId
,
data
:
{
activityId
}
}
=
context
const
{
awardReceiveExpiredTime
}
=
activityInfo
const
myPrizeList
=
await
awardSer
.
getAwardsInfoList
(
{
openId
,
activityId
,
type
:
{
$ne
:
PRIZE_TYPE
.
THANKS
}
},
{
projection
:
{
_id
:
1
,
name
:
1
,
image
:
1
,
type
:
1
,
drawStatus
:
1
,
shipStatus
:
1
,
receiveName
:
1
,
phone
:
1
,
address
:
1
,
provice
:
1
,
city
:
1
,
area
:
1
,
remark
:
1
,
useUrk
:
1
,
shipCompany
:
1
,
shipNum
:
1
},
sort
:
{
createTime
:
-
1
}
}
)
return
resultsModel
.
success
({
list
:
awardSer
.
formateMyPrizeList
(
myPrizeList
,
awardReceiveExpiredTime
)
})
}
/**
* 领取实物
*/
@
commonDecorator
.
checkParams
([
'activityId'
,
'id'
,
'name'
,
'phone'
,
'province'
,
'city'
,
'addressDetail'
,
'streetName'
,])
@
commonDecorator
.
registeInfos
([
'activityInfo'
,])
@
commonDecorator
.
preCheck
([
'[object Object]'
,
'[object Object]'
,])
@
services
([
AwardsService
])
async
receiveObjectPrize
(
context
:
IContext
<
IReceiveOjectParams
>
,
{
activityInfo
,
vipInfo
}:
IControllerInfos
,
[
awardSer
]:
[
AwardsService
]
):
Promise
<
IResult
<
boolean
>>
{
let
{
province
,
city
,
area
,
streetName
,
addressDetail
,
id
,
name
,
phone
,
activityId
}
=
context
.
data
// 若有过期时间,且已过期
let
{
awardReceiveExpiredTime
}
=
activityInfo
if
(
awardReceiveExpiredTime
&&
Date
.
now
()
>
awardReceiveExpiredTime
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
ERROR_PRIZE_EXPIRED
)
}
let
result
=
await
awardSer
.
recieveObjectPrize
(
id
,
{
activityId
,
province
,
city
,
area
,
streetName
,
addressDetail
,
name
,
phone
})
if
((
result
as
CodeType
).
code
)
{
return
resultsModel
.
error
(
result
as
CodeType
)
}
return
resultsModel
.
success
(
result
as
true
)
}
/**
* 权益重新领取
*/
@
services
([
AwardsService
])
async
receiveEnamePrize
(
context
:
IContext
<
IReceiveEnameParams
>
,
{},
[
awardSer
]:
[
AwardsService
])
{
let
{
id
,
activityId
}
=
context
.
data
let
result
=
await
awardSer
.
recieveEnamePrize
(
id
,
activityId
)
if
((
result
as
CodeType
).
code
)
{
return
resultsModel
.
error
(
result
as
CodeType
)
}
if
((
result
as
IAwards
).
remark
)
{
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
(
result
as
IAwards
).
remark
)
}
return
resultsModel
.
success
(
result
)
}
/**
* 概率抽奖
*/
@
checkParams
([
'activityId'
,
'prizeDataType'
])
@
services
([
AwardsService
])
@
preCheck
([
checkActivityTime
])
async
drawLotteryPrize
(
context
:
IContext
<
IParams
>
,
{
userInfo
}:
IControllerInfos
,
[
awardSer
]:
[
AwardsService
])
{
const
{
openId
}
=
context
const
{
activityId
,
prizeDataType
}
=
context
.
data
// 获取奖池配置
const
prizesPool
=
await
awardSer
.
getPrizeConfig
({
activityId
,
// 根据需求配置筛选条件
prizeDataType
})
const
thanksPrize
=
prizesPool
.
find
(
v
=>
v
.
type
===
PRIZE_TYPE
.
THANKS
)
||
{
type
:
PRIZE_TYPE
.
THANKS
,
prizeDataType
,
name
:
'谢谢参与'
}
// 根据概率获取
let
prize
=
await
awardSer
.
getPrizeByProbability
(
prizesPool
)
// 未找到奖品,降级到谢谢参与
if
(
!
prize
)
{
prize
=
thanksPrize
}
let
reduceResult
:
ICodeType
|
number
=
1
// 不是积分奖品, 检查是否扣库存
if
(
prize
.
type
!==
PRIZE_TYPE
.
CREDITS
&&
prize
.
type
!==
PRIZE_TYPE
.
THANKS
)
{
reduceResult
=
await
awardSer
.
reduceStock
(
prize
.
_id
)
}
// 扣库存失败降级到谢谢参与
if
((
reduceResult
as
ICodeType
)?.
code
||
!
reduceResult
)
{
prize
=
thanksPrize
}
const
{
type
,
_id
,
ename
,
image
,
name
,
useUrl
}
=
prize
const
{
userNick
}
=
userInfo
let
record
=
{
openId
,
prizeId
:
_id
,
activityId
,
drawStatus
:
DRAW_STATUS
.
WAITAWARD
,
prizeDataType
,
remark
:
''
,
useUrl
,
type
,
ename
,
name
,
image
,
userNick
,
createDay
:
getToday
()
}
// 奖品信息 insert c_awards表
const
result
=
await
awardSer
.
addAward
(
record
)
return
resultsModel
.
success
({
id
:
result
,
type
,
name
,
image
})
}
}
\ No newline at end of file
v2.0/src/controller/common/task.controller.ts
deleted
100644 → 0
View file @
18fd9dc1
/** @format */
import
{
CODE_TYPES
}
from
'./../constants'
import
{
checkParams
,
services
,
registeInfos
,
preCheck
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
TaskService
,
BaseService
}
from
'../service'
import
{
ITaskInfo
}
from
'../service/task.service'
import
{
checkActivityTime
}
from
'../utils/common/check/checkActivityTime'
import
{
getTotalCompleteTask
}
from
'../utils/common/task'
import
{
update
}
from
'../decorator/common/update'
import
{
updateVip
}
from
'../utils/common/update/updateVip'
import
{
checkTaskLimit
}
from
'../utils/common/check/checkTaskLimit'
import
{
checkExchangeCreditsTask
}
from
'../utils/common/check/checkExchangeCreditsTask'
import
{
checkRemainTimes
}
from
'../utils/common/check/checkRemainTimes'
export
default
class
Task
{
/**
* 任务列表
*/
@
checkParams
([
'activityId'
])
@
registeInfos
([
'vipInfo'
])
@
services
([
TaskService
])
@
preCheck
([
checkActivityTime
])
@
update
([
updateVip
])
async
getTaskList
(
context
:
IContext
<
{
activityId
:
string
}
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
[
taskService
]:
[
TaskService
]
):
Promise
<
IResult
<
ITaskInfo
[]
>>
{
return
resultsModel
.
success
([
taskService
.
initTask
(
'member'
,
'加入会员'
,
activityInfo
,
userInfo
),
taskService
.
initTask
(
'follow'
,
'关注店铺'
,
activityInfo
,
userInfo
)
// taskService.initTask('sign', '签到', activityInfo, userInfo),
// taskService.initTask('orderGoods', '购买商品', activityInfo, userInfo),
// taskService.initTask('browseGoods', '浏览商品', activityInfo, userInfo),
// taskService.initTask('collectGoods', '收藏商品', activityInfo, userInfo),
// taskService.initTask('jumpLink', '浏览页面', activityInfo, userInfo),
// taskService.initTask('invites', '邀请好友', activityInfo, userInfo)
// taskService.initTask('exchangeCredits', '积分兑换', activityInfo, updatedUserInfo)
])
}
/**
* 完成任务
*
* 商品相关任务 需要传itemId参数
* 积分兑换任务 需要传credits参数
*/
@
checkParams
([
'activityId'
,
'taskType'
])
@
registeInfos
([
'session'
])
@
services
([
TaskService
])
@
preCheck
([
checkActivityTime
,
checkTaskLimit
,
checkExchangeCreditsTask
])
async
doCompleteTask
(
context
:
IContext
<
{
activityId
:
string
taskType
:
ITaskType
itemId
?:
string
// 涉及到商品的任务需传itemId
credits
?:
number
}
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
[
taskService
]:
[
TaskService
]
):
Promise
<
IResult
<
boolean
>>
{
const
{
taskType
,
itemId
}
=
context
.
data
// 更新user表
const
result
=
await
taskService
.
completeTask
(
taskType
,
activityInfo
,
userInfo
,
{
itemId
})
return
result
?
resultsModel
.
success
(
true
)
:
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
'任务完成失败'
)
}
/**
* 领取任务奖励
*/
@
checkParams
([
'activityId'
,
'taskType'
,
'rewardsKey'
])
@
services
([
TaskService
])
@
preCheck
([
checkActivityTime
,
checkRemainTimes
])
async
receiveTaskRewards
(
context
:
IContext
<
{
activityId
:
string
taskType
:
ITaskType
rewardsKey
:
string
//领取的奖励增加的key值 如: gameTimes 前端传入
}
>
,
{
userInfo
}:
IControllerInfos
,
[
taskService
]:
[
TaskService
]
):
Promise
<
IResult
<
{
rewards
:
number
}
>>
{
const
{
rewardsKey
}
=
context
.
data
const
{
taskType
}
=
context
.
data
const
rewards
=
await
taskService
.
receiveTaskRewards
(
taskType
,
rewardsKey
,
userInfo
)
return
resultsModel
.
success
({
rewards
})
}
/**
* 获取收藏商品列表
*/
@
checkParams
([
'activityId'
,
'itemIds'
])
@
registeInfos
([
'session'
])
@
services
([
BaseService
])
async
getCollectGoodsList
(
context
:
IContext
<
IParams
>
,
{
session
,
userInfo
}:
IControllerInfos
,
[
baseService
]:
[
BaseService
]
)
{
const
{
itemIds
}
=
context
.
data
const
list
=
await
baseService
.
getItemListByIds
(
itemIds
,
session
)
const
{
taskInfo
}
=
getTotalCompleteTask
(
'collectGoods'
,
userInfo
)
const
listWithCollectStatus
=
list
.
map
(
v
=>
{
return
{
...
v
,
// 完成列表是否含有itemId
collected
:
taskInfo
.
some
(
completeItem
=>
completeItem
.
itemId
===
v
.
itemId
)
}
})
return
resultsModel
.
success
(
listWithCollectStatus
)
}
}
v2.0/src/controller/common/user.controller.ts
View file @
b1a4368f
...
...
@@ -35,11 +35,7 @@ export default class User {
{
session
,
activityUserNick
}:
IControllerInfos
,
[
userService
]:
[
UserService
]
):
Promise
<
IResult
<
IVipInfo
>>
{
const
commonUserGetshopvipResult
=
await
userService
.
getShopVip
(
context
,
session
,
activityUserNick
)
const
commonUserGetshopvipResult
=
await
userService
.
getShopVip
(
context
,
session
,
activityUserNick
)
return
resultsModel
.
success
({
...
commonUserGetshopvipResult
})
...
...
v2.0/src/controller/share.controller.ts
View file @
b1a4368f
...
...
@@ -51,10 +51,8 @@ export default class Share {
openId
})
if
(
!
result
)
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
,
'邀请失败!'
)
await
statService
.
addStat
(
STAT_TYPE
.
INITE_SUCCESS
,
userInfo
)
return
resultsModel
.
success
(
true
)
return
resultsModel
.
success
(
result
)
}
}
v2.0/src/controller/user.controller.ts
View file @
b1a4368f
...
...
@@ -53,7 +53,7 @@ export default class User {
activityId
:
string
key
:
string
// 排序的key值 如 score
timeKey
:
string
// 排序时间的key值 如:updateScoreTime
limit
:
number
limit
?
:
number
}
>
,
{
userInfo
}:
IControllerInfos
,
[
userService
]:
[
UserService
]
...
...
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