zhangyu 1 tydzień temu
rodzic
commit
e63eda1c5e
28 zmienionych plików z 841 dodań i 90 usunięć
  1. 1 3
      src/main/java/com/futu/goose/filter/AuthInterceptor.java
  2. 1 1
      src/main/java/com/futu/goose/filter/WebConfig.java
  3. 21 0
      src/main/java/com/futu/goose/orders/controller/CouponController.java
  4. 20 0
      src/main/java/com/futu/goose/orders/controller/OrderController.java
  5. 23 0
      src/main/java/com/futu/goose/orders/controller/ProductController.java
  6. 12 0
      src/main/java/com/futu/goose/orders/dto/OrderDto.java
  7. 9 0
      src/main/java/com/futu/goose/orders/dto/ProductDto.java
  8. 20 0
      src/main/java/com/futu/goose/orders/mapper/TCouponMapper.java
  9. 20 0
      src/main/java/com/futu/goose/orders/mapper/TOrderItemMapper.java
  10. 20 0
      src/main/java/com/futu/goose/orders/mapper/TOrderMapper.java
  11. 22 0
      src/main/java/com/futu/goose/orders/mapper/TProductMapper.java
  12. 67 0
      src/main/java/com/futu/goose/orders/pojo/TCoupon.java
  13. 62 0
      src/main/java/com/futu/goose/orders/pojo/TOrder.java
  14. 51 0
      src/main/java/com/futu/goose/orders/pojo/TOrderItem.java
  15. 57 0
      src/main/java/com/futu/goose/orders/pojo/TProduct.java
  16. 15 0
      src/main/java/com/futu/goose/orders/service/TCouponService.java
  17. 13 0
      src/main/java/com/futu/goose/orders/service/TOrderItemService.java
  18. 16 0
      src/main/java/com/futu/goose/orders/service/TOrderService.java
  19. 15 0
      src/main/java/com/futu/goose/orders/service/TProductService.java
  20. 32 0
      src/main/java/com/futu/goose/orders/service/impl/TCouponServiceImpl.java
  21. 22 0
      src/main/java/com/futu/goose/orders/service/impl/TOrderItemServiceImpl.java
  22. 201 0
      src/main/java/com/futu/goose/orders/service/impl/TOrderServiceImpl.java
  23. 32 0
      src/main/java/com/futu/goose/orders/service/impl/TProductServiceImpl.java
  24. 0 86
      src/main/java/com/futu/goose/store/pojo/Shop.java
  25. 24 0
      src/main/resources/mapper/TCouponMapper.xml
  26. 20 0
      src/main/resources/mapper/TOrderItemMapper.xml
  27. 23 0
      src/main/resources/mapper/TOrderMapper.xml
  28. 22 0
      src/main/resources/mapper/TProductMapper.xml

+ 1 - 3
src/main/java/com/futu/goose/filter/AuthInterceptor.java

@@ -8,7 +8,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 
-@Component
+//@Component
 public class AuthInterceptor implements HandlerInterceptor {
     @Autowired
     private RedisClient redisClient;
@@ -32,8 +32,6 @@ public class AuthInterceptor implements HandlerInterceptor {
         }
         // 从 Redis 中获取存储的 token
         String storedToken = (String) redisClient.get("token");
-        System.out.println(storedToken);
-        System.out.println(token);
         if (storedToken == null || !storedToken.equals(token)) {
             response.setStatus(HttpServletResponse.SC_FORBIDDEN);
             response.setContentType("application/json;charset=UTF-8");

+ 1 - 1
src/main/java/com/futu/goose/filter/WebConfig.java

@@ -5,7 +5,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
-@Configuration
+//@Configuration
 public class WebConfig implements WebMvcConfigurer {
 
     @Autowired

+ 21 - 0
src/main/java/com/futu/goose/orders/controller/CouponController.java

@@ -0,0 +1,21 @@
+package com.futu.goose.orders.controller;
+
+import com.futu.goose.orders.pojo.TCoupon;
+import com.futu.goose.orders.service.TCouponService;
+import com.futu.goose.utils.Result;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RestController
+@RequestMapping("/coupon")
+public class CouponController {
+    @Resource
+    private TCouponService couponService;
+    @RequestMapping("/addCoupon")
+     public Result addCoupon(@RequestBody TCoupon coupon){
+        return couponService.addCoupon(coupon);
+    }
+}

+ 20 - 0
src/main/java/com/futu/goose/orders/controller/OrderController.java

@@ -0,0 +1,20 @@
+package com.futu.goose.orders.controller;
+
+import com.futu.goose.orders.dto.OrderDto;
+import com.futu.goose.orders.service.TOrderService;
+import com.futu.goose.utils.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/orders")
+public class OrderController {
+    @Autowired
+    private TOrderService orderService;
+    @RequestMapping("/addOrders")
+    public Result addOrders(@RequestBody OrderDto orderDto){
+        return orderService.addOrders(orderDto);
+    }
+}

+ 23 - 0
src/main/java/com/futu/goose/orders/controller/ProductController.java

@@ -0,0 +1,23 @@
+package com.futu.goose.orders.controller;
+
+import com.futu.goose.orders.mapper.TProductMapper;
+import com.futu.goose.orders.pojo.TProduct;
+import com.futu.goose.orders.service.TProductService;
+import com.futu.goose.utils.Result;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RestController
+@RequestMapping("/product")
+public class ProductController {
+    @Autowired
+    private TProductService tProductService;
+    @RequestMapping("addProduct")
+    public Result addProduct(@RequestBody TProduct product){
+        return tProductService.addProduct(product);
+    }
+}

+ 12 - 0
src/main/java/com/futu/goose/orders/dto/OrderDto.java

@@ -0,0 +1,12 @@
+package com.futu.goose.orders.dto;
+
+import com.futu.goose.orders.pojo.TOrder;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class OrderDto  {
+    private Long id;
+    private List<ProductDto> productList;
+}

+ 9 - 0
src/main/java/com/futu/goose/orders/dto/ProductDto.java

@@ -0,0 +1,9 @@
+package com.futu.goose.orders.dto;
+
+import lombok.Data;
+
+@Data
+public class ProductDto {
+    private Long productId;
+    private Integer num;
+}

+ 20 - 0
src/main/java/com/futu/goose/orders/mapper/TCouponMapper.java

@@ -0,0 +1,20 @@
+package com.futu.goose.orders.mapper;
+
+import com.futu.goose.orders.pojo.TCoupon;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author 张大宇
+* @description 针对表【t_coupon(优惠券表)】的数据库操作Mapper
+* @createDate 2025-05-13 16:26:58
+* @Entity com.futu.goose.orders.pojo.TCoupon
+*/
+@Mapper
+public interface TCouponMapper extends BaseMapper<TCoupon> {
+
+}
+
+
+
+

+ 20 - 0
src/main/java/com/futu/goose/orders/mapper/TOrderItemMapper.java

@@ -0,0 +1,20 @@
+package com.futu.goose.orders.mapper;
+
+import com.futu.goose.orders.pojo.TOrderItem;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author 张大宇
+* @description 针对表【t_order_item(订单明细表)】的数据库操作Mapper
+* @createDate 2025-05-13 16:26:58
+* @Entity com.futu.goose.orders.pojo.TOrderItem
+*/
+@Mapper
+public interface TOrderItemMapper extends BaseMapper<TOrderItem> {
+
+}
+
+
+
+

+ 20 - 0
src/main/java/com/futu/goose/orders/mapper/TOrderMapper.java

@@ -0,0 +1,20 @@
+package com.futu.goose.orders.mapper;
+
+import com.futu.goose.orders.pojo.TOrder;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author 张大宇
+* @description 针对表【t_order(订单主表)】的数据库操作Mapper
+* @createDate 2025-05-13 16:26:58
+* @Entity com.futu.goose.orders.pojo.TOrder
+*/
+@Mapper
+public interface TOrderMapper extends BaseMapper<TOrder> {
+
+}
+
+
+
+

+ 22 - 0
src/main/java/com/futu/goose/orders/mapper/TProductMapper.java

@@ -0,0 +1,22 @@
+package com.futu.goose.orders.mapper;
+
+import com.futu.goose.orders.pojo.TProduct;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.futu.goose.utils.Result;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+* @author 张大宇
+* @description 针对表【t_product(商品表)】的数据库操作Mapper
+* @createDate 2025-05-13 16:26:58
+* @Entity com.futu.goose.orders.pojo.TProduct
+*/
+@Mapper
+public interface TProductMapper extends BaseMapper<TProduct> {
+
+
+}
+
+
+
+

+ 67 - 0
src/main/java/com/futu/goose/orders/pojo/TCoupon.java

@@ -0,0 +1,67 @@
+package com.futu.goose.orders.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 优惠券表
+ * @TableName t_coupon
+ */
+@TableName(value ="t_coupon")
+@Data
+public class TCoupon implements Serializable {
+    /**
+     * 优惠券ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 用户ID
+     */
+    private Long userId;
+
+    /**
+     * 优惠券码
+     */
+    private String couponCode;
+
+    /**
+     * 优惠券类型
+     */
+    private String type;
+
+    /**
+     * 优惠金额(满减)
+     */
+    private BigDecimal amount;
+
+    /**
+     * 满减门槛
+     */
+    private BigDecimal threshold;
+
+    /**
+     * 状态
+     */
+    private String status;
+
+    /**
+     * 过期时间
+     */
+    private Date expireTime;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+}

+ 62 - 0
src/main/java/com/futu/goose/orders/pojo/TOrder.java

@@ -0,0 +1,62 @@
+package com.futu.goose.orders.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 订单主表
+ * @TableName t_order
+ */
+@TableName(value ="t_order")
+@Data
+public class TOrder implements Serializable {
+    /**
+     * 订单ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 用户ID
+     */
+    private Long userId;
+
+    /**
+     * 商品总金额
+     */
+    private BigDecimal totalAmount;
+
+    /**
+     * 优惠金额
+     */
+    private BigDecimal discountAmount;
+
+    /**
+     * 实付金额
+     */
+    private BigDecimal payableAmount;
+
+    /**
+     * 优惠券ID
+     */
+    private Long couponId;
+
+    /**
+     * 订单状态
+     */
+    private String status;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+}

+ 51 - 0
src/main/java/com/futu/goose/orders/pojo/TOrderItem.java

@@ -0,0 +1,51 @@
+package com.futu.goose.orders.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import lombok.Data;
+
+/**
+ * 订单明细表
+ * @TableName t_order_item
+ */
+@TableName(value ="t_order_item")
+@Data
+public class TOrderItem implements Serializable {
+    /**
+     * 明细ID
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 订单ID
+     */
+    private Long orderId;
+
+    /**
+     * 商品SKU ID
+     */
+    private Long skuId;
+
+    /**
+     * 商品数量
+     */
+    private Integer quantity;
+
+    /**
+     * 商品单价
+     */
+    private BigDecimal unitPrice;
+
+    /**
+     * 商品小计金额
+     */
+    private BigDecimal totalAmount;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+}

+ 57 - 0
src/main/java/com/futu/goose/orders/pojo/TProduct.java

@@ -0,0 +1,57 @@
+package com.futu.goose.orders.pojo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+import lombok.Data;
+
+/**
+ * 商品表
+ * @TableName t_product
+ */
+@TableName(value ="t_product")
+@Data
+public class TProduct implements Serializable {
+    /**
+     * 商品ID
+     */
+    @TableId
+    private Long id;
+
+    /**
+     * SKU ID
+     */
+    private Long skuId;
+
+    /**
+     * 商品名称
+     */
+    private String name;
+
+    /**
+     * 商品价格
+     */
+    private BigDecimal price;
+
+    /**
+     * 库存
+     */
+    private Integer stock;
+
+    /**
+     * 商品状态
+     */
+    private String status;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+}

+ 15 - 0
src/main/java/com/futu/goose/orders/service/TCouponService.java

@@ -0,0 +1,15 @@
+package com.futu.goose.orders.service;
+
+import com.futu.goose.orders.pojo.TCoupon;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.futu.goose.utils.Result;
+
+/**
+* @author 张大宇
+* @description 针对表【t_coupon(优惠券表)】的数据库操作Service
+* @createDate 2025-05-13 16:26:58
+*/
+public interface TCouponService extends IService<TCoupon> {
+
+    Result addCoupon(TCoupon coupon);
+}

+ 13 - 0
src/main/java/com/futu/goose/orders/service/TOrderItemService.java

@@ -0,0 +1,13 @@
+package com.futu.goose.orders.service;
+
+import com.futu.goose.orders.pojo.TOrderItem;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+* @author 张大宇
+* @description 针对表【t_order_item(订单明细表)】的数据库操作Service
+* @createDate 2025-05-13 16:26:58
+*/
+public interface TOrderItemService extends IService<TOrderItem> {
+
+}

+ 16 - 0
src/main/java/com/futu/goose/orders/service/TOrderService.java

@@ -0,0 +1,16 @@
+package com.futu.goose.orders.service;
+
+import com.futu.goose.orders.dto.OrderDto;
+import com.futu.goose.orders.pojo.TOrder;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.futu.goose.utils.Result;
+
+/**
+* @author 张大宇
+* @description 针对表【t_order(订单主表)】的数据库操作Service
+* @createDate 2025-05-13 16:26:58
+*/
+public interface TOrderService extends IService<TOrder> {
+
+    Result addOrders(OrderDto orderDto);
+}

+ 15 - 0
src/main/java/com/futu/goose/orders/service/TProductService.java

@@ -0,0 +1,15 @@
+package com.futu.goose.orders.service;
+
+import com.futu.goose.orders.pojo.TProduct;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.futu.goose.utils.Result;
+
+/**
+* @author 张大宇
+* @description 针对表【t_product(商品表)】的数据库操作Service
+* @createDate 2025-05-13 16:26:58
+*/
+public interface TProductService extends IService<TProduct> {
+
+    Result addProduct(TProduct product);
+}

+ 32 - 0
src/main/java/com/futu/goose/orders/service/impl/TCouponServiceImpl.java

@@ -0,0 +1,32 @@
+package com.futu.goose.orders.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.futu.goose.orders.pojo.TCoupon;
+import com.futu.goose.orders.service.TCouponService;
+import com.futu.goose.orders.mapper.TCouponMapper;
+import com.futu.goose.utils.Result;
+import com.futu.goose.utils.SnowflakeIdGenerator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+* @author 张大宇
+* @description 针对表【t_coupon(优惠券表)】的数据库操作Service实现
+* @createDate 2025-05-13 16:26:58
+*/
+@Service
+public class TCouponServiceImpl extends ServiceImpl<TCouponMapper, TCoupon>
+    implements TCouponService{
+    @Autowired
+    private TCouponMapper couponMapper;
+    @Override
+    public Result addCoupon(TCoupon coupon) {
+        coupon.setId(SnowflakeIdGenerator.getSnowId());
+        couponMapper.insert(coupon);
+        return new Result(true, "添加成功");
+    }
+}
+
+
+
+

+ 22 - 0
src/main/java/com/futu/goose/orders/service/impl/TOrderItemServiceImpl.java

@@ -0,0 +1,22 @@
+package com.futu.goose.orders.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.futu.goose.orders.pojo.TOrderItem;
+import com.futu.goose.orders.service.TOrderItemService;
+import com.futu.goose.orders.mapper.TOrderItemMapper;
+import org.springframework.stereotype.Service;
+
+/**
+* @author 张大宇
+* @description 针对表【t_order_item(订单明细表)】的数据库操作Service实现
+* @createDate 2025-05-13 16:26:58
+*/
+@Service
+public class TOrderItemServiceImpl extends ServiceImpl<TOrderItemMapper, TOrderItem>
+    implements TOrderItemService{
+
+}
+
+
+
+

+ 201 - 0
src/main/java/com/futu/goose/orders/service/impl/TOrderServiceImpl.java

@@ -0,0 +1,201 @@
+package com.futu.goose.orders.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.futu.goose.orders.dto.OrderDto;
+import com.futu.goose.orders.dto.ProductDto;
+import com.futu.goose.orders.mapper.TCouponMapper;
+import com.futu.goose.orders.mapper.TOrderItemMapper;
+import com.futu.goose.orders.mapper.TProductMapper;
+import com.futu.goose.orders.pojo.TCoupon;
+import com.futu.goose.orders.pojo.TOrder;
+import com.futu.goose.orders.pojo.TOrderItem;
+import com.futu.goose.orders.pojo.TProduct;
+import com.futu.goose.orders.service.TOrderService;
+import com.futu.goose.orders.mapper.TOrderMapper;
+import com.futu.goose.utils.RedisClient;
+import com.futu.goose.utils.Result;
+import com.futu.goose.utils.SnowflakeIdGenerator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * @author 张大宇
+ * @description 针对表【t_order(订单主表)】的数据库操作Service实现
+ * @createDate 2025-05-13 16:26:58
+ */
+@Service
+public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder>
+        implements TOrderService {
+
+    @Autowired
+    private TOrderMapper orderMapper;
+
+    @Autowired
+    private TOrderItemMapper orderItemMapper;
+
+    @Autowired
+    private TProductMapper productMapper;
+
+    @Autowired
+    private TCouponMapper couponMapper;
+
+    @Autowired
+    private RedisClient redisClient;
+
+    @Override
+    public Result addOrders(OrderDto orderDto) {
+        // 输入校验
+        if (orderDto == null) {
+            return new Result(false, "订单信息不能为空");
+        }
+
+        // 创建订单对象
+        TOrder tOrder = new TOrder();
+        tOrder.setId(SnowflakeIdGenerator.getSnowId());
+
+        // 获取用户ID
+        Object uidObj = redisClient.get("uid");
+        Long userId = parseUserId(uidObj);
+        tOrder.setUserId(userId);
+
+        // 设置优惠券ID
+        Long couponId = orderDto.getId();
+        tOrder.setCouponId(couponId);
+
+        // 获取优惠券信息并校验
+        TCoupon tCoupon = null;
+        if (couponId != null) {
+            QueryWrapper<TCoupon> wrapper = new QueryWrapper<>();
+            tCoupon = couponMapper.selectOne(wrapper.lambda().eq(TCoupon::getId, couponId));
+        }
+
+        // 检查优惠券有效性
+        if (tCoupon == null || !"可用".equals(tCoupon.getStatus())) {
+            return new Result(false, "优惠券不可用或不存在");
+        }
+
+        // 计算商品总金额
+        BigDecimal totalAmount = calculateTotalAmount(orderDto.getProductList());
+        if (totalAmount == null || totalAmount.compareTo(BigDecimal.ZERO) <= 0) {
+            return new Result(false, "订单金额不能为零或负数");
+        }
+
+        // 设置订单总金额
+        tOrder.setTotalAmount(totalAmount);
+
+        // 计算优惠金额
+        BigDecimal discountAmount = calculateDiscountAmount(totalAmount, tCoupon);
+        tOrder.setDiscountAmount(discountAmount);
+
+        // 计算应付金额
+        BigDecimal payableAmount = totalAmount.subtract(discountAmount);
+        tOrder.setPayableAmount(payableAmount);
+
+        // 插入订单主表
+        orderMapper.insert(tOrder);
+
+        // 插入订单明细
+        createOrderItems(tOrder.getId(), orderDto.getProductList());
+
+        return new Result(true, "订单创建成功");
+    }
+
+    // 解析用户ID
+    private Long parseUserId(Object uidObj) {
+        if (uidObj == null) {
+            throw new IllegalArgumentException("用户ID不能为空");
+        }
+
+        if (uidObj instanceof Long) {
+            return (Long) uidObj;
+        } else if (uidObj instanceof Integer) {
+            return Long.valueOf((Integer) uidObj);
+        } else if (uidObj instanceof String) {
+            try {
+                return Long.parseLong((String) uidObj);
+            } catch (NumberFormatException e) {
+                throw new IllegalArgumentException("无效的用户ID格式: " + uidObj, e);
+            }
+        } else {
+            throw new IllegalArgumentException("不支持的用户ID类型: " + uidObj.getClass());
+        }
+    }
+
+    // 计算商品总金额
+    private BigDecimal calculateTotalAmount(List<ProductDto> productList) {
+        if (productList == null || productList.isEmpty()) {
+            return null;
+        }
+
+        BigDecimal total = BigDecimal.ZERO;
+
+        for (ProductDto productDto : productList) {
+            if (productDto == null || productDto.getProductId() == null || productDto.getNum() <= 0) {
+                continue; // 跳过无效商品
+            }
+
+            // 查询商品信息
+            QueryWrapper<TProduct> queryWrapper = new QueryWrapper<>();
+            TProduct tProduct = productMapper.selectOne(
+                    queryWrapper.lambda().eq(TProduct::getId, productDto.getProductId()));
+
+            if (tProduct != null && tProduct.getPrice() != null) {
+                // 计算商品小计: 单价 * 数量
+                BigDecimal quantity = new BigDecimal(productDto.getNum());
+                BigDecimal subtotal = tProduct.getPrice().multiply(quantity);
+                total = total.add(subtotal);
+            }
+        }
+
+        return total;
+    }
+
+    // 计算优惠金额
+    private BigDecimal calculateDiscountAmount(BigDecimal totalAmount, TCoupon coupon) {
+        if (totalAmount == null || coupon == null) {
+            return BigDecimal.ZERO;
+        }
+
+        // 判断是否达到优惠门槛
+        if (totalAmount.compareTo(coupon.getThreshold()) >= 0) {
+            return coupon.getAmount();
+        }
+
+        return BigDecimal.ZERO;
+    }
+
+    // 创建订单明细
+    private void createOrderItems(Long orderId, List<ProductDto> productList) {
+        if (orderId == null || productList == null || productList.isEmpty()) {
+            return;
+        }
+
+        for (ProductDto productDto : productList) {
+            if (productDto == null || productDto.getProductId() == null || productDto.getNum() <= 0) {
+                continue; // 跳过无效商品
+            }
+
+            // 查询商品信息
+            QueryWrapper<TProduct> queryWrapper = new QueryWrapper<>();
+            TProduct tProduct = productMapper.selectOne(
+                    queryWrapper.lambda().eq(TProduct::getId, productDto.getProductId()));
+
+            if (tProduct != null) {
+                // 创建订单明细
+                TOrderItem orderItem = new TOrderItem();
+                orderItem.setId(SnowflakeIdGenerator.getSnowId());
+                orderItem.setOrderId(orderId);
+                orderItem.setSkuId(tProduct.getSkuId());
+                orderItem.setUnitPrice(tProduct.getPrice());
+                orderItem.setQuantity(productDto.getNum());
+                orderItem.setTotalAmount(tProduct.getPrice().multiply(new BigDecimal(productDto.getNum())));
+                // 插入订单明细
+                orderItemMapper.insert(orderItem);
+            }
+        }
+    }
+}

+ 32 - 0
src/main/java/com/futu/goose/orders/service/impl/TProductServiceImpl.java

@@ -0,0 +1,32 @@
+package com.futu.goose.orders.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.futu.goose.orders.pojo.TProduct;
+import com.futu.goose.orders.service.TProductService;
+import com.futu.goose.orders.mapper.TProductMapper;
+import com.futu.goose.utils.Result;
+import com.futu.goose.utils.SnowflakeIdGenerator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+* @author 张大宇
+* @description 针对表【t_product(商品表)】的数据库操作Service实现
+* @createDate 2025-05-13 16:26:58
+*/
+@Service
+public class TProductServiceImpl extends ServiceImpl<TProductMapper, TProduct>
+    implements TProductService{
+    @Autowired
+    private TProductMapper tProductMapper;
+    @Override
+    public Result addProduct(TProduct product) {
+        product.setId(SnowflakeIdGenerator.getSnowId());
+        tProductMapper.insert(product);
+        return new Result(true,"添加成功");
+    }
+}
+
+
+
+

+ 0 - 86
src/main/java/com/futu/goose/store/pojo/Shop.java

@@ -163,92 +163,6 @@ public class Shop implements Serializable {
      */
     private Date deletedAt;
 
-    /**
-     * 店铺网站URL
-     */
-    private String shopWebsite;
-
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
-
-    @Override
-    public boolean equals(Object that) {
-        if (this == that) {
-            return true;
-        }
-        if (that == null) {
-            return false;
-        }
-        if (getClass() != that.getClass()) {
-            return false;
-        }
-        Shop other = (Shop) that;
-        return (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
-                && (this.getShopName() == null ? other.getShopName() == null : this.getShopName().equals(other.getShopName()))
-                && (this.getShopLogo() == null ? other.getShopLogo() == null : this.getShopLogo().equals(other.getShopLogo()))
-                && (this.getShopDesc() == null ? other.getShopDesc() == null : this.getShopDesc().equals(other.getShopDesc()))
-                && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
-                && (this.getCategoryId() == null ? other.getCategoryId() == null : this.getCategoryId().equals(other.getCategoryId()))
-                && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
-                && (this.getContactPhone() == null ? other.getContactPhone() == null : this.getContactPhone().equals(other.getContactPhone()))
-                && (this.getContactEmail() == null ? other.getContactEmail() == null : this.getContactEmail().equals(other.getContactEmail()))
-                && (this.getProvince() == null ? other.getProvince() == null : this.getProvince().equals(other.getProvince()))
-                && (this.getCity() == null ? other.getCity() == null : this.getCity().equals(other.getCity()))
-                && (this.getDistrict() == null ? other.getDistrict() == null : this.getDistrict().equals(other.getDistrict()))
-                && (this.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress()))
-                && (this.getLongitude() == null ? other.getLongitude() == null : this.getLongitude().equals(other.getLongitude()))
-                && (this.getLatitude() == null ? other.getLatitude() == null : this.getLatitude().equals(other.getLatitude()))
-                && (this.getBannerImages() == null ? other.getBannerImages() == null : this.getBannerImages().equals(other.getBannerImages()))
-                && (this.getSocialMedia() == null ? other.getSocialMedia() == null : this.getSocialMedia().equals(other.getSocialMedia()))
-                && (this.getOpeningHours() == null ? other.getOpeningHours() == null : this.getOpeningHours().equals(other.getOpeningHours()))
-                && (this.getSeoTitle() == null ? other.getSeoTitle() == null : this.getSeoTitle().equals(other.getSeoTitle()))
-                && (this.getSeoKeywords() == null ? other.getSeoKeywords() == null : this.getSeoKeywords().equals(other.getSeoKeywords()))
-                && (this.getSeoDescription() == null ? other.getSeoDescription() == null : this.getSeoDescription().equals(other.getSeoDescription()))
-                && (this.getRating() == null ? other.getRating() == null : this.getRating().equals(other.getRating()))
-                && (this.getSalesCount() == null ? other.getSalesCount() == null : this.getSalesCount().equals(other.getSalesCount()))
-                && (this.getCourseCount() == null ? other.getCourseCount() == null : this.getCourseCount().equals(other.getCourseCount()))
-                && (this.getFollowerCount() == null ? other.getFollowerCount() == null : this.getFollowerCount().equals(other.getFollowerCount()))
-                && (this.getViewCount() == null ? other.getViewCount() == null : this.getViewCount().equals(other.getViewCount()))
-                && (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
-                && (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()))
-                && (this.getDeletedAt() == null ? other.getDeletedAt() == null : this.getDeletedAt().equals(other.getDeletedAt()))
-                && (this.getShopWebsite() == null ? other.getShopWebsite() == null : this.getShopWebsite().equals(other.getShopWebsite()));
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode());
-        result = prime * result + ((getShopName() == null) ? 0 : getShopName().hashCode());
-        result = prime * result + ((getShopLogo() == null) ? 0 : getShopLogo().hashCode());
-        result = prime * result + ((getShopDesc() == null) ? 0 : getShopDesc().hashCode());
-        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
-        result = prime * result + ((getCategoryId() == null) ? 0 : getCategoryId().hashCode());
-        result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
-        result = prime * result + ((getContactPhone() == null) ? 0 : getContactPhone().hashCode());
-        result = prime * result + ((getContactEmail() == null) ? 0 : getContactEmail().hashCode());
-        result = prime * result + ((getProvince() == null) ? 0 : getProvince().hashCode());
-        result = prime * result + ((getCity() == null) ? 0 : getCity().hashCode());
-        result = prime * result + ((getDistrict() == null) ? 0 : getDistrict().hashCode());
-        result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode());
-        result = prime * result + ((getLongitude() == null) ? 0 : getLongitude().hashCode());
-        result = prime * result + ((getLatitude() == null) ? 0 : getLatitude().hashCode());
-        result = prime * result + ((getBannerImages() == null) ? 0 : getBannerImages().hashCode());
-        result = prime * result + ((getSocialMedia() == null) ? 0 : getSocialMedia().hashCode());
-        result = prime * result + ((getOpeningHours() == null) ? 0 : getOpeningHours().hashCode());
-        result = prime * result + ((getSeoTitle() == null) ? 0 : getSeoTitle().hashCode());
-        result = prime * result + ((getSeoKeywords() == null) ? 0 : getSeoKeywords().hashCode());
-        result = prime * result + ((getSeoDescription() == null) ? 0 : getSeoDescription().hashCode());
-        result = prime * result + ((getRating() == null) ? 0 : getRating().hashCode());
-        result = prime * result + ((getSalesCount() == null) ? 0 : getSalesCount().hashCode());
-        result = prime * result + ((getCourseCount() == null) ? 0 : getCourseCount().hashCode());
-        result = prime * result + ((getFollowerCount() == null) ? 0 : getFollowerCount().hashCode());
-        result = prime * result + ((getViewCount() == null) ? 0 : getViewCount().hashCode());
-        result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
-        result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
-        result = prime * result + ((getDeletedAt() == null) ? 0 : getDeletedAt().hashCode());
-        result = prime * result + ((getShopWebsite() == null) ? 0 : getShopWebsite().hashCode());
-        return result;
-    }
 }

+ 24 - 0
src/main/resources/mapper/TCouponMapper.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.futu.goose.orders.mapper.TCouponMapper">
+
+    <resultMap id="BaseResultMap" type="com.futu.goose.orders.pojo.TCoupon">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="userId" column="user_id" jdbcType="BIGINT"/>
+            <result property="couponCode" column="coupon_code" jdbcType="VARCHAR"/>
+            <result property="type" column="type" jdbcType="VARCHAR"/>
+            <result property="amount" column="amount" jdbcType="DECIMAL"/>
+            <result property="threshold" column="threshold" jdbcType="DECIMAL"/>
+            <result property="status" column="status" jdbcType="VARCHAR"/>
+            <result property="expireTime" column="expire_time" jdbcType="TIMESTAMP"/>
+            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,user_id,coupon_code,
+        type,amount,threshold,
+        status,expire_time,create_time
+    </sql>
+</mapper>

+ 20 - 0
src/main/resources/mapper/TOrderItemMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.futu.goose.orders.mapper.TOrderItemMapper">
+
+    <resultMap id="BaseResultMap" type="com.futu.goose.orders.pojo.TOrderItem">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="orderId" column="order_id" jdbcType="BIGINT"/>
+            <result property="skuId" column="sku_id" jdbcType="BIGINT"/>
+            <result property="quantity" column="quantity" jdbcType="INTEGER"/>
+            <result property="unitPrice" column="unit_price" jdbcType="DECIMAL"/>
+            <result property="totalAmount" column="total_amount" jdbcType="DECIMAL"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,order_id,sku_id,
+        quantity,unit_price,total_amount
+    </sql>
+</mapper>

+ 23 - 0
src/main/resources/mapper/TOrderMapper.xml

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.futu.goose.orders.mapper.TOrderMapper">
+
+    <resultMap id="BaseResultMap" type="com.futu.goose.orders.pojo.TOrder">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="userId" column="user_id" jdbcType="BIGINT"/>
+            <result property="totalAmount" column="total_amount" jdbcType="DECIMAL"/>
+            <result property="discountAmount" column="discount_amount" jdbcType="DECIMAL"/>
+            <result property="payableAmount" column="payable_amount" jdbcType="DECIMAL"/>
+            <result property="couponId" column="coupon_id" jdbcType="BIGINT"/>
+            <result property="status" column="status" jdbcType="VARCHAR"/>
+            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,user_id,total_amount,
+        discount_amount,payable_amount,coupon_id,
+        status,create_time
+    </sql>
+</mapper>

+ 22 - 0
src/main/resources/mapper/TProductMapper.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.futu.goose.orders.mapper.TProductMapper">
+
+    <resultMap id="BaseResultMap" type="com.futu.goose.orders.pojo.TProduct">
+            <id property="id" column="id" jdbcType="BIGINT"/>
+            <result property="skuId" column="sku_id" jdbcType="BIGINT"/>
+            <result property="name" column="name" jdbcType="VARCHAR"/>
+            <result property="price" column="price" jdbcType="DECIMAL"/>
+            <result property="stock" column="stock" jdbcType="INTEGER"/>
+            <result property="status" column="status" jdbcType="VARCHAR"/>
+            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        id,sku_id,name,
+        price,stock,status,
+        create_time
+    </sql>
+</mapper>