Commit 2dbe42a1 authored by qinhaitao's avatar qinhaitao

feat: 🎸 接口数据

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