bug fix 1018

This commit is contained in:
Cauchy
2023-10-18 16:37:58 +08:00
parent 5dee4b619e
commit c90ecfb7ce
33 changed files with 309 additions and 114 deletions

View File

@@ -10,10 +10,15 @@ import com.peanut.config.Constants;
import com.peanut.config.DelayQueueConfig;
import com.peanut.modules.book.entity.*;
import com.peanut.modules.book.service.*;
import com.peanut.modules.book.vo.ExpressQueryResponseVo;
import com.peanut.modules.book.vo.request.ProductRequestVo;
import com.peanut.modules.book.vo.request.ProductTransportVo;
import com.peanut.modules.book.vo.response.ExpressQueryResponseVo;
import com.peanut.modules.book.vo.ShippingAddressRequestVo;
import com.peanut.modules.book.vo.UserAddressVo;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService;
import com.peanut.modules.sys.entity.SysConfigEntity;
import com.peanut.modules.sys.service.SysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -24,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -61,12 +67,16 @@ public class BuyOrderController {
private WxpayService wxpayService;
@Autowired
private RabbitTemplate rabbitTemplate;
@Autowired
private ShopProductBookService shopProductBookService;
@Autowired
private ExpressOrderService expressOrderService;
@Autowired
private UserAddressService userAddressService;
@Autowired
private ExpressFeeService expressFeeService;
@Autowired
private SysConfigService sysConfigService;
/**
* 列表
@@ -91,11 +101,11 @@ public class BuyOrderController {
@Transactional
public R buySave(@RequestBody BuyOrder buyOrder) throws IOException {
// 获取订单详情
List<BuyOrderDetail> products = buyOrder.getProducts();
List<BuyOrderDetail> buyOrderDetails = buyOrder.getProducts();
// 订单总金额
BigDecimal totalPrice = new BigDecimal(0);
// 遍历商品总价计算
for (BuyOrderDetail buyOrderDetail : products) {
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
Integer productId = buyOrderDetail.getProductId();
int quantity = buyOrderDetail.getQuantity();
ShopProductEntity product = shopProductService.getById(productId);
@@ -120,16 +130,24 @@ public class BuyOrderController {
String orderSn = IdWorker.getTimeId().substring(0, 32);
buyOrder.setOrderSn(orderSn);
buyOrder.setPaymentDate(new Date());
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", buyOrder.getAddressId());
UserAddress userAddress = userAddressService.getOne(queryWrapper);
UserAddressVo vo = new UserAddressVo();
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
buyOrder.setProvince(vo.getProvince());
buyOrder.setCity(vo.getCity());
buyOrder.setDistrict(vo.getCity());
buyOrderService.save(buyOrder);
for (BuyOrderDetail buyOrderDetail : products) {
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
buyOrderDetail.setOrderId(buyOrder.getOrderId());
buyOrderDetail.setUserId(buyOrder.getUserId());
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
handleBuyCart(buyOrder, buyOrderDetail);
}
}
buyOrderDetailService.saveBatch(products);
buyOrderDetailService.saveBatch(buyOrderDetails);
// 1. 虚拟币支付
if (Constants.PAYMENT_METHOD_VIRTUAL.equals(buyOrder.getPaymentMethod())) {
buyOrder.setOrderStatus(Constants.ORDER_STATUS_TO_BE_SHIPPED);
@@ -138,7 +156,7 @@ public class BuyOrderController {
// 更新订单状态
buyOrderService.updateOrderStatus(user.getId(), buyOrder.getOrderSn(), "0");
recordTransaction(buyOrder, user, totalPrice);
addEbookToUser(products, buyOrder);
addEbookToUser(buyOrderDetails, buyOrder);
} else {
return R.error(500, "花生币余额不足!");
}
@@ -163,6 +181,24 @@ public class BuyOrderController {
return R.ok(result);
}
@RequestMapping(path = "/calculateTransportPrice", method = RequestMethod.POST)
public R getTransportPrice(@RequestBody ProductTransportVo vo) {
String regionCode = vo.getRegionCode();
List<ProductRequestVo> products = vo.getProducts();
BigDecimal totalWeight = new BigDecimal(0);
for (ProductRequestVo product : products) {
ShopProductEntity shopProduct = shopProductService.getById(product.getProductId());
BigDecimal weight = BigDecimal.valueOf(Double.valueOf(shopProduct.getWeight()) / 1000.0);
totalWeight = totalWeight.add(weight.multiply(new BigDecimal(product.getQuantity())));
}
totalWeight = totalWeight.setScale(0, RoundingMode.UP);
QueryWrapper<SysConfigEntity> configQueryWrapper = new QueryWrapper<>();
configQueryWrapper.eq("param_key", "DEFAULT_EXPRESS");
SysConfigEntity config = sysConfigService.getOne(configQueryWrapper);
BigDecimal expressFee = expressFeeService.calculateExpressFee(config.getParamValue(), totalWeight, regionCode);
return R.ok().put("result", expressFee);
}
/**
* 修改