Commit 0bf31793 authored by maggie's avatar maggie

排行榜开奖

parent 3ea93a86
...@@ -559,6 +559,37 @@ ...@@ -559,6 +559,37 @@
"return": true "return": true
} }
] ]
},
"endOfActivityRewards": {
"desc": "排行榜开奖",
"decorators": [
{
"type": "common",
"name": "noCheckUser"
}
],
"main": [
{
"type": "common",
"service": "base",
"function": "getNeedRewardsActivityList",
"params": [],
"return": false
},
{
"type": "common",
"service": "awards",
"function": "openPrize",
"params": [
{ "type": "var", "value": "commonBaseGetNeedRewardsActivityListResult1" },
{ "type": "var", "value": 1 },
{ "value": "sortKey" },
{ "value": "sortTimeKey" },
{ "type": "var", "value": 200 }
],
"return": true
}
]
} }
}, },
"share": { "share": {
......
...@@ -109,7 +109,6 @@ export enum STAT_TYPE { ...@@ -109,7 +109,6 @@ export enum STAT_TYPE {
INITE_SUCCESS INITE_SUCCESS
} }
// 每次参与消耗次数 // 每次参与消耗次数
export const JOIN_NEED_TIMES = 1 export const JOIN_NEED_TIMES = 1
......
...@@ -103,19 +103,15 @@ export default class AwardsController { ...@@ -103,19 +103,15 @@ export default class AwardsController {
[commonBaseService, commonAwardsService]: [CommonBaseService, CommonAwardsService] [commonBaseService, commonAwardsService]: [CommonBaseService, CommonAwardsService]
) { ) {
const activityList = await commonBaseService.getNeedRewardsActivityList() const activityList = await commonBaseService.getNeedRewardsActivityList()
const fail = [] const openResult = await commonAwardsService.openPrize(
const success = [] activityList,
for (let activity of activityList) { PRIZE_DATA_TYPE.RANKING,
const res = await commonAwardsService.openPrize(activity, PRIZE_DATA_TYPE.RANKING, 'sortKey', 'sortTimeKey', 200) 'sortKey',
if (res) { 'sortTimeKey',
success.push(activity._id) 200
} else { )
fail.push(activity._id)
}
}
return resultsModel.success({ return resultsModel.success({
fail, ...openResult
success
}) })
} }
} }
/** @format */ /** @format */
import { services, checkParams, preCheck, registeInfos } from '../../decorator/common' import { services, checkParams, preCheck, registeInfos, noCheckUser } from '../../decorator/common'
import { import {
checkPrizeExpired, checkPrizeExpired,
checkValidObjectPrize, checkValidObjectPrize,
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
} from '../../utils/common/check' } from '../../utils/common/check'
import customUtil from '../../utils/custom' import customUtil from '../../utils/custom'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { CommonAwardsService } from '../../service/common' import { CommonAwardsService, CommonBaseService } from '../../service/common'
export default class AwardsController { export default class AwardsController {
/** /**
...@@ -86,4 +86,26 @@ export default class AwardsController { ...@@ -86,4 +86,26 @@ export default class AwardsController {
...commonAwardsDrawLotteryResult1 ...commonAwardsDrawLotteryResult1
}) })
} }
/**
* 排行榜开奖
*/
@noCheckUser
@services([CommonBaseService, CommonAwardsService])
async endOfActivityRewards(
context: IContext<IParams>,
{ activityInfo, userInfo }: IControllerInfos,
[commonBaseService, commonAwardsService]: [CommonBaseService, CommonAwardsService]
) {
const commonBaseGetNeedRewardsActivityListResult1 = await commonBaseService.getNeedRewardsActivityList()
const commonAwardsOpenPrizeResult2 = await commonAwardsService.openPrize(
commonBaseGetNeedRewardsActivityListResult1,
1,
'sortKey',
'sortTimeKey',
200
)
return resultsModel.success({
...commonAwardsOpenPrizeResult2
})
}
} }
...@@ -33,6 +33,7 @@ export default { ...@@ -33,6 +33,7 @@ export default {
receiveObjectPrize: CommonAwardsControllerInstance.receiveObjectPrize, receiveObjectPrize: CommonAwardsControllerInstance.receiveObjectPrize,
receiveEnamePrize: CommonAwardsControllerInstance.receiveEnamePrize, receiveEnamePrize: CommonAwardsControllerInstance.receiveEnamePrize,
drawLotteryPrize: CommonAwardsControllerInstance.drawLotteryPrize, drawLotteryPrize: CommonAwardsControllerInstance.drawLotteryPrize,
endOfActivityRewards: CommonAwardsControllerInstance.endOfActivityRewards,
getShareInfo: CommonShareControllerInstance.getShareInfo, getShareInfo: CommonShareControllerInstance.getShareInfo,
doHelp: CommonShareControllerInstance.doHelp, doHelp: CommonShareControllerInstance.doHelp,
testAddStat: CustomTest1ControllerInstance.testAddStat, testAddStat: CustomTest1ControllerInstance.testAddStat,
......
...@@ -325,60 +325,65 @@ export default class AwardsService extends UserService { ...@@ -325,60 +325,65 @@ export default class AwardsService extends UserService {
* @param sortTimeKey * @param sortTimeKey
* @param limit * @param limit
*/ */
async openPrize(activityInfo, prizeDataType, sortKey: string, sortTimeKey: string, limit?: number) { async openPrize(activityList, prizeDataType, sortKey: string, sortTimeKey: string, limit?: number) {
const { _id } = activityInfo const fail = []
await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.OPENING } }) const success = []
const prizeConfigList = await this.getPrizeConfig({ for (let activityInfo of activityList) {
activityId: _id, const { _id } = activityInfo
prizeDataType await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.OPENING } })
}) const prizeConfigList = await this.getPrizeConfig({
const userList = await this.userdao.find<IUserInfo>( activityId: _id,
{ prizeDataType
activityId: _id })
}, const userList = await this.userdao.find<IUserInfo>(
{ {
sort: { [sortKey]: -1, [sortTimeKey]: 1 }, activityId: _id
limit: limit || 100 },
} {
) sort: { [sortKey]: -1, [sortTimeKey]: 1 },
const prizeList = [] limit: limit || 100
prizeConfigList.forEach(prizeConfig => { }
const { rank, _id: prizeId, type, name, image, credits } = prizeConfig )
let [min, max] = rank.split('-') const prizeList = []
if (!max) max = min prizeConfigList.forEach(prizeConfig => {
for (let i = +min - 1; i < +max + 1; i++) { const { rank, _id: prizeId, type, name, image, credits } = prizeConfig
if (userList[i]) { let [min, max] = rank.split('-')
const { openId, userNick } = userList[i] if (!max) max = min
prizeList.push({ for (let i = +min - 1; i < +max + 1; i++) {
openId, if (userList[i]) {
prizeId, const { openId, userNick } = userList[i]
activityId: _id, prizeList.push({
drawStatus: DRAW_STATUS.WAITAWARD, openId,
prizeDataType, prizeId,
remark: '', activityId: _id,
credits: +credits, drawStatus: DRAW_STATUS.WAITAWARD,
type, prizeDataType,
name, remark: '',
image, credits: +credits,
userNick, type,
createDay: getToday(), name,
shipStatus: type === PRIZE_TYPE.OBJECT ? SHIP_STATUS.NO_ADDRESS : '', image,
createTime: Date.now(), userNick,
updateTime: Date.now() createDay: getToday(),
}) shipStatus: type === PRIZE_TYPE.OBJECT ? SHIP_STATUS.NO_ADDRESS : '',
createTime: Date.now(),
updateTime: Date.now()
})
}
} }
})
let result = null
if (prizeList.length) {
result = await this.awardsdao.insertMany(prizeList)
}
if (result) {
await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.SUCCESS } })
success.push(_id)
} else {
await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.FAIL } })
fail.push(_id)
} }
})
let result = null
if (prizeList.length) {
result = await this.awardsdao.insertMany(prizeList)
}
if (result) {
await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.SUCCESS } })
return true
} else {
await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.FAIL } })
return false
} }
return { success, fail }
} }
} }
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
type IActivityInfo = ICommonActivityInfo & ICustomActivityInfo type IActivityInfo = ICommonActivityInfo & ICustomActivityInfo
interface ICustomActivityInfo { interface ICustomActivityInfo {}
}
interface ICommonActivityInfo { interface ICommonActivityInfo {
_id?: string _id?: string
id?: string id?: string
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
type IAwards = ICommonAwards & ICustomAwards type IAwards = ICommonAwards & ICustomAwards
interface ICustomAwards { interface ICustomAwards {}
}
interface ICommonAwards { interface ICommonAwards {
_id?: string _id?: string
id?: string id?: string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment