后端:商品确认下单的信息 api 接口,后续需要结合促销,完善这个接口。
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
package cn.iocoder.mall.order.application.controller.users;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.CartService;
|
||||
import cn.iocoder.mall.order.api.OrderService;
|
||||
import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderCreateBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderPageBO;
|
||||
import cn.iocoder.mall.order.api.dto.CalcOrderPriceDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCreateDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderQueryDTO;
|
||||
import cn.iocoder.mall.order.application.convert.CartConvert;
|
||||
import cn.iocoder.mall.order.application.convert.OrderConvertAPP;
|
||||
import cn.iocoder.mall.order.application.po.user.OrderCreatePO;
|
||||
import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO;
|
||||
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* 订单API(users)
|
||||
*
|
||||
@@ -23,8 +30,10 @@ import org.springframework.web.bind.annotation.*;
|
||||
@RequestMapping("users/order")
|
||||
public class UsersOrderController {
|
||||
|
||||
@Autowired
|
||||
@Reference(validation = "true")
|
||||
private OrderService orderService;
|
||||
@Reference(validation = "true")
|
||||
private CartService cartService;
|
||||
|
||||
@GetMapping("order_page")
|
||||
public CommonResult<OrderPageBO> getOrderPage(@Validated OrderQueryDTO orderQueryDTO) {
|
||||
@@ -40,4 +49,19 @@ public class UsersOrderController {
|
||||
orderCreateDTO.setUserId(userId);
|
||||
return orderService.createOrder(orderCreateDTO);
|
||||
}
|
||||
|
||||
@GetMapping("/confirm_create_order")
|
||||
public CommonResult<UsersOrderConfirmCreateVO> getConfirmCreateOrder(@RequestParam("skuId") Integer skuId,
|
||||
@RequestParam("quantity") Integer quantity) {
|
||||
// 创建 CalcOrderPriceDTO 对象,并执行价格计算
|
||||
CalcOrderPriceDTO calcOrderPriceDTO = new CalcOrderPriceDTO()
|
||||
.setItems(Collections.singletonList(new CalcOrderPriceDTO.Item(skuId, quantity, true)));
|
||||
CommonResult<CalcOrderPriceBO> calcOrderPriceResult = cartService.calcOrderPrice(calcOrderPriceDTO);
|
||||
if (calcOrderPriceResult.isError()) {
|
||||
return CommonResult.error(calcOrderPriceResult);
|
||||
}
|
||||
// 执行数据拼装
|
||||
return CommonResult.success(CartConvert.INSTANCE.convert(calcOrderPriceResult.getData()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.mall.order.application.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO;
|
||||
import cn.iocoder.mall.order.application.vo.UsersOrderConfirmCreateVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface CartConvert {
|
||||
|
||||
CartConvert INSTANCE = Mappers.getMapper(CartConvert.class);
|
||||
|
||||
UsersOrderConfirmCreateVO convert(CalcOrderPriceBO calcOrderPriceBO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
package cn.iocoder.mall.order.application.vo;
|
||||
|
||||
import cn.iocoder.mall.product.api.bo.ProductAttrAndValuePairBO;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UsersOrderConfirmCreateVO {
|
||||
|
||||
/**
|
||||
* 商品分组数组
|
||||
*/
|
||||
private List<ItemGroup> itemGroups;
|
||||
/**
|
||||
* 费用
|
||||
*/
|
||||
private Fee fee;
|
||||
|
||||
/**
|
||||
* 商品分组
|
||||
*
|
||||
* 多个商品,参加同一个活动,从而形成分组。
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class ItemGroup {
|
||||
|
||||
// TODO 优惠活动
|
||||
private Object activity;
|
||||
/**
|
||||
* 商品数组
|
||||
*/
|
||||
private List<Sku> items;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Sku {
|
||||
|
||||
// SKU 自带信息
|
||||
/**
|
||||
* sku 编号
|
||||
*/
|
||||
private Integer id;
|
||||
/**
|
||||
* SPU 信息
|
||||
*/
|
||||
private Spu spu;
|
||||
/**
|
||||
* 图片地址
|
||||
*/
|
||||
private String picURL;
|
||||
/**
|
||||
* 规格值数组
|
||||
*/
|
||||
private List<ProductAttrAndValuePairBO> attrs; // TODO 后面改下
|
||||
/**
|
||||
* 价格,单位:分
|
||||
*/
|
||||
private Integer price;
|
||||
/**
|
||||
* 库存数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
// 非 SKU 自带信息
|
||||
|
||||
/**
|
||||
* 购买数量
|
||||
*/
|
||||
private Integer buyQuantity;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Spu {
|
||||
|
||||
/**
|
||||
* SPU 编号
|
||||
*/
|
||||
private Integer id;
|
||||
|
||||
// ========== 基本信息 =========
|
||||
/**
|
||||
* SPU 名字
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 分类编号
|
||||
*/
|
||||
private Integer cid;
|
||||
/**
|
||||
* 商品主图地址
|
||||
*
|
||||
* 数组,以逗号分隔
|
||||
*
|
||||
* 建议尺寸:800*800像素,你可以拖拽图片调整顺序,最多上传15张
|
||||
*/
|
||||
private List<String> picUrls;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 费用(合计)
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Fee {
|
||||
|
||||
/**
|
||||
* 总价
|
||||
*/
|
||||
private Integer originalTotal;
|
||||
/**
|
||||
* 优惠总价
|
||||
*
|
||||
* 注意,满多少元包邮,不算在优惠中。
|
||||
*/
|
||||
private Integer discountTotal;
|
||||
/**
|
||||
* 邮费
|
||||
*/
|
||||
private Integer postageTotal;
|
||||
/**
|
||||
* 最终价格
|
||||
*
|
||||
* 计算公式 = 总价 - 优惠总价 + 邮费
|
||||
*/
|
||||
private Integer presentTotal;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 邮费信息
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class Postage {
|
||||
|
||||
/**
|
||||
* 需要满足多少钱,可以包邮。单位:分
|
||||
*/
|
||||
private Integer threshold;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user