Commit e50a7390 authored by qinhaitao's avatar qinhaitao

feat: 🎸 发奖情况

parent 610099a0
No preview for this file type
...@@ -39,6 +39,13 @@ export const TAOBAO_SUCCESS_ORDER_STATUS: string[] = [ ...@@ -39,6 +39,13 @@ export const TAOBAO_SUCCESS_ORDER_STATUS: string[] = [
'PAID_FORBID_CONSIGN' 'PAID_FORBID_CONSIGN'
] ]
export const ACTIVITY_OPEN_PRIZE_STATUS = {
//开奖状态
AWAIT: 1,
FAIL: 2,
SUCCESS: 3
}
// 活动状态 // 活动状态
export const enum ACTIVITY_STATUS { export const enum ACTIVITY_STATUS {
NORMAL = 1, NORMAL = 1,
......
...@@ -3,7 +3,14 @@ ...@@ -3,7 +3,14 @@
import { services, checkParams, preCheck, preUpdate } from '../decorator/common' import { services, checkParams, preCheck, preUpdate } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { CommonUserService, CommonGameService } from '../service/common' import { CommonUserService, CommonGameService } from '../service/common'
import { checkActivityTime, checkJoinId, checkUserInfo, checkVip, checkGameTimes } from '../utils/common/check' import {
checkActivityTime,
checkJoinId,
checkUserInfo,
checkVip,
checkGameTimes,
checkOpenPrizeStatus
} from '../utils/common/check'
import { updateUserInfo, reduceGameTimes } from '../utils/common/update' import { updateUserInfo, reduceGameTimes } from '../utils/common/update'
export interface ISumitGameControllerInfos extends IControllerInfos { export interface ISumitGameControllerInfos extends IControllerInfos {
...@@ -46,19 +53,33 @@ export default class Game { ...@@ -46,19 +53,33 @@ export default class Game {
}) })
} }
@checkParams(['activityId', 'id', 'score']) @checkParams(['activityId', 'id', 'score', 'rankKey?', 'timeKey?'])
@services([CommonGameService]) @services([CommonGameService])
@preCheck([checkJoinId]) @preCheck([checkJoinId])
async submitGame( async submitGame(
context: IContext<IParams>, context: IContext<IParams>,
{ userInfo, joinInfo }: ISumitGameControllerInfos, { userInfo }: ISumitGameControllerInfos,
[gameService]: [CommonGameService] [gameService]: [CommonGameService],
{ joinInfo }: IPreCheckData
) { ) {
const { id, score } = context.data const { id, score, rankKey = 'totalScore', timeKey = 'updateScoreTime' } = context.data
const rankKey = 'totalScore' const result = await gameService.submitGame(id, score, rankKey, timeKey, userInfo, joinInfo)
const rankTime = 'updateScoreTime'
const result = await gameService.submitGame(id, score, rankKey, rankTime, userInfo, joinInfo)
return resultsModel.success(result) return resultsModel.success(result)
} }
@checkParams(['activityId', 'rankKey?', 'timeKey?'])
@services([CommonGameService])
@preCheck([checkOpenPrizeStatus])
async getMyRankPrize(
context: IContext<IParams>,
{ userInfo, activityInfo }: IControllerInfos,
[gameService]: [CommonGameService]
) {
const { rankKey = 'totalScore', timeKey = 'updateScoreTime' } = context.data
const myRankInfo = await gameService.getMyRankInfo(rankKey, timeKey, userInfo)
return resultsModel.success({})
}
} }
...@@ -38,14 +38,14 @@ export default class User { ...@@ -38,14 +38,14 @@ export default class User {
/** /**
* 获取排行榜 * 获取排行榜
*/ */
@checkParams(['activityId', 'key?', 'timeKey?', 'limit?']) @checkParams(['activityId', 'rankKey?', 'timeKey?', 'limit?'])
@services([CommonUserService]) @services([CommonUserService])
async getRankList(context: IContext<IParams>, { userInfo }: IControllerInfos, [userService]: [CommonUserService]) { async getRankList(context: IContext<IParams>, { userInfo }: IControllerInfos, [userService]: [CommonUserService]) {
const { key = 'totalScore', timeKey = 'updateScoreTime', limit = 200 } = context.data const { rankKey = 'totalScore', timeKey = 'updateScoreTime', limit = 200 } = context.data
const rankInfo = await userService.getMyRankInfo(key, timeKey, userInfo) const rankInfo = await userService.getMyRankInfo(rankKey, timeKey, userInfo)
const list = await userService.getRank(key, timeKey, limit) const list = await userService.getRank(rankKey, timeKey, limit)
return resultsModel.success({ return resultsModel.success({
...rankInfo, ...rankInfo,
......
...@@ -23,6 +23,16 @@ export const BusinessError = { ...@@ -23,6 +23,16 @@ export const BusinessError = {
code: `220003`, code: `220003`,
defaultMsg: `活动已结束` defaultMsg: `活动已结束`
}, },
// 活动未结束
ERROR_ACTIVITY_NO_OVER: {
code: `220004`,
defaultMsg: `活动未结束`
},
// 活动已开奖
ERROR_ACTIVITY_OPENED_PRIZE: {
code: `220005`,
defaultMsg: `活动已开奖`
},
// 用户不存在 // 用户不存在
ERROR_NO_USER: { ERROR_NO_USER: {
code: `310002`, code: `310002`,
......
/** @format */
import { resultsModel } from '../../../sdk'
import { CODE_TYPES } from '../../../errorCode'
import { ACTIVITY_OPEN_PRIZE_STATUS } from '../../../constants'
// 检查开奖
export default async function checkOpenPrizeStatus(context: IContext<IParams>, { activityInfo }: IControllerInfos) {
const now = Date.now()
const { startTime, endTime, openPrizeStatus } = activityInfo
// 活动未结束
if (endTime > now) {
return resultsModel.error(CODE_TYPES.ERROR_ACTIVITY_NO_OVER, '活动未结束')
}
if (now < startTime) {
return resultsModel.error(CODE_TYPES.ERROR_ACTIVITY_NOSTART, `活动未开始`)
}
if (openPrizeStatus === ACTIVITY_OPEN_PRIZE_STATUS.SUCCESS) {
return resultsModel.error(CODE_TYPES.ERROR_ACTIVITY_OPENED_PRIZE, `活动已开奖`)
}
}
...@@ -11,6 +11,7 @@ import checkValidPrize, { checkValidEnamePrize, checkValidObjectPrize } from './ ...@@ -11,6 +11,7 @@ import checkValidPrize, { checkValidEnamePrize, checkValidObjectPrize } from './
import checkVip from './checkVip' import checkVip from './checkVip'
import checkUserInfo, { checkGameTimes } from './checkUserInfo' import checkUserInfo, { checkGameTimes } from './checkUserInfo'
import checkJoinId from './checkJoinId' import checkJoinId from './checkJoinId'
import checkOpenPrizeStatus from './checkOpenPrizeStatus'
const check = { const check = {
checkActivityTime, checkActivityTime,
...@@ -27,7 +28,8 @@ const check = { ...@@ -27,7 +28,8 @@ const check = {
checkVip, checkVip,
checkUserInfo, checkUserInfo,
checkJoinId, checkJoinId,
checkGameTimes checkGameTimes,
checkOpenPrizeStatus
} }
export default check export default check
...@@ -47,5 +49,6 @@ export { ...@@ -47,5 +49,6 @@ export {
checkVip, checkVip,
checkUserInfo, checkUserInfo,
checkJoinId, checkJoinId,
checkGameTimes checkGameTimes,
checkOpenPrizeStatus
} }
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