|
@@ -20,10 +20,34 @@ class CashBackService extends CrudService {
|
|
|
const { populate } = this.ctx.service.trade.orderDetail.getRefMods();
|
|
|
const orderDetail = await this.orderDetailModel.findById(orderDetail_id).populate(populate);
|
|
|
if (!orderDetail) return;
|
|
|
- const money = this.ctx.service.util.orderDetail.computedRealPay(orderDetail);
|
|
|
+ // 找到商品的返现类型
|
|
|
+ let rmoney = 0;
|
|
|
+ const { goods: goodsSpec, type } = orderDetail;
|
|
|
+ // 根据订单类型判断应该取哪个价钱,为下面的百分比计算取值用
|
|
|
+ let priceKey;
|
|
|
+ if (type === '1') priceKey = 'ggrp';
|
|
|
+ else priceKey = 'grp';
|
|
|
+ const moneyDetail = this.ctx.service.util.orderDetail.moneyDetail(orderDetail);
|
|
|
+ for (const gs of goodsSpec) {
|
|
|
+ const goods = _.get(gs, 'goods');
|
|
|
+ if (!goods) continue;
|
|
|
+ const { is_cashBack, cb_config } = goods;
|
|
|
+ // 0:返现(使用)
|
|
|
+ if (is_cashBack !== '0') continue;
|
|
|
+ const type = _.get(cb_config, 'back_type');
|
|
|
+ if (!type) continue;
|
|
|
+ const money = _.get(cb_config, 'money');
|
|
|
+ if (type === 'fixed') rmoney = this.ctx.plus(rmoney, money);
|
|
|
+ else if (type === 'percent') {
|
|
|
+ const specId = _.get(gs, '_id');
|
|
|
+ const realPay = _.get(moneyDetail, `${specId}.${priceKey}`);
|
|
|
+ const grm = this.ctx.multiply(realPay, this.ctx.divide(money, 10));
|
|
|
+ rmoney = this.ctx.plus(rmoney, grm);
|
|
|
+ }
|
|
|
+ }
|
|
|
const { inviter, _id: order_detail } = orderDetail;
|
|
|
if (!inviter) return;
|
|
|
- const obj = { inviter, order_detail, money, time: moment().format('YYYY-MM-DD HH:mm:ss') };
|
|
|
+ const obj = { inviter, order_detail, money: rmoney, time: moment().format('YYYY-MM-DD HH:mm:ss') };
|
|
|
tran.insert('CashBack', obj);
|
|
|
}
|
|
|
}
|