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
d4474579
Commit
d4474579
authored
Nov 06, 2020
by
maggie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save
parent
37702f50
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
104 additions
and
218 deletions
+104
-218
config.json
v2.0/compileServer/config.json
+64
-0
awards.controller.njk
...Server/templates/controllers/common/awards.controller.njk
+0
-218
stat.controller.ts
v2.0/src/controller/common/stat.controller.ts
+40
-0
No files found.
v2.0/compileServer/config.json
View file @
d4474579
...
...
@@ -275,6 +275,70 @@
}
]
}
},
"stat"
:
{
"addStat"
:
{
"desc"
:
"增加埋点记录"
,
"decorators"
:
[
{
"type"
:
"common"
,
"name"
:
"checkParams"
,
"params"
:
[
"activityId"
,
"type"
]
}
],
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"addStat"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.type"
},
{
"type"
:
"var"
,
"value"
:
"userInfo"
}
],
"return"
:
true
}
]
},
"getStats"
:
{
"desc"
:
"统计数据"
,
"decorators"
:
[
{
"type"
:
"common"
,
"name"
:
"checkParams"
,
"params"
:
[
"activityId"
,
"startDay"
,
"endDay"
]
}
],
"main"
:
[
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"getStats"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.activityId"
},
{
"type"
:
"var"
,
"value"
:
"context.data.startDay"
},
{
"type"
:
"var"
,
"value"
:
"context.data.endDay"
}
]
},
{
"type"
:
"common"
,
"service"
:
"stat"
,
"function"
:
"buildExcel"
,
"params"
:
[
{
"type"
:
"var"
,
"value"
:
"context.data.startDay"
},
{
"type"
:
"var"
,
"value"
:
"context.data.endDay"
},
{
"type"
:
"var"
,
"value"
:
"commonStatGetstatsResult1"
}
],
"return"
:
true
}
]
}
}
}
}
...
...
v2.0/compileServer/templates/controllers/common/awards.controller.njk
deleted
100644 → 0
View file @
37702f50
/** @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 {
/**
* 我的奖品列表
*/
{%- for decorator in model.getMyPrizeList.decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([{% for param in decorator.params -%}'{{ param }}',{%- endfor %}])
{%- endfor %}
@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)
})
}
/**
* 领取实物
*/
{%- for decorator in model.receiveObjectPrize.decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([{% for param in decorator.params -%}'{{ param }}',{%- endfor %}])
{%- endfor %}
@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)
}
/**
* 权益重新领取
*/
{%- for decorator in model.receiveEnamePrize.decorators %}
@{{ decorator.type }}Decorator.{{ decorator.name }}([{% for param in decorator.params -%}'{{ param }}',{%- endfor %}])
{%- endfor %}
@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/stat.controller.ts
0 → 100644
View file @
d4474579
/** @format */
import
commonDecorator
,
{
services
}
from
'../../decorator/common'
import
commonUtilCheck
from
'../../utils/common/check'
import
commonUtilUpdate
from
'../../utils/common/update'
import
{
resultsModel
}
from
'../../sdk'
import
{
StatService
}
from
'../../service'
export
default
class
Stat
{
/**
* 增加埋点记录
*/
@
commonDecorator
.
checkParams
([
'activityId'
,
'type'
])
@
services
([
StatService
])
async
addStat
(
context
:
IContext
<
IParams
>
,
{
activityInfo
,
userInfo
}:
IControllerInfos
,
[
statService
]:
[
StatService
]
)
{
const
commonStatAddstatResult1
=
await
statService
.
addStat
(
context
.
data
.
type
,
userInfo
)
return
resultsModel
.
success
({
...
commonStatAddstatResult1
})
}
/**
* 统计数据
*/
@
commonDecorator
.
checkParams
([
'activityId'
,
'startDay'
,
'endDay'
])
@
services
([
StatService
])
async
getStats
(
context
:
IContext
<
IParams
>
,
{
activityInfo
,
userInfo
}:
IControllerInfos
,
[
statService
]:
[
StatService
]
)
{
const
commonStatGetstatsResult1
=
await
statService
.
getStats
(
context
.
data
.
activityId
,
context
.
data
.
startDay
,
context
.
data
.
endDay
)
const
commonStatBuildexcelResult2
=
await
statService
.
buildExcel
(
context
.
data
.
startDay
,
context
.
data
.
endDay
,
commonStatGetstatsResult1
)
return
resultsModel
.
success
({
...
commonStatBuildexcelResult2
})
}
}
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