|
@@ -11,6 +11,17 @@ class CashBackService extends CrudService {
|
|
this.model = this.ctx.model.User.CashBack;
|
|
this.model = this.ctx.model.User.CashBack;
|
|
this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
|
|
this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ async computedTotal({ customer }) {
|
|
|
|
+ assert(customer, '缺少用户信息');
|
|
|
|
+ const res = await this.model.find({ inviter: customer });
|
|
|
|
+ const total = res.reduce((p, n) => {
|
|
|
|
+ let point = n.point;
|
|
|
|
+ if (!(n.source === '0' || n.source === '1')) point = -point;
|
|
|
|
+ return this.ctx.plus(p, point);
|
|
|
|
+ }, 0);
|
|
|
|
+ return total;
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 添加检查返现
|
|
* 添加检查返现
|
|
* @param {String} orderDetail_id 订单详情id
|
|
* @param {String} orderDetail_id 订单详情id
|
|
@@ -47,7 +58,10 @@ class CashBackService extends CrudService {
|
|
}
|
|
}
|
|
const { inviter, _id: order_detail } = orderDetail;
|
|
const { inviter, _id: order_detail } = orderDetail;
|
|
if (!inviter) return;
|
|
if (!inviter) return;
|
|
- const obj = { inviter: _.get(inviter, '_id'), order_detail, money: rmoney, time: moment().format('YYYY-MM-DD HH:mm:ss') };
|
|
|
|
|
|
+ const obj = { inviter: _.get(inviter, '_id'), source_id: order_detail, source: '0', money: rmoney, time: moment().format('YYYY-MM-DD HH:mm:ss') };
|
|
|
|
+ // 检查是否已经返利
|
|
|
|
+ const num = await this.model.count({ inviter, source_id: order_detail, source: '0' });
|
|
|
|
+ if (num > 0) return;
|
|
tran.insert('CashBack', obj);
|
|
tran.insert('CashBack', obj);
|
|
}
|
|
}
|
|
}
|
|
}
|