lrf 2 years ago
parent
commit
5deec0df4f
2 changed files with 8 additions and 6 deletions
  1. 1 1
      app/controller/trade/config/.afterSale.js
  2. 7 5
      app/service/trade/afterSale.js

+ 1 - 1
app/controller/trade/config/.afterSale.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['order_detail', 'customer', 'shop', 'goods', 'type', 'reason', 'desc', 'file', 'transport', 'apply_time', 'end_time', 'status', 'result'],
+    requestBody: ['order_detail', 'goods_id', 'customer', 'shop', 'goods', 'type', 'reason', 'desc', 'file', 'transport', 'apply_time', 'end_time', 'status', 'result'],
   },
   destroy: {
     params: ['!id'],

+ 7 - 5
app/service/trade/afterSale.js

@@ -15,13 +15,15 @@ class AfterSaleService extends CrudService {
     this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
     this.tran = new Transaction();
   }
-  async create({ order_id, goods_id, ...others }) {
-    const orderDetail = await this.orderDetailModel.findById(order_id);
+  async create({ order_detail, goods_id, ...others }) {
+    const orderDetail = await this.orderDetailModel.findById(order_detail);
     if (!orderDetail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
+    // TODO:查看订单是否签收
+
     // 查询该商品是不是申请退款,如果是申请退款,查看是否有记录,如果有记录,是否已经退款
     const type = _.get(others, 'type');
     if (type === '0') {
-      const record = await this.model.find({ order_detail: order_id, 'goods._id': goods_id, type: '0' });
+      const record = await this.model.find({ order_detail, 'goods._id': goods_id, type: '0' });
       if (record) {
         const rs = _.get(record, 'status');
         if (rs === '0' || rs === '1') throw new BusinessError(ErrorCode.DATA_EXISTED, '已申请退款,正在等待处理');
@@ -29,7 +31,7 @@ class AfterSaleService extends CrudService {
       }
     } else {
       // 如果是换货/维修,那么可以重复多次,也就是需要查当前该货物是否有未结束的售后,如果有,则不能添加
-      const num = await this.model.count({ order_detail: order_id, 'goods._id': goods_id, type, status: [ '2', '3' ] });
+      const num = await this.model.count({ order_detail, 'goods._id': goods_id, type, status: [ '2', '3' ] });
       if (num) throw new BusinessError(ErrorCode.DATA_INVALID, '商品正在售后中');
     }
     const { goods: goodsList } = orderDetail;
@@ -37,7 +39,7 @@ class AfterSaleService extends CrudService {
     if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未在当前订单中搜索到要售后的商品');
     const { shop, customer } = orderDetail;
     const apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
-    const obj = { order_detail: order_id, customer, shop, goods, ...others, apply_time, status: '0' };
+    const obj = { order_detail, customer, shop, goods, ...others, apply_time, status: '0' };
     await this.model.create(obj);
   }