This commit is contained in:
Cauchy
2023-10-18 13:02:54 +08:00
parent 113243e918
commit 5dee4b619e
27 changed files with 386 additions and 216 deletions

View File

@@ -10,6 +10,8 @@ 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.ShippingAddressRequestVo;
import com.peanut.modules.pay.weChatPay.dto.WechatPaymentInfo;
import com.peanut.modules.pay.weChatPay.service.WxpayService;
import lombok.extern.slf4j.Slf4j;
@@ -35,7 +37,7 @@ import java.util.stream.Collectors;
*/
@Slf4j
@RestController
@RequestMapping("book/buyorder")
@RequestMapping("book/buyOrder")
public class BuyOrderController {
@Autowired
private BuyOrderService buyOrderService;
@@ -56,8 +58,6 @@ public class BuyOrderController {
@Autowired
private UserEbookBuyService userEbookBuyService;
@Autowired
private UserRecordService userRecordService;
@Autowired
private WxpayService wxpayService;
@Autowired
private RabbitTemplate rabbitTemplate;
@@ -65,6 +65,9 @@ public class BuyOrderController {
@Autowired
private ShopProductBookService shopProductBookService;
@Autowired
private ExpressOrderService expressOrderService;
/**
* 列表
*/
@@ -86,7 +89,7 @@ public class BuyOrderController {
*/
@RequestMapping("/buySave")
@Transactional
public R buySave(@RequestBody BuyOrderEntity buyOrder) throws IOException {
public R buySave(@RequestBody BuyOrder buyOrder) throws IOException {
// 获取订单详情
List<BuyOrderDetail> products = buyOrder.getProducts();
// 订单总金额
@@ -165,7 +168,7 @@ public class BuyOrderController {
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody BuyOrderEntity buyOrder) {
public R update(@RequestBody BuyOrder buyOrder) {
buyOrderService.updateById(buyOrder);
return R.ok();
}
@@ -180,68 +183,61 @@ public class BuyOrderController {
}
/**
* 信息
* 获取订单详情
*
* @param orderId 订单 ID
* @return R
*/
@RequestMapping("/appGetOrderInfo/{type}")
public R appGetOrderInfo(@PathVariable String type, @RequestParam("orderId") Integer orderId) {
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
buyOrder.setTimestamp(buyOrder.getCreateTime().getTime() / 1000);
List<BuyOrderDetail> orderDetail = null;
if ("1".equals(type)) {
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", orderId));
} else {
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
.eq("order_id", orderId));
}
for (BuyOrderDetail buyOrderDetail : orderDetail) {
@RequestMapping(value = "/getOrderInfo", method = RequestMethod.GET)
public R appGetOrderInfo(@RequestParam("orderId") Integer orderId) {
BuyOrder buyOrder = buyOrderService.getById(orderId);
QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_id", orderId);
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
ShopProductEntity prod = shopProductService.getById(buyOrderDetail.getProductId());
if (prod != null) {
buyOrderDetail.setImage(prod.getProductImages());
}
}
return R.ok().put("result", buyOrder);
}
List<BuyOrderDetail> resultOrder = new ArrayList<BuyOrderDetail>();
Set<String> sn_no = new HashSet<String>();
for (BuyOrderDetail buyOrderDetail : orderDetail) {
resultOrder.add(buyOrderDetail);
// sn_no.add(buyOrderDetail.getExpressOrderId());
}
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>()
.eq("orderSn", buyOrder.getOrderSn())
.eq("userid", buyOrder.getUserId())
.eq("orderdid", buyOrder.getOrderId())
.last("LIMIT 1"));
Integer id = null;
if (userRecordEntity != null) {
id = userRecordEntity.getId();
}
buyOrder.setProducts(resultOrder);
Date createDate = buyOrder.getCreateTime();
return R.ok().put("buyOrder", buyOrder).put("CreateTime", createDate).put("userRecordid", id);
@RequestMapping(value = "/modifyOrderAddress", method = RequestMethod.POST)
public R modifyOrderAddress(@RequestBody ShippingAddressRequestVo addressRequestVo) {
BuyOrder buyOrder = buyOrderService.getById(addressRequestVo.getOrderId());
buyOrder.setProvince(addressRequestVo.getProvince());
buyOrder.setCity(addressRequestVo.getCity());
buyOrder.setDistrict(addressRequestVo.getCounty());
buyOrder.setShippingUser(addressRequestVo.getName());
buyOrder.setUserPhone(addressRequestVo.getMobile());
buyOrderService.updateById(buyOrder);
return R.ok();
}
/**
* 及时查询快递信息
* 查询订单快递
*
* @param orderId 订单号
* @return R
*/
// @RequestMapping("/queryFMS")
// public R queryFMS(@RequestParam Map<String, String> params) {
// List<BuyOrderDetailEntity> detailList = this.buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>().eq("order_id", params.get("orderId")));
// List<JSONObject> jsonList = new ArrayList<>();
// JSONObject jsonObj = null;
// for (BuyOrderDetailEntity detail : detailList) {
// jsonObj = buyOrderService.queryFMS(detail.getShipperCode(), detail.getShippingSn());
// if (Objects.isNull(jsonObj)) {
// return R.ok("暂未查到物流信息!");
// }
// jsonObj.put("ShipperName", detail.getShipperName());
// jsonList.add(jsonObj);
//
// }
// return R.ok().put("rntStr", jsonList);
// }
@RequestMapping(value = "/queryExpress", method = RequestMethod.GET)
public R queryExpress(@RequestParam("orderId") Integer orderId) {
QueryWrapper<BuyOrderDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("order_id", orderId);
List<BuyOrderDetail> buyOrderDetailList = buyOrderDetailService.list(queryWrapper);
List<ExpressQueryResponseVo> result = new ArrayList<>();
for (BuyOrderDetail buyOrderDetail : buyOrderDetailList) {
ExpressQueryResponseVo vo = new ExpressQueryResponseVo();
vo.setOrderDetailId(buyOrderDetail.getId());
ExpressQueryResponse expressQueryResponse = expressOrderService.queryExpressOrder(buyOrderDetail.getExpressCompanyCode(), buyOrderDetail.getExpressBillNo());
vo.setLogisticCode(expressQueryResponse.getLogisticCode());
vo.setTraces(expressQueryResponse.getTraces());
result.add(vo);
}
return R.ok().put("result", result);
}
/**
* 检查可合并的订单信息
@@ -270,15 +266,13 @@ public class BuyOrderController {
* 分包发货
*
* @param expressCompanyCode 快递公司编码
* @param userAddressId 用户地址 ID
* @param buyOrderDetailId 订单详情列表
* @return R
*/
@RequestMapping(value = "/createSplitPackages", method = RequestMethod.POST)
public R createSplitPackageOrder(@RequestParam("expressCompanyCode") String expressCompanyCode,
@RequestParam("userAddressId") Integer userAddressId,
@RequestBody List<Integer> buyOrderDetailId) throws Exception {
buyOrderService.createSplitPackageOrder(expressCompanyCode, userAddressId, buyOrderDetailId);
buyOrderService.createSplitPackageOrder(expressCompanyCode, buyOrderDetailId);
return R.ok();
}
@@ -318,7 +312,7 @@ public class BuyOrderController {
* @param buyOrder
* @return
*/
private BigDecimal useCouponAmount(BuyOrderEntity buyOrder) {
private BigDecimal useCouponAmount(BuyOrder buyOrder) {
Integer couponId = buyOrder.getCouponId();
if (couponId != null) {
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
@@ -339,7 +333,7 @@ public class BuyOrderController {
* @param buyOrder
* @return
*/
private BigDecimal getShoppingAmount(BuyOrderEntity buyOrder) {
private BigDecimal getShoppingAmount(BuyOrder buyOrder) {
return buyOrder.getOrderMoney() == null ? BigDecimal.ZERO : buyOrder.getShippingMoney();
}
@@ -366,7 +360,7 @@ public class BuyOrderController {
* @param user
* @param totalPrice
*/
private void recordTransaction(BuyOrderEntity buyOrder, MyUserEntity user, BigDecimal totalPrice) {
private void recordTransaction(BuyOrder buyOrder, MyUserEntity user, BigDecimal totalPrice) {
TransactionDetailsEntity transactionDetailsEntity = new TransactionDetailsEntity();
transactionDetailsEntity.setRemark("订单编号为 - " + buyOrder.getOrderSn());
transactionDetailsEntity.setUserId(user.getId());
@@ -384,7 +378,7 @@ public class BuyOrderController {
* @param products
* @param buyOrder
*/
private void addEbookToUser(List<BuyOrderDetail> products, BuyOrderEntity buyOrder) {
private void addEbookToUser(List<BuyOrderDetail> products, BuyOrder buyOrder) {
List<Integer> productIds = products.stream().map(BuyOrderDetail::getProductId).collect(Collectors.toList());
for (Integer productId : productIds) {
List<Integer> collect = shopProductBookService.getBaseMapper().selectList(new LambdaQueryWrapper<ShopProductBookEntity>()
@@ -400,7 +394,7 @@ public class BuyOrderController {
* @param buyOrder
* @param buyOrderDetail
*/
private void handleBuyCart(BuyOrderEntity buyOrder, BuyOrderDetail buyOrderDetail) {
private void handleBuyCart(BuyOrder buyOrder, BuyOrderDetail buyOrderDetail) {
List<OrderCartEntity> orderCartList = orderCartService.getBaseMapper().selectList(new QueryWrapper<OrderCartEntity>()
.eq("user_id", buyOrder.getUserId()).eq("product_id", buyOrderDetail.getProductId()));
if (orderCartList.size() > 0) {