✨ feat(37需求): 修改返利逻辑
This commit is contained in:
@@ -1156,6 +1156,7 @@ export enum ITEM_CHANGE_REASON {
|
||||
ACT_WEEKLY_FUND_SIGN = 182, // 周基金签到
|
||||
ACT_MONTHLY_FUND_BUY = 183, // 月基金一次性购买
|
||||
ACT_MONTHLY_FUND_SIGN = 184, // 月基金签到
|
||||
RECEIVE_REBATE = 185, // 领取返利
|
||||
}
|
||||
|
||||
export enum TA_EVENT {
|
||||
|
||||
@@ -671,6 +671,8 @@ export const STATUS = {
|
||||
ACTIVITY_MONTHLY_FUND_HAS_SIGN: { code: 60063, simStr: '本次签到奖励已领取' },
|
||||
ACTIVITY_PUBLIC_ACCOUNT_WAIT: { code: 60064, simStr: '请在公众号输入口令' },
|
||||
ACTIVITY_PUBLIC_ACCOUNT_RECEIVED: { code: 60065, simStr: '已领取' },
|
||||
ACTIVITY_REBATE_DAY_NOT_REACH: { code: 60066, simStr: '暂不可领取' },
|
||||
ACTIVITY_REBATE_HAS_RECEIVED: { code: 60067, simStr: '奖励已领取' },
|
||||
|
||||
// GM后台相关状态 60000 - 69999
|
||||
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
|
||||
|
||||
@@ -1,43 +1,51 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
|
||||
class ReceiveRecord {
|
||||
|
||||
@prop({ required: true })
|
||||
day: number; // 领取的玩家id
|
||||
|
||||
@prop({ required: true })
|
||||
receiveRoleId: string; // 领取的玩家id
|
||||
|
||||
@prop({ required: true })
|
||||
time: Date; // 领取时间
|
||||
}
|
||||
|
||||
/**
|
||||
* 累计充值活动
|
||||
* 返利
|
||||
*/
|
||||
@index({ channelId: 1 })
|
||||
@index({ id: 1 })
|
||||
|
||||
export default class HistoryOrder extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
@prop({ required: false })
|
||||
serverId: number; // 区号
|
||||
|
||||
@prop({ required: true })
|
||||
channelId: string; // 37账号id
|
||||
|
||||
@prop({ required: true })
|
||||
@prop({ required: false })
|
||||
roleId: string; // 当时的玩家id
|
||||
|
||||
@prop({ required: true })
|
||||
@prop({ required: false })
|
||||
roleName: string; // 当时的玩家名
|
||||
|
||||
@prop({ required: true })
|
||||
totalPay: number; // 总支付金额
|
||||
|
||||
@prop({ required: true })
|
||||
isReceived: boolean; // 是否领取
|
||||
|
||||
@prop({ required: true })
|
||||
receiveRoleId: string; // 领取的玩家id
|
||||
@prop({ required: false, type: ReceiveRecord, _id: false })
|
||||
receiveRecords: ReceiveRecord[]; // 是否领取
|
||||
|
||||
public static async findByChannelId(channelId: string) {
|
||||
let result: HistoryOrderModelType[] = await HistoryOrderModel.find({ channelId }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async receive(id: string, roleId: string) {
|
||||
await HistoryOrderModel.findByIdAndUpdate(id, { $set: { isReceived: true, receiveRoleId: roleId } }, { new: true }).lean();
|
||||
}
|
||||
public static async receive(channelId: string, roleId: string, day: number) {
|
||||
await HistoryOrderModel.updateMany({ channelId }, { $push: { receiveRecords: { day, receiveRoleId: roleId, time: new Date() } } }, { new: true });
|
||||
}
|
||||
}
|
||||
|
||||
export const HistoryOrderModel = getModelForClass(HistoryOrder);
|
||||
|
||||
119
shared/domain/activityField/rebateField.ts
Normal file
119
shared/domain/activityField/rebateField.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import moment = require('moment');
|
||||
import { ActivityModelType } from '../../db/Activity';
|
||||
import { HistoryOrderModelType } from '../../db/HistoryOrder';
|
||||
|
||||
import { ActivityBase } from './activityField';
|
||||
import { deltaDays } from '../../pubUtils/util';
|
||||
import { UserType } from '../../db/User';
|
||||
|
||||
// 数据库
|
||||
interface ItemDataInDb {
|
||||
day: number; // 第几天
|
||||
percent: number; // 百分比
|
||||
unitReward: string; // 每1元充值金额对应的奖励
|
||||
}
|
||||
|
||||
interface RebatesDataInDb {
|
||||
rebates: ItemDataInDb[];
|
||||
}
|
||||
|
||||
class ItemData {
|
||||
day: number; // 第几天
|
||||
percent: number; // 百分比,10%在这里填10,这天玩家可以领取的奖励就是 "充值金额*percent/100*unitReward"
|
||||
rewards: string; // type&id&count, 玩家可以领取的奖励
|
||||
unitReward: string; // 单价
|
||||
hasReceived: boolean = false; // 是否已经领取
|
||||
|
||||
constructor(item: ItemDataInDb) {
|
||||
this.day = item.day;
|
||||
this.percent = item.percent;
|
||||
this.unitReward = item.unitReward;
|
||||
}
|
||||
|
||||
public setRewards(totalPay: number) {
|
||||
this.rewards = multiRewards(this.unitReward, totalPay * this.percent / 100);
|
||||
}
|
||||
|
||||
public setHasReceive() {
|
||||
this.hasReceived = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 数据
|
||||
export class RebateData extends ActivityBase {
|
||||
originEndTime: number = 0;
|
||||
rebates: ItemData[] = [];
|
||||
totalPay: number = 0;
|
||||
playerCreateTime: number = 0;
|
||||
channelId: string;
|
||||
|
||||
constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
|
||||
super(activityData, createTime, serverTime);
|
||||
this.initData(activityData.data);
|
||||
this.originEndTime = this.endTime;
|
||||
this.playerCreateTime = createTime;
|
||||
this.nextRefreshTime = moment('2100-01-01').valueOf();
|
||||
this.endTime = moment('2100-01-01').valueOf();
|
||||
this.todayIndex = deltaDays(moment(createTime).toDate(), new Date) + 1;
|
||||
}
|
||||
|
||||
public initData(data: string) {
|
||||
let dataObj: RebatesDataInDb = JSON.parse(data);
|
||||
for(let item of (dataObj?.rebates||[])) this.rebates.push(new ItemData(item));
|
||||
}
|
||||
|
||||
public setPlayerRecords(playerRecords: HistoryOrderModelType[], user: UserType) {
|
||||
for(let record of playerRecords) {
|
||||
this.totalPay += record.totalPay;
|
||||
}
|
||||
for(let rebate of this.rebates) {
|
||||
rebate.setRewards(this.totalPay);
|
||||
}
|
||||
|
||||
if(playerRecords.length > 0) {
|
||||
let { receiveRecords = [] } = playerRecords[0];
|
||||
for(let { day } of receiveRecords) {
|
||||
let rebate = this.findRebateByDay(day);
|
||||
if(rebate) rebate.setHasReceive();
|
||||
}
|
||||
}
|
||||
this.channelId = user.channelId;
|
||||
}
|
||||
|
||||
public findRebateByDay(day: number) {
|
||||
return this.rebates.find(cur => cur.day == day);
|
||||
}
|
||||
|
||||
private checkReceivedAll() {
|
||||
return !this.rebates.find(cur => !cur.hasReceived);
|
||||
}
|
||||
|
||||
public getShowResult() {
|
||||
console.log('###', this.totalPay)
|
||||
if(this.totalPay <= 0) return null;
|
||||
console.log('###', this.checkReceivedAll())
|
||||
if(this.checkReceivedAll()) return null;
|
||||
console.log('###', this.originEndTime, this.playerCreateTime)
|
||||
if(this.originEndTime < this.playerCreateTime) return null;
|
||||
|
||||
return {
|
||||
...this.getBaseKeys(),
|
||||
rebates: this.rebates,
|
||||
originEndTime: this.originEndTime,
|
||||
totalPay: this.totalPay,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function multiRewards(rewards: string, multi: number) {
|
||||
let arr = rewards.split('|');
|
||||
return arr.map(str => {
|
||||
let [type, id, count] = str.split('&')||[];
|
||||
if(type && id && count) {
|
||||
let _count = Math.floor(parseInt(count) * multi);
|
||||
if(isNaN(_count)) return null;
|
||||
return `${type}&${id}&${_count}`;
|
||||
}
|
||||
}).filter(cur => cur).join('|');
|
||||
}
|
||||
@@ -286,5 +286,11 @@
|
||||
"activityType": 52,
|
||||
"name": "MONTHLY_FUND",
|
||||
"string": "月基金"
|
||||
},
|
||||
{
|
||||
"id": 53,
|
||||
"activityType": 53,
|
||||
"name": "REBATE",
|
||||
"string": "返利"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user