lrf 2 tahun lalu
induk
melakukan
f615fe0b90

+ 3 - 0
app/controller/trade/config/.afterSale.js

@@ -83,4 +83,7 @@ module.exports = {
   getTransportInfo: {
   getTransportInfo: {
     params: ['!id'],
     params: ['!id'],
   },
   },
+  canRefund: {
+    params: ['!id'],
+  },
 };
 };

+ 23 - 10
app/service/trade/afterSale.js

@@ -15,6 +15,7 @@ class AfterSaleService extends CrudService {
     this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
     this.orderDetailModel = this.ctx.model.Trade.OrderDetail;
     this.orderModel = this.ctx.model.Trade.Order;
     this.orderModel = this.ctx.model.Trade.Order;
     this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
     this.goodsSpecModel = this.ctx.model.Shop.GoodsSpec;
+    this.configModel = this.ctx.model.System.Config;
     this.tran = new Transaction();
     this.tran = new Transaction();
   }
   }
   /**
   /**
@@ -34,11 +35,11 @@ class AfterSaleService extends CrudService {
     if (!orderDetail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
     if (!orderDetail) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单信息');
     // 查看该商品是否已经申请售后
     // 查看该商品是否已经申请售后
     let goods;
     let goods;
-    const hasData = await this.model.count({ order_detail, 'goods._id': goods_id, status: { $nin: [ '!1', '!2', '!3', '!4', '!5' ] } });
+    const hasData = await this.model.count({ order_detail, 'goods._id': goods_id, status: { $nin: ['!1', '!2', '!3', '!4', '!5'] } });
     if (hasData > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该商品已有正在处理中的售后申请.请勿重复申请');
     if (hasData > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '该商品已有正在处理中的售后申请.请勿重复申请');
     if (type !== '4' && type !== '5') {
     if (type !== '4' && type !== '5') {
       const { goods: goodsList } = orderDetail;
       const { goods: goodsList } = orderDetail;
-      goods = goodsList.find(f => {
+      goods = goodsList.find((f) => {
         return ObjectId(f._id).equals(goods_id);
         return ObjectId(f._id).equals(goods_id);
       });
       });
       if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未在当前订单中搜索到要售后的商品');
       if (!goods) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未在当前订单中搜索到要售后的商品');
@@ -218,7 +219,7 @@ class AfterSaleService extends CrudService {
     // 已退款记录
     // 已退款记录
     const goodsRefundList = [];
     const goodsRefundList = [];
     // 在下面处理已退款记录中,应该把当前的这个售后项,作为已处理售后
     // 在下面处理已退款记录中,应该把当前的这个售后项,作为已处理售后
-    const tasq = { order_detail: data.order_detail, 'goods._id': _.get(data, 'goods._id'), status: [ '-1', '-2' ] };
+    const tasq = { order_detail: data.order_detail, 'goods._id': _.get(data, 'goods._id'), status: ['-1', '-2'] };
     const asdd = JSON.parse(JSON.stringify(data));
     const asdd = JSON.parse(JSON.stringify(data));
     if (_.get(update, 'money')) asdd.money = _.get(update, 'money');
     if (_.get(update, 'money')) asdd.money = _.get(update, 'money');
     const tr = await this.checkIsAllRefund(data);
     const tr = await this.checkIsAllRefund(data);
@@ -229,7 +230,7 @@ class AfterSaleService extends CrudService {
       const { goods, _id: order_detail } = od;
       const { goods, _id: order_detail } = od;
       // 组合成查售后的条件
       // 组合成查售后的条件
       // 然后查这些商品有没有退款审核成功的记录, 且只有退全款的商品才能退券
       // 然后查这些商品有没有退款审核成功的记录, 且只有退全款的商品才能退券
-      const afterSaleQuerys = goods.map(i => ({ order_detail, 'goods._id': i._id, status: [ '-1', '-2' ] }));
+      const afterSaleQuerys = goods.map((i) => ({ order_detail, 'goods._id': i._id, status: ['-1', '-2'] }));
       for (const asq of afterSaleQuerys) {
       for (const asq of afterSaleQuerys) {
         const asd = await this.model.findOne(asq);
         const asd = await this.model.findOne(asq);
         if (asd) {
         if (asd) {
@@ -245,7 +246,7 @@ class AfterSaleService extends CrudService {
       // 该优惠券影响的商品id列表
       // 该优惠券影响的商品id列表
       const goodsIds = Object.keys(_.get(dd, uc_id, {}));
       const goodsIds = Object.keys(_.get(dd, uc_id, {}));
       // 然后在已退款/退货记录中找,这个优惠券影响的商品是否都退款了.退全额
       // 然后在已退款/退货记录中找,这个优惠券影响的商品是否都退款了.退全额
-      const r = goodsIds.every(i => goodsRefundList.find(f => i === f['goods._id']));
+      const r = goodsIds.every((i) => goodsRefundList.find((f) => i === f['goods._id']));
       if (r) {
       if (r) {
         // 说明这个优惠券影响的商品都退了,这个优惠券也就能退了
         // 说明这个优惠券影响的商品都退了,这个优惠券也就能退了
         tran.update('UserCoupon', uc_id, { status: '0' });
         tran.update('UserCoupon', uc_id, { status: '0' });
@@ -264,15 +265,15 @@ class AfterSaleService extends CrudService {
     // 获取拆分订单的数据,并找到商品列表
     // 获取拆分订单的数据,并找到商品列表
     const goodsList = _.get(orderDetail, 'goods');
     const goodsList = _.get(orderDetail, 'goods');
     // 依次找这些商品是否都售后完成,都售后完成,就改订单状态
     // 依次找这些商品是否都售后完成,都售后完成,就改订单状态
-    const asList = await this.model.find({ order_detail, status: { $nin: [ '0', '!1', '!2', '!3', '!4', '!5' ] } });
+    const asList = await this.model.find({ order_detail, status: { $nin: ['0', '!1', '!2', '!3', '!4', '!5'] } });
     let status;
     let status;
     let fl = [];
     let fl = [];
     // 将当前数据添加进去
     // 将当前数据添加进去
     fl.push({ goods: _.get(data, 'goods._id'), status: 'finish' });
     fl.push({ goods: _.get(data, 'goods._id'), status: 'finish' });
     for (const gs of goodsList) {
     for (const gs of goodsList) {
-      const r = asList.find(f => ObjectId(_.get(f, 'goods._id')).equals(_.get(gs, '_id')));
+      const r = asList.find((f) => ObjectId(_.get(f, 'goods._id')).equals(_.get(gs, '_id')));
       if (r) {
       if (r) {
-        const finishList = [ '-1', '-2', '-3', '-4', '-5' ];
+        const finishList = ['-1', '-2', '-3', '-4', '-5'];
         if (finishList.includes(r.status)) fl.push({ goods: gs._id, status: 'finish' });
         if (finishList.includes(r.status)) fl.push({ goods: gs._id, status: 'finish' });
       }
       }
     }
     }
@@ -320,7 +321,7 @@ class AfterSaleService extends CrudService {
       const { goods, _id: order_detail } = od;
       const { goods, _id: order_detail } = od;
       // 组合成查售后的条件
       // 组合成查售后的条件
       // 然后查这些商品有没有退款审核成功的记录, 且只有退全款的商品才能退券
       // 然后查这些商品有没有退款审核成功的记录, 且只有退全款的商品才能退券
-      const afterSaleQuerys = goods.map(i => ({ order_detail, 'goods._id': i._id, status: [ '-1', '-2' ] }));
+      const afterSaleQuerys = goods.map((i) => ({ order_detail, 'goods._id': i._id, status: ['-1', '-2'] }));
       for (const asq of afterSaleQuerys) {
       for (const asq of afterSaleQuerys) {
         const asd = await this.model.findOne(asq);
         const asd = await this.model.findOne(asq);
         if (asd) {
         if (asd) {
@@ -336,7 +337,7 @@ class AfterSaleService extends CrudService {
       // 该优惠券影响的商品id列表
       // 该优惠券影响的商品id列表
       const goodsIds = Object.keys(_.get(dd, uc_id, {}));
       const goodsIds = Object.keys(_.get(dd, uc_id, {}));
       // 然后在已退款/退货记录中找,这个优惠券影响的商品是否都退款了.退全额
       // 然后在已退款/退货记录中找,这个优惠券影响的商品是否都退款了.退全额
-      const r = goodsIds.every(i => goodsRefundList.find(f => i === f['goods._id']));
+      const r = goodsIds.every((i) => goodsRefundList.find((f) => i === f['goods._id']));
       if (r) {
       if (r) {
         // 说明这个优惠券影响的商品都退了,这个优惠券也就能退了
         // 说明这个优惠券影响的商品都退了,这个优惠券也就能退了
         tran.update('UserCoupon', uc_id, { status: '0' });
         tran.update('UserCoupon', uc_id, { status: '0' });
@@ -487,6 +488,18 @@ class AfterSaleService extends CrudService {
     }
     }
     return result;
     return result;
   }
   }
+
+  async canRefund({ id }) {
+    const od = await this.orderDetailModel.findById(id, { buy_time: 1 }).lean();
+    if (!od) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到订单数据');
+    const config = await this.configModel.findOne({}, { reward_day: 1 }).lean();
+    const rd = _.get(config, 'reward_day', 14);
+    const min = this.ctx.multiply(rd, this.ctx.multiply(24, 60));
+    const buy_time = _.get(od, 'buy_time');
+    const m = moment().diff(buy_time, 'm');
+    const r = m < min;
+    return r;
+  }
 }
 }
 
 
 module.exports = AfterSaleService;
 module.exports = AfterSaleService;

+ 1 - 0
app/z_router/trade/afterSale.js

@@ -7,6 +7,7 @@ const rkey = 'afterSale';
 const ckey = 'trade.afterSale';
 const ckey = 'trade.afterSale';
 const keyZh = '售后';
 const keyZh = '售后';
 const routes = [
 const routes = [
+  { method: 'get', path: `${rkey}/canRefund/:id`, controller: `${ckey}.canRefund`, name: `${ckey}canRefund`, zh: `${keyZh}查询是否可以退款退货` },
   { method: 'get', path: `${rkey}/getTransportInfo/:id`, controller: `${ckey}.getTransportInfo`, name: `${ckey}getTransportInfo`, zh: `${keyZh}查询售后快递` },
   { method: 'get', path: `${rkey}/getTransportInfo/:id`, controller: `${ckey}.getTransportInfo`, name: `${ckey}getTransportInfo`, zh: `${keyZh}查询售后快递` },
   { method: 'post', path: `${rkey}/orderCancel`, controller: `${ckey}.orderCancel`, name: `${ckey}orderCancel`, zh: '取消订单' },
   { method: 'post', path: `${rkey}/orderCancel`, controller: `${ckey}.orderCancel`, name: `${ckey}orderCancel`, zh: '取消订单' },
   { method: 'post', path: `${rkey}/cgfr`, controller: `${ckey}.cgfr`, name: `${ckey}cgfr`, zh: '查询退货商品的金额设置' },
   { method: 'post', path: `${rkey}/cgfr`, controller: `${ckey}.cgfr`, name: `${ckey}cgfr`, zh: '查询退货商品的金额设置' },