返利:修改返利逻辑

This commit is contained in:
luying
2022-09-17 11:44:33 +08:00
parent 3a1e2e08d1
commit 9d9efc451d
5 changed files with 27 additions and 17 deletions

View File

@@ -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);
}
}
}
}
}