Commit b5973b30 authored by maggie's avatar maggie

排行榜开奖

parent 1e833915
......@@ -42,8 +42,9 @@ export const TAOBAO_SUCCESS_ORDER_STATUS: string[] = [
export const ACTIVITY_OPEN_PRIZE_STATUS = {
//开奖状态
AWAIT: 1,
FAIL: 2,
SUCCESS: 3
OPENING: 2,
SUCCESS: 3,
FAIL: 4
}
// 活动状态
......
/** @format */
import { services, checkParams, registeInfos } from '../decorator/common'
import { services, checkParams, registeInfos, noCheckUser } from '../decorator/common'
import { resultsModel } from '../sdk'
import { CommonAwardsService } from '../service/common'
import { CommonAwardsService, CommonBaseService } from '../service/common'
import preCheck from '../decorator/common/preCheck'
import {
checkActivityTime,
......@@ -10,6 +10,7 @@ import {
checkValidEnamePrize,
checkValidObjectPrize
} from '../utils/common/check/'
import { PRIZE_DATA_TYPE } from '../constants'
export interface IReceivePrizeControllerInfos extends IControllerInfos {
awardInfo: IAwards
......@@ -90,4 +91,31 @@ export default class AwardsController {
return resultsModel.success(drawResult)
}
/**
* 活动结束开奖
*/
@noCheckUser
@services([CommonBaseService, CommonAwardsService])
async endOfActivityRewards(
context: IContext<IParams>,
{},
[commonBaseService, commonAwardsService]: [CommonBaseService, CommonAwardsService]
) {
const activityList = await commonBaseService.getNeedRewardsActivityList()
const fail = []
const success = []
for (let activity of activityList) {
const res = await commonAwardsService.openPrize(activity, PRIZE_DATA_TYPE.RANKING, 'sortKey', 'sortTimeKey', 200)
if (res) {
success.push(activity._id)
} else {
fail.push(activity._id)
}
}
return resultsModel.success({
fail,
success
})
}
}
......@@ -13,7 +13,8 @@ import {
ACTIVITY_STATUS,
DELETE_STATUS,
SWICH_TOCK,
SHIP_STATUS
SHIP_STATUS,
ACTIVITY_OPEN_PRIZE_STATUS
} from '../../constants'
import { AWARDS_DB_NAME, PRIZE_CONFIG_DB_NAME } from '../../db'
import { sendTBAward, getSellerSession, rand, formatPrizeProbalityRange } from '../../utils'
......@@ -315,4 +316,65 @@ export default class AwardsService extends UserService {
}
)
}
/**
* 排行榜开奖
* @param activityInfo
*/
async openPrize(activityInfo, prizeDataType, sortKey: string, sortTimeKey: string, limit?: number) {
const { _id } = activityInfo
await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.OPENING } })
const prizeConfigList = await this.getPrizeConfig({
activityId: _id,
prizeDataType
})
const userList = await this.userdao.find<IUserInfo>(
{
activityId: _id
},
{
sort: { [sortKey]: -1, [sortTimeKey]: 1 },
limit: limit || 100
}
)
const prizeList = []
prizeConfigList.forEach(prizeConfig => {
const { rank, _id: prizeId, type, name, image, credits } = prizeConfig
let [min, max] = rank.split('-')
if (!max) max = min
for (let i = +min - 1; i < +max + 1; i++) {
if (userList[i]) {
const { openId, userNick } = userList[i]
prizeList.push({
openId,
prizeId,
activityId: _id,
drawStatus: DRAW_STATUS.WAITAWARD,
prizeDataType,
remark: '',
credits: +credits,
type,
name,
image,
userNick,
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 } })
return true
} else {
await this.activitydao.update({ _id }, { $set: { openPrizeStatus: ACTIVITY_OPEN_PRIZE_STATUS.FAIL } })
return false
}
}
}
......@@ -6,7 +6,7 @@
import { BaseDao, TBAPIS } from '../../sdk'
import { ACTIVITY_CONFIG_DB_NAME } from '../../db'
import { ACTIVITY_STATUS } from '../../constants'
import { ACTIVITY_OPEN_PRIZE_STATUS, ACTIVITY_STATUS } from '../../constants'
export default class BaseService {
context: IContext<any>
......@@ -52,4 +52,14 @@ export default class BaseService {
)
return { list }
}
/**
* 获取需要开奖的活动列表
*/
async getNeedRewardsActivityList() {
return await this.activitydao.find<IActivityInfo>({
endTime: { $lt: Date.now() },
openPrizeStatus: { $in: [ACTIVITY_OPEN_PRIZE_STATUS.AWAIT, ACTIVITY_OPEN_PRIZE_STATUS.FAIL] }
})
}
}
......@@ -20,7 +20,7 @@ interface ICommonActivityPrize {
properiodfrom?: number
lockStatus?: number
switchStock?: number
rank?: string | number
rank?: string
credits?: string | number
useUrl?: string
stock?: number
......
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