Commit 45372cdfb85e270303f73296894bda853e61556e

Authored by fengliang
1 parent 5fb74499

update:运费效验与计算

etrade-order/src/main/java/com/diligrp/etrade/order/api/OrderController.java
@@ -28,6 +28,7 @@ import com.xxl.job.core.handler.annotation.XxlJob; @@ -28,6 +28,7 @@ import com.xxl.job.core.handler.annotation.XxlJob;
28 import jakarta.annotation.Resource; 28 import jakarta.annotation.Resource;
29 import jakarta.validation.Valid; 29 import jakarta.validation.Valid;
30 import jodd.util.StringUtil; 30 import jodd.util.StringUtil;
  31 +import org.apache.commons.lang3.StringUtils;
31 import org.redisson.api.RBucket; 32 import org.redisson.api.RBucket;
32 import org.redisson.api.RLock; 33 import org.redisson.api.RLock;
33 import org.redisson.api.RedissonClient; 34 import org.redisson.api.RedissonClient;
@@ -59,9 +60,6 @@ public class OrderController { @@ -59,9 +60,6 @@ public class OrderController {
59 @Resource 60 @Resource
60 private RedissonClient redissonClient; 61 private RedissonClient redissonClient;
61 62
62 - @Resource  
63 - private BasicDataConfigRpc basicDataConfigRpc;  
64 -  
65 /** 63 /**
66 * 买家创建订单 64 * 买家创建订单
67 * @return 65 * @return
@@ -787,24 +785,20 @@ public class OrderController { @@ -787,24 +785,20 @@ public class OrderController {
787 * @return 785 * @return
788 */ 786 */
789 @RequestMapping(value = "/getTransportFee",method = {RequestMethod.POST},produces="application/json;charset=UTF-8") 787 @RequestMapping(value = "/getTransportFee",method = {RequestMethod.POST},produces="application/json;charset=UTF-8")
790 - public Message<TransportFeeDto> getTransportFee(@RequestBody OrderDto order){ 788 + public Message<TransportFeeDto> getTransportFee(@RequestBody OrderTransportFeeQuery order){
791 try{ 789 try{
792 - if(order.getMarketId()==null){  
793 - return Message.failure(OrderErrorCode.PARAM_ERROR,"市场不能为空"); 790 + if(order.getBuyerId() == null){
  791 + return Message.failure(OrderErrorCode.PARAM_ERROR,"买家不能为空");
794 } 792 }
795 - ConfigQueryDto query = new ConfigQueryDto();  
796 - query.setMarketId(order.getMarketId());  
797 - query.setType("TransportFee");  
798 - BaseOutput<List<ConfigDto>> listBaseOutput = basicDataConfigRpc.queryAll(query);  
799 - if("200".equals(listBaseOutput.getCode())){  
800 - List<ConfigDto> configDtos = listBaseOutput.getData();  
801 - if(configDtos!=null&&configDtos.size()>0) {  
802 - ConfigDto configDto = configDtos.get(0);  
803 - TransportFeeDto transportFeeDto = new TransportFeeDto();  
804 - long l = Long.parseLong(configDto.getValue());  
805 - transportFeeDto.setTransportFee(l);  
806 - return Message.success(transportFeeDto);  
807 - } 793 + if (StringUtils.isBlank(order.getAchieveAddress())){
  794 + return Message.failure(OrderErrorCode.PARAM_ERROR,"收货地址不能为空");
  795 + }
  796 + if (order.getTotleAmount() == null){
  797 + return Message.failure(OrderErrorCode.PARAM_ERROR,"商品总价不能为空");
  798 + }
  799 + TransportFeeDto transportFeeDto = orderService.getTransportFee(order);
  800 + if(transportFeeDto!=null){
  801 + return Message.success(transportFeeDto);
808 } 802 }
809 return Message.success(new TransportFeeDto()); 803 return Message.success(new TransportFeeDto());
810 }catch (PlatformServiceException pe) { 804 }catch (PlatformServiceException pe) {
etrade-order/src/main/java/com/diligrp/etrade/order/dao/OrderMapper.java
@@ -131,4 +131,11 @@ public interface OrderMapper extends MybatisMapperSupport { @@ -131,4 +131,11 @@ public interface OrderMapper extends MybatisMapperSupport {
131 * @param ids 131 * @param ids
132 */ 132 */
133 void updateDeductState(@Param("ids")List<Long> ids); 133 void updateDeductState(@Param("ids")List<Long> ids);
  134 +
  135 + /**
  136 + * 查询是否存在已支付相同配送地址订单
  137 + * @param orderTransportFeeQuery
  138 + * @return
  139 + */
  140 + Integer selectOrderByTransportFee(OrderTransportFeeQuery orderTransportFeeQuery);
134 } 141 }
etrade-order/src/main/java/com/diligrp/etrade/order/domain/OrderTransportFeeQuery.java 0 → 100644
  1 +package com.diligrp.etrade.order.domain;
  2 +
  3 +import java.math.BigDecimal;
  4 +import java.time.LocalDateTime;
  5 +
  6 +public class OrderTransportFeeQuery {
  7 + /**
  8 + * 买方客户id
  9 + */
  10 + private Long buyerId;
  11 +
  12 + /**
  13 + * 店铺id
  14 + */
  15 + private Long shopId;
  16 +
  17 + /**
  18 + * 市场id
  19 + */
  20 + private Long marketId;
  21 +
  22 + /**
  23 + * 开始时间
  24 + */
  25 + private LocalDateTime startTime;
  26 +
  27 + /**
  28 + * 结束时间
  29 + */
  30 + private LocalDateTime endTime;
  31 +
  32 + /**
  33 + * 收货地址
  34 + */
  35 + private String achieveAddress;
  36 +
  37 + /**
  38 + * 订单总金额
  39 + */
  40 + private BigDecimal totleAmount;
  41 +
  42 + public Long getBuyerId() {
  43 + return buyerId;
  44 + }
  45 +
  46 + public void setBuyerId(Long buyerId) {
  47 + this.buyerId = buyerId;
  48 + }
  49 +
  50 + public Long getShopId() {
  51 + return shopId;
  52 + }
  53 +
  54 + public void setShopId(Long shopId) {
  55 + this.shopId = shopId;
  56 + }
  57 +
  58 + public Long getMarketId() {
  59 + return marketId;
  60 + }
  61 +
  62 + public void setMarketId(Long marketId) {
  63 + this.marketId = marketId;
  64 + }
  65 +
  66 + public LocalDateTime getStartTime() {
  67 + return startTime;
  68 + }
  69 +
  70 + public void setStartTime(LocalDateTime startTime) {
  71 + this.startTime = startTime;
  72 + }
  73 +
  74 + public LocalDateTime getEndTime() {
  75 + return endTime;
  76 + }
  77 +
  78 + public void setEndTime(LocalDateTime endTime) {
  79 + this.endTime = endTime;
  80 + }
  81 +
  82 + public String getAchieveAddress() {
  83 + return achieveAddress;
  84 + }
  85 +
  86 + public void setAchieveAddress(String achieveAddress) {
  87 + this.achieveAddress = achieveAddress;
  88 + }
  89 +
  90 + public BigDecimal getTotleAmount() {
  91 + return totleAmount;
  92 + }
  93 +
  94 + public void setTotleAmount(BigDecimal totleAmount) {
  95 + this.totleAmount = totleAmount;
  96 + }
  97 +}
etrade-order/src/main/java/com/diligrp/etrade/order/service/OrderGoodsService.java
1 package com.diligrp.etrade.order.service; 1 package com.diligrp.etrade.order.service;
2 2
3 import com.diligrp.etrade.order.domain.OrderCreateDto; 3 import com.diligrp.etrade.order.domain.OrderCreateDto;
  4 +import com.diligrp.etrade.order.domain.OrderDto;
4 import com.diligrp.etrade.order.domain.ProductDto; 5 import com.diligrp.etrade.order.domain.ProductDto;
5 import com.diligrp.etrade.order.model.Order; 6 import com.diligrp.etrade.order.model.Order;
6 import com.diligrp.etrade.order.model.OrderGoods; 7 import com.diligrp.etrade.order.model.OrderGoods;
  8 +import com.diligrp.etrade.shop.domain.response.ShopExpressVo;
7 import com.diligrp.etrade.shop.domain.response.ShopVo; 9 import com.diligrp.etrade.shop.domain.response.ShopVo;
8 import org.springframework.transaction.annotation.Transactional; 10 import org.springframework.transaction.annotation.Transactional;
9 11
etrade-order/src/main/java/com/diligrp/etrade/order/service/OrderService.java
@@ -256,4 +256,6 @@ public interface OrderService { @@ -256,4 +256,6 @@ public interface OrderService {
256 * 获取订单状态 256 * 获取订单状态
257 */ 257 */
258 OrderDto checkOrderState(String code); 258 OrderDto checkOrderState(String code);
  259 +
  260 + TransportFeeDto getTransportFee(OrderTransportFeeQuery order);
259 } 261 }
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderGoodsServiceImpl.java
@@ -22,6 +22,7 @@ import com.diligrp.etrade.rpc.type.CustomerState; @@ -22,6 +22,7 @@ import com.diligrp.etrade.rpc.type.CustomerState;
22 import com.diligrp.etrade.shop.domain.request.ShopCo; 22 import com.diligrp.etrade.shop.domain.request.ShopCo;
23 import com.diligrp.etrade.shop.domain.request.StockDeductRequest; 23 import com.diligrp.etrade.shop.domain.request.StockDeductRequest;
24 import com.diligrp.etrade.shop.domain.response.ProductDetailVo; 24 import com.diligrp.etrade.shop.domain.response.ProductDetailVo;
  25 +import com.diligrp.etrade.shop.domain.response.ShopExpressVo;
25 import com.diligrp.etrade.shop.domain.response.ShopVo; 26 import com.diligrp.etrade.shop.domain.response.ShopVo;
26 import com.diligrp.etrade.shop.exception.InsufficientStockException; 27 import com.diligrp.etrade.shop.exception.InsufficientStockException;
27 import com.diligrp.etrade.shop.exception.StockNotFoundException; 28 import com.diligrp.etrade.shop.exception.StockNotFoundException;
@@ -163,22 +164,22 @@ public class OrderGoodsServiceImpl implements OrderGoodsService { @@ -163,22 +164,22 @@ public class OrderGoodsServiceImpl implements OrderGoodsService {
163 } 164 }
164 //配送情况增加计算运费 165 //配送情况增加计算运费
165 if(buyerOrderDto.getAchieveType().equals(OrderAchieveType.SELLER_DELIVERY.getCodeInteger())&&transportFeeFlag){ 166 if(buyerOrderDto.getAchieveType().equals(OrderAchieveType.SELLER_DELIVERY.getCodeInteger())&&transportFeeFlag){
166 - ConfigQueryDto query = new ConfigQueryDto();  
167 - query.setType("TransportFee");  
168 - query.setMarketId(buyerOrderDto.getMarketId());  
169 - BaseOutput<List<ConfigDto>> listBaseOutput = basicDataConfigRpc.queryAll(query);  
170 - Long transportFee = buyerOrderDto.getTransportFee().multiply(NumberTransform.ONE_HUNDERD).longValue();  
171 - Long transportFeeConfig = 0L;  
172 - if("200".equals(listBaseOutput.getCode())){  
173 - List<ConfigDto> configDtos = listBaseOutput.getData();  
174 - if(configDtos!=null&&configDtos.size()>0) {  
175 - ConfigDto configDto = configDtos.get(0);  
176 - transportFeeConfig = Long.parseLong(configDto.getValue());  
177 - }  
178 - }  
179 - if(!transportFee.equals(transportFeeConfig)){  
180 - throw new OrderException(OrderErrorCode.PARAM_ERROR,"运费与设置不一致,请刷新后重试");  
181 - } 167 +// ConfigQueryDto query = new ConfigQueryDto();
  168 +// query.setType("TransportFee");
  169 +// query.setMarketId(buyerOrderDto.getMarketId());
  170 +// BaseOutput<List<ConfigDto>> listBaseOutput = basicDataConfigRpc.queryAll(query);
  171 +// Long transportFee = buyerOrderDto.getTransportFee().multiply(NumberTransform.ONE_HUNDERD).longValue();
  172 +// Long transportFeeConfig = 0L;
  173 +// if("200".equals(listBaseOutput.getCode())){
  174 +// List<ConfigDto> configDtos = listBaseOutput.getData();
  175 +// if(configDtos!=null&&configDtos.size()>0) {
  176 +// ConfigDto configDto = configDtos.get(0);
  177 +// transportFeeConfig = Long.parseLong(configDto.getValue());
  178 +// }
  179 +// }
  180 +// if(!transportFee.equals(transportFeeConfig)){
  181 +// throw new OrderException(OrderErrorCode.PARAM_ERROR,"运费与设置不一致,请刷新后重试");
  182 +// }
182 allmount = allmount.add(buyerOrderDto.getTransportFee()); 183 allmount = allmount.add(buyerOrderDto.getTransportFee());
183 } 184 }
184 //效验库存 185 //效验库存
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/OrderServiceImpl.java
@@ -42,8 +42,13 @@ import com.diligrp.etrade.rpc.util.Constants; @@ -42,8 +42,13 @@ import com.diligrp.etrade.rpc.util.Constants;
42 import com.diligrp.etrade.shared.SharedConfiguration; 42 import com.diligrp.etrade.shared.SharedConfiguration;
43 import com.diligrp.etrade.shared.domain.OrderQrCode; 43 import com.diligrp.etrade.shared.domain.OrderQrCode;
44 import com.diligrp.etrade.shop.domain.request.ShopCo; 44 import com.diligrp.etrade.shop.domain.request.ShopCo;
  45 +import com.diligrp.etrade.shop.domain.request.ShopExpressQueryCo;
  46 +import com.diligrp.etrade.shop.domain.response.ShopExpressVo;
45 import com.diligrp.etrade.shop.domain.response.ShopVo; 47 import com.diligrp.etrade.shop.domain.response.ShopVo;
  48 +import com.diligrp.etrade.shop.service.ShopExpressSettingService;
46 import com.diligrp.etrade.shop.service.ShopService; 49 import com.diligrp.etrade.shop.service.ShopService;
  50 +import com.diligrp.etrade.shop.type.ExpressCondition;
  51 +import com.diligrp.etrade.shop.type.ExpressType;
47 import jakarta.annotation.Resource; 52 import jakarta.annotation.Resource;
48 import org.apache.commons.collections4.CollectionUtils; 53 import org.apache.commons.collections4.CollectionUtils;
49 import org.apache.commons.lang3.StringUtils; 54 import org.apache.commons.lang3.StringUtils;
@@ -82,6 +87,9 @@ public class OrderServiceImpl implements OrderService { @@ -82,6 +87,9 @@ public class OrderServiceImpl implements OrderService {
82 private OrderGoodsService orderGoodsService; 87 private OrderGoodsService orderGoodsService;
83 88
84 @Resource 89 @Resource
  90 + private ShopExpressSettingService shopExpressSettingService;
  91 +
  92 + @Resource
85 private OrderPaymentService orderPaymentService; 93 private OrderPaymentService orderPaymentService;
86 94
87 @Resource 95 @Resource
@@ -133,6 +141,7 @@ public class OrderServiceImpl implements OrderService { @@ -133,6 +141,7 @@ public class OrderServiceImpl implements OrderService {
133 orderCreateDto.setShopCustomerId(shop.getCustomerId()); 141 orderCreateDto.setShopCustomerId(shop.getCustomerId());
134 orderCreateDto.setShopName(shop.getName()); 142 orderCreateDto.setShopName(shop.getName());
135 orderCreateDto.setShopCustomerName(shop.getCustomerName()); 143 orderCreateDto.setShopCustomerName(shop.getCustomerName());
  144 + setTransportFee(orderCreateDto,transportFeeFlag);
136 //效验买方地址是否可配送 145 //效验买方地址是否可配送
137 orderDeliveryService.checkPersonContact(orderCreateDto); 146 orderDeliveryService.checkPersonContact(orderCreateDto);
138 //验证订单商品总重量与订单商品总价格 147 //验证订单商品总重量与订单商品总价格
@@ -144,6 +153,33 @@ public class OrderServiceImpl implements OrderService { @@ -144,6 +153,33 @@ public class OrderServiceImpl implements OrderService {
144 return order; 153 return order;
145 } 154 }
146 155
  156 + private void setTransportFee(OrderCreateDto orderCreateDto, Boolean transportFeeFlag) {
  157 + if(!transportFeeFlag || orderCreateDto.getAchieveType().equals(OrderAchieveType.BUYER_SELF.getCodeInteger())){
  158 + return;
  159 + }
  160 + OrderTransportFeeQuery orderTransportFeeQuery = new OrderTransportFeeQuery();
  161 + orderTransportFeeQuery.setShopId(orderCreateDto.getShopId());
  162 + orderTransportFeeQuery.setBuyerId(orderCreateDto.getBuyerId());
  163 + orderTransportFeeQuery.setMarketId(orderCreateDto.getMarketId());
  164 + orderTransportFeeQuery.setAchieveAddress(orderCreateDto.getDelivery().getAddress());
  165 + if(orderCreateDto.getTransportFee()!=null){
  166 + orderTransportFeeQuery.setTotleAmount(orderCreateDto.getTotleAmount().subtract(orderCreateDto.getTransportFee()));
  167 + }else{
  168 + orderCreateDto.setTransportFee(NumberTransform.ZERO);
  169 + orderTransportFeeQuery.setTotleAmount(orderCreateDto.getTotleAmount());
  170 + }
  171 + TransportFeeDto transportFee = getTransportFee(orderTransportFeeQuery);
  172 + if(transportFee != null){
  173 + if(!transportFee.getTransportFee().equals(orderCreateDto.getTransportFee().multiply(NumberTransform.ONE_HUNDERD).setScale(2,RoundingMode.HALF_UP).longValue())){
  174 + throw new OrderException(OrderErrorCode.PARAM_ERROR,"运费与设置不一致,请刷新后重试");
  175 + }
  176 + }else{
  177 + throw new OrderException(OrderErrorCode.PARAM_ERROR,"运费与设置不一致,请刷新后重试");
  178 + }
  179 +
  180 +
  181 + }
  182 +
147 /** 183 /**
148 * 买方效验 184 * 买方效验
149 * @param customerId 185 * @param customerId
@@ -1033,6 +1069,68 @@ public class OrderServiceImpl implements OrderService { @@ -1033,6 +1069,68 @@ public class OrderServiceImpl implements OrderService {
1033 } 1069 }
1034 1070
1035 @Override 1071 @Override
  1072 + public TransportFeeDto getTransportFee(OrderTransportFeeQuery order) {
  1073 + TransportFeeDto transportFeeDto = new TransportFeeDto();
  1074 + ShopExpressQueryCo shopExpressQueryCo = new ShopExpressQueryCo();
  1075 + shopExpressQueryCo.setShopId(order.getShopId());
  1076 + ShopExpressVo shopExpressVo = shopExpressSettingService.detail(shopExpressQueryCo);
  1077 + if(shopExpressVo == null){
  1078 + throw new OrderException(OrderErrorCode.PARAM_ERROR,"当前商家暂不支持配送");
  1079 + }else{
  1080 + if(CollectionUtils.isEmpty(shopExpressVo.getType())){
  1081 + throw new OrderException(OrderErrorCode.PARAM_ERROR,"当前商家暂不支持配送");
  1082 + }else if(!shopExpressVo.getType().contains(ExpressType.DELIVERY.getCode())){
  1083 + throw new OrderException(OrderErrorCode.PARAM_ERROR,"当前商家暂不支持配送");
  1084 + }
  1085 + }
  1086 + if(shopExpressVo.getFee()!=null){
  1087 + return transportFeeDto;
  1088 + }
  1089 + if(CollectionUtils.isNotEmpty(shopExpressVo.getCondition())){
  1090 + if(shopExpressVo.getCondition().contains(ExpressCondition.MONEY.getCode())){
  1091 + if(order.getTotleAmount().compareTo(shopExpressVo.getFreeAmount())>=0){
  1092 + return transportFeeDto;
  1093 + }else{
  1094 + transportFeeDto.setTransportFee(shopExpressVo.getFee().multiply(NumberTransform.ONE_HUNDERD).longValue());
  1095 + }
  1096 + }
  1097 + if(shopExpressVo.getCondition().contains(ExpressCondition.LOGIC.getCode())){
  1098 + if(shopExpressVo.getFreeTime() == null){
  1099 + return transportFeeDto;
  1100 + }else{
  1101 + LocalDateTime now = LocalDateTime.now();
  1102 + LocalDateTime newDateTime = now.toLocalDate().atTime(shopExpressVo.getFreeTime());
  1103 + OrderTransportFeeQuery orderTransportFeeQuery = new OrderTransportFeeQuery();
  1104 + if(newDateTime.isBefore(now)){
  1105 + orderTransportFeeQuery.setStartTime(newDateTime);
  1106 + orderTransportFeeQuery.setEndTime(newDateTime.plusHours(shopExpressVo.getPeriod()));
  1107 + }else{
  1108 + orderTransportFeeQuery.setStartTime(newDateTime.minusHours(shopExpressVo.getPeriod()));
  1109 + orderTransportFeeQuery.setEndTime(newDateTime);
  1110 + }
  1111 + orderTransportFeeQuery.setShopId(shopExpressVo.getShopId());
  1112 +
  1113 + orderTransportFeeQuery.setBuyerId(order.getBuyerId());
  1114 + orderTransportFeeQuery.setMarketId(order.getMarketId());
  1115 + orderTransportFeeQuery.setAchieveAddress(order.getAchieveAddress());
  1116 + Integer number = orderMapper.selectOrderByTransportFee(orderTransportFeeQuery);
  1117 + if(number!=null &&number>0){
  1118 + transportFeeDto.setTransportFee(0L);
  1119 + return transportFeeDto;
  1120 + }else{
  1121 + transportFeeDto.setTransportFee(shopExpressVo.getFee().multiply(NumberTransform.ONE_HUNDERD).longValue());
  1122 + return transportFeeDto;
  1123 + }
  1124 + }
  1125 + }
  1126 + return transportFeeDto;
  1127 + }else{
  1128 + transportFeeDto.setTransportFee(shopExpressVo.getFee().multiply(NumberTransform.ONE_HUNDERD).longValue());
  1129 + return transportFeeDto;
  1130 + }
  1131 + }
  1132 +
  1133 + @Override
1036 public Integer checkPayStateOnLine(String paymentId, Long marketId) { 1134 public Integer checkPayStateOnLine(String paymentId, Long marketId) {
1037 WeChatPayFunctionDto functionDto = new WeChatPayFunctionDto(paymentId,"online",marketId); 1135 WeChatPayFunctionDto functionDto = new WeChatPayFunctionDto(paymentId,"online",marketId);
1038 OrderPaymentCheckDto orderPaymentCheckDto = this.wxChatPayCheck(functionDto); 1136 OrderPaymentCheckDto orderPaymentCheckDto = this.wxChatPayCheck(functionDto);
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/order/OrderMapper.xml
@@ -522,4 +522,18 @@ @@ -522,4 +522,18 @@
522 parameterType="java.lang.String"> 522 parameterType="java.lang.String">
523 select verify_state,`state`,achieve_state,order_status,pay_state from `order` where `code` = #{code} 523 select verify_state,`state`,achieve_state,order_status,pay_state from `order` where `code` = #{code}
524 </select> 524 </select>
  525 + <select id="selectOrderByTransportFee" resultType="java.lang.Integer"
  526 + parameterType="com.diligrp.etrade.order.domain.OrderTransportFeeQuery">
  527 + select count(*) from `order` ord
  528 + left join order_delivery ode on ord.`code` = ode.order_code
  529 + <where>
  530 + ord.buyer_id = #{buyerId}
  531 + and ord.shop_id = #{shopId}
  532 + and ord.achieve_type = 2
  533 + and ord.pay_state = 3
  534 + and ode.address = #{achieveAddress}
  535 + and ord.paytime >= #{startTime}
  536 + and #{endTime} > ord.paytime
  537 + </where>
  538 + </select>
525 </mapper> 539 </mapper>
526 \ No newline at end of file 540 \ No newline at end of file