|
@@ -140,6 +140,12 @@ class UserCouponService extends CrudService {
|
|
uc.canUse = false;
|
|
uc.canUse = false;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ // 3.检查是否满足优惠券是用条件
|
|
|
|
+ r = this.checkCanUse_discount(uc, goods);
|
|
|
|
+ if (!r) {
|
|
|
|
+ uc.canUse = false;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
uc.canUse = true;
|
|
uc.canUse = true;
|
|
}
|
|
}
|
|
return couponList;
|
|
return couponList;
|
|
@@ -211,6 +217,27 @@ class UserCouponService extends CrudService {
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 检查该优惠券是否可以在这些商品中使用
|
|
|
|
+ * @param {Object} userCoupon 用户领取的优惠券
|
|
|
|
+ * @param {Array} shopGoods 按店铺分组的商品列表
|
|
|
|
+ */
|
|
|
|
+ checkCanUse_discount(userCoupon, shopGoods) {
|
|
|
|
+ const { coupon } = userCoupon;
|
|
|
|
+ const { discount_config = {} } = coupon;
|
|
|
|
+ const limit = _.get(discount_config, 'limit');
|
|
|
|
+ if (limit === 'nolimit') return true;
|
|
|
|
+ const goods_total = shopGoods.reduce((p, n) =>
|
|
|
|
+ this.ctx.plus(
|
|
|
|
+ p,
|
|
|
|
+ n.goods.reduce((gp, gn) =>
|
|
|
|
+ this.ctx.plus(gp, this.ctx.multiply(gn.sell_money, gn.buy_num)), 0)
|
|
|
|
+ )
|
|
|
|
+ , 0);
|
|
|
|
+ if (this.ctx.minus(goods_total, limit) > 0) return true;
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ }
|
|
/**
|
|
/**
|
|
* 计算订单使用优惠券的明细
|
|
* 计算订单使用优惠券的明细
|
|
* @param {Array} couponIds 订单使用的用户领取的优惠券数据id数组
|
|
* @param {Array} couponIds 订单使用的用户领取的优惠券数据id数组
|