|
@@ -3421,8 +3421,8 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
if (orderInfo.getOrderStatus() != Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
|
|
|
LOGGER.info("[微信退款开始--------orderRefund]"+order.getOrderSn());
|
|
|
-// WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn(), totalActualPrice,
|
|
|
-// orderInfo.getActualPrice().doubleValue());
|
|
|
+ WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn(), totalActualPrice,
|
|
|
+ orderInfo.getActualPrice().doubleValue());
|
|
|
order.setPayStatus(Integer.parseInt(Dict.payStatus.item_5.getItem()));
|
|
|
order.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_401.getItem()));
|
|
|
//修改为退款成功
|
|
@@ -3432,8 +3432,8 @@ public class OrderServiceImpl implements OrderService {
|
|
|
pickUpCodeEntity.setPickUpCodeStatus(Dict.PickUpCodeStatusEnum.item_3.getStatus());
|
|
|
pickUpCodeService.update(pickUpCodeEntity);
|
|
|
//新增退款记录
|
|
|
- OrderRefundEntity orderRefund = orderRefundLog("wx453456511","wx453456566","26999",order.getId(),user.getUserId(),order.getMerchOrderSn());
|
|
|
- //OrderRefundEntity orderRefund = orderRefundLog(result.getRefund_id(),result.getOut_trade_no(),result.getRefund_fee(),order.getId(),user.getUserId(),order.getMerchOrderSn());
|
|
|
+ //OrderRefundEntity orderRefund = orderRefundLog("wx453456511","wx453456566","26999",order.getId(),user.getUserId(),order.getMerchOrderSn());
|
|
|
+ OrderRefundEntity orderRefund = orderRefundLog(result.getRefund_id(),result.getOut_trade_no(),result.getRefund_fee(),order.getId(),user.getUserId(),order.getMerchOrderSn());
|
|
|
orderRefundDao.save(orderRefund);
|
|
|
//还原库存,调用免税mall接口退款和积分回退接口
|
|
|
restoreInventoryMsMall(order);
|
|
@@ -4619,36 +4619,58 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
|
List<MkActivitiesScoreEntity> mkActivitiesScoreEntities = mkActivitiesScoreService.queryActivityInfoByMkaIdList(mkaIdList);
|
|
|
|
|
|
- // 参与了积分抵扣的sku集合
|
|
|
- List<String> scoreDeductionSkuList = mkActivitiesScoreEntities.stream()
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesScoreEntities)) {
|
|
|
+ LOGGER.error("查询积分抵扣活动SKU为空!");
|
|
|
+ throw new ServiceException("查询积分抵扣活动SKU为空!请先导入积分抵扣活动信息!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 参与了积分抵扣的sku集合,过滤的是参与的sku,如果该list不为空,则默认其余的sku不参与积分抵扣
|
|
|
+ List<String> scoreDeductionAllowSkuList = mkActivitiesScoreEntities.stream()
|
|
|
.filter(m -> Constants.RejectStatus.ALLOW.getCode().equals(m.getReject()))
|
|
|
.map(MkActivitiesScoreEntity::getSku)
|
|
|
.collect(Collectors.toList());
|
|
|
- // 转换成map,保存参与了积分抵扣活动的sku,积分计算比例的数据,key===>sku,value===>最大抵扣比例
|
|
|
- Map<String, BigDecimal> skuScoreLimitMap = mkActivitiesScoreEntities.stream()
|
|
|
- .filter(m -> Constants.RejectStatus.ALLOW.getCode().equals(m.getReject()))
|
|
|
- .collect(Collectors.toMap(MkActivitiesScoreEntity::getSku, mkActivitiesScoreEntity -> {
|
|
|
- BigDecimal scoreLimit = mkActivitiesScoreEntity.getScoreLimit();
|
|
|
- if (Objects.isNull(scoreLimit)) {
|
|
|
- LOGGER.error("商品:【{}】,未设置最大抵扣比例!请设置后再计算优惠价!", mkActivitiesScoreEntity.getSku());
|
|
|
- throw new ServiceException(String.format("商品:【%s】,未设置最大抵扣比例!请设置后再计算优惠价!", mkActivitiesScoreEntity.getSku()));
|
|
|
- }
|
|
|
- return scoreLimit;
|
|
|
- }, (k1, k2) -> k2));
|
|
|
+ // 不参与积分抵扣的sku集合,如果该list不为空,则默认其余的sku参与积分抵扣
|
|
|
+ List<String> scoreDeductionRejectSkuList = mkActivitiesScoreEntities.stream()
|
|
|
+ .filter(m -> Constants.RejectStatus.REJECT.getCode().equals(m.getReject()))
|
|
|
+ .map(MkActivitiesScoreEntity::getSku)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && !CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
|
|
|
+ LOGGER.error("积分抵扣表中既有参与又有不参与!与需求不符!");
|
|
|
+ throw new ServiceException("导入的积分抵扣活动商品设置有误!请确保导入的数据中只有参与或者不参与!");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
|
|
|
+ LOGGER.error("积分抵扣表中无是否参与字段!");
|
|
|
+ throw new ServiceException("导入的积分抵扣活动商品设置有误!导入的活动商品数据中必须有参与或者不参与!");
|
|
|
+ }
|
|
|
+
|
|
|
// 当前订单中参与了积分抵扣活动的sku总支付金额
|
|
|
BigDecimal skuTotalPrice = BigDecimal.ZERO;
|
|
|
for (GoodsDetailsDto goodsDetailsDto : goodsDetailsDtos) {
|
|
|
String sku = goodsDetailsDto.getGoodsSn();
|
|
|
if (!promotionSkuList.contains(sku)) {
|
|
|
- if (scoreDeductionSkuList.contains(sku)) {
|
|
|
- BigDecimal skuActualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
|
|
|
- skuTotalPrice = skuTotalPrice.add(skuActualPaymentAmount);
|
|
|
+ if (CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && !CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
|
|
|
+ if (!scoreDeductionRejectSkuList.contains(sku)) {
|
|
|
+ BigDecimal skuActualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
|
|
|
+ skuTotalPrice = skuTotalPrice.add(skuActualPaymentAmount);
|
|
|
+ }
|
|
|
+ } else if (!CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
|
|
|
+ if (scoreDeductionAllowSkuList.contains(sku)) {
|
|
|
+ BigDecimal skuActualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
|
|
|
+ skuTotalPrice = skuTotalPrice.add(skuActualPaymentAmount);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 2. 计算积分抵扣后的总价格
|
|
|
if (isCalculateScorePrice.get()) {
|
|
|
- Integer scoreLimit = haiKongProperties.getMemberScoreLimit();
|
|
|
+ // HAIKONG_MEMBER_SCORE_LIMIT 系统参数,海控平台统一30积分1块钱
|
|
|
+ String scoreLimitStr = sysConfigDao.queryByKey(Constants.HAIKONG_MEMBER_SCORE_LIMIT);
|
|
|
+ if (org.springframework.util.StringUtils.isEmpty(scoreLimitStr)) {
|
|
|
+ LOGGER.error("计算优惠价格时,未设置统一的抵扣规则!");
|
|
|
+ throw new ServiceException(String.format("请先设置统一的积分规则,设置方式:【系统管理】-->【系统参数】,参数名为:【%s】", Constants.HAIKONG_MEMBER_SCORE_LIMIT));
|
|
|
+ }
|
|
|
+ Integer scoreLimit = Integer.parseInt(scoreLimitStr);
|
|
|
if (score < scoreLimit) {
|
|
|
LOGGER.error("用户【{}】的积分数量为:{},最低需要{}积分才能抵扣!", memberCode, score, scoreLimit);
|
|
|
calculateOrderDiscountPriceResponseVO.setAfterScore(score);
|
|
@@ -4658,16 +4680,36 @@ public class OrderServiceImpl implements OrderService {
|
|
|
int scoreInteger = score % scoreLimit == 0 ? score : score - (score % scoreLimit);
|
|
|
// 过滤掉参与过限时特价并且与积分抵扣互斥的sku,以及未参加积分抵扣活动的sku
|
|
|
goodsDetailsDtos = goodsDetailsDtos.stream().filter(goodsDetailsDto -> {
|
|
|
- if (!promotionSkuList.contains(goodsDetailsDto.getSku()) && scoreDeductionSkuList.contains(goodsDetailsDto.getSku())) {
|
|
|
- return true;
|
|
|
+ String sku = goodsDetailsDto.getSku();
|
|
|
+ if (!promotionSkuList.contains(sku)) {
|
|
|
+ // 如果导入的商品都为不参与,则其余的商品都默认参与积分抵扣活动
|
|
|
+ if (CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && !CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
|
|
|
+ if (!scoreDeductionRejectSkuList.contains(sku)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ // 如果导入的商品都为参与,则默认其余商品不参与
|
|
|
+ } else if (!CollectionUtils.isEmpty(scoreDeductionAllowSkuList) && CollectionUtils.isEmpty(scoreDeductionRejectSkuList)) {
|
|
|
+ if (scoreDeductionAllowSkuList.contains(sku)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
// 满赠商品不参与积分分摊计算
|
|
|
return !Constants.ActivityTopicEnum.MZ.getTopicName().equals(goodsDetailsDto.getActivity());
|
|
|
}).collect(Collectors.toList());
|
|
|
+ // 系统设置的最大抵扣比例(最多能抵扣订单金额的比例),在系统管理的系统参数中设置,KEY为 HAIKONG_MEMBER_MAX_SCORE_RATIO
|
|
|
+ String scoreRatioStr = sysConfigDao.queryByKey(Constants.HAIKONG_MEMBER_MAX_SCORE_RATIO);
|
|
|
+ if (org.springframework.util.StringUtils.isEmpty(scoreRatioStr)) {
|
|
|
+ LOGGER.error("计算优惠价格时,未设置订单的最大积分抵扣比例!");
|
|
|
+ throw new ServiceException(String.format("请先设置订单的最大积分抵扣比例,设置方式:【系统管理】-->【系统参数】,参数名为:【%s】", Constants.HAIKONG_MEMBER_MAX_SCORE_RATIO));
|
|
|
+ }
|
|
|
+ BigDecimal scoreRatio = new BigDecimal(scoreRatioStr);
|
|
|
// 总分摊积分
|
|
|
BigDecimal shareScore = BigDecimal.ZERO;
|
|
|
// 取整后的积分数量
|
|
|
BigDecimal scoreIntegerDecimal = BigDecimal.valueOf(scoreInteger);
|
|
|
+ // 计算积分能抵扣的金额
|
|
|
+ BigDecimal scoreCanDeductionPrice = scoreIntegerDecimal.divide(BigDecimal.valueOf(scoreLimit), 0, BigDecimal.ROUND_FLOOR);
|
|
|
// 订单详情积分抵扣总金额
|
|
|
BigDecimal goodsDetailScoreDeductionPrice = BigDecimal.ZERO;
|
|
|
int size = goodsDetailsDtos.size();
|
|
@@ -4678,14 +4720,12 @@ public class OrderServiceImpl implements OrderService {
|
|
|
String activity = goodsDetailsDto.getActivity();
|
|
|
goodsDetailsDto.setActivity(org.springframework.util.StringUtils.isEmpty(activity) ? "积分抵扣" : activity.contains("积分抵扣") ? activity : activity + ",积分抵扣");
|
|
|
String sku = goodsDetailsDto.getGoodsSn();
|
|
|
- // 系统设置的最大抵扣比例(最多能抵扣订单金额的比例),导入积分抵扣活动时设置
|
|
|
- BigDecimal scoreLimitDecimal = skuScoreLimitMap.get(sku);
|
|
|
String prodBarcode = goodsDetailsDto.getProdBarcode();
|
|
|
// 此字段 = 零售价 - 其他活动优惠金额
|
|
|
BigDecimal actualPaymentAmount = goodsDetailsDto.getActualPaymentAmount();
|
|
|
// 当前商品最大支持抵扣的金额
|
|
|
BigDecimal currentSkuMaxDeductionPrice = actualPaymentAmount.multiply(BigDecimal.valueOf(goodsDetailsDto.getSellVolume()))
|
|
|
- .multiply(scoreLimitDecimal);
|
|
|
+ .multiply(scoreRatio).setScale(0, BigDecimal.ROUND_FLOOR);
|
|
|
// 其他活动优惠金额
|
|
|
BigDecimal otherDiscountedPrice = Objects.isNull(goodsDetailsDto.getDiscountedPrice()) ? BigDecimal.ZERO : goodsDetailsDto.getDiscountedPrice();
|
|
|
|
|
@@ -4695,21 +4735,23 @@ public class OrderServiceImpl implements OrderService {
|
|
|
BigDecimal discountedPrice = BigDecimal.ZERO;
|
|
|
// 计算抵扣,当商品不是最后一个商品
|
|
|
if (i < index) {
|
|
|
- shareScoreItem = actualPaymentAmount.divide(skuTotalPrice, 10, BigDecimal.ROUND_HALF_UP).multiply(scoreIntegerDecimal).setScale(0, BigDecimal.ROUND_FLOOR);
|
|
|
+ shareScoreItem = actualPaymentAmount.multiply(scoreIntegerDecimal).divide(skuTotalPrice, 0, BigDecimal.ROUND_FLOOR);
|
|
|
discountedPrice = shareScoreItem.divide(BigDecimal.valueOf(scoreLimit), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
|
// 订单商品详情最后一个商品并且详情不止一个商品
|
|
|
- if (i == index && size > 1) {// 商品总价
|
|
|
+ if (i == index && size > 1) {
|
|
|
// 最后一个商品分摊积分 = 积分总数 - 已分摊积分
|
|
|
shareScoreItem = scoreIntegerDecimal.subtract(shareScore);
|
|
|
- discountedPrice = shareScoreItem.divide(BigDecimal.valueOf(scoreLimit), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+// discountedPrice = shareScoreItem.divide(BigDecimal.valueOf(scoreLimit), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ // 2021-12-13最后一个商品修改计算方式,原计算方式:(总抵扣积分 - 已分摊积分) / 30,改为:积分能抵扣的金额 - 已抵扣金额
|
|
|
+ discountedPrice = scoreCanDeductionPrice.subtract(goodsDetailScoreDeductionPrice);
|
|
|
}
|
|
|
// 订单商品详情只有一个商品的情况下
|
|
|
if (size == 1) {
|
|
|
// 总计分为所有积分取整
|
|
|
- shareScore = scoreIntegerDecimal;
|
|
|
+ shareScoreItem = scoreIntegerDecimal;
|
|
|
// 3-3. 计算积分抵扣后的价格
|
|
|
- discountedPrice = shareScore.divide(BigDecimal.valueOf(scoreLimit), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ discountedPrice = shareScoreItem.divide(BigDecimal.valueOf(scoreLimit), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
|
// 当前计算出来的积分抵扣金额如果比最大的还要大,则积分抵扣金额为最大抵扣金额,并且积分需要重新计算
|
|
|
if (discountedPrice.compareTo(currentSkuMaxDeductionPrice) > 0) {
|
|
@@ -5057,7 +5099,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
orderGoodsVo.setInventoryType(goodsDto.getInventoryType());
|
|
|
orderGoodsVo.setDefectiveProductsGrade(goodsDto.getDefectiveProductsGrade());
|
|
|
|
|
|
- BigDecimal number = new BigDecimal(Long.valueOf(goodsDto.getSellVolume()));
|
|
|
+ /*BigDecimal number = new BigDecimal(Long.valueOf(goodsDto.getSellVolume()));
|
|
|
BigDecimal goodsTotal = goodsDto.getRetailPrice().multiply(number);//单商品总价
|
|
|
BigDecimal rate = goodsTotal.divide(orderInfo.getGoods_price(), 2, BigDecimal.ROUND_HALF_UP);//当前商品总价/订单总价(不含运费、不含优惠券)
|
|
|
BigDecimal freightPrice = BigDecimal.valueOf(orderInfo.getFreight_price());
|
|
@@ -5085,13 +5127,13 @@ public class OrderServiceImpl implements OrderService {
|
|
|
orderGoodsVo.setSettlePrice(goodsTotal);//商品结算平摊价格
|
|
|
} else {
|
|
|
orderGoodsVo.setSettlePrice(settlePrice);//商品结算平摊价格
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
// 计算税费
|
|
|
- GoodsEntity goodsEntity = goodsService.queryObject(goodsDto.getId().intValue());
|
|
|
+ /*GoodsEntity goodsEntity = goodsService.queryObject(goodsDto.getId().intValue());
|
|
|
BigDecimal goodsTax = CalculateTax.calculateFinalTax(goodsEntity, goodsDto.getStoreRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
- goodsTax = goodsTax.multiply(number).setScale(2, RoundingMode.HALF_UP);
|
|
|
- orderGoodsVo.setTaxPrice(goodsTax);
|
|
|
+ goodsTax = goodsTax.multiply(number).setScale(2, RoundingMode.HALF_UP);*/
|
|
|
+ orderGoodsVo.setTaxPrice(goodsDto.getGoodsTaxes());
|
|
|
|
|
|
return orderGoodsVo;
|
|
|
}
|