|
@@ -22,8 +22,8 @@ class CashBackService extends CrudService {
|
|
const min = this.ctx.multiply(rd, this.ctx.multiply(24, 60));
|
|
const min = this.ctx.multiply(rd, this.ctx.multiply(24, 60));
|
|
let total = 0;
|
|
let total = 0;
|
|
for (const i of res) {
|
|
for (const i of res) {
|
|
- const { source, money } = i;
|
|
|
|
- const sn = parseInt(source);
|
|
|
|
|
|
+ const { status, money } = i;
|
|
|
|
+ const sn = parseInt(status);
|
|
if (sn >= 0) total = this.ctx.plus(total, money);
|
|
if (sn >= 0) total = this.ctx.plus(total, money);
|
|
else total = this.ctx.minus(total, money);
|
|
else total = this.ctx.minus(total, money);
|
|
}
|
|
}
|
|
@@ -31,10 +31,10 @@ class CashBackService extends CrudService {
|
|
// 上面总价包含了提现金额
|
|
// 上面总价包含了提现金额
|
|
// 下面计算的金额是可以提现的金额 提现总金额 - 提现金额
|
|
// 下面计算的金额是可以提现的金额 提现总金额 - 提现金额
|
|
let canGet = 0;
|
|
let canGet = 0;
|
|
- const inBill = res.filter(f => parseInt(f.source) >= 0);
|
|
|
|
- const outBill = res.filter(f => parseInt(f.source) < 0);
|
|
|
|
- const getOutBill = res.filter(f => f.source === '-1');
|
|
|
|
- const outBillMoney = getOutBill.reduce((p, n) => this.ctx.plus(p, n.money), 0);
|
|
|
|
|
|
+ const inBill = res.filter(f => parseInt(f.status) >= 0);
|
|
|
|
+ const outBill = res.filter(f => parseInt(f.status) < 0);
|
|
|
|
+ // const getOutBill = res.filter(f => f.status === '-1');
|
|
|
|
+ // const outBillMoney = getOutBill.reduce((p, n) => this.ctx.plus(p, n.money), 0);
|
|
for (const i of inBill) {
|
|
for (const i of inBill) {
|
|
const cAt = _.get(i, 'time');
|
|
const cAt = _.get(i, 'time');
|
|
const m = moment().diff(cAt, 'm');
|
|
const m = moment().diff(cAt, 'm');
|
|
@@ -49,7 +49,7 @@ class CashBackService extends CrudService {
|
|
canGet = this.ctx.plus(canGet, cg);
|
|
canGet = this.ctx.plus(canGet, cg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- canGet = this.ctx.minus(canGet, outBillMoney);
|
|
|
|
|
|
+ // canGet = this.ctx.minus(canGet, outBillMoney);
|
|
return { total, canGet };
|
|
return { total, canGet };
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -78,11 +78,13 @@ class CashBackService extends CrudService {
|
|
const type = _.get(cb_config, 'back_type');
|
|
const type = _.get(cb_config, 'back_type');
|
|
if (!type) continue;
|
|
if (!type) continue;
|
|
const money = _.get(cb_config, 'money');
|
|
const money = _.get(cb_config, 'money');
|
|
|
|
+ // 返现/比例小于等于 0则不需要进行
|
|
|
|
+ if (this.ctx.minus(money, 0) <= 0) continue;
|
|
if (type === 'fixed') rmoney = this.ctx.plus(rmoney, money);
|
|
if (type === 'fixed') rmoney = this.ctx.plus(rmoney, money);
|
|
else if (type === 'percent') {
|
|
else if (type === 'percent') {
|
|
const specId = _.get(gs, '_id');
|
|
const specId = _.get(gs, '_id');
|
|
const realPay = _.get(moneyDetail, `${specId}.${priceKey}`);
|
|
const realPay = _.get(moneyDetail, `${specId}.${priceKey}`);
|
|
- const grm = this.ctx.multiply(realPay, this.ctx.divide(money, 10));
|
|
|
|
|
|
+ const grm = this.ctx.multiply(realPay, this.ctx.divide(money, 100));
|
|
rmoney = this.ctx.plus(rmoney, grm);
|
|
rmoney = this.ctx.plus(rmoney, grm);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -94,6 +96,20 @@ class CashBackService extends CrudService {
|
|
if (num > 0) return;
|
|
if (num > 0) return;
|
|
tran.insert('CashBack', obj);
|
|
tran.insert('CashBack', obj);
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 退货退流水
|
|
|
|
+ * @param {Object} afterSale 修改前的售后数据
|
|
|
|
+ * @param {Transaction} tran 数据库事务
|
|
|
|
+ */
|
|
|
|
+ async refund(afterSale, tran) {
|
|
|
|
+ const source_id = _.get(afterSale, 'order_detail');
|
|
|
|
+ const inBill = await this.model.findOne({ source_id }).lean();
|
|
|
|
+ if (!inBill) return;
|
|
|
|
+ const outBill = _.pick(inBill, [ 'inviter', 'money', 'source', 'source_id' ]);
|
|
|
|
+ outBill.time = moment().format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
+ outBill.status = '-1';
|
|
|
|
+ tran.insert('CashBack', outBill);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
module.exports = CashBackService;
|
|
module.exports = CashBackService;
|