|
|
@@ -70,6 +70,7 @@ import com.fs.store.enums.ShippingTempEnum;
|
|
|
import com.fs.store.mapper.FsStoreProductAttrValueMapper;
|
|
|
import com.fs.store.mapper.FsUserMapper;
|
|
|
import com.fs.store.mapper.FsWarehousesMapper;
|
|
|
+import com.fs.store.param.LiveOrderComputedParam;
|
|
|
import com.fs.store.service.*;
|
|
|
import com.fs.store.service.channel.PaymentHandler;
|
|
|
import com.fs.store.service.channel.PaymentHandlerHolder;
|
|
|
@@ -1291,6 +1292,105 @@ public class LiveOrderServiceImpl implements ILiveOrderService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public LiveOrderComputeDTO computedOrder(long l, LiveOrderComputedParam param) {
|
|
|
+ String orderKey= redisCache.getCacheObject("orderKey:"+param.getOrderKey());
|
|
|
+ if (StringUtils.isEmpty(orderKey)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ FsStoreProduct fsStoreProduct = fsStoreProductService.selectFsStoreProductById(param.getProductId());
|
|
|
+ BigDecimal payPrice = fsStoreProduct.getPrice().multiply(new BigDecimal(param.getTotalNum()));
|
|
|
+ BigDecimal payDelivery = handleDeliveryMoney(param.getCityId(), fsStoreProduct, param.getTotalNum());
|
|
|
+
|
|
|
+
|
|
|
+ return LiveOrderComputeDTO.builder().payPrice(payPrice)
|
|
|
+ .payDelivery(payDelivery)
|
|
|
+ .totalPrice(payPrice.add(payDelivery))
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private BigDecimal handleDeliveryMoney(Long cityId, FsStoreProduct fsStoreProduct, String totalNumSize) {
|
|
|
+ BigDecimal storePostage = BigDecimal.ZERO;
|
|
|
+ List<Long> citys = new ArrayList<>();
|
|
|
+ citys.add(cityId);
|
|
|
+ citys.add(0l);
|
|
|
+ String ids = String.valueOf(fsStoreProduct.getTempId());
|
|
|
+ List<FsShippingTemplates> shippingTemplatesList = shippingTemplatesService.selectFsShippingTemplatesByIds(ids);
|
|
|
+ String cityIds = String.join(",", citys.stream()
|
|
|
+ .map(String::valueOf).collect(Collectors.toList()));
|
|
|
+ List<FsShippingTemplatesRegion> shippingTemplatesRegionList = shippingTemplatesRegionService.selectFsShippingTemplatesRegionListByTempIdsAndCityIds(ids,cityIds);
|
|
|
+ Map<Long, Integer> shippingTemplatesMap = shippingTemplatesList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(FsShippingTemplates::getId,
|
|
|
+ FsShippingTemplates::getType));
|
|
|
+ //提取运费模板有相同值覆盖
|
|
|
+ Map<Long, FsShippingTemplatesRegion> shippingTemplatesRegionMap =
|
|
|
+ shippingTemplatesRegionList.stream()
|
|
|
+ .collect(Collectors.toMap(FsShippingTemplatesRegion::getTempId,
|
|
|
+ YxShippingTemplatesRegion -> YxShippingTemplatesRegion,
|
|
|
+ (key1, key2) -> key2));
|
|
|
+ Long tempId = Long.valueOf(fsStoreProduct.getTempId());
|
|
|
+ double num = 0d;
|
|
|
+ Integer templateType = shippingTemplatesMap.get(tempId);
|
|
|
+ List<FsStoreProductAttrValue> productAttrValues = fsStoreProductAttrValueMapper.selectFsStoreProductAttrValueByProductId(fsStoreProduct.getProductId());
|
|
|
+ if(productAttrValues == null || productAttrValues.isEmpty()) {
|
|
|
+ return storePostage;
|
|
|
+ }
|
|
|
+ FsStoreProductAttrValue productAttrValue = productAttrValues.get(0);
|
|
|
+ Integer totalNum = Integer.valueOf(totalNumSize);
|
|
|
+ // TYPE_1: 按件数计算
|
|
|
+ if (ShippingTempEnum.TYPE_1.getValue().equals(templateType)) {
|
|
|
+ num = totalNum.doubleValue();
|
|
|
+ }
|
|
|
+ // TYPE_2: 按重量计算(数量 × 重量)
|
|
|
+ else if (ShippingTempEnum.TYPE_2.getValue().equals(templateType)) {
|
|
|
+ num = NumberUtil.mul(totalNum, productAttrValue.getWeight()).doubleValue();
|
|
|
+ }
|
|
|
+ // TYPE_3: 按体积计算(数量 × 体积)
|
|
|
+ else if (ShippingTempEnum.TYPE_3.getValue().equals(templateType)) {
|
|
|
+ num = NumberUtil.mul(totalNum, productAttrValue.getVolume()).doubleValue();
|
|
|
+ }
|
|
|
+ FsShippingTemplatesRegion shippingTemplatesRegion = shippingTemplatesRegionMap.get(tempId);
|
|
|
+ if (shippingTemplatesRegion == null) {
|
|
|
+ log.error("没有找到运费模板");
|
|
|
+ return storePostage;
|
|
|
+ }
|
|
|
+ BigDecimal price = NumberUtil.round(NumberUtil.mul(totalNum, fsStoreProduct.getPrice()), 2);
|
|
|
+
|
|
|
+ TemplateDTO templateDTO = TemplateDTO.builder()
|
|
|
+ .number(num) // 累计数量(件数/重量/体积)
|
|
|
+ .price(price) // 累计金额
|
|
|
+ .first(shippingTemplatesRegion.getFirst().doubleValue()) // 首件数量
|
|
|
+ .firstPrice(shippingTemplatesRegion.getFirstPrice()) // 首件运费
|
|
|
+ .continues(shippingTemplatesRegion.getContinues().doubleValue()) // 续件数量
|
|
|
+ .continuePrice(shippingTemplatesRegion.getContinuePrice()) // 续件运费
|
|
|
+ .tempId(tempId) // 模板ID
|
|
|
+ .cityId(cityId) // 城市ID
|
|
|
+ .build();
|
|
|
+ //只满足首件
|
|
|
+ if (Double.compare(templateDTO.getNumber(), templateDTO.getFirst()) <= 0) {
|
|
|
+ storePostage = NumberUtil.round(NumberUtil.add(storePostage,
|
|
|
+ templateDTO.getFirstPrice()), 2);
|
|
|
+ } else {
|
|
|
+ BigDecimal firstPrice = NumberUtil.add(storePostage, templateDTO.getFirstPrice());
|
|
|
+
|
|
|
+ if (templateDTO.getContinues() <= 0) {
|
|
|
+ storePostage = firstPrice;
|
|
|
+ } else {
|
|
|
+ //续件平均值且向上取整数
|
|
|
+ double average = Math.ceil(NumberUtil.div(NumberUtil.sub(templateDTO.getNumber(),
|
|
|
+ templateDTO.getFirst()),
|
|
|
+ templateDTO.getContinues().doubleValue()));
|
|
|
+ //最终邮费
|
|
|
+ storePostage = NumberUtil.add(firstPrice, NumberUtil.mul(average,
|
|
|
+ templateDTO.getContinuePrice()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return storePostage;
|
|
|
+ }
|
|
|
+
|
|
|
public boolean containsAddress(String companyName) {
|
|
|
String[] items= {"新疆","西藏","内蒙古","海南"};
|
|
|
boolean found = false;
|