|
@@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.internal.LinkedTreeMap;
|
|
@@ -21,7 +20,7 @@ import com.kmall.admin.dao.vip.Mall2MemberPointsDao;
|
|
|
import com.kmall.admin.dao.vip.Mall2PointsRulesDao;
|
|
|
import com.kmall.admin.dto.*;
|
|
|
import com.kmall.admin.entity.*;
|
|
|
-import com.kmall.admin.entity.kmall2eccs.KtoEccsEntity;
|
|
|
+import com.kmall.admin.entity.mk.MkActivitiesEntity;
|
|
|
import com.kmall.admin.entity.mk.store.MkStorePromOrderRealEntity;
|
|
|
import com.kmall.admin.entity.record.NewRetailOrderRestoreStockRecordEntity;
|
|
|
import com.kmall.admin.entity.vip.Mall2MemberConsumptionRecordsEntity;
|
|
@@ -29,15 +28,21 @@ import com.kmall.admin.entity.vip.Mall2MemberPointsEntity;
|
|
|
import com.kmall.admin.entity.vip.Mall2PointsRulesEntity;
|
|
|
import com.kmall.admin.fromcomm.dao.SysConfigDao;
|
|
|
import com.kmall.admin.fromcomm.entity.SysUserEntity;
|
|
|
+import com.kmall.admin.haikong.constant.Constants;
|
|
|
+import com.kmall.admin.haikong.constant.VmcconnectUrlEnum;
|
|
|
+import com.kmall.admin.haikong.dto.WareQueryStockResponseDTO;
|
|
|
import com.kmall.admin.haikong.utils.ListUtils;
|
|
|
-import com.kmall.admin.haikong.vo.QueryGoodsVo;
|
|
|
+import com.kmall.admin.haikong.vo.CalculateOrderDiscountPriceResponseVO;
|
|
|
+import com.kmall.admin.haikong.vo.QueryGoodsVO;
|
|
|
import com.kmall.admin.haikong.client.HaiKongMemberTemplate;
|
|
|
import com.kmall.admin.haikong.client.HaiKongWarehouseTemplate;
|
|
|
+import com.kmall.admin.haikong.client.VmcShopTemplate;
|
|
|
import com.kmall.admin.haikong.config.HaiKongProperties;
|
|
|
import com.kmall.admin.haikong.dto.MemberInfoDTO;
|
|
|
import com.kmall.admin.haikong.utils.Response;
|
|
|
import com.kmall.admin.service.*;
|
|
|
import com.kmall.admin.service.kmall2eccs.KtoEccsService;
|
|
|
+import com.kmall.admin.service.mk.MkActivitiesService;
|
|
|
import com.kmall.admin.service.mk.store.MkStoreCampMinusService;
|
|
|
import com.kmall.admin.service.mk.store.MkStoreTicketDiscountService;
|
|
|
import com.kmall.admin.service.record.NewRetailOrderRestoreStockRecordService;
|
|
@@ -48,6 +53,7 @@ import com.kmall.admin.utils.data.response.ResponseMessageData;
|
|
|
import com.kmall.admin.utils.jackson.JacksonUtil;
|
|
|
import com.kmall.admin.utils.oms.OmsSign;
|
|
|
import com.kmall.admin.utils.pdf.BarcodeUtil;
|
|
|
+import com.kmall.admin.haikong.vo.CalculateOrderDiscountPriceVO;
|
|
|
import com.kmall.admin.websocket.WebSocketServer;
|
|
|
import com.kmall.api.entity.OrderGoodsRestoreVo;
|
|
|
import com.kmall.api.entity.OrderGoodsVo;
|
|
@@ -95,6 +101,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -194,9 +201,6 @@ public class OrderServiceImpl implements OrderService {
|
|
|
private Mall2LowPriceWarningDao lowPriceWarningDao;
|
|
|
|
|
|
@Autowired
|
|
|
- private MkActivitiesCouponService mkActivitiesCouponService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
private OrderRefundService orderRefundService;
|
|
|
@Autowired
|
|
|
private OrderExceptionRecordService orderExceptionRecordService;
|
|
@@ -204,10 +208,6 @@ public class OrderServiceImpl implements OrderService {
|
|
|
@Autowired
|
|
|
private AddressInfoService addressInfoService;
|
|
|
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private KtoEccsService ktoEccsService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private CustomsClearanceTimeliness customsClearanceTimeliness;
|
|
|
|
|
@@ -219,6 +219,38 @@ public class OrderServiceImpl implements OrderService {
|
|
|
|
|
|
@Autowired
|
|
|
private HaiKongProperties haiKongProperties;
|
|
|
+ /**
|
|
|
+ * 免税mall接口工具类
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private VmcShopTemplate vmcShopTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MkActivitiesService mkActivitiesService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 满赠
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private MkActivitiesFullGiftService mkActivitiesFullGiftService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠券
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private MkActivitiesCouponService mkActivitiesCouponService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 限时特价
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private MkActivitiesPromotionService mkActivitiesPromotionService;
|
|
|
+ /**
|
|
|
+ * 免税mall日志记录
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private MallVmcSendLogDao mallVmcSendLogDao;
|
|
|
+
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -808,8 +840,6 @@ public class OrderServiceImpl implements OrderService {
|
|
|
map.put("orderId", order.getId());
|
|
|
List<OrderGoodsEntity> orderGoodsVoList = orderGoodsDao.queryList(map);
|
|
|
|
|
|
- // TODO 退单的库存明细存入表中,准备发送到中控
|
|
|
- List<KtoEccsEntity> ktoEccsEntities = new LinkedList<>();
|
|
|
for (OrderGoodsEntity orderGoodsEntity : orderGoodsVoList) {
|
|
|
ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao
|
|
|
.queryByGoodsIdAndStoreId(order.getStoreId().longValue(), orderGoodsEntity.getGoodsId().longValue());
|
|
@@ -820,42 +850,17 @@ public class OrderServiceImpl implements OrderService {
|
|
|
if (sellVolume.compareTo(Constant.ZERO) < 0) {
|
|
|
sellVolume = Constant.ZERO;
|
|
|
}
|
|
|
-
|
|
|
+// GoodsEntity goodsEntity = goodsDao.queryObject(orderGoodsEntity.getGoodsId());
|
|
|
+// if (goodsEntity != null) {
|
|
|
+// stockNum = goodsEntity.getGoodsNumber();
|
|
|
+// //还原商户商品库存
|
|
|
+// resetGoodsStock(stockNum, storeRelaEntity, orderGoodsEntity, sellVolume, changeReason, user);
|
|
|
+// }
|
|
|
Integer stockNum = 0;
|
|
|
- GoodsEntity goodsEntity = goodsDao.queryObject(orderGoodsEntity.getGoodsId());
|
|
|
- if (goodsEntity != null) {
|
|
|
- stockNum = goodsEntity.getGoodsNumber();
|
|
|
- //还原商户商品库存
|
|
|
- resetGoodsStock(stockNum, storeRelaEntity, orderGoodsEntity, sellVolume, changeReason, user);
|
|
|
- }
|
|
|
if (null != storeRelaEntity.getStockNum()) {
|
|
|
stockNum = storeRelaEntity.getStockNum();
|
|
|
resetStoreGoodsStock(stockNum, storeRelaEntity, orderGoodsEntity, sellVolume, changeReason, user);//还原门店库存
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-// orderGoodsVoList
|
|
|
- KtoEccsEntity ktoEccsEntity = new KtoEccsEntity();
|
|
|
- ktoEccsEntity.setRequestData(JSON.toJSONString(orderGoodsEntity));
|
|
|
- ktoEccsEntity.setRequestType("04");
|
|
|
- ktoEccsEntity.setSendStatus("00");
|
|
|
- if (user != null) {
|
|
|
- ktoEccsEntity.setCreaterSn(user.getUserId() + "");
|
|
|
- } else {
|
|
|
- ktoEccsEntity.setCreaterSn("9999");
|
|
|
- }
|
|
|
- ktoEccsEntity.setCreateTime(new Date());
|
|
|
- ktoEccsEntities.add(ktoEccsEntity);
|
|
|
- }
|
|
|
- if (ktoEccsEntities.size() > 0) {
|
|
|
- if (ktoEccsEntities.size() > 50) {
|
|
|
- List<List<KtoEccsEntity>> partition = Lists.partition(ktoEccsEntities, 50);
|
|
|
- for (List<KtoEccsEntity> ktoEccs : partition) {
|
|
|
- ktoEccsService.saveBatch(ktoEccs);
|
|
|
- }
|
|
|
- } else {
|
|
|
- ktoEccsService.saveBatch(ktoEccsEntities);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -939,8 +944,6 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
goodsDao.update(goodsEntity);
|
|
|
|
|
|
-// storeRelaEntity.setSellVolume(Integer.parseInt(sellVolume.toString()));
|
|
|
-// productStoreRelaDao.update(storeRelaEntity);
|
|
|
String username = "system";
|
|
|
if (user != null) {
|
|
|
username = user.getUsername();
|
|
@@ -1006,6 +1009,44 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 海控还原门店商品库存
|
|
|
+ * @param stockNum
|
|
|
+ * @param storeRelaEntity
|
|
|
+ * @param orderGoodsEntity
|
|
|
+ * @param sellVolume
|
|
|
+ * @param user
|
|
|
+ */
|
|
|
+ private void resetStoreGoodsStockMall(Integer stockNum, ProductStoreRelaEntity storeRelaEntity,
|
|
|
+ OrderGoodsEntity orderGoodsEntity, BigDecimal sellVolume,SysUserEntity user) {
|
|
|
+ storeRelaEntity.setSellVolume(Integer.parseInt(sellVolume.toString())); // 减退库存
|
|
|
+ //库存数量 + 商品数量
|
|
|
+ storeRelaEntity.setStockNum(stockNum + orderGoodsEntity.getNumber());//库存数量
|
|
|
+ //待退款数量 - 商品数量
|
|
|
+ storeRelaEntity.setToBeRestored(storeRelaEntity.getToBeRestored() - orderGoodsEntity.getNumber());
|
|
|
+ productStoreRelaDao.update(storeRelaEntity);
|
|
|
+
|
|
|
+ String username = "system";
|
|
|
+ if (user != null) {
|
|
|
+ username = user.getUsername();
|
|
|
+ }
|
|
|
+ StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
|
|
|
+ storeMngChangeEntity.setChangeType(Dict.changeType.item_0.getItem());
|
|
|
+ storeMngChangeEntity.setChangeReason("前端退款");
|
|
|
+ storeMngChangeEntity.setGoodsId(storeRelaEntity.getGoodsId().intValue());
|
|
|
+ storeMngChangeEntity.setStoreId(storeRelaEntity.getStoreId().intValue());
|
|
|
+ storeMngChangeEntity.setMerchSn(storeRelaEntity.getMerchSn());
|
|
|
+ storeMngChangeEntity.setStoreChangeNum(orderGoodsEntity.getNumber());
|
|
|
+ storeMngChangeEntity.setStoreOriginalNum(stockNum);
|
|
|
+ storeMngChangeEntity.setStoreValidNum(stockNum + orderGoodsEntity.getNumber());
|
|
|
+ storeMngChangeEntity.setCreateTime(new Date());
|
|
|
+ storeMngChangeEntity.setModTime(new Date());
|
|
|
+ storeMngChangeEntity.setCreaterSn(username);
|
|
|
+ storeMngChangeEntity.setModerSn(username);
|
|
|
+ storeMngChangeEntity.setIsValid(0);
|
|
|
+ storeMngChangeDao.save(storeMngChangeEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 查询该退款订单编号是否是推广渠道订单,是则修改渠道定时扫描状态
|
|
|
*
|
|
|
* @param orderInfo
|
|
@@ -2036,9 +2077,23 @@ public class OrderServiceImpl implements OrderService {
|
|
|
LOGGER.error("调用库存系统接口出现错误!返回结果为空!");
|
|
|
throw new ServiceException("调用库存系统接口出现错误!");
|
|
|
}
|
|
|
- // TODO 解析xml,组装成map key=>sku value=>库存
|
|
|
+ WareQueryStockResponseDTO wareQueryStockResponseDTO = JacksonUtil.fromStringJson(queryWarehouseStockResponse, WareQueryStockResponseDTO.class);
|
|
|
+ if (Objects.isNull(wareQueryStockResponseDTO)) {
|
|
|
+ throw new ServiceException("解析一步达库存系统响应数据出现错误!");
|
|
|
+ }
|
|
|
+ List<WareQueryStockResponseDTO.WareQueryStockResponseItemDTO> items = wareQueryStockResponseDTO.getItems();
|
|
|
+ // 解析xml,组装成map key=>sku value=>库存
|
|
|
Map<String, Integer> stockMap = new HashMap<>(16);
|
|
|
-
|
|
|
+ items.forEach(item -> {
|
|
|
+ String itemCode = item.getItemCode();
|
|
|
+ Integer quantity = item.getQuantity();
|
|
|
+ if (stockMap.containsKey(itemCode)) {
|
|
|
+ // 避免出现sku相同情况
|
|
|
+ stockMap.put(itemCode, stockMap.get(itemCode) + quantity);
|
|
|
+ } else {
|
|
|
+ stockMap.put(itemCode, quantity);
|
|
|
+ }
|
|
|
+ });
|
|
|
// 订单总价格(含税价)
|
|
|
BigDecimal orderPrice = BigDecimal.ZERO;
|
|
|
// 商品总价格(不含税)
|
|
@@ -2047,27 +2102,31 @@ public class OrderServiceImpl implements OrderService {
|
|
|
BigDecimal totalTax = BigDecimal.ZERO;
|
|
|
|
|
|
List<OrderGoodsEntity> orderGoodsEntities = new ArrayList<>();
|
|
|
+ List<GoodsEntity> goodsEntities = new ArrayList<>();
|
|
|
|
|
|
// TODO 根据商品条码、sku、门店id查询相对应的商品信息,并组装成对象
|
|
|
- List<QueryGoodsVo> queryGoodsVoList = new ArrayList<>();
|
|
|
+ List<QueryGoodsVO> queryGoodsVOList = new ArrayList<>();
|
|
|
goodsList.forEach(map -> {
|
|
|
- QueryGoodsVo queryGoodsVo = new QueryGoodsVo();
|
|
|
+ QueryGoodsVO queryGoodsVo = new QueryGoodsVO();
|
|
|
queryGoodsVo.setProdBarcode((String) map.get("prodBarcode"));
|
|
|
queryGoodsVo.setSku((String) map.get("goodsSn"));
|
|
|
queryGoodsVo.setStoreId(storeId);
|
|
|
queryGoodsVo.setSellVolume((Integer) map.get("sellVolume"));
|
|
|
queryGoodsVo.setRetailPrice(new BigDecimal(String.valueOf(map.get("retailPrice"))));
|
|
|
- queryGoodsVo.setGoodstaxes(new BigDecimal(String.valueOf(map.get("goodstaxes"))));
|
|
|
+ queryGoodsVo.setGoodsTaxes(new BigDecimal(String.valueOf(map.get("goodstaxes"))));
|
|
|
queryGoodsVo.setDisCountedPrice(new BigDecimal(String.valueOf(map.get("disCountedPrice"))));
|
|
|
- queryGoodsVoList.add(queryGoodsVo);
|
|
|
+ queryGoodsVOList.add(queryGoodsVo);
|
|
|
});
|
|
|
// 将在循环中查询数据库改为一次性查询
|
|
|
- List<GoodsEntity> goodsEntityList = goodsService.queryGoodsStockByQueryGoodsVoList(queryGoodsVoList);
|
|
|
+ List<GoodsEntity> goodsEntityList = goodsService.queryGoodsStockByQueryGoodsVoList(queryGoodsVOList);
|
|
|
// 复制集合数据
|
|
|
ListUtils listUtils = BeanUtils.instantiate(ListUtils.class);
|
|
|
- listUtils.copyList(goodsEntityList, queryGoodsVoList);
|
|
|
+ listUtils.copyList(goodsEntityList, queryGoodsVOList);
|
|
|
+ // 用来存储是否达到满赠条件的map
|
|
|
+ Map<String, BigDecimal> categoryConditionMap = new HashMap<>();
|
|
|
+ Map<String, BigDecimal> brandConditionMap = new HashMap<>();
|
|
|
|
|
|
- for (QueryGoodsVo goodsEntity : queryGoodsVoList) {
|
|
|
+ for (QueryGoodsVO goodsEntity : queryGoodsVOList) {
|
|
|
OrderGoodsEntity orderGoodsEntity = new OrderGoodsEntity();
|
|
|
// 要购买的数量
|
|
|
Integer sellVolume = goodsEntity.getSellVolume();
|
|
@@ -2078,7 +2137,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
// 订单金额(含税价),订单总金额,用户支付的金额
|
|
|
BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
// 商品预估税率
|
|
|
- BigDecimal goodsTaxes = goodsEntity.getGoodstaxes();
|
|
|
+ BigDecimal goodsTaxes = goodsEntity.getGoodsTaxes();
|
|
|
// 商品优惠金额
|
|
|
BigDecimal disCountedPrice = goodsEntity.getDisCountedPrice();
|
|
|
// 商品金额(不包含税的价格),推送海关电子订单需要
|
|
@@ -2089,29 +2148,91 @@ public class OrderServiceImpl implements OrderService {
|
|
|
totalTax = totalTax.add(goodsTaxes);
|
|
|
// 当前sku
|
|
|
String currentSku = goodsEntity.getSku();
|
|
|
- // TODO 判断库存。。
|
|
|
- if (!stockMap.containsKey(currentSku)) {
|
|
|
- LOGGER.error("库存系统中不包含此sku:【{}】,校验库存出错!下单失败!", currentSku);
|
|
|
- throw new ServiceException(String.format("不包含此sku:【%s】", currentSku));
|
|
|
- }
|
|
|
// 仓库库存
|
|
|
Integer warehouseStock = stockMap.get(currentSku);
|
|
|
- // 当前出区数
|
|
|
- Integer exitRegionNumber = goodsEntity.getExitRegionNumber();
|
|
|
// 门店库存
|
|
|
Integer stockNum = goodsEntity.getStockNum();
|
|
|
- // 保税仓库存 + 门店库存 - 出区数 >= 购买数
|
|
|
- if (!((warehouseStock + stockNum) - exitRegionNumber >= sellVolume)) {
|
|
|
- // 库存不足
|
|
|
- LOGGER.error("sku【{}】库存不足!商品条码:【{}】,门店库存:【{}】,保税仓库存:【{}】,当前出区数:【{}】", currentSku, prodBarcode, stockNum, warehouseStock, exitRegionNumber);
|
|
|
- throw new ServiceException(String.format("sku【%s】库存不足!商品条码:【%s】,门店库存:【%s】,保税仓库存:【%s】,当前出区数:【%s】", currentSku, prodBarcode, stockNum, warehouseStock, exitRegionNumber));
|
|
|
+ // 判断库存。。
|
|
|
+ if (!stockMap.containsKey(currentSku)) {
|
|
|
+ LOGGER.error("库存系统中不包含此sku:【{}】,校验库存出错!下单失败!", currentSku);
|
|
|
+ throw new ServiceException(String.format("不包含此sku:【%s】", currentSku));
|
|
|
+ } else {
|
|
|
+ // 保税仓库存 + 展销店库存 - 出区数 >= 购买数
|
|
|
+ // 当前出区数
|
|
|
+ Integer exitRegionNumber = goodsEntity.getExitRegionNumber();
|
|
|
+ // 保税仓库存 + 门店库存 - 出区数 >= 购买数
|
|
|
+ if (!((warehouseStock + stockNum) - exitRegionNumber >= sellVolume)) {
|
|
|
+ // 库存不足
|
|
|
+ LOGGER.error("sku【{}】库存不足!商品条码:【{}】,门店库存:【{}】,保税仓库存:【{}】,当前出区数:【{}】", currentSku, prodBarcode, stockNum, warehouseStock, exitRegionNumber);
|
|
|
+ throw new ServiceException(String.format("sku【%s】库存不足!商品条码:【%s】,门店库存:【%s】,保税仓库存:【%s】,当前出区数:【%s】", currentSku, prodBarcode, stockNum, warehouseStock, exitRegionNumber));
|
|
|
+ }
|
|
|
}
|
|
|
// 设置订单详情信息
|
|
|
GoodsEntity entity = new GoodsEntity(goodsEntity);
|
|
|
- orderGoodsEntity = wrapOrderGoods(orderGoodsEntity, entity);
|
|
|
+ wrapOrderGoods(orderGoodsEntity, entity);
|
|
|
orderGoodsEntities.add(orderGoodsEntity);
|
|
|
+
|
|
|
+ // 设置条件信息,暂不支持门店满赠活动
|
|
|
+ String categoryId = String.valueOf(entity.getCategoryId());
|
|
|
+ String brandId = String.valueOf(entity.getBrandId());
|
|
|
+ if (!categoryConditionMap.containsKey(categoryId)) {
|
|
|
+ categoryConditionMap.put(categoryId, retailPrice);
|
|
|
+ } else {
|
|
|
+ categoryConditionMap.put(categoryId, categoryConditionMap.get(categoryId).add(retailPrice));
|
|
|
+ }
|
|
|
+// if (!brandConditionMap.containsKey(brandId)) {
|
|
|
+// brandConditionMap.put(brandId, retailPrice);
|
|
|
+// } else {
|
|
|
+// brandConditionMap.put(brandId, brandConditionMap.get(brandId).add(retailPrice));
|
|
|
+// }
|
|
|
+ }
|
|
|
+ // 2. 判断购买的商品是否能参与满减活动
|
|
|
+ // 2.1 查询当前门店是否有满赠的活动
|
|
|
+ List<MkActivitiesEntity> activitiesEntities = mkActivitiesService.queryByNowByMz(String.valueOf(storeId), DateUtils.format(new Date(), "yyyy-MM-dd"));
|
|
|
+ if (CollectionUtils.isEmpty(activitiesEntities)) {
|
|
|
+ LOGGER.error("----- 该门店【{}】暂无满赠活动! -----", storeId);
|
|
|
+ } else {
|
|
|
+ // 当前门店的活动编号
|
|
|
+ List<Long> activitiesSnList = activitiesEntities.stream().map(MkActivitiesEntity::getMkaId).collect(Collectors.toList());
|
|
|
+ // 活动
|
|
|
+ List<MkActivitiesFullGiftEntity> mkActivitiesFullGiftEntities = mkActivitiesFullGiftService.queryByMkaIdList(activitiesSnList);
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesFullGiftEntities)) {
|
|
|
+ LOGGER.error("----- 该门店【{}】暂无满赠活动! -----", storeId);
|
|
|
+ } else {
|
|
|
+ mkActivitiesFullGiftEntities.forEach(mkActivitiesFullGiftEntity -> {
|
|
|
+ // 存在品牌满赠活动,暂不支持品牌满赠活动
|
|
|
+// String brandId = String.valueOf(mkActivitiesFullGiftEntity.getBrandId());
|
|
|
+// if (brandConditionMap.containsKey(brandId)) {
|
|
|
+// if (brandConditionMap.get(brandId).compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) > 0) {
|
|
|
+// // 该品牌满足满赠条件
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+ // 存在分类满赠活动
|
|
|
+ String categoryId = String.valueOf(mkActivitiesFullGiftEntity.getCategoryId());
|
|
|
+ if (!CollectionUtils.isEmpty(categoryConditionMap) && categoryConditionMap.containsKey(categoryId)) {
|
|
|
+ if (categoryConditionMap.get(categoryId).compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) > 0) {
|
|
|
+ // 该分类满足满赠条件
|
|
|
+ String giftBarcode = mkActivitiesFullGiftEntity.getGiftBarcode();
|
|
|
+ String giftGoodsSn = mkActivitiesFullGiftEntity.getGiftGoodsSn();
|
|
|
+ String shopSn = mkActivitiesFullGiftEntity.getShopSn();
|
|
|
+ GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(giftBarcode, Integer.parseInt(shopSn), giftGoodsSn);
|
|
|
+ // 存储赠送数
|
|
|
+ goodsEntity.setGoodsNumber(mkActivitiesFullGiftEntity.getGiftNumber());
|
|
|
+ OrderGoodsEntity orderGoodsEntity = new OrderGoodsEntity();
|
|
|
+ wrapOrderGoods(orderGoodsEntity, goodsEntity);
|
|
|
+ orderGoodsEntity.setRetailPrice(BigDecimal.ZERO);
|
|
|
+ orderGoodsEntity.setDiscountedPrice(BigDecimal.ZERO);
|
|
|
+ orderGoodsEntity.setActualPaymentAmount(BigDecimal.ZERO);
|
|
|
+ orderGoodsEntities.add(orderGoodsEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
- // 2. 校验是否是会员,调用会员系统查询会员信息,查询接口:
|
|
|
+
|
|
|
+
|
|
|
+ // 3. 校验是否是会员,调用会员系统查询会员信息,查询接口:
|
|
|
// 优惠后价格
|
|
|
BigDecimal afterDiscountPrice;
|
|
|
if (org.springframework.util.StringUtils.isEmpty(couponBarCode)) {
|
|
@@ -2136,6 +2257,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
afterDiscountPrice = calculatePreferentialPrice(orderPrice, 0, goodsList, storeId, userInfo);
|
|
|
}
|
|
|
} else {
|
|
|
+ LOGGER.error("查询会员信息失败!响应结果:{}", queryMemberInfoResponse);
|
|
|
throw new ServiceException("查询会员信息失败!请重新下单!");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -2143,7 +2265,7 @@ public class OrderServiceImpl implements OrderService {
|
|
|
throw new ServiceException("查询会员信息失败!请重新下单!");
|
|
|
}
|
|
|
}
|
|
|
- // 3. 调用付款接口
|
|
|
+ // 4. 调用付款接口
|
|
|
// 判断是微信的支付码还是支付宝的支付码
|
|
|
if (parCode.startsWith("28")) {
|
|
|
// 支付宝支付
|
|
@@ -2163,9 +2285,9 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 4. 扣减库存
|
|
|
+ // 5. 扣减库存
|
|
|
|
|
|
- // 5. 推送订单到免税mall
|
|
|
+ // 6. 订单入库
|
|
|
|
|
|
|
|
|
return resultObj;
|
|
@@ -2181,7 +2303,9 @@ public class OrderServiceImpl implements OrderService {
|
|
|
// 设置商品信息
|
|
|
BeanUtils.copyProperties(goodsEntity, orderGoodsEntity);
|
|
|
// 设置订单信息
|
|
|
-
|
|
|
+ // 销售数
|
|
|
+ orderGoodsEntity.setNumber(goodsEntity.getGoodsNumber());
|
|
|
+ // TODO other...
|
|
|
return orderGoodsEntity;
|
|
|
}
|
|
|
|
|
@@ -3160,7 +3284,6 @@ public class OrderServiceImpl implements OrderService {
|
|
|
orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_402.getItem())) {
|
|
|
return R.error("订单已退款");
|
|
|
}
|
|
|
-
|
|
|
if (orderInfo.getOrderStatus() == Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
|
|
|
return R.error("订单正在准备,请稍等!");
|
|
|
}
|
|
@@ -3175,12 +3298,10 @@ public class OrderServiceImpl implements OrderService {
|
|
|
}
|
|
|
|
|
|
String payFlag = order.getPayFlag();
|
|
|
-
|
|
|
String key = "kmall_order_refund_" + order.getOrderSn();
|
|
|
if (JedisUtil.exists(key)) {
|
|
|
return R.error("订单退款操作过快,请等待!");
|
|
|
}
|
|
|
-
|
|
|
JedisUtil.set(key, System.currentTimeMillis() + "", 3);
|
|
|
if (orderInfo.getPayStatus() == Integer.parseInt(Dict.payStatus.item_3.getItem())) {
|
|
|
return R.error("订单正在退款中,请勿重复退款");
|
|
@@ -3196,67 +3317,34 @@ public class OrderServiceImpl implements OrderService {
|
|
|
cdl.await();
|
|
|
|
|
|
if (Dict.payFlag.item_weixin.getItem().equals(payFlag)) {
|
|
|
-
|
|
|
Double totalActualPrice = orderDao.getTotalActualPrice(orderInfo.getMerchOrderSn());
|
|
|
if (totalActualPrice == null) {
|
|
|
totalActualPrice = 0d;
|
|
|
}
|
|
|
- String refundResult = "";
|
|
|
if (orderInfo.getOrderStatus() != Integer.parseInt(Dict.orderStatus.item_0.getItem())) {
|
|
|
- LOGGER.info("微信退款开始");
|
|
|
-
|
|
|
- WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn().toString(), totalActualPrice,
|
|
|
+ LOGGER.info("[微信退款开始--------orderRefund]"+order.getOrderSn());
|
|
|
+ WechatRefundApiResult result = WechatUtil.wxRefund(orderInfo.getOrderSn(), totalActualPrice,
|
|
|
orderInfo.getActualPrice().doubleValue());
|
|
|
- OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
- orderRefund.setRefundId(result.getRefund_id());
|
|
|
- orderRefund.setOutRefundNo(result.getOut_trade_no());
|
|
|
- orderRefund.setRefundMoney(BigDecimal.valueOf(Long.valueOf(result.getRefund_fee())).divide(Constant.ONE_HUNDRED));
|
|
|
- orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_2.getItem()));//退款处理中
|
|
|
- orderRefund.setModTime(new Date());
|
|
|
- orderRefund.setRefundTime(new Date());
|
|
|
- orderRefund.setOrderId(Integer.parseInt(order.getId() + ""));
|
|
|
- orderRefund.setUserId(user.getUserId().intValue());
|
|
|
- orderRefund.setRefundId(order.getUserId() + "");
|
|
|
- orderRefund.setCreateTime(new Date());
|
|
|
- List<OrderEntity> list = orderDao.queryObjectByMerchOrderSn(order.getMerchOrderSn());
|
|
|
- if (list.size() > 1) {//多条订单
|
|
|
- orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_2.getItem()));//部分退款
|
|
|
- } else {
|
|
|
- orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));//用户全额退款
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
order.setPayStatus(Integer.parseInt(Dict.payStatus.item_5.getItem()));
|
|
|
order.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_401.getItem()));
|
|
|
- LOGGER.info("微信退款");
|
|
|
-
|
|
|
- orderDao.update(order);//修改为退款成功
|
|
|
+ //修改为退款成功
|
|
|
+ orderDao.update(order);
|
|
|
// 修改小票码
|
|
|
PickUpCodeEntity pickUpCodeEntity = pickUpCodeService.queryObject(order.getOrderSn());
|
|
|
pickUpCodeEntity.setPickUpCodeStatus("3");
|
|
|
pickUpCodeService.update(pickUpCodeEntity);
|
|
|
+ //还原库存,调用免税mall接口退款
|
|
|
+ restoreInventoryMsMall(order);
|
|
|
+ //新增退款记录
|
|
|
+ OrderRefundEntity orderRefund = orderRefundLog(result.getRefund_id(),result.getOut_trade_no(),result.getRefund_fee(),order.getId(),user.getUserId(),order.getMerchOrderSn());
|
|
|
+ orderRefundDao.save(orderRefund);
|
|
|
|
|
|
- // 判断该订单是否进入oms系统
|
|
|
- if (!arrivedOms(order.getOrderSn())) {
|
|
|
- // oms无该订单,则直接退款
|
|
|
- restoreInventory(order, "收银端退款");
|
|
|
- orderRefund.setRestore(1);
|
|
|
- } else {
|
|
|
- // 如果oms有订单,统一进入锁库存情况
|
|
|
- orderRefund.setRestore(0);
|
|
|
- toBeRestoreInventory(order);
|
|
|
- }
|
|
|
-
|
|
|
- orderRefundDao.save(orderRefund);//退款记录
|
|
|
}
|
|
|
// 支付宝的退款代码
|
|
|
} else if (Dict.payFlag.item_alipay.getItem().equals(payFlag)) {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ LOGGER.info("[支付宝退款开始--------orderRefund]"+order.getOrderSn());
|
|
|
AliPayMicropayApiResult userRefund = AliPayUtil.aliTradeRefund(order.getOrderSn(), order.getActualPrice().toString(),
|
|
|
"用户退款", order.getStoreId() + "");
|
|
|
-
|
|
|
// 是否已退款校验
|
|
|
try {
|
|
|
String fundChange = userRefund.getFundChange();
|
|
@@ -3264,56 +3352,109 @@ public class OrderServiceImpl implements OrderService {
|
|
|
return R.error("资金已退回,请勿重复退款!");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
+ LOGGER.error("[支付宝退款校验出错]",e.getMessage());
|
|
|
}
|
|
|
-
|
|
|
LOGGER.info(userRefund.getSubMsg());
|
|
|
-
|
|
|
- OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
- orderRefund.setRefundId(userRefund.getTradeNo());
|
|
|
- orderRefund.setOutRefundNo(userRefund.getOutTradeNo());
|
|
|
- orderRefund.setRefundMoney(new BigDecimal(userRefund.getRefundFee()));
|
|
|
-
|
|
|
-
|
|
|
- orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_2.getItem()));//退款成功
|
|
|
- orderRefund.setModTime(new Date());
|
|
|
- orderRefund.setRefundTime(new Date());
|
|
|
- orderRefund.setOrderId(Integer.parseInt(order.getId() + ""));
|
|
|
- orderRefund.setUserId(user.getUserId().intValue());
|
|
|
- orderRefund.setRefundId(order.getUserId() + "");
|
|
|
- orderRefund.setCreateTime(new Date());
|
|
|
- List<OrderEntity> list = orderDao.queryObjectByMerchOrderSn(order.getMerchOrderSn());
|
|
|
- if (list.size() > 1) {//多条订单
|
|
|
- orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_2.getItem()));//部分退款
|
|
|
- } else {
|
|
|
- orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));//用户全额退款
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
order.setPayStatus(Integer.parseInt(Dict.payStatus.item_5.getItem()));
|
|
|
order.setOrderStatus(Integer.parseInt(Dict.orderStatus.item_401.getItem()));
|
|
|
- orderDao.update(order);//修改为退款成功
|
|
|
+ //修改为退款成功
|
|
|
+ orderDao.update(order);
|
|
|
// 修改小票码
|
|
|
PickUpCodeEntity pickUpCodeEntity = pickUpCodeService.queryObject(order.getOrderSn());
|
|
|
pickUpCodeEntity.setPickUpCodeStatus("3");
|
|
|
pickUpCodeService.update(pickUpCodeEntity);
|
|
|
- // 判断该订单是否进入oms系统
|
|
|
- if (!arrivedOms(order.getOrderSn())) {
|
|
|
- // oms无该订单,则直接退款
|
|
|
- restoreInventory(order, "收银端退款");
|
|
|
- orderRefund.setRestore(1);
|
|
|
- } else {
|
|
|
- // 如果oms有订单,统一进入锁库存情况
|
|
|
- orderRefund.setRestore(0);
|
|
|
- toBeRestoreInventory(order);
|
|
|
+ //还原库存,调用免税mall接口退款
|
|
|
+ restoreInventoryMsMall(order);
|
|
|
+ //新增退款记录
|
|
|
+ OrderRefundEntity orderRefund = orderRefundLog(userRefund.getTradeNo(),userRefund.getOutTradeNo(),userRefund.getRefundFee(),order.getId(),user.getUserId(),order.getMerchOrderSn());
|
|
|
+ orderRefundDao.save(orderRefund);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok("退款成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增退款记录
|
|
|
+ * @param refundId
|
|
|
+ * @param OutTradeNo
|
|
|
+ * @param refundFee
|
|
|
+ * @param orderId
|
|
|
+ * @param userId
|
|
|
+ * @param merchOrderSn
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private OrderRefundEntity orderRefundLog(String refundId,String OutTradeNo,String refundFee,Long orderId,Long userId,String merchOrderSn){
|
|
|
+ OrderRefundEntity orderRefund = new OrderRefundEntity();
|
|
|
+ orderRefund.setRefundId(refundId);
|
|
|
+ orderRefund.setOutRefundNo(OutTradeNo);
|
|
|
+ orderRefund.setRefundMoney(BigDecimal.valueOf(Long.valueOf(refundFee)).divide(Constant.ONE_HUNDRED));
|
|
|
+ orderRefund.setRefundStatus(Integer.parseInt(Dict.RefundStatus.item_2.getItem()));//退款处理中
|
|
|
+ orderRefund.setModTime(new Date());
|
|
|
+ orderRefund.setRefundTime(new Date());
|
|
|
+ orderRefund.setOrderId(orderId.intValue());
|
|
|
+ orderRefund.setUserId(userId.intValue());
|
|
|
+ orderRefund.setRefundId(userId + "");
|
|
|
+ orderRefund.setCreateTime(new Date());
|
|
|
+ Integer sum = orderDao.queryObjectByMerchOrderSnHkMall(merchOrderSn);
|
|
|
+ if (sum > 1) {//多条订单
|
|
|
+ orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_2.getItem()));//部分退款
|
|
|
+ } else {
|
|
|
+ orderRefund.setRefundType(Integer.parseInt(Dict.RefundType.item_1.getItem()));//用户全额退款
|
|
|
+ }
|
|
|
+ orderRefund.setRestore(1);
|
|
|
+ return orderRefund;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 海控订单退款
|
|
|
+ * @param order
|
|
|
+ */
|
|
|
+ private void restoreInventoryMsMall(OrderEntity order) {
|
|
|
+ Map<String, Object> map = new HashMap();
|
|
|
+ SysUserEntity user = ShiroUtils.getUserEntity();
|
|
|
+ map.put("orderId", order.getId());
|
|
|
+ //mall_order_goodsd,订单明细
|
|
|
+ List<OrderGoodsEntity> orderGoodsVoList = orderGoodsDao.queryListHkMall(map);
|
|
|
+ for (OrderGoodsEntity orderGoodsEntity : orderGoodsVoList) {
|
|
|
+ ProductStoreRelaEntity storeRelaEntity = productStoreRelaDao
|
|
|
+ .queryByGoodsIdAndStoreIdHkMall(order.getStoreId().longValue(), orderGoodsEntity.getGoodsId().longValue());
|
|
|
+ if (null == storeRelaEntity || null == storeRelaEntity.getSellVolume()) {
|
|
|
+ storeRelaEntity.setSellVolume(0);
|
|
|
+ }
|
|
|
+ //销售量 - 商品数量
|
|
|
+ BigDecimal sellVolume = new BigDecimal(storeRelaEntity.getSellVolume() - orderGoodsEntity.getNumber());//销售量
|
|
|
+ if (sellVolume.compareTo(Constant.ZERO) < 0) {
|
|
|
+ sellVolume = Constant.ZERO;
|
|
|
}
|
|
|
|
|
|
- orderRefundDao.save(orderRefund);//退款记录
|
|
|
+ //还原门店库存
|
|
|
+ if (null != storeRelaEntity.getStockNum()) {
|
|
|
+ resetStoreGoodsStockMall(storeRelaEntity.getStockNum(), storeRelaEntity, orderGoodsEntity, sellVolume, user);
|
|
|
+ }
|
|
|
}
|
|
|
+ //调用免税mall接口
|
|
|
+ vmcShopMall(order);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *海控免税mall接口
|
|
|
+ * @param order
|
|
|
+ */
|
|
|
+ private void vmcShopMall(OrderEntity order) {
|
|
|
+ LOGGER.info("=======> [调用VMCShop接口开始发送退款订单数据]"+order.getOrderSn());
|
|
|
+ String body = JacksonUtil.toJson(order.getOrderSn());
|
|
|
+ String response = vmcShopTemplate.refundOrder(body);
|
|
|
+ //解析响应数据
|
|
|
+ LOGGER.info("=======> [发送退款订单数据成功,开始处理后续流程]"+response);
|
|
|
+ //Map<String,String> res = JSON.parseObject(response,Map.class);
|
|
|
+
|
|
|
+ saveVmcSend(order.getOrderSn(),VmcconnectUrlEnum.ORDERS_CANCEL_ORDER.getMethod(),body,response);
|
|
|
+ LOGGER.info(order.getOrderSn()+"[发送退款订单数据]"+JSON.toJSONString(order));
|
|
|
|
|
|
- return R.ok("退款成功");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Transactional
|
|
|
public void toBeRestoreInventory(OrderEntity order) {
|
|
|
|
|
@@ -3873,6 +4014,405 @@ public class OrderServiceImpl implements OrderService {
|
|
|
return TicketPrintUtil.print(head, goodsList, cashInfo, cusListing, mailInfo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算优惠价格,活动价格
|
|
|
+ *
|
|
|
+ * @param calculateOrderDiscountPriceVo 请求参数
|
|
|
+ * @return 商品集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CalculateOrderDiscountPriceResponseVO calculateOrderDiscountPrice(CalculateOrderDiscountPriceVO calculateOrderDiscountPriceVo) {
|
|
|
+ if (Objects.isNull(calculateOrderDiscountPriceVo)) {
|
|
|
+ LOGGER.error("计算活动优惠价格,请求参数为null!");
|
|
|
+ throw new ServiceException("计算活动优惠价格,请求参数为null!");
|
|
|
+ }
|
|
|
+ CalculateOrderDiscountPriceResponseVO calculateOrderDiscountPriceResponseVO = new CalculateOrderDiscountPriceResponseVO();
|
|
|
+ String storeId = calculateOrderDiscountPriceVo.getStoreId();
|
|
|
+ String memberCode = calculateOrderDiscountPriceVo.getMemberCode();
|
|
|
+ List<GoodsDetailsDto> goodsDetailsDtos = calculateOrderDiscountPriceVo.getGoodsList();
|
|
|
+ BigDecimal orderTotalPrice = BigDecimal.ZERO;
|
|
|
+ List<QueryGoodsVO> goodsVos = new ArrayList<>();
|
|
|
+ for (GoodsDetailsDto good : goodsDetailsDtos) {
|
|
|
+ QueryGoodsVO queryGoodsVo = new QueryGoodsVO();
|
|
|
+ BeanUtils.copyProperties(good, queryGoodsVo);
|
|
|
+ queryGoodsVo.setSku(good.getGoodsSn());
|
|
|
+ queryGoodsVo.setStoreId(Integer.parseInt(storeId));
|
|
|
+ orderTotalPrice = orderTotalPrice.add(good.getActualPaymentAmount());
|
|
|
+ goodsVos.add(queryGoodsVo);
|
|
|
+ }
|
|
|
+ calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(orderTotalPrice);
|
|
|
+ calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
|
+
|
|
|
+ // 查询商品表
|
|
|
+ List<GoodsEntity> goodsEntities = goodsService.queryGoodsStockByQueryGoodsVoList(goodsVos);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
|
|
|
+ * 参数: 当前时间 门店id
|
|
|
+ */
|
|
|
+ List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId, DateUtils.format(new Date(), "yyyy-MM-dd"));
|
|
|
+ // 活动优先级判定,特价>打折>满减/满赠>优惠券>积分抵扣;
|
|
|
+// List<Constants.ActivityTopicEnum> activityTopicEnums = Arrays.asList(Constants.ActivityTopicEnum.values());
|
|
|
+// for (MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList) {
|
|
|
+// for (Constants.ActivityTopicEnum activityTopicEnum : activityTopicEnums) {
|
|
|
+// if (activityTopicEnum.get) {
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ /*
|
|
|
+ * 活动相关规则:
|
|
|
+ * 1. 优先优惠券再去计算积分
|
|
|
+ * 2. 满赠的赠品商品在推送定时时零售价为0
|
|
|
+ * 3. 任何活动都优先于积分计算
|
|
|
+ * 4. 活动之间具有互斥性
|
|
|
+ */
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesEntityList) && org.springframework.util.StringUtils.isEmpty(memberCode)) {
|
|
|
+ LOGGER.info("门店【{}】,在当前时间无相关活动信息!", storeId);
|
|
|
+ for (GoodsDetailsDto goodsDetailsDto : goodsDetailsDtos) {
|
|
|
+ GoodsEntity goodsEntity = new GoodsEntity();
|
|
|
+ BeanUtils.copyProperties(goodsDetailsDto, goodsEntity);
|
|
|
+ goodsEntity.setGoodsRate(new BigDecimal(goodsDetailsDto.getGoodsRate()));
|
|
|
+ // 无活动情况,实际支付价 = 零售价
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity , goodsEntity.getRetailPrice(), goodsService).setScale(3,RoundingMode.HALF_UP);
|
|
|
+ // 预估税
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
+ }
|
|
|
+ calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
|
+ return calculateOrderDiscountPriceResponseVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Integer> brandIdList = goodsEntities.stream().map(GoodsEntity::getBrandId).collect(Collectors.toList());
|
|
|
+ List<Integer> categoryIdList = goodsEntities.stream().map(GoodsEntity::getCategoryId).collect(Collectors.toList());
|
|
|
+ // 活动互斥标识
|
|
|
+ AtomicBoolean activityFlag = new AtomicBoolean(true);
|
|
|
+ // 判断活动类型,并确定购物栏中商品是否满足活动条件
|
|
|
+ mkActivitiesEntityList.forEach(mkActivitiesEntity -> {
|
|
|
+ String mkaStoreId = mkActivitiesEntity.getMkaStoreId();
|
|
|
+ Long mkaId = mkActivitiesEntity.getMkaId();
|
|
|
+ String mkaTopic = mkActivitiesEntity.getMkaTopic();
|
|
|
+ Constants.ActivityTopicEnum activityTopicEnum = Constants.ActivityTopicEnum.valueOf(mkaTopic);
|
|
|
+ // 活动之间的优先级:特价>打折>满减/满赠>优惠券>积分抵扣
|
|
|
+ if (activityTopicEnum == Constants.ActivityTopicEnum.LSCX && activityFlag.get()) {
|
|
|
+ // 判断商品是否符合限时特价活动要求
|
|
|
+ List<MkActivitiesPromotionEntity> mkActivitiesPromotionEntities = mkActivitiesPromotionService.queryListByMkaIdAndStoreId(mkaId.intValue(), storeId);
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesPromotionEntities)) {
|
|
|
+ LOGGER.error("查询临时促销活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
+ throw new ServiceException(String.format("查询临时促销活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
+ }
|
|
|
+ // 限时特价,直接替换实际支付价即可,并且拿特价计算税款
|
|
|
+ mkActivitiesPromotionEntities.forEach(mkActivitiesPromotionEntity -> {
|
|
|
+ String entityBarcode = mkActivitiesPromotionEntity.getBarcode();
|
|
|
+ String entityGoodsSn = mkActivitiesPromotionEntity.getGoodsSn();
|
|
|
+ BigDecimal activityPrice = mkActivitiesPromotionEntity.getActivityPrice();
|
|
|
+ String shopSn = mkActivitiesPromotionEntity.getShopSn();
|
|
|
+ goodsEntities.forEach(goodsEntity -> {
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
+ String storeId2 = String.valueOf(goodsEntity.getStoreId());
|
|
|
+ BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
+ if (entityBarcode.equals(prodBarcode) && entityGoodsSn.equals(sku) && shopSn.equals(storeId2)) {
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, activityPrice, goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ BeanUtils.copyProperties(goodsDetailsDto, goodsEntity);
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(activityPrice);
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
+ goodsDetailsDto.setActivity("限时促销");
|
|
|
+ goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(activityPrice));
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
+ activityFlag.set(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else if (activityTopicEnum == Constants.ActivityTopicEnum.MZ && activityFlag.get()) {
|
|
|
+ // 判断商品是否符合满赠活动要求
|
|
|
+ MkActivitiesFullGiftEntity mkActivitiesFullGiftEntity = mkActivitiesFullGiftService.queryObjectByMkaIdAndStoreId(mkaId.intValue(), storeId);
|
|
|
+ if (Objects.isNull(mkActivitiesFullGiftEntity)) {
|
|
|
+ LOGGER.error("查询满赠活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
+ throw new ServiceException(String.format("查询满赠活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
+ }
|
|
|
+ Long brandId = mkActivitiesFullGiftEntity.getBrandId();
|
|
|
+ Long categoryId = mkActivitiesFullGiftEntity.getCategoryId();
|
|
|
+ Constants.ActivityType fullGiftActivityType = Constants.ActivityType.valueOf(mkActivitiesFullGiftEntity.getFullGiftType());
|
|
|
+ switch (fullGiftActivityType) {
|
|
|
+ case BRAND:
|
|
|
+ if (brandIdList.contains(brandId.intValue())) {
|
|
|
+ // 活动包含该商品品牌,此次订单该品牌商品
|
|
|
+ List<GoodsEntity> goodsEntityList = goodsEntities.stream().filter(goodsEntity -> brandId.intValue() == goodsEntity.getBrandId()).collect(Collectors.toList());
|
|
|
+ AtomicReference<BigDecimal> brandTotalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
+ goodsEntityList.forEach(goodsEntity -> {
|
|
|
+ brandTotalPrice.set(brandTotalPrice.get().add(goodsEntity.getRetailPrice()));
|
|
|
+ });
|
|
|
+ if (brandTotalPrice.get().compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) >= 0) {
|
|
|
+ // 满足满赠条件
|
|
|
+ String giftGoodsSn = mkActivitiesFullGiftEntity.getGiftGoodsSn();
|
|
|
+ String giftBarcode = mkActivitiesFullGiftEntity.getGiftBarcode();
|
|
|
+ GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(giftBarcode, Integer.parseInt(mkaStoreId), giftGoodsSn);
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(BigDecimal.ZERO);
|
|
|
+ goodsDetailsDto.setActivity("满赠商品");
|
|
|
+ goodsDetailsDto.setGiftNumber(mkActivitiesFullGiftEntity.getGiftNumber());
|
|
|
+ goodsDetailsDto.setDiscountedPrice(goodsEntity.getRetailPrice());
|
|
|
+ // 添加进商品详情列表
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
+ activityFlag.set(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case CATEGORY:
|
|
|
+ if (categoryIdList.contains(categoryId.intValue())) {
|
|
|
+ // 活动包含该商品分类
|
|
|
+ List<GoodsEntity> goodsEntityList = goodsEntities.stream().filter(goodsEntity -> brandId.equals(mkActivitiesFullGiftEntity.getCategoryId())).collect(Collectors.toList());
|
|
|
+ AtomicReference<BigDecimal> categoryTotalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
|
+ goodsEntityList.forEach(goodsEntity -> {
|
|
|
+ categoryTotalPrice.set(categoryTotalPrice.get().add(goodsEntity.getRetailPrice()));
|
|
|
+ });
|
|
|
+ if (categoryTotalPrice.get().compareTo(mkActivitiesFullGiftEntity.getQualifiedAmount()) >= 0) {
|
|
|
+ // 满足满赠条件
|
|
|
+ String giftGoodsSn = mkActivitiesFullGiftEntity.getGiftGoodsSn();
|
|
|
+ String giftBarcode = mkActivitiesFullGiftEntity.getGiftBarcode();
|
|
|
+ GoodsEntity goodsEntity = goodsService.queryGoodsStockByBarcodeAndStoreIdAndSku(giftBarcode, Integer.parseInt(mkaStoreId), giftGoodsSn);
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(BigDecimal.ZERO);
|
|
|
+ goodsDetailsDto.setActivity("满赠商品");
|
|
|
+ goodsDetailsDto.setGiftNumber(mkActivitiesFullGiftEntity.getGiftNumber());
|
|
|
+ goodsDetailsDto.setDiscountedPrice(goodsEntity.getRetailPrice());
|
|
|
+ // 添加进商品详情列表
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
+ activityFlag.set(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ LOGGER.error("未知满赠类型【{},{}】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode());
|
|
|
+ throw new ServiceException(String.format("未知满赠类型【%s,%s】!请联系管理员!", fullGiftActivityType.getActivityType(), fullGiftActivityType.getActivityTypeCode()));
|
|
|
+ }
|
|
|
+ } else if (activityTopicEnum == Constants.ActivityTopicEnum.YHJ && activityFlag.get()) {
|
|
|
+ // 判断商品是否符合优惠券活动要求
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("shop_sn", storeId);
|
|
|
+ params.put("mka_id", mkaId);
|
|
|
+ List<MkActivitiesCouponEntity> mkActivitiesCouponEntities = mkActivitiesCouponService.queryList(params);
|
|
|
+ if (CollectionUtils.isEmpty(mkActivitiesCouponEntities)) {
|
|
|
+ LOGGER.error("查询优惠券活动信息结果为空!mka_id:{}, store_id:{}", mkaId, storeId);
|
|
|
+ throw new ServiceException(String.format("查询优惠券活动信息结果为空!mka_id:%s, store_id:%s", mkaId, storeId));
|
|
|
+ }
|
|
|
+ MkActivitiesCouponEntity mkActivitiesCouponEntity = mkActivitiesCouponEntities.get(0);
|
|
|
+ Integer couponEntityBrandId = mkActivitiesCouponEntity.getBrandId();
|
|
|
+ Integer couponEntityCategoryId = mkActivitiesCouponEntity.getCategoryId();
|
|
|
+ Integer couponEntityStoreId = Integer.parseInt(mkActivitiesCouponEntity.getShopSn());
|
|
|
+ BigDecimal couponPrice = mkActivitiesCouponEntity.getCouponPrice();
|
|
|
+ Constants.ActivityType couponActivityType = Constants.ActivityType.valueOf(mkActivitiesCouponEntity.getActivityType());
|
|
|
+ switch (couponActivityType) {
|
|
|
+ case BRAND:
|
|
|
+ goodsEntities.forEach(goodsEntity -> {
|
|
|
+ if (couponEntityBrandId.equals(goodsEntity.getBrandId())) {
|
|
|
+ BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
+ if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
|
+ LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
|
+ throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
|
+ }
|
|
|
+ BigDecimal discountAfterPrice = retailPrice.subtract(couponPrice);
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(discountAfterPrice);
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
+ goodsDetailsDto.setActivity("优惠券活动");
|
|
|
+ goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
+ activityFlag.set(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case CATEGORY:
|
|
|
+ goodsEntities.forEach(goodsEntity -> {
|
|
|
+ if (couponEntityCategoryId.equals(goodsEntity.getCategoryId())) {
|
|
|
+ BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
+ if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
|
+ LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
|
+ throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
|
+ }
|
|
|
+ BigDecimal discountAfterPrice = retailPrice.subtract(couponPrice);
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(discountAfterPrice);
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
+ goodsDetailsDto.setActivity("优惠券活动");
|
|
|
+ goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
+ activityFlag.set(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case PRODUCT:
|
|
|
+ mkActivitiesCouponEntities.forEach(mkActivitiesCouponEntity1 -> {
|
|
|
+ // 单个商品优惠券,有多条记录
|
|
|
+ String activityProductBarcode = mkActivitiesCouponEntity1.getBarcode();
|
|
|
+ String activitySku = mkActivitiesCouponEntity1.getGoodsSn();
|
|
|
+ goodsEntities.forEach(goodsEntity -> {
|
|
|
+ String sku = goodsEntity.getSku();
|
|
|
+ String prodBarcode = goodsEntity.getProdBarcode();
|
|
|
+ // 条码、sku、门店都需一致
|
|
|
+ if (activitySku.equals(sku) && activityProductBarcode.equals(prodBarcode) && couponEntityStoreId.equals(goodsEntity.getStoreId())) {
|
|
|
+ BigDecimal retailPrice = goodsEntity.getRetailPrice();
|
|
|
+ if (couponPrice.compareTo(retailPrice) <= 0) {
|
|
|
+ LOGGER.error("优惠券优惠金额【{}】大于或等于商品【条码:{},sku:{}】的零售价【{}】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice);
|
|
|
+ throw new ServiceException(String.format("优惠券优惠金额【%s】大于或等于商品【条码:%s,sku:%s】的零售价【%s】,请检查优惠券金额设置!", couponPrice, prodBarcode, sku, retailPrice));
|
|
|
+ }
|
|
|
+ BigDecimal discountAfterPrice = retailPrice.subtract(couponPrice);
|
|
|
+ GoodsDetailsDto goodsDetailsDto = new GoodsDetailsDto();
|
|
|
+ BeanUtils.copyProperties(goodsEntity, goodsDetailsDto);
|
|
|
+ // 除了限时促销(需要向海关备案),其它活动都拿海关备案价来算税款
|
|
|
+ BigDecimal tax = CalculateTax.calculateFinalTax(goodsEntity, goodsEntity.getRetailPrice(), goodsService).setScale(3, RoundingMode.HALF_UP);
|
|
|
+ goodsDetailsDto.setActualPaymentAmount(discountAfterPrice);
|
|
|
+ goodsDetailsDto.setGoodstaxes(String.valueOf(tax.multiply(new BigDecimal(goodsDetailsDto.getSellVolume()))));
|
|
|
+ goodsDetailsDto.setActivity("优惠券活动");
|
|
|
+ goodsDetailsDto.setDiscountedPrice(retailPrice.subtract(discountAfterPrice));
|
|
|
+ goodsDetailsDtos.add(goodsDetailsDto);
|
|
|
+ activityFlag.set(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ LOGGER.error("未知的优惠券活动分类类型:【{},{}】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
|
|
|
+ throw new ServiceException(String.format("未知的优惠券活动分类类型:【%s,%s】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LOGGER.error("未知的满赠活动分类类型:【{},{}】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName());
|
|
|
+ throw new ServiceException(String.format("未知的满赠活动分类类型:【%s,%s】,请联系管理员!", activityTopicEnum.getTopicCode(), activityTopicEnum.getTopicName()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 计算完活动优惠后,计算积分抵扣。(活动与积分抵扣不互斥)
|
|
|
+ if (!org.springframework.util.StringUtils.isEmpty(memberCode)) {
|
|
|
+ String memberInfoByCodeResponseJson;
|
|
|
+ Response<MemberInfoDTO> response;
|
|
|
+ try {
|
|
|
+ // 查询会员信息
|
|
|
+ memberInfoByCodeResponseJson = haiKongMemberTemplate.getMemberInfoByCode("{\"code\":" + memberCode + "}");
|
|
|
+ response = JacksonUtil.fromListJson(memberInfoByCodeResponseJson, new TypeReference<Response<MemberInfoDTO>>() {
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.error("请求会员系统失败或处理响应失败!", e);
|
|
|
+ throw new ServiceException(e);
|
|
|
+ }
|
|
|
+ BigDecimal afterDiscountPrice;
|
|
|
+ if (Objects.nonNull(response) && response.getSuccess()) {
|
|
|
+ MemberInfoDTO memberInfoDTO = response.getData();
|
|
|
+ Integer score = memberInfoDTO.getScore();
|
|
|
+ if (Objects.nonNull(score) && score > 0) {
|
|
|
+ // 有积分
|
|
|
+ afterDiscountPrice = calculatePreferentialPrice(orderTotalPrice, score, storeId, memberCode);
|
|
|
+ calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(afterDiscountPrice);
|
|
|
+ // 订单完成后再添加积分消费记录,以及同步积分信息
|
|
|
+ }
|
|
|
+ } else if (Objects.nonNull(response)) {
|
|
|
+ LOGGER.error("查询会员信息失败!响应结果:{}", memberInfoByCodeResponseJson);
|
|
|
+ throw new ServiceException(String.format("错误码:%s,错误信息:%s", response.getErrorCode(), response.getErrorMessage()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ calculateOrderDiscountPriceResponseVO.setGoodsDetailsDtos(goodsDetailsDtos);
|
|
|
+ orderTotalPrice = BigDecimal.ZERO;
|
|
|
+ for (GoodsDetailsDto goodsDetailsDto : goodsDetailsDtos) {
|
|
|
+ orderTotalPrice = orderTotalPrice.add(goodsDetailsDto.getActualPaymentAmount());
|
|
|
+ }
|
|
|
+ calculateOrderDiscountPriceResponseVO.setOrderTotalPrice(orderTotalPrice);
|
|
|
+ return calculateOrderDiscountPriceResponseVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算积分抵扣后的订单总金额
|
|
|
+ * @param orderTotalPrice 订单商品详情
|
|
|
+ * @param score 积分
|
|
|
+ * @param storeId 门店id
|
|
|
+ * @param memberCode 会员码
|
|
|
+ * @return 积分抵扣后的订单总金额
|
|
|
+ */
|
|
|
+ private BigDecimal calculatePreferentialPrice(BigDecimal orderTotalPrice, Integer score, String storeId, String memberCode) {
|
|
|
+ // 1. 判断是否有积分,是否需要计算积分抵扣后的价格
|
|
|
+ AtomicBoolean isCalculateScorePrice = new AtomicBoolean(false);
|
|
|
+ if (Objects.nonNull(score) && score > 0) {
|
|
|
+ isCalculateScorePrice.set(true);
|
|
|
+ }
|
|
|
+ // 2. 计算积分抵扣后的总价格
|
|
|
+ if (isCalculateScorePrice.get()) {
|
|
|
+ // 3-1. 计算总价的50%,百分比可以进行设置
|
|
|
+ BigDecimal halfPrice = orderTotalPrice.multiply(new BigDecimal("0.5")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ Integer scoreLimit = haiKongProperties.getScoreLimit();
|
|
|
+ if (score < scoreLimit) {
|
|
|
+ LOGGER.warn("用户【{}】的积分数量为:{},最低需要30积分才能抵扣!", memberCode, score);
|
|
|
+ return orderTotalPrice;
|
|
|
+ } else {
|
|
|
+ // 3-2. 计算出积分能抵扣的价格
|
|
|
+ int scoreMayDeductionPrice = (int) (score / scoreLimit);
|
|
|
+ BigDecimal scoreMayDeductionPriceDecimal = new BigDecimal(scoreMayDeductionPrice);
|
|
|
+ // 3-3. 计算积分抵扣后的价格
|
|
|
+ if (halfPrice.compareTo(scoreMayDeductionPriceDecimal) > 0) {
|
|
|
+ // 积分能抵扣的金额大于订单总额的50%,按50%抵扣
|
|
|
+ scoreMayDeductionPriceDecimal = halfPrice;
|
|
|
+ }
|
|
|
+ orderTotalPrice = orderTotalPrice.subtract(scoreMayDeductionPriceDecimal);
|
|
|
+ LOGGER.info("会员【{}】,积分抵扣前剩余:{},积分抵扣订单金额后剩余:{},积分抵扣后的订单总额为:{}", memberCode, score, scoreMayDeductionPriceDecimal.multiply(new BigDecimal(scoreLimit)), orderTotalPrice);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LOGGER.info("会员【{}】的积分为0,不参加积分抵扣!", memberCode);
|
|
|
+ }
|
|
|
+ return orderTotalPrice;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重发订单
|
|
|
+ * @param orderSn
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R resendOrderHkMall(String orderSn) {
|
|
|
+ LOGGER.info("=======> [调用VMCShop接口开始发送退款订单数据]"+orderSn);
|
|
|
+ String body = JacksonUtil.toJson(orderSn);
|
|
|
+ String response = vmcShopTemplate.resendOrder(body);
|
|
|
+ //解析响应数据
|
|
|
+ LOGGER.info("=======> [resendOrderHkMall---重发订单数据成功,开始处理后续流程]"+response);
|
|
|
+ //记录发送至免税Mall日志
|
|
|
+ saveVmcSend(orderSn,VmcconnectUrlEnum.ORDERS_RETRY_ORDER.getMethod(),body,response);
|
|
|
+ Map<String,String> res = JSON.parseObject(response,Map.class);
|
|
|
+ if("0".equals(res.get("code"))){
|
|
|
+ return R.ok();
|
|
|
+ }else{
|
|
|
+ return R.error(500,"重发订单失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录发送至免税Mall日志
|
|
|
+ * @param orderSn
|
|
|
+ * @param body
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ private void saveVmcSend(String orderSn,String urlType,String body,String response){
|
|
|
+ MallVmcSendlogEntity mallVmcSendlogEntity = new MallVmcSendlogEntity();
|
|
|
+ mallVmcSendlogEntity.setOrderSn(orderSn);
|
|
|
+ mallVmcSendlogEntity.setVmcType(urlType);
|
|
|
+ mallVmcSendlogEntity.setRequestMsg(body);
|
|
|
+ mallVmcSendlogEntity.setResponseMsg(response);
|
|
|
+ mallVmcSendLogDao.saveVmcSend(mallVmcSendlogEntity);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 设置订单数据
|