|
@@ -37,9 +37,10 @@ class OrderDetailService extends CrudService {
|
|
|
assert(order_id, '缺少支付订单信息');
|
|
|
const order = await this.orderModel.findById(order_id);
|
|
|
if (!order) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到支付订单的数据');
|
|
|
- const { customer, address, goods: shopGoods, no, status, buy_time, pay, total_detail: otd } = order;
|
|
|
+ // 返现部分
|
|
|
+ const { customer, address, goods: shopGoods, no, status, buy_time, pay, total_detail: otd, inviter } = order;
|
|
|
if (status === '0') throw new BusinessError(ErrorCode.DATA_INVALID, '订单未支付');
|
|
|
- const orderDetailData = { customer, address, order: order_id, buy_time, pay_time: _.get(pay, 'pay_time'), status };
|
|
|
+ const orderDetailData = { customer, address, order: order_id, buy_time, pay_time: _.get(pay, 'pay_time'), status, inviter };
|
|
|
const shopMoneyDetail = this.ctx.service.util.order.shopMoneyDetail(order);
|
|
|
// 分订单计数器
|
|
|
let noTimes = 1;
|
|
@@ -81,14 +82,6 @@ class OrderDetailService extends CrudService {
|
|
|
// await this.model.insertMany(arr);
|
|
|
}
|
|
|
|
|
|
- async afterUpdate(filter, body, data) {
|
|
|
- const status = _.get(data, 'status');
|
|
|
- if (status === '3') {
|
|
|
- // 处理积分,签收再加
|
|
|
- await this.ctx.service.user.point.addPoints(data._id);
|
|
|
- }
|
|
|
- return data;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 将商品规格列表中,优惠的部分提取出来,分单用
|
|
@@ -248,6 +241,29 @@ class OrderDetailService extends CrudService {
|
|
|
return { data: list, total };
|
|
|
}
|
|
|
|
|
|
+ async update(filter, update, { projection } = {}) {
|
|
|
+ assert(filter);
|
|
|
+ assert(update);
|
|
|
+ const { _id, id } = filter;
|
|
|
+ if (_id || id) filter = { _id: ObjectId(_id || id) };
|
|
|
+ const entity = await this.model.findOne(filter).exec();
|
|
|
+ if (!entity) throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
|
|
|
+ try {
|
|
|
+ this.tran.update('OrderDetail', filter._id, update);
|
|
|
+ // 积分部分
|
|
|
+ await this.ctx.service.user.point.addPoints(filter._id, this.tran);
|
|
|
+ // 返现部分
|
|
|
+ await this.ctx.service.user.cashBack.create(filter._id, this.tran);
|
|
|
+ await this.tran.run();
|
|
|
+ const e = await this.model.findOne(filter, projection).exec();
|
|
|
+ return e;
|
|
|
+ } catch (error) {
|
|
|
+ await this.tran.rollback();
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ this.tran.clean();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = OrderDetailService;
|