| | |
| | | } |
| | | try { |
| | | JSONObject content = JSON.parseObject(coupon.getContent()); |
| | | BigDecimal deductionAmount = content.getBigDecimal("deductionAmount"); |
| | | // 满减券使用 deductionAmount,代金券历史规则将抵扣额存放在 conditionalAmount。 |
| | | BigDecimal deductionAmount = Integer.valueOf(2).equals(coupon.getType()) |
| | | ? content.getBigDecimal("conditionalAmount") |
| | | : content.getBigDecimal("deductionAmount"); |
| | | return deductionAmount == null ? BigDecimal.ZERO : deductionAmount.max(BigDecimal.ZERO); |
| | | } catch (Exception e) { |
| | | LOGGER.warn("解析优惠券抵扣规则失败,couponId={}", coupon.getId(), e); |
| | |
| | | List<CouponListVo> listVos = new ArrayList<>(); |
| | | for (Map<String, Object> userCoupon : userCoupons) { |
| | | Integer type = Integer.valueOf(userCoupon.get("type").toString()); |
| | | // 支付减免只支持满减券和代金券;体验券/抵扣券不能用于订单金额计算。 |
| | | if (type != 1 && type != 2) { |
| | | continue; |
| | | } |
| | | CouponListVo couponListVo = new CouponListVo(); |
| | | couponListVo.setId(Long.valueOf(userCoupon.get("id").toString())); |
| | | couponListVo.setName(userCoupon.get("name").toString()); |
| | |
| | | @Override |
| | | public List<CouponListVo> querySiteCouponList(Integer uid, Integer siteId, Double price, String lon, String lat) throws Exception { |
| | | Site site = siteClient.querySiteById(siteId); |
| | | Integer storeId = site.getStoreId(); |
| | | return queryStoreCouponList(uid, site.getStoreId(), price, lon, lat); |
| | | } |
| | | |
| | | @Override |
| | | public List<CouponListVo> queryStoreCouponList(Integer uid, Integer storeId, Double price, String lon, String lat) throws Exception { |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(lon, lat); |
| | | String provinceCode = geocode.get("provinceCode"); |
| | | String cityCode = geocode.get("cityCode"); |
| | |
| | | List<CouponListVo> listVos = new ArrayList<>(); |
| | | for (Map<String, Object> userCoupon : userCoupons) { |
| | | Integer type = Integer.valueOf(userCoupon.get("type").toString()); |
| | | if (type != 1 && type != 2) { |
| | | continue; |
| | | } |
| | | CouponListVo couponListVo = new CouponListVo(); |
| | | couponListVo.setId(Long.valueOf(userCoupon.get("id").toString())); |
| | | couponListVo.setName(userCoupon.get("name").toString()); |
| | | couponListVo.setType(type); |
| | | couponListVo.setEffectiveTime(userCoupon.get("endTime").toString()); |
| | | String content = userCoupon.get("content").toString(); |
| | | BigDecimal orderAmount = BigDecimal.valueOf(price == null ? 0D : price).max(BigDecimal.ZERO); |
| | | if (type == 1) {//满减{"num1":1,"num2":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | | Double num1 = jsonObject.getDouble("conditionalAmount"); |
| | |
| | | } |
| | | couponListVo.setUseCondition("满" + num1 + "元可用"); |
| | | couponListVo.setFavorable(jsonObject.getString("deductionAmount")); |
| | | BigDecimal discount = BigDecimal.valueOf(jsonObject.getDouble("deductionAmount")) |
| | | .min(orderAmount); |
| | | couponListVo.setDiscountAmount(discount); |
| | | couponListVo.setPayableAmount(orderAmount.subtract(discount)); |
| | | } |
| | | if (type == 2) {//代金券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |
| | |
| | | if (num1 == null) { |
| | | num1 = 0d; |
| | | } |
| | | if (price.compareTo(num1) < 0) { |
| | | continue; |
| | | } |
| | | // 代金券可全额抵扣,面额超过订单金额时按订单金额抵扣,不应从列表中剔除。 |
| | | couponListVo.setUseCondition(""); |
| | | couponListVo.setFavorable(num1 + ""); |
| | | BigDecimal discount = BigDecimal.valueOf(num1).max(BigDecimal.ZERO).min(orderAmount); |
| | | couponListVo.setDiscountAmount(discount); |
| | | couponListVo.setPayableAmount(orderAmount.subtract(discount)); |
| | | } |
| | | if (type == 3) {//体验券{"num1":1} |
| | | JSONObject jsonObject = JSON.parseObject(content); |