This commit is contained in:
Cauchy
2023-10-24 13:08:01 +08:00
parent 7c9540f3ae
commit b57b196dd5
12 changed files with 502 additions and 520 deletions

View File

@@ -5,27 +5,24 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.peanut.common.utils.PageUtils;
import com.peanut.common.utils.Query;
import com.peanut.common.utils.R;
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.UserAddressVo;
import com.peanut.modules.book.vo.request.BuyOrderListRequestVo;
import com.peanut.modules.book.vo.request.ModifyOrderAddressRequestVo;
import com.peanut.modules.book.vo.request.ProductRequestVo;
import com.peanut.modules.book.vo.request.ProductTransportVo;
import com.peanut.modules.book.vo.response.BuyOrderResponseVo;
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.book.vo.response.OrderAddressResponseVo;
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.apache.poi.ss.formula.functions.Count;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@@ -182,7 +179,7 @@ public class BuyOrderController {
buyOrderService.save(buyOrder);
for (BuyOrderDetail buyOrderDetail : buyOrderDetails) {
buyOrderDetail.setOrderId(buyOrder.getOrderId());
buyOrderDetail.setOrderId(buyOrder.getId());
buyOrderDetail.setUserId(buyOrder.getUserId());
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
handleBuyCart(buyOrder, buyOrderDetail);
@@ -207,12 +204,12 @@ public class BuyOrderController {
rabbitTemplate.convertAndSend(
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
buyOrder.getOrderId(),
buyOrder.getId(),
messagePostProcessor()
);
WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
paymentInfo.setOrderSn(orderSn);
paymentInfo.setBuyOrderId(buyOrder.getOrderId());
paymentInfo.setBuyOrderId(buyOrder.getId());
paymentInfo.setTotalAmount(totalPrice);
wxpayService.prepay(paymentInfo);
}
@@ -229,9 +226,9 @@ public class BuyOrderController {
* @return
* @throws IOException
*/
@RequestMapping(value = "placeOrder", method = RequestMethod.POST)
@RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
public R placeOrder(@RequestBody BuyOrder buyOrder) throws IOException {
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductInfoList();
List<BuyOrderProduct> buyOrderProductList = buyOrder.getProductList();
// 订单总金额
BigDecimal totalPrice = new BigDecimal(0);
// 遍历商品总价计算
@@ -244,8 +241,6 @@ public class BuyOrderController {
return R.error(500, "库存不足");
}
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
//buyOrderDetail.setProductName(product.getProductName());
//buyOrderDetail.setProductPrice(product.getPrice());
int originWeight = product.getWeight();
int originWeightIntValue = originWeight / 100;
int originWeightDecimalValue = originWeightIntValue % 100;
@@ -272,7 +267,7 @@ public class BuyOrderController {
buyOrderService.save(buyOrder);
for (BuyOrderProduct buyOrderDetail : buyOrderProductList) {
buyOrderDetail.setOrderId(buyOrder.getOrderId());
buyOrderDetail.setOrderId(buyOrder.getId());
//buyOrderDetail.setUserId(buyOrder.getUserId());
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
handleBuyCart(buyOrder, buyOrderDetail);
@@ -298,12 +293,12 @@ public class BuyOrderController {
rabbitTemplate.convertAndSend(
DelayQueueConfig.ORDER_TO_BE_PAY_EXCHANGE,
DelayQueueConfig.ORDER_TO_BE_PAY_ROUTING_KEY,
buyOrder.getOrderId(),
buyOrder.getId(),
messagePostProcessor()
);
WechatPaymentInfo paymentInfo = new WechatPaymentInfo();
paymentInfo.setOrderSn(orderSn);
paymentInfo.setBuyOrderId(buyOrder.getOrderId());
paymentInfo.setBuyOrderId(buyOrder.getId());
paymentInfo.setTotalAmount(totalPrice);
wxpayService.prepay(paymentInfo);
}
@@ -347,6 +342,40 @@ public class BuyOrderController {
}
/**
* @param orderSn 订单号
* @return R
*/
@RequestMapping(value = "/cancelOrder", method = RequestMethod.GET)
@Transactional
public R appDelete(@RequestParam("orderSn") String orderSn) {
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_sn", orderSn);
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
if (buyOrder == null) {
return R.error("订单不存在");
}
if (buyOrder.getCouponId() != null) {
Integer couponId = buyOrder.getCouponId();
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
couponHistory.setUseStatus(0);
couponHistoryService.updateById(couponHistory);
}
// 库存回滚
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
buyOrderProductQueryWrapper.eq("order_id",buyOrder.getId());
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.list(buyOrderProductQueryWrapper);
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
Integer productId = buyOrderProduct.getProductId();
ShopProduct product = shopProductService.getById(productId);
product.setProductStock(product.getProductStock() + buyOrderProduct.getQuantity());
shopProductService.updateById(product);
}
buyOrderService.removeById(buyOrder.getId());
return R.ok();
}
/**
* 修改
*/
@@ -389,7 +418,7 @@ public class BuyOrderController {
}
// 库存回滚
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", byId.getOrderId()));
.eq("order_id", byId.getId()));
for (BuyOrderDetail buyOrderDetailEntity : buyOrderDetailEntities) {
Integer productId = buyOrderDetailEntity.getProductId();
ShopProduct product = shopProductService.getById(productId);
@@ -401,39 +430,6 @@ public class BuyOrderController {
return R.ok();
}
/**
* @param orderSn 订单号
* @return R
*/
@RequestMapping("/cancelOrder")
@Transactional
public R appDelete(@RequestParam("orderSn") String orderSn) {
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_sn", orderSn);
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
if (buyOrder == null) {
return R.error("订单不存在");
}
if (buyOrder.getCouponId() != null) {
Integer couponId = buyOrder.getCouponId();
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
couponHistory.setUseStatus(0);
couponHistoryService.updateById(couponHistory);
}
// 库存回滚
List<BuyOrderProduct> buyOrderProductList = buyOrderProductService.getBaseMapper().selectList(new QueryWrapper<BuyOrderProduct>()
.eq("order_id", buyOrder.getOrderId()));
for (BuyOrderProduct buyOrderProduct : buyOrderProductList) {
Integer productId = buyOrderProduct.getProductId();
ShopProduct product = shopProductService.getById(productId);
product.setProductStock(product.getProductStock() + buyOrderProduct.getQuantity());
shopProductService.updateById(product);
}
buyOrderService.removeById(buyOrder.getOrderId());
return R.ok();
}
/**
* 充值专用订单生成接口
@@ -464,7 +460,7 @@ public class BuyOrderController {
@RequestMapping("/getOrderDetail")
public R getOrderDetail(@RequestParam Integer orderId) {
LambdaQueryWrapper<BuyOrder> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(BuyOrder::getOrderId, orderId);
wrapper.eq(BuyOrder::getId, orderId);
BuyOrder one = buyOrderService.getOne(wrapper);
if (one.equals(null)) {
return R.error("order error:order is null");
@@ -509,10 +505,11 @@ public class BuyOrderController {
* @param addressRequestVo 地址请求 value object
* @return R
*/
@RequestMapping(value = "/modifyOrderAddress", method = RequestMethod.POST)
public R modifyOrderAddress(@RequestBody ShippingAddressRequestVo addressRequestVo) {
BuyOrder buyOrder = buyOrderService.getById(addressRequestVo.getOrderId());
@RequestMapping(value = "/modifyConsigneeAddress", method = RequestMethod.POST)
public R modifyOrderAddress(@RequestBody ModifyOrderAddressRequestVo addressRequestVo) {
QueryWrapper<BuyOrder> buyOrderQueryWrapper = new QueryWrapper<>();
buyOrderQueryWrapper.eq("order_sn", addressRequestVo.getOrderSn());
BuyOrder buyOrder = buyOrderService.getOne(buyOrderQueryWrapper);
String provinceCode = addressRequestVo.getProvinceCode();
QueryWrapper<Province> provinceQueryWrapper = new QueryWrapper<>();
provinceQueryWrapper.eq("region_code", provinceCode);
@@ -528,8 +525,8 @@ public class BuyOrderController {
countyQueryWrapper.eq("region_code", countyCode);
County county = countyService.getOne(countyQueryWrapper);
buyOrder.setDistrict(county.getCountyName());
buyOrder.setShippingUser(addressRequestVo.getName());
buyOrder.setUserPhone(addressRequestVo.getMobile());
buyOrder.setShippingUser(addressRequestVo.getConsigneeName());
buyOrder.setUserPhone(addressRequestVo.getConsigneeMobile());
buyOrder.setAddress(addressRequestVo.getAddress());
buyOrderService.updateById(buyOrder);
return R.ok();
@@ -541,7 +538,7 @@ public class BuyOrderController {
* @param orderSn 订单号
* @return R
*/
@RequestMapping(value = "/getOrderAddress", method = RequestMethod.GET)
@RequestMapping(value = "/getConsigneeAddress", method = RequestMethod.GET)
public R getOrderAddress(@RequestParam("orderSn") String orderSn) {
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_sn", orderSn);
@@ -584,7 +581,7 @@ public class BuyOrderController {
QueryWrapper<BuyOrder> buyOrderQueryWrapper = new QueryWrapper<>();
buyOrderQueryWrapper.eq("order_sn", orderSn);
BuyOrder buyOrder = buyOrderService.getOne(buyOrderQueryWrapper);
Integer orderId = buyOrder.getOrderId();
Integer orderId = buyOrder.getId();
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
buyOrderProductQueryWrapper.eq("order_id", orderId);
@@ -629,13 +626,13 @@ public class BuyOrderController {
* 分包发货
*
* @param expressCompanyCode 快递公司编码
* @param buyOrderDetailId 订单详情列表
* @param buyOrderProductId 订单商品
* @return R
*/
@RequestMapping(value = "/delivery", method = RequestMethod.POST)
public R delivery(@RequestParam("expressCompanyCode") String expressCompanyCode,
@RequestBody List<Integer> buyOrderDetailId) throws Exception {
buyOrderService.delivery(expressCompanyCode, buyOrderDetailId);
@RequestBody List<Integer> buyOrderProductId) throws Exception {
buyOrderService.delivery(expressCompanyCode, buyOrderProductId);
return R.ok();
}
@@ -700,7 +697,7 @@ public class BuyOrderController {
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
couponHistory.setUseStatus(1);
couponHistory.setUseTime(new Date());
couponHistory.setOrderId(Long.valueOf(buyOrder.getOrderId()));
couponHistory.setOrderId(Long.valueOf(buyOrder.getId()));
couponHistory.setOrderSn(buyOrder.getOrderSn());
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
@@ -709,21 +706,6 @@ public class BuyOrderController {
return BigDecimal.ZERO;
}
@RequestMapping("/modifyConsigneeAddress")
public R modifyConsigneeAddress(@RequestBody ModifyOrderAddressRequestVo requestVo) {
QueryWrapper<BuyOrder> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_sn", requestVo.getOrderSn());
BuyOrder buyOrder = buyOrderService.getOne(queryWrapper);
buyOrder.setShippingUser(requestVo.getConsigneeName());
buyOrder.setUserPhone(requestVo.getConsigneeMobile());
buyOrder.setProvince(requestVo.getProvince());
buyOrder.setCity(requestVo.getCity());
buyOrder.setDistrict(requestVo.getCounty());
buyOrder.setAddress(requestVo.getAddress());
buyOrder.setAddressModified(1);
buyOrderService.updateById(buyOrder);
return R.ok();
}
/**
* 计算运费