|
@@ -9,6 +9,7 @@ class CashBackService extends CrudService {
|
|
|
constructor(ctx) {
|
|
|
super(ctx, 'cashback');
|
|
|
this.model = this.ctx.model.User.CashBack;
|
|
|
+ this.configModel = this.ctx.model.System.Config;
|
|
|
this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
|
|
|
}
|
|
|
|
|
@@ -16,6 +17,9 @@ class CashBackService extends CrudService {
|
|
|
assert(customer, '缺少用户信息');
|
|
|
// status(状态) 和 source(来源) 均表示钱是入账还是出账,判断一个就行,主要还是依靠来源吧
|
|
|
const res = await this.model.find({ inviter: customer }).lean();
|
|
|
+ const config = await this.configModel.findOne({}, { reward_day: 1 }).lean();
|
|
|
+ const rd = _.get(config, 'reward_day', 14);
|
|
|
+ const min = this.ctx.multiply(rd, this.ctx.multiply(24, 60));
|
|
|
let total = 0;
|
|
|
for (const i of res) {
|
|
|
const { source, money } = i;
|
|
@@ -23,7 +27,30 @@ class CashBackService extends CrudService {
|
|
|
if (sn >= 0) total = this.ctx.plus(total, money);
|
|
|
else total = this.ctx.minus(total, money);
|
|
|
}
|
|
|
- return total;
|
|
|
+ // 计算提现金额
|
|
|
+ // 上面总价包含了提现金额
|
|
|
+ // 下面计算的金额是可以提现的金额 提现总金额 - 提现金额
|
|
|
+ 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);
|
|
|
+ for (const i of inBill) {
|
|
|
+ const cAt = _.get(i, 'time');
|
|
|
+ const m = moment().diff(cAt, 'm');
|
|
|
+ if (m >= min) {
|
|
|
+ // 已经过了提款时间,那就再找下,是否有该记录相应的退款
|
|
|
+ const { money, source_id } = i;
|
|
|
+ let cg = money;
|
|
|
+ const os = outBill.filter(f => f.source_id === source_id);
|
|
|
+ for (const o of os) {
|
|
|
+ cg = this.ctx.minus(cg, o.money);
|
|
|
+ }
|
|
|
+ canGet = this.ctx.plus(canGet, cg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ canGet = this.ctx.minus(canGet, outBillMoney);
|
|
|
+ return { total, canGet };
|
|
|
}
|
|
|
/**
|
|
|
* 添加检查返现
|