flow
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
@@ -22,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -88,11 +88,11 @@ public class BuyOrderController {
|
||||
@Transactional
|
||||
public R buySave(@RequestBody BuyOrderEntity buyOrder) throws IOException {
|
||||
// 获取订单详情
|
||||
List<BuyOrderDetailEntity> products = buyOrder.getProducts();
|
||||
List<BuyOrderDetail> products = buyOrder.getProducts();
|
||||
// 订单总金额
|
||||
BigDecimal totalPrice = new BigDecimal(0);
|
||||
// 遍历商品总价计算
|
||||
for (BuyOrderDetailEntity buyOrderDetail : products) {
|
||||
for (BuyOrderDetail buyOrderDetail : products) {
|
||||
Integer productId = buyOrderDetail.getProductId();
|
||||
int quantity = buyOrderDetail.getQuantity();
|
||||
ShopProductEntity product = shopProductService.getById(productId);
|
||||
@@ -103,7 +103,11 @@ public class BuyOrderController {
|
||||
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||
buyOrderDetail.setProductName(product.getProductName());
|
||||
buyOrderDetail.setProductPrice(product.getPrice());
|
||||
buyOrderDetail.setAddressId(buyOrder.getAddressId());
|
||||
int originWeight = product.getWeight();
|
||||
int originWeightIntValue = originWeight / 100;
|
||||
int originWeightDecimalValue = originWeightIntValue % 100;
|
||||
buyOrderDetail.setWeight(BigDecimal.valueOf(originWeightIntValue).add(BigDecimal.valueOf(originWeightDecimalValue).divide(new BigDecimal(100),
|
||||
MathContext.DECIMAL64)));
|
||||
buyOrderDetail.setProductUrl(product.getProductImages());
|
||||
buyOrderDetail.setOrderStatus(Constants.ORDER_STATUS_TO_BE_PAID);
|
||||
}
|
||||
@@ -115,7 +119,7 @@ public class BuyOrderController {
|
||||
buyOrder.setPaymentDate(new Date());
|
||||
buyOrderService.save(buyOrder);
|
||||
|
||||
for (BuyOrderDetailEntity buyOrderDetail : products) {
|
||||
for (BuyOrderDetail buyOrderDetail : products) {
|
||||
buyOrderDetail.setOrderId(buyOrder.getOrderId());
|
||||
buyOrderDetail.setUserId(buyOrder.getUserId());
|
||||
if (Constants.BUY_TYPE_CART.equals(buyOrder.getBuyType())) {
|
||||
@@ -182,27 +186,27 @@ public class BuyOrderController {
|
||||
public R appGetOrderInfo(@PathVariable String type, @RequestParam("orderId") Integer orderId) {
|
||||
BuyOrderEntity buyOrder = buyOrderService.getById(orderId);
|
||||
buyOrder.setTimestamp(buyOrder.getCreateTime().getTime() / 1000);
|
||||
List<BuyOrderDetailEntity> orderDetail = null;
|
||||
List<BuyOrderDetail> orderDetail = null;
|
||||
if ("1".equals(type)) {
|
||||
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
|
||||
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", orderId));
|
||||
} else {
|
||||
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetailEntity>()
|
||||
orderDetail = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", orderId));
|
||||
}
|
||||
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
|
||||
for (BuyOrderDetail buyOrderDetail : orderDetail) {
|
||||
|
||||
ShopProductEntity prod = shopProductService.getById(buyOrderDetailEntity.getProductId());
|
||||
ShopProductEntity prod = shopProductService.getById(buyOrderDetail.getProductId());
|
||||
if (prod != null) {
|
||||
buyOrderDetailEntity.setImage(prod.getProductImages());
|
||||
buyOrderDetail.setImage(prod.getProductImages());
|
||||
}
|
||||
}
|
||||
|
||||
List<BuyOrderDetailEntity> resultOrder = new ArrayList<BuyOrderDetailEntity>();
|
||||
List<BuyOrderDetail> resultOrder = new ArrayList<BuyOrderDetail>();
|
||||
Set<String> sn_no = new HashSet<String>();
|
||||
for (BuyOrderDetailEntity buyOrderDetailEntity : orderDetail) {
|
||||
resultOrder.add(buyOrderDetailEntity);
|
||||
sn_no.add(buyOrderDetailEntity.getShippingSn());
|
||||
for (BuyOrderDetail buyOrderDetail : orderDetail) {
|
||||
resultOrder.add(buyOrderDetail);
|
||||
sn_no.add(buyOrderDetail.getExpressOrderId());
|
||||
}
|
||||
|
||||
UserRecordEntity userRecordEntity = userRecordService.getBaseMapper().selectOne(new QueryWrapper<UserRecordEntity>()
|
||||
@@ -222,22 +226,22 @@ public class BuyOrderController {
|
||||
/**
|
||||
* 及时查询快递信息
|
||||
*/
|
||||
@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("/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);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 检查可合并的订单信息
|
||||
@@ -267,14 +271,14 @@ public class BuyOrderController {
|
||||
*
|
||||
* @param expressCompanyCode 快递公司编码
|
||||
* @param userAddressId 用户地址 ID
|
||||
* @param productIds 商品 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> productIds) {
|
||||
buyOrderService.createSplitPackageOrder(expressCompanyCode, userAddressId, productIds);
|
||||
@RequestBody List<Integer> buyOrderDetailId) throws Exception {
|
||||
buyOrderService.createSplitPackageOrder(expressCompanyCode, userAddressId, buyOrderDetailId);
|
||||
return R.ok();
|
||||
|
||||
}
|
||||
@@ -297,7 +301,7 @@ public class BuyOrderController {
|
||||
* @param product
|
||||
* @return
|
||||
*/
|
||||
private boolean handleStock(BuyOrderDetailEntity buyOrderDetail, ShopProductEntity product) {
|
||||
private boolean handleStock(BuyOrderDetail buyOrderDetail, ShopProductEntity product) {
|
||||
int quantity = buyOrderDetail.getQuantity();
|
||||
if (product.getProductStock() - quantity < 0) {
|
||||
return false;
|
||||
@@ -380,8 +384,8 @@ public class BuyOrderController {
|
||||
* @param products
|
||||
* @param buyOrder
|
||||
*/
|
||||
private void addEbookToUser(List<BuyOrderDetailEntity> products, BuyOrderEntity buyOrder) {
|
||||
List<Integer> productIds = products.stream().map(BuyOrderDetailEntity::getProductId).collect(Collectors.toList());
|
||||
private void addEbookToUser(List<BuyOrderDetail> products, BuyOrderEntity 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>()
|
||||
.eq(ShopProductBookEntity::getProductId, productId)
|
||||
@@ -396,7 +400,7 @@ public class BuyOrderController {
|
||||
* @param buyOrder
|
||||
* @param buyOrderDetail
|
||||
*/
|
||||
private void handleBuyCart(BuyOrderEntity buyOrder, BuyOrderDetailEntity buyOrderDetail) {
|
||||
private void handleBuyCart(BuyOrderEntity 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) {
|
||||
|
||||
Reference in New Issue
Block a user