|
@@ -12,6 +12,7 @@ class ShopInBillService extends CrudService {
|
|
|
this.model = this.ctx.model.Shop.ShopInBill;
|
|
|
this.shopModel = this.ctx.model.Shop.Shop;
|
|
|
this.orderUtil = this.ctx.service.util.orderDetail;
|
|
|
+ this.configModel = this.ctx.model.System.Config;
|
|
|
}
|
|
|
/**
|
|
|
* 正常购物创建店铺流水
|
|
@@ -57,6 +58,41 @@ class ShopInBillService extends CrudService {
|
|
|
else obj.receipts = limit;
|
|
|
tran.insert('ShopInBill', obj);
|
|
|
}
|
|
|
+
|
|
|
+ async computedTotal({ shop }) {
|
|
|
+ const list = await this.model.find({ shop }).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 list) {
|
|
|
+ const { source, receipts: money } = i;
|
|
|
+ const sn = parseInt(source);
|
|
|
+ if (sn >= 0) total = this.ctx.plus(total, money);
|
|
|
+ else total = this.ctx.minus(total, money);
|
|
|
+ }
|
|
|
+ let canGet = 0;
|
|
|
+ const inBill = list.filter(f => parseInt(f.source) >= 0);
|
|
|
+ const outBill = list.filter(f => parseInt(f.source) < 0);
|
|
|
+ const getOutBill = list.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 { receipts: 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.receipts);
|
|
|
+ }
|
|
|
+ canGet = this.ctx.plus(canGet, cg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ canGet = this.ctx.minus(canGet, outBillMoney);
|
|
|
+ return { total, canGet };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = ShopInBillService;
|