Commit 2dbe42a1 authored by qinhaitao's avatar qinhaitao

feat: 🎸 接口数据

parent 0bd83d36
...@@ -108,12 +108,30 @@ export enum STAT_TYPE { ...@@ -108,12 +108,30 @@ export enum STAT_TYPE {
INITE_SUCCESS INITE_SUCCESS
} }
// 集卡阶梯奖励状态
export enum CARD_PRIZE_STATUS { export enum CARD_PRIZE_STATUS {
LOCK = 1, LOCK = 1,
UN_LOCK, UN_LOCK,
SUCCESS SUCCESS
} }
// 免费次数赠送类型
export enum FREE_TYPE {
FOERVER = 1,
EVERY_DAY = 2
}
export enum FEATURE_OPEN_STATUS {
CLOSE = 1,
OPEN = 2
}
export const GIFT_CARD_STATUS = FEATURE_OPEN_STATUS.OPEN
export const TASK_OPEN_STATUS = FEATURE_OPEN_STATUS.OPEN
export const JOIN_NEED_TIMES = 1
export const appId = '${需要补充}' export const appId = '${需要补充}'
// 商铺id 拼接vip链接用 // 商铺id 拼接vip链接用
......
/** @format */ /** @format */
import { PRIZE_DATA_TYPE } from '../constants' import { GIFT_CARD_STATUS, JOIN_NEED_TIMES, PRIZE_DATA_TYPE, TASK_OPEN_STATUS } from '../constants'
import { services, checkParams, preCheck, preUpdate } from '../decorator/common' import { services, checkParams, preCheck, preUpdate } from '../decorator/common'
import { CODE_TYPES } from '../errorCode' import { CODE_TYPES } from '../errorCode'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { CommonCardService, CommonAwardsService } from '../service/common' import { CommonCardService, CommonAwardsService } from '../service/common'
import { getToday } from '../utils'
import { checkActivityTime, checkUserInfo, checkVip, checkInviteId, checkInviteUserCard } from '../utils/common/check' import { checkActivityTime, checkUserInfo, checkVip, checkInviteId, checkInviteUserCard } from '../utils/common/check'
import { updateUserInfo } from '../utils/common/update' import checkCardGameTimes from '../utils/common/check/checkCardGameTimes'
import { reduceCardGameTimes, updateUserInfo } from '../utils/common/update'
export interface ISumitGameControllerInfos extends IControllerInfos { export interface ISumitGameControllerInfos extends IControllerInfos {
joinInfo: IJoinRecord joinInfo: IJoinRecord
...@@ -21,7 +23,7 @@ export default class Card { ...@@ -21,7 +23,7 @@ export default class Card {
[cardService]: [CommonCardService, CommonAwardsService] [cardService]: [CommonCardService, CommonAwardsService]
) { ) {
const { activityId } = context.data const { activityId } = context.data
const { joinedTimes, gameTimes } = userInfo const { joinedTimes, gameTimes, gameTimesEverday } = userInfo
const myCardInfo = cardService.getMyCardInfo(userInfo) const myCardInfo = cardService.getMyCardInfo(userInfo)
...@@ -39,9 +41,13 @@ export default class Card { ...@@ -39,9 +41,13 @@ export default class Card {
myCardInfo.cardTypeCollectedCount myCardInfo.cardTypeCollectedCount
) )
const today = getToday()
return resultsModel.success({ return resultsModel.success({
joinedTimes, joinedTimes,
gameTimes, gameTimes: gameTimes + (gameTimesEverday?.[today] || 0),
giftCardStatus: GIFT_CARD_STATUS,
taskOpenStatus: TASK_OPEN_STATUS,
...myCardInfo, ...myCardInfo,
joinedTimesPrizeList, joinedTimesPrizeList,
collectedCardTypePrizeList collectedCardTypePrizeList
...@@ -50,22 +56,8 @@ export default class Card { ...@@ -50,22 +56,8 @@ export default class Card {
@checkParams(['activityId']) @checkParams(['activityId'])
@services([CommonCardService]) @services([CommonCardService])
@preCheck([ @preCheck([checkActivityTime, checkVip, checkCardGameTimes])
checkActivityTime, @preUpdate([reduceCardGameTimes(JOIN_NEED_TIMES)])
checkVip,
checkUserInfo(
{
gameTimes: { $gte: 1 }
},
CODE_TYPES.ERROR_NO_GAME_TIMES
)
])
@preUpdate([
updateUserInfo({
$where: `this.gameTimes >= 1`,
$inc: { gameTimes: -1 }
})
])
async doJoin(context: IContext<IParams>, { userInfo }: IControllerInfos, [cardService]: [CommonCardService]) { async doJoin(context: IContext<IParams>, { userInfo }: IControllerInfos, [cardService]: [CommonCardService]) {
const { activityId } = context.data const { activityId } = context.data
......
/** @format */ /** @format */
export const customInitUserInfo: ICustomUserInfo = { import { FREE_TYPE } from './constants'
gameTimes: 0, import { getToday } from './utils'
// maxScore: 0,
// totalScore: 0, // login初始化用户信息
export const initCustomUserWhenLogin = (context: IContext<IParams>, activityInfo: IActivityInfo): ICustomUserInfo => {
const { freeTimes, freeType } = activityInfo?.collectCardConfig || {}
return {
gameTimes: freeType === FREE_TYPE.FOERVER ? freeTimes : 0,
gameTimesEverday: {
[getToday()]: freeType === FREE_TYPE.EVERY_DAY ? freeTimes : 0
},
joinedTimes: 0, joinedTimes: 0,
cardsCollectedCount: 0, cardsCollectedCount: 0,
cardInfo: {} cardInfo: {}
}
}
export const updateUserWhenLogin = (
context: IContext<IParams>,
activityInfo: IActivityInfo,
userInfo: IUserInfo
): IUpdateQuery => {
const { freeTimes, freeType } = activityInfo?.collectCardConfig || {}
const today = getToday()
let projection: IUpdateQuery = {
$inc: {}
}
const firstLoginToday = !userInfo?.login?.[today]
if (firstLoginToday && freeType === FREE_TYPE.EVERY_DAY) {
projection.$inc[`gameTimesEverday.${today}`] = freeTimes
}
return projection
} }
...@@ -254,7 +254,7 @@ export default class AwardsService extends UserService { ...@@ -254,7 +254,7 @@ export default class AwardsService extends UserService {
prize = thanksPrize prize = thanksPrize
} }
const { type, _id, ename, image, name, useUrl } = prize const { type, _id, ename, image, name, useUrl, credits } = prize
const { userNick } = userInfo const { userNick } = userInfo
let record = { let record = {
...@@ -269,6 +269,7 @@ export default class AwardsService extends UserService { ...@@ -269,6 +269,7 @@ export default class AwardsService extends UserService {
ename, ename,
name, name,
image, image,
credits: +credits,
userNick, userNick,
createDay: getToday() createDay: getToday()
} }
......
...@@ -7,13 +7,14 @@ ...@@ -7,13 +7,14 @@
import { BaseDao } from '../../sdk' import { BaseDao } from '../../sdk'
import BaseService from './base.service' import BaseService from './base.service'
import { USER_DB_NAME } from '../../db' import { USER_DB_NAME } from '../../db'
import { customInitUserInfo } from '../../customUser' import { initCustomUserWhenLogin, updateUserWhenLogin } from '../../customUser'
import { getToday, formatUpdateUserProjection, initCustomUser } from '../../utils' import { getToday, formatUpdateUserProjection } from '../../utils'
import { isNewVip } from '../../utils/common/userUpdate' import { isNewVip } from '../../utils/common/userUpdate'
import { formatUserNick, formatUpdatedDataByProjection } from '../../utils/common/format' import { formatUserNick, formatUpdatedDataByProjection } from '../../utils/common/format'
import { setNewFollowUserData, setNewVipUserData } from '../../utils/common/userUpdate' import { setNewFollowUserData, setNewVipUserData } from '../../utils/common/userUpdate'
import { getShopVip, formatVipCbUrl } from '../../utils/common/vip' import { getShopVip, formatVipCbUrl } from '../../utils/common/vip'
import { get } from 'mpath' import { get } from 'mpath'
import { merge } from 'lodash'
class UserService extends BaseService { class UserService extends BaseService {
userdao: IBaseDao userdao: IBaseDao
...@@ -45,7 +46,7 @@ class UserService extends BaseService { ...@@ -45,7 +46,7 @@ class UserService extends BaseService {
async doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo) { async doLogin(userInfo: IUserInfo, vipInfo: IVipInfo, activityInfo: IActivityInfo) {
if (!userInfo) { if (!userInfo) {
const customUserInfo = initCustomUser(this.context, activityInfo, customInitUserInfo) const customUserInfo = initCustomUserWhenLogin(this.context, activityInfo)
userInfo = await this.initUserData(vipInfo, activityInfo, customUserInfo) userInfo = await this.initUserData(vipInfo, activityInfo, customUserInfo)
} else { } else {
userInfo = await this.updateUserData(vipInfo, userInfo, activityInfo) userInfo = await this.updateUserData(vipInfo, userInfo, activityInfo)
...@@ -135,7 +136,7 @@ class UserService extends BaseService { ...@@ -135,7 +136,7 @@ class UserService extends BaseService {
const { isFollow } = data const { isFollow } = data
const today = getToday() const today = getToday()
let projection = { let projection: IUpdateQuery = {
$set: { $set: {
updateTime: Date.now() updateTime: Date.now()
}, },
...@@ -153,7 +154,6 @@ class UserService extends BaseService { ...@@ -153,7 +154,6 @@ class UserService extends BaseService {
const followBefore = userInfo.follow.flag const followBefore = userInfo.follow.flag
const followNow = isFollow const followNow = isFollow
if (!followBefore && followNow && !userInfo.follow.newFollow) { if (!followBefore && followNow && !userInfo.follow.newFollow) {
// @ts-ignore
projection.$set.follow = setNewFollowUserData(userInfo.follow) projection.$set.follow = setNewFollowUserData(userInfo.follow)
projection.$push[`taskInfo.${today}.follow`] = { createTime: Date.now() } projection.$push[`taskInfo.${today}.follow`] = { createTime: Date.now() }
projection.$inc[`remainTimes.follow`] = follow.value projection.$inc[`remainTimes.follow`] = follow.value
...@@ -162,12 +162,13 @@ class UserService extends BaseService { ...@@ -162,12 +162,13 @@ class UserService extends BaseService {
// 之前进入活动非会员,现在进入会员,则视为新会员用户 // 之前进入活动非会员,现在进入会员,则视为新会员用户
const newVip = isNewVip(userInfo, vipInfo) const newVip = isNewVip(userInfo, vipInfo)
if (newVip) { if (newVip) {
// @ts-ignore
projection.$set.member = setNewVipUserData(userInfo.member) projection.$set.member = setNewVipUserData(userInfo.member)
projection.$push[`taskInfo.${today}.member`] = { createTime: Date.now() } projection.$push[`taskInfo.${today}.member`] = { createTime: Date.now() }
projection.$inc[`remainTimes.member`] = member.value projection.$inc[`remainTimes.member`] = member.value
} }
projection = merge({}, projection, updateUserWhenLogin(this.context, activityInfo, userInfo))
await this.updateUser(userInfo._id, projection) await this.updateUser(userInfo._id, projection)
return formatUpdatedDataByProjection(userInfo, projection) return formatUpdatedDataByProjection(userInfo, projection)
......
...@@ -26,6 +26,7 @@ interface ICommonAwards { ...@@ -26,6 +26,7 @@ interface ICommonAwards {
area?: string area?: string
receiveTime?: number receiveTime?: number
shipStatus?: number shipStatus?: number
credtis?: number
shipCompany?: string shipCompany?: string
shipNum?: string | number shipNum?: string | number
remark: string remark: string
......
...@@ -9,6 +9,9 @@ interface ICustomUserInfo { ...@@ -9,6 +9,9 @@ interface ICustomUserInfo {
updateScoreTime?: number updateScoreTime?: number
// 集卡 // 集卡
joinedTimes?: number joinedTimes?: number
gameTimesEverday?: {
[key: string]: number
}
cardsCollectedCount?: number cardsCollectedCount?: number
cardInfo: { cardInfo: {
[key: string]: number [key: string]: number
......
/** @format */
import { resultsModel } from '../../../sdk'
import { CODE_TYPES } from '../../../errorCode'
import { getToday } from '../getToday'
export default async function checkCardGameTimes(context: IContext<IParams>, { vipInfo, userInfo }: IControllerInfos) {
const { gameTimes, gameTimesEverday } = userInfo
const today = getToday()
if (!gameTimesEverday?.[today] && !gameTimes) {
return CODE_TYPES.ERROR_NO_GAME_TIMES
}
}
...@@ -13,6 +13,8 @@ import checkUserInfo, { checkGameTimes } from './checkUserInfo' ...@@ -13,6 +13,8 @@ import checkUserInfo, { checkGameTimes } from './checkUserInfo'
import checkJoinId from './checkJoinId' import checkJoinId from './checkJoinId'
import checkOpenPrizeStatus from './checkOpenPrizeStatus' import checkOpenPrizeStatus from './checkOpenPrizeStatus'
import checkInviteUserCard from './checkInviteUserCard' import checkInviteUserCard from './checkInviteUserCard'
import checkCardGameTimes from './checkCardGameTimes'
const check = { const check = {
checkActivityTime, checkActivityTime,
checkExchangeCreditsTask, checkExchangeCreditsTask,
...@@ -30,7 +32,8 @@ const check = { ...@@ -30,7 +32,8 @@ const check = {
checkJoinId, checkJoinId,
checkGameTimes, checkGameTimes,
checkOpenPrizeStatus, checkOpenPrizeStatus,
checkInviteUserCard checkInviteUserCard,
checkCardGameTimes
} }
export default check export default check
...@@ -52,5 +55,6 @@ export { ...@@ -52,5 +55,6 @@ export {
checkJoinId, checkJoinId,
checkGameTimes, checkGameTimes,
checkOpenPrizeStatus, checkOpenPrizeStatus,
checkInviteUserCard checkInviteUserCard,
checkCardGameTimes
} }
/** @format */
export const initCustomUser = (
context: IContext<IParams>,
activityInfo: IActivityInfo,
customUserInfo: ICustomUserInfo
) => {
return {
...customUserInfo,
gameTimes: activityInfo?.collectCardConfig?.freeTimes || 0
}
}
...@@ -3,7 +3,7 @@ import updateVip from './updateVip' ...@@ -3,7 +3,7 @@ import updateVip from './updateVip'
import updateSignTask from './updateSignTask' import updateSignTask from './updateSignTask'
import updateOrderGoods from './updateOrderGoods' import updateOrderGoods from './updateOrderGoods'
import updateFirstLoginToday from './updateFirstLoginToday' import updateFirstLoginToday from './updateFirstLoginToday'
import updateUserInfo, { reduceGameTimes } from './updateUserInfo' import updateUserInfo, { reduceGameTimes, reduceCardGameTimes } from './updateUserInfo'
const update = { const update = {
updateVip, updateVip,
...@@ -11,9 +11,18 @@ const update = { ...@@ -11,9 +11,18 @@ const update = {
updateOrderGoods, updateOrderGoods,
updateFirstLoginToday, updateFirstLoginToday,
updateUserInfo, updateUserInfo,
reduceGameTimes reduceGameTimes,
reduceCardGameTimes
} }
export default update export default update
export { updateVip, updateSignTask, updateOrderGoods, updateFirstLoginToday, updateUserInfo, reduceGameTimes } export {
updateVip,
updateSignTask,
updateOrderGoods,
updateFirstLoginToday,
updateUserInfo,
reduceGameTimes,
reduceCardGameTimes
}
...@@ -13,9 +13,33 @@ export default function updateUserInfo(update?: IPreUpdateQuery) { ...@@ -13,9 +13,33 @@ export default function updateUserInfo(update?: IPreUpdateQuery) {
} }
} }
export function reduceGameTimes(gameTimes: number) { export function reduceGameTimes(needGameTimes: number) {
return updateUserInfo({ return updateUserInfo({
$where: `this.gameTimes >= ${gameTimes}`, $where: `this.gameTimes >= ${needGameTimes}`,
$inc: { gameTimes: -gameTimes } $inc: { gameTimes: -needGameTimes }
}) })
} }
export function reduceCardGameTimes(needGameTimes: number) {
return async function (
context: IContext<IParams>,
{ userInfo }: IControllerInfos
): Promise<IPreUpdateQuery | undefined> {
if (!userInfo) return {}
let projection: IPreUpdateQuery = { $inc: {} }
const today = getToday()
const { gameTimes, gameTimesEverday } = userInfo
if (gameTimesEverday?.[today]) {
projection.$inc[`gameTimesEverday.${today}`] = -needGameTimes
projection.$where[`this.gameTimesEverday.${today} >= ${needGameTimes}`] = -needGameTimes
return projection
}
if (gameTimes) {
projection.$inc[`gameTimes`] = -needGameTimes
projection.$where[`this.gameTimes >= ${needGameTimes}`] = -needGameTimes
return projection
}
}
}
...@@ -27,5 +27,3 @@ export * from './common/userUpdate' ...@@ -27,5 +27,3 @@ export * from './common/userUpdate'
export * from './common/format' export * from './common/format'
export * from './common/doHandler' export * from './common/doHandler'
export * from './common/initCustomUser'
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