|
@@ -51,9 +51,8 @@ class AfterSaleService extends CrudService {
|
|
|
const type = _.get(entity, 'type');
|
|
|
const status = _.get(update, 'status');
|
|
|
// 同意退款,则直接进行退款,然后再将状态修改为已退款
|
|
|
- if (type === '0' && status === '1') {
|
|
|
+ if (type !== '2' && status === '1') {
|
|
|
await this.toRefund({ afterSale_id: entity._id, goods_id: _.get(entity, 'goods._id') }, this.tran);
|
|
|
- this.tran.update('AfterSale', entity._id, { status: '-1' });
|
|
|
}
|
|
|
await this.tran.run();
|
|
|
} catch (error) {
|
|
@@ -96,12 +95,15 @@ class AfterSaleService extends CrudService {
|
|
|
|
|
|
// 找下当前这个订单有多少次售后记录
|
|
|
let num = await this.model.count({ order_detail: data.order_detail });
|
|
|
- num += 1;
|
|
|
+ num += 2;
|
|
|
// 组成退款单号
|
|
|
const out_refund_no = `${order_no}-r${num}`;
|
|
|
const obj = { reason, money, order_no, out_refund_no };
|
|
|
// 退款请求
|
|
|
- await this.ctx.service.trade.pay.refund(obj);
|
|
|
+ const res = await this.ctx.service.trade.pay.refund(obj);
|
|
|
+ if (res.errcode && res.errcode !== 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, res.errmsg);
|
|
|
+ tran.update('AfterSale', afterSale_id, { status: '-1' });
|
|
|
+ await tran.run();
|
|
|
|
|
|
// 检查优惠券是否都退了
|
|
|
// TODO: 查看支付订单-优惠明细中,该优惠券影响的商品是否都有退款/退货成功的记录
|
|
@@ -137,6 +139,7 @@ class AfterSaleService extends CrudService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // console.log(goodsRefundList);
|
|
|
// 获取支付单的优惠明细
|
|
|
const dd = _.get(order, 'total_detail.discount_detail', {});
|
|
|
for (const uc_id in dd) {
|