|
|
@@ -23,7 +23,6 @@ import com.fs.company.mapper.CompanyUserMapper;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.company.util.WechatApi;
|
|
|
import com.fs.core.utils.OrderCodeUtils;
|
|
|
-import com.fs.course.domain.FsCourseCheckinPrize;
|
|
|
import com.fs.course.domain.FsCourseCheckinReceive;
|
|
|
import com.fs.course.mapper.FsCourseCheckinPrizeMapper;
|
|
|
import com.fs.course.mapper.FsCourseCheckinReceiveMapper;
|
|
|
@@ -40,7 +39,6 @@ import com.fs.his.config.FsSysConfig;
|
|
|
import com.fs.his.domain.*;
|
|
|
import com.fs.his.dto.ErpRemarkDTO;
|
|
|
import com.fs.his.enums.BusinessTypeEnum;
|
|
|
-import com.fs.his.enums.FsInquiryOrderStatusEnum;
|
|
|
import com.fs.his.enums.FsUserIntegralLogTypeEnum;
|
|
|
import com.fs.his.enums.PaymentMethodEnum;
|
|
|
import com.fs.his.mapper.*;
|
|
|
@@ -52,6 +50,13 @@ import com.fs.his.vo.FsIntegralOrderListUVO;
|
|
|
import com.fs.his.vo.FsIntegralOrderListVO;
|
|
|
import com.fs.his.vo.FsIntegralOrderPVO;
|
|
|
import com.fs.his.vo.FsStoreProductDeliverExcelVO;
|
|
|
+import com.fs.hisStore.domain.FsShippingTemplatesFreeScrm;
|
|
|
+import com.fs.hisStore.domain.FsShippingTemplatesRegionScrm;
|
|
|
+import com.fs.hisStore.domain.FsShippingTemplatesScrm;
|
|
|
+import com.fs.hisStore.enums.ShippingTempEnum;
|
|
|
+import com.fs.hisStore.mapper.FsShippingTemplatesFreeScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsShippingTemplatesRegionScrmMapper;
|
|
|
+import com.fs.hisStore.mapper.FsShippingTemplatesScrmMapper;
|
|
|
import com.fs.huifuPay.domain.HuiFuRefundResult;
|
|
|
import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
|
|
|
import com.fs.huifuPay.service.HuiFuService;
|
|
|
@@ -62,8 +67,6 @@ import com.fs.ybPay.domain.OrderResult;
|
|
|
import com.fs.ybPay.dto.OrderQueryDTO;
|
|
|
import com.fs.ybPay.service.IPayService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.redisson.api.RObjectAsync;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
@@ -77,6 +80,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@@ -84,6 +88,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.fs.his.utils.PhoneUtil.decryptPhone;
|
|
|
|
|
|
@@ -188,6 +193,14 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService {
|
|
|
private FsUserCouponMapper fsUserCouponMapper;
|
|
|
@Autowired
|
|
|
private FsCouponMapper fsCouponMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsCityMapper fsCityMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsShippingTemplatesScrmMapper fsShippingTemplatesScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsShippingTemplatesFreeScrmMapper fsShippingTemplatesFreeScrmMapper;
|
|
|
+ @Autowired
|
|
|
+ private FsShippingTemplatesRegionScrmMapper fsShippingTemplatesRegionScrmMapper;
|
|
|
|
|
|
//ERP 类型到服务的映射
|
|
|
private Map<Integer, IErpOrderService> erpServiceMap;
|
|
|
@@ -332,38 +345,7 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService {
|
|
|
|
|
|
// 计算优惠券
|
|
|
if (param.getUserCouponId() != null) {
|
|
|
-
|
|
|
- // 查询用户优惠券,判断是否有效,是否未使用
|
|
|
- FsUserCoupon fsUserCoupon = fsUserCouponMapper.selectFsUserCouponById(param.getUserCouponId());
|
|
|
- if (fsUserCoupon == null || !Objects.equals(fsUserCoupon.getUserId(), param.getUserId())) {
|
|
|
- return R.error("无效的优惠券");
|
|
|
- }
|
|
|
- if (fsUserCoupon.getBusinessType() != 4) {
|
|
|
- return R.error("优惠券类型不匹配,无法使用");
|
|
|
- }
|
|
|
-
|
|
|
- if (fsUserCoupon.getStatus() == 1) {
|
|
|
- return R.error("优惠券已使用");
|
|
|
- }
|
|
|
-
|
|
|
- if (fsUserCoupon.getStatus() == 2 || fsUserCoupon.getLimitTime().before(new Date())) {
|
|
|
- return R.error("优惠券已过期");
|
|
|
- }
|
|
|
-
|
|
|
- // 查看优惠券具体类型
|
|
|
- FsCoupon fsCoupon = fsCouponMapper.selectFsCouponByCouponId(fsUserCoupon.getCouponId());
|
|
|
- if (fsCoupon == null) {
|
|
|
- return R.error("无效的优惠券");
|
|
|
- }
|
|
|
-
|
|
|
- if (fsCoupon.getCouponType() != 7) {
|
|
|
- return R.error("无效的优惠券");
|
|
|
- }
|
|
|
-
|
|
|
- moneyDTO.setDiscountIntegral(moneyDTO.getIntegral());
|
|
|
- moneyDTO.setIntegral(BigDecimal.ZERO);
|
|
|
- moneyDTO.setDiscountCash(moneyDTO.getCash());
|
|
|
- moneyDTO.setCash(BigDecimal.ZERO);
|
|
|
+ applyCoupon(param.getUserCouponId(), user.getUserId(), integralGoods, moneyDTO);
|
|
|
}
|
|
|
|
|
|
if (moneyDTO.getIntegral().intValue() > 0 && user.getIntegral() < moneyDTO.getIntegral().intValue()) {
|
|
|
@@ -383,6 +365,43 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService {
|
|
|
return createOrder(user, address, moneyDTO, goodsItem, param.getCompanyUserId(), param.getUserCouponId());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算优惠
|
|
|
+ */
|
|
|
+ private void applyCoupon(Long userCouponId, Long userId, FsIntegralGoods integralGoods, ComputeIntegralOrderMoneyDTO moneyDTO) {
|
|
|
+ // 查询用户优惠券,判断是否有效,是否未使用
|
|
|
+ FsUserCoupon fsUserCoupon = fsUserCouponMapper.selectFsUserCouponById(userCouponId);
|
|
|
+ if (fsUserCoupon == null || !Objects.equals(fsUserCoupon.getUserId(), userId)) {
|
|
|
+ throw new CustomException("无效的优惠券");
|
|
|
+ }
|
|
|
+ if (fsUserCoupon.getBusinessType() != 4) {
|
|
|
+ throw new CustomException("优惠券类型不匹配,无法使用");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fsUserCoupon.getStatus() == 1) {
|
|
|
+ throw new CustomException("优惠券已使用");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fsUserCoupon.getStatus() == 2 || fsUserCoupon.getLimitTime().before(new Date())) {
|
|
|
+ throw new CustomException("优惠券已过期");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查看优惠券具体类型
|
|
|
+ FsCoupon fsCoupon = fsCouponMapper.selectFsCouponByCouponId(fsUserCoupon.getCouponId());
|
|
|
+ if (fsCoupon == null) {
|
|
|
+ throw new CustomException("无效的优惠券");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fsCoupon.getCouponType() != 7 || !fsCoupon.getFreeGoodsId().equals(integralGoods.getGoodsId())) {
|
|
|
+ throw new CustomException("无效的优惠券");
|
|
|
+ }
|
|
|
+
|
|
|
+ moneyDTO.setDiscountIntegral(moneyDTO.getIntegral());
|
|
|
+ moneyDTO.setIntegral(BigDecimal.ZERO);
|
|
|
+ moneyDTO.setDiscountCash(moneyDTO.getCash());
|
|
|
+ moneyDTO.setCash(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建订单
|
|
|
*/
|
|
|
@@ -398,6 +417,9 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService {
|
|
|
throw new CustomException("订单生成失败,请重试");
|
|
|
}
|
|
|
|
|
|
+ // 运费计算
|
|
|
+ calcDeliveryMoney(moneyDTO, address, goodsItem);
|
|
|
+
|
|
|
// 现金
|
|
|
if (moneyDTO.getCash().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
// 现金+积分
|
|
|
@@ -423,6 +445,7 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService {
|
|
|
order.setTotalMoney(moneyDTO.getTotalCash());
|
|
|
order.setPayMoney(moneyDTO.getCash());
|
|
|
order.setDiscountMoney(moneyDTO.getDiscountCash());
|
|
|
+ order.setDeliveryMoney(moneyDTO.getDeliveryMoney());
|
|
|
order.setUserCouponId(userCouponId);
|
|
|
order.setItemJson(JSONUtil.toJsonStr(goodsItem));
|
|
|
order.setUserName(address.getRealName());
|
|
|
@@ -510,6 +533,118 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算运费
|
|
|
+ */
|
|
|
+ private void calcDeliveryMoney(ComputeIntegralOrderMoneyDTO moneyDTO, FsUserAddress address, List<FsIntegralGoods> goodsItem) {
|
|
|
+ // 解析省市信息
|
|
|
+ FsCity province = fsCityMapper.selectByNameAndParentId(address.getProvince(), "0");
|
|
|
+ if (province == null) return;
|
|
|
+
|
|
|
+ FsCity city = fsCityMapper.selectByNameAndParentId(address.getCity(), province.getCityId());
|
|
|
+ if (city == null) return;
|
|
|
+
|
|
|
+ // 按运费模板分组(过滤无模板商品)
|
|
|
+ Map<Long, List<FsIntegralGoods>> templateGroupMap = goodsItem.stream()
|
|
|
+ .filter(goods -> goods.getTempId() != null)
|
|
|
+ .collect(Collectors.groupingBy(FsIntegralGoods::getTempId));
|
|
|
+
|
|
|
+ BigDecimal totalDeliveryMoney = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (Map.Entry<Long, List<FsIntegralGoods>> entry : templateGroupMap.entrySet()) {
|
|
|
+ BigDecimal fee = calcTemplateFee(entry.getKey(), entry.getValue(), province, city);
|
|
|
+ totalDeliveryMoney = totalDeliveryMoney.add(fee);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新 DTO
|
|
|
+ moneyDTO.setDeliveryMoney(totalDeliveryMoney);
|
|
|
+ moneyDTO.setCash(moneyDTO.getCash().add(totalDeliveryMoney));
|
|
|
+ moneyDTO.setTotalCash(moneyDTO.getTotalCash().add(totalDeliveryMoney));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算单个运费模板的运费
|
|
|
+ */
|
|
|
+ private BigDecimal calcTemplateFee(Long tempId, List<FsIntegralGoods> goodsList, FsCity province, FsCity city) {
|
|
|
+ FsShippingTemplatesScrm template = fsShippingTemplatesScrmMapper.selectFsShippingTemplatesById(tempId);
|
|
|
+
|
|
|
+ // 仅处理按件计费模板
|
|
|
+ if (template == null || !ShippingTempEnum.TYPE_1.getValue().equals(template.getType())) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 汇总商品总件数与总金额
|
|
|
+ int totalNum = 0;
|
|
|
+ BigDecimal totalPrice = BigDecimal.ZERO;
|
|
|
+ for (FsIntegralGoods goods : goodsList) {
|
|
|
+ int num = goods.getNum() != null ? goods.getNum() : 0;
|
|
|
+ if (num <= 0) continue;
|
|
|
+ totalNum += num;
|
|
|
+ if (goods.getCash() != null) {
|
|
|
+ totalPrice = totalPrice.add(goods.getCash().multiply(BigDecimal.valueOf(num)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (totalNum <= 0) return BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 检查指定包邮
|
|
|
+ if (isFreeShipping(template, province, city, totalNum, totalPrice)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询运费区域配置(优先精确匹配,降级全国)
|
|
|
+ FsShippingTemplatesRegionScrm region = fsShippingTemplatesRegionScrmMapper.selectByTempIdAndProvinceIdAndCityId(template.getId(), province.getCityId(), city.getCityId());
|
|
|
+ if (region == null) {
|
|
|
+ region = fsShippingTemplatesRegionScrmMapper.selectByTempIdAndProvinceIdAndCityId(template.getId(), "0", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ return region != null ? calcShippingFee(region, totalNum) : BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否满足包邮条件
|
|
|
+ */
|
|
|
+ private boolean isFreeShipping(FsShippingTemplatesScrm template, FsCity province, FsCity city, int totalNum, BigDecimal totalPrice) {
|
|
|
+ if (template.getAppoint() == null || template.getAppoint() != 1) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ FsShippingTemplatesFreeScrm freeRule = fsShippingTemplatesFreeScrmMapper
|
|
|
+ .selectByTempIdAndProvinceIdAndCityId(template.getId(), province.getCityId(), city.getCityId());
|
|
|
+ if (freeRule == null) return false;
|
|
|
+
|
|
|
+ // 件数满足包邮(0 表示不限件数)
|
|
|
+ boolean freeByNum = freeRule.getNumber() == null
|
|
|
+ || freeRule.getNumber().intValue() == 0
|
|
|
+ || totalNum >= freeRule.getNumber().intValue();
|
|
|
+
|
|
|
+ // 金额满足包邮(0 表示不限金额)
|
|
|
+ boolean freeByPrice = freeRule.getPrice() != null
|
|
|
+ && freeRule.getPrice().compareTo(BigDecimal.ZERO) > 0
|
|
|
+ && totalPrice.compareTo(freeRule.getPrice()) >= 0;
|
|
|
+
|
|
|
+ return freeByNum || freeByPrice; // 满足任一条件即可包邮
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据区域配置计算运费(按件计费)
|
|
|
+ */
|
|
|
+ private BigDecimal calcShippingFee(FsShippingTemplatesRegionScrm region, int totalNum) {
|
|
|
+ BigDecimal firstCount = region.getFirst();
|
|
|
+ BigDecimal firstPrice = region.getFirstPrice();
|
|
|
+ BigDecimal continueCount = region.getContinues();
|
|
|
+ BigDecimal continuePrice = region.getContinuePrice();
|
|
|
+
|
|
|
+ if (totalNum <= firstCount.intValue() || continueCount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return firstPrice;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 超出首件部分,向上取整计算续件费用
|
|
|
+ BigDecimal extra = BigDecimal.valueOf(totalNum).subtract(firstCount);
|
|
|
+ BigDecimal continueUnits = extra.divide(continueCount, 0, RoundingMode.CEILING);
|
|
|
+ return firstPrice.add(continueUnits.multiply(continuePrice));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建购物车订单
|
|
|
*
|
|
|
@@ -1393,79 +1528,83 @@ public class FsIntegralOrderServiceImpl implements IFsIntegralOrderService {
|
|
|
*/
|
|
|
@Override
|
|
|
public R computeOrder(FsIntegralOrderComputeParam param) {
|
|
|
-
|
|
|
- // 查询积分订单,判断订单是否存在,状态是否未支付
|
|
|
- FsIntegralOrder order = fsIntegralOrderMapper.selectFsIntegralOrderByOrderId(param.getOrderId());
|
|
|
- if (order == null) {
|
|
|
- return R.error("订单不存在!");
|
|
|
- }
|
|
|
-
|
|
|
- if (order.getIsPay() != 0 || order.getStatus() != 4) {
|
|
|
- return R.error("订单状态不正确");
|
|
|
- }
|
|
|
-
|
|
|
// 查询用户,判断用户是否存在
|
|
|
FsUser fsUser = fsUserMapper.selectFsUserById(param.getUserId());
|
|
|
if (fsUser == null || fsUser.getIsDel() == 1) {
|
|
|
return R.error("用户不存在");
|
|
|
}
|
|
|
|
|
|
- // 返回扣减后的支付金额
|
|
|
- return R.ok().put("data", computeOrderMoney(param.getUserId(), new BigDecimal(order.getTotalIntegral()), order.getTotalMoney(), param.getUserCouponId(), order.getItemJson()));
|
|
|
- }
|
|
|
+ if (param.getGoodsId() == null && (param.getCartIds() == null || param.getCartIds().isEmpty())) {
|
|
|
+ return R.error("商品不能为空");
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 计算优惠后的价格
|
|
|
- */
|
|
|
- private ComputeIntegralOrderMoneyDTO computeOrderMoney(Long userId, BigDecimal orderIntegral, BigDecimal orderMoney, Long userCouponId, String goodsJson) {
|
|
|
ComputeIntegralOrderMoneyDTO moneyDTO = new ComputeIntegralOrderMoneyDTO();
|
|
|
- moneyDTO.setIntegral(orderIntegral);
|
|
|
- moneyDTO.setCash(orderMoney);
|
|
|
+ List<FsIntegralGoods> goodsItem = new ArrayList<>();
|
|
|
|
|
|
- // 不使用优惠券
|
|
|
- if (null == userCouponId) {
|
|
|
- return moneyDTO;
|
|
|
- }
|
|
|
+ // 判断是购物车还是单商品
|
|
|
+ if (param.getGoodsId() != null) {
|
|
|
+ FsIntegralGoods fsIntegralGoods = fsIntegralGoodsMapper.selectFsIntegralGoodsByGoodsId(param.getGoodsId());
|
|
|
+ if (fsIntegralGoods == null) {
|
|
|
+ return R.error("积分商品不存在");
|
|
|
+ }
|
|
|
|
|
|
- // 查询用户优惠券,判断是否有效,是否未使用
|
|
|
- FsUserCoupon fsUserCoupon = fsUserCouponMapper.selectFsUserCouponById(userCouponId);
|
|
|
- if (fsUserCoupon == null || !Objects.equals(fsUserCoupon.getUserId(), userId)) {
|
|
|
- return moneyDTO;
|
|
|
- }
|
|
|
+ if (fsIntegralGoods.getStatus() == 0) {
|
|
|
+ return R.error("积分商品已下架");
|
|
|
+ }
|
|
|
|
|
|
- if (fsUserCoupon.getBusinessType() != 4) {
|
|
|
- return moneyDTO;
|
|
|
- }
|
|
|
+ fsIntegralGoods.setNum(1);
|
|
|
+ goodsItem.add(fsIntegralGoods);
|
|
|
|
|
|
- if (fsUserCoupon.getStatus() == 1) {
|
|
|
- return moneyDTO;
|
|
|
- }
|
|
|
+ moneyDTO.setTotalCash(fsIntegralGoods.getCash());
|
|
|
+ moneyDTO.setCash(fsIntegralGoods.getCash());
|
|
|
+ moneyDTO.setTotalIntegral(new BigDecimal(fsIntegralGoods.getIntegral()));
|
|
|
+ moneyDTO.setIntegral(new BigDecimal(fsIntegralGoods.getIntegral()));
|
|
|
|
|
|
- if (fsUserCoupon.getStatus() == 2 || fsUserCoupon.getLimitTime().before(new Date())) {
|
|
|
- return moneyDTO;
|
|
|
- }
|
|
|
+ // 优惠金额计算
|
|
|
+ if (param.getUserCouponId() != null) {
|
|
|
+ applyCoupon(param.getUserCouponId(), fsUser.getUserId(), fsIntegralGoods, moneyDTO);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Wrapper<FsIntegralCart> wrapper = Wrappers.<FsIntegralCart>lambdaQuery().eq(FsIntegralCart::getUserId, fsUser.getUserId())
|
|
|
+ .in(FsIntegralCart::getId, param.getCartIds());
|
|
|
+ List<FsIntegralCart> carts = cartService.list(wrapper);
|
|
|
+ if (carts.isEmpty()) {
|
|
|
+ return R.error("购物车商品不存在");
|
|
|
+ }
|
|
|
|
|
|
- // 查看优惠券具体类型
|
|
|
- FsCoupon fsCoupon = fsCouponMapper.selectFsCouponByCouponId(fsUserCoupon.getCouponId());
|
|
|
- if (fsCoupon == null) {
|
|
|
- return moneyDTO;
|
|
|
+ for (FsIntegralCart cart : carts) {
|
|
|
+ FsIntegralGoods integralGoods = fsIntegralGoodsMapper.selectFsIntegralGoodsByGoodsId(cart.getGoodsId());
|
|
|
+ if (Objects.isNull(integralGoods)) {
|
|
|
+ throw new CustomException("商品不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算所需积分和现金
|
|
|
+ BigDecimal totalIntegral = new BigDecimal(integralGoods.getIntegral()).multiply(new BigDecimal(cart.getCartNum()));
|
|
|
+ BigDecimal totalCash = integralGoods.getCash().multiply(new BigDecimal(cart.getCartNum()));
|
|
|
+
|
|
|
+ moneyDTO.setTotalIntegral(moneyDTO.getTotalIntegral().add(totalIntegral));
|
|
|
+ moneyDTO.setTotalCash(moneyDTO.getTotalCash().add(totalCash));
|
|
|
+
|
|
|
+ integralGoods.setNum(cart.getCartNum());
|
|
|
+ goodsItem.add(integralGoods);
|
|
|
+ }
|
|
|
+
|
|
|
+ moneyDTO.setIntegral(moneyDTO.getTotalIntegral());
|
|
|
+ moneyDTO.setCash(moneyDTO.getTotalCash());
|
|
|
}
|
|
|
|
|
|
- // 积分商品免单券
|
|
|
- if (fsCoupon.getCouponType() == 7) {
|
|
|
- // 查找指定减免积分商品并减免价格
|
|
|
- List<FsIntegralGoods> goodsItem = JSONUtil.toBean(goodsJson, new TypeReference<List<FsIntegralGoods>>(){}, true);
|
|
|
- goodsItem.stream().filter(g -> g.getGoodsId().equals(fsCoupon.getFreeGoodsId())).findFirst().ifPresent(g -> {
|
|
|
- BigDecimal integral = orderIntegral.subtract(new BigDecimal(g.getIntegral()));
|
|
|
- BigDecimal cash = orderMoney.subtract(g.getCash());
|
|
|
- moneyDTO.setIntegral(integral);
|
|
|
- moneyDTO.setDiscountIntegral(new BigDecimal(g.getIntegral()));
|
|
|
- moneyDTO.setCash(cash);
|
|
|
- moneyDTO.setDiscountCash(g.getCash());
|
|
|
- });
|
|
|
+ // 运费计算
|
|
|
+ if (param.getUserAddressId() != null) {
|
|
|
+ FsUserAddress fsUserAddress = fsUserAddressMapper.selectFsUserAddressByAddressId(param.getUserAddressId());
|
|
|
+ if (fsUserAddress == null || fsUserAddress.getIsDel() == 1 || fsUserAddress.getIsConfirm() == 0
|
|
|
+ || !fsUser.getUserId().equals(fsUserAddress.getUserId())) {
|
|
|
+ return R.error("收货地址不存在");
|
|
|
+ }
|
|
|
+ calcDeliveryMoney(moneyDTO, fsUserAddress, goodsItem);
|
|
|
}
|
|
|
|
|
|
- return moneyDTO;
|
|
|
+ // 返回扣减后的支付金额
|
|
|
+ return R.ok().put("data", moneyDTO);
|
|
|
}
|
|
|
|
|
|
}
|