返利:修改返利逻辑
This commit is contained in:
@@ -32,7 +32,7 @@ import { makeTaskPass } from './activity/taskPassService';
|
||||
import { addGuildPay } from './activity/guildPayService';
|
||||
import { sendMessageToUserWithSuc } from './pushService';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { checkParamPrice } from '../pubUtils/sdkUtil';
|
||||
import { checkParamPrice, needRebate } from '../pubUtils/sdkUtil';
|
||||
import { checkShopCanBuyInOrder, makeShopOrder } from './shopService';
|
||||
import { UserModel } from '../db/User';
|
||||
import { HistoryOrderModel } from '../db/HistoryOrder';
|
||||
@@ -359,18 +359,22 @@ export async function refundOrderFromRedisPub(message: string) {
|
||||
export async function rebateHistoryOrder(roleId: string, uid: number) {
|
||||
let user = await UserModel.findUserByUid(uid);
|
||||
if(user) {
|
||||
let historyOrder = await HistoryOrderModel.findByChannelId(user.channelId);
|
||||
if(historyOrder && !historyOrder.isReceived) {
|
||||
let totalPay = historyOrder.totalPay;
|
||||
if(totalPay > 0) {
|
||||
let gold = 0;
|
||||
let goods = parseGoodStr(RECHARGE.RECHARGE_RMB_RETURN_RATIO).map(({ id, count }) => {
|
||||
let result = Math.floor(count * totalPay)
|
||||
gold += result;
|
||||
return { id, count: result }
|
||||
});
|
||||
await sendMailByContent(MAIL_TYPE.REBATE, roleId, { goods, params: [`${totalPay}`, `${gold}`] });
|
||||
await HistoryOrderModel.receive(user.channelId, roleId);
|
||||
let historyOrders = await HistoryOrderModel.findByChannelId(user.channelId);
|
||||
if(needRebate() && historyOrders.length > 0) {
|
||||
for(let historyOrder of historyOrders) {
|
||||
if(!historyOrder.isReceived) {
|
||||
let totalPay = historyOrder.totalPay;
|
||||
if(totalPay > 0) {
|
||||
let gold = 0;
|
||||
let goods = parseGoodStr(RECHARGE.RECHARGE_RMB_RETURN_RATIO).map(({ id, count }) => {
|
||||
let result = Math.floor(count * totalPay)
|
||||
gold += result;
|
||||
return { id, count: result }
|
||||
});
|
||||
await sendMailByContent(MAIL_TYPE.REBATE, roleId, { goods, params: [`${totalPay}`, `${gold}`] });
|
||||
await HistoryOrderModel.receive(user.channelId, roleId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,12 @@ export default class HistoryOrder extends BaseModel {
|
||||
receiveRoleId: string; // 领取的玩家id
|
||||
|
||||
public static async findByChannelId(channelId: string) {
|
||||
let result: HistoryOrderModelType = await HistoryOrderModel.findOne({ channelId }).lean();
|
||||
let result: HistoryOrderModelType[] = await HistoryOrderModel.find({ channelId }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async receive(channelId: string, roleId: string) {
|
||||
let result: HistoryOrderModelType = await HistoryOrderModel.findOneAndUpdate({ channelId }, { $set: { isReceived: true, receiveRoleId: roleId } }, { new: true }).lean();
|
||||
return result;
|
||||
await HistoryOrderModel.updateMany({ channelId }, { $set: { isReceived: true, receiveRoleId: roleId } }, { new: true }).lean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ export interface DicServerConst {
|
||||
readonly ACCESS_CODE_EXPIRE_TIME: number;
|
||||
// 是否跳过加密
|
||||
readonly SKIP_ENCODE: number;
|
||||
// 是否返利
|
||||
readonly NEED_REBATE: number;
|
||||
}
|
||||
|
||||
export const dicServerConst: DicServerConst = {} as DicServerConst;
|
||||
|
||||
@@ -165,4 +165,8 @@ export function canPay() {
|
||||
|
||||
export function isSkipEncode(isDevelop = false) {
|
||||
return gameData.serverConst.SKIP_ENCODE === 1 && isDevelop;
|
||||
}
|
||||
|
||||
export function needRebate() {
|
||||
return gameData.serverConst.NEED_REBATE == 1;
|
||||
}
|
||||
@@ -22,5 +22,6 @@
|
||||
"DEBUG_TIME": 1,
|
||||
"CHECK_WORD": 1,
|
||||
"CAN_PAY": 1,
|
||||
"SKIP_ENCODE": 0
|
||||
"SKIP_ENCODE": 0,
|
||||
"NEED_REBATE": 0
|
||||
}
|
||||
Reference in New Issue
Block a user