一些问题的修复
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.config;
|
||||
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.utils.JwtUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -13,6 +15,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
public class AuthInterceptor implements HandlerInterceptor {
|
||||
|
||||
private final JwtUtil jwtUtil;
|
||||
private final UserMapper userMapper;
|
||||
|
||||
private static final String AUTHORIZATION_HEADER = "Authorization";
|
||||
private static final String BEARER_PREFIX = "Bearer ";
|
||||
@@ -40,17 +43,37 @@ public class AuthInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
if (!jwtUtil.isAccessToken(token)) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":401,\"message\":\"Token类型错误\"}");
|
||||
writeJsonResponse(response, HttpServletResponse.SC_UNAUTHORIZED, "Token类型错误");
|
||||
return false;
|
||||
}
|
||||
|
||||
Long userId = jwtUtil.getUserIdFromToken(token);
|
||||
String account = jwtUtil.getAccountFromToken(token);
|
||||
UserDO currentUser = userMapper.selectById(userId);
|
||||
if (currentUser == null || Integer.valueOf(1).equals(currentUser.getIsDelete())) {
|
||||
writeJsonResponse(response, HttpServletResponse.SC_UNAUTHORIZED, "用户不存在或已失效");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isAdminPath(path) && (currentUser.getType() == null || currentUser.getType() < 2)) {
|
||||
writeJsonResponse(response, HttpServletResponse.SC_FORBIDDEN, "无后台访问权限");
|
||||
return false;
|
||||
}
|
||||
|
||||
request.setAttribute("userId", userId);
|
||||
request.setAttribute("account", account);
|
||||
request.setAttribute("userType", currentUser.getType());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isAdminPath(String path) {
|
||||
return path.startsWith("/admin/") || path.startsWith("/order/admin/");
|
||||
}
|
||||
|
||||
private void writeJsonResponse(HttpServletResponse response, int status, String message) throws Exception {
|
||||
response.setStatus(status);
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write("{\"code\":" + status + ",\"message\":\"" + message + "\"}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
"/user/refresh-token",
|
||||
"/user/send-verification-code",
|
||||
"/user/phone-login",
|
||||
"/user/reset-password-by-phone",
|
||||
"/user/get/account/**",
|
||||
"/shop/list/simple",
|
||||
"/product/**",
|
||||
"/tag/**",
|
||||
"/file/**",
|
||||
"/admin/auth/login",
|
||||
"/admin/object-storage-file/upload",
|
||||
"/admin/auth/refresh",
|
||||
"/error",
|
||||
"/health/**"
|
||||
);
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/balance-change-detail")
|
||||
@RequestMapping({"/balance-change-detail", "/api/balance-change-detail"})
|
||||
@RequiredArgsConstructor
|
||||
public class BalanceChangeDetailController {
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/balance")
|
||||
@RequestMapping({"/balance", "/api/balance"})
|
||||
@RequiredArgsConstructor
|
||||
public class BalanceController {
|
||||
|
||||
|
||||
@@ -31,6 +31,13 @@ public class CartController {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PostMapping("/batch-remove")
|
||||
public Result<Void> batchRemoveFromCart(@RequestBody List<Long> cartItemIds, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
cartService.batchRemoveFromCart(userId, cartItemIds);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public Result<Void> updateCartQuantity(@RequestBody CartDTO cartDTO, HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/comment")
|
||||
@RequestMapping({"/comment", "/api/comment"})
|
||||
@RequiredArgsConstructor
|
||||
public class CommentController {
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/effect-diagram")
|
||||
@RequestMapping({"/effect-diagram", "/api/effect-diagram"})
|
||||
@RequiredArgsConstructor
|
||||
public class EffectDiagramController {
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/login-identity")
|
||||
@RequestMapping({"/login-identity", "/api/login-identity"})
|
||||
@RequiredArgsConstructor
|
||||
public class LoginIdentityController {
|
||||
|
||||
|
||||
@@ -59,4 +59,12 @@ public class OrderController {
|
||||
orderService.processOrder(orderId, status);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
// 美甲师查看自己的订单
|
||||
@GetMapping("/artist/list")
|
||||
public Result<List<OrderVO>> getArtistOrders(HttpServletRequest request) {
|
||||
Long userId = (Long) request.getAttribute("userId");
|
||||
List<OrderVO> orderList = orderService.getOrdersByArtistId(userId);
|
||||
return Result.success(orderList);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
* @date 2026-02-25
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/permission")
|
||||
@RequestMapping({"/permission", "/api/permission"})
|
||||
@RequiredArgsConstructor
|
||||
public class PermissionController {
|
||||
|
||||
|
||||
+13
-9
@@ -1,15 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.controller;
|
||||
|
||||
import com.xiaowang.yuminailcore.common.Result;
|
||||
import com.xiaowang.yuminailcore.dto.BindEmailRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PhoneLoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RefreshTokenRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.SendVerificationCodeRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UpdatePhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.dto.*;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
import com.xiaowang.yuminailcore.mapper.UserMapper;
|
||||
import com.xiaowang.yuminailcore.vo.LoginResponseVO;
|
||||
@@ -190,6 +182,18 @@ public class UserController {
|
||||
return Result.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过手机号验证码重置密码
|
||||
*
|
||||
* @param resetPasswordRequestDTO 重置密码请求DTO
|
||||
* @return 是否重置成功
|
||||
*/
|
||||
@PostMapping("/reset-password-by-phone")
|
||||
public Result<Boolean> resetPasswordByPhone(@RequestBody ResetPasswordRequestDTO resetPasswordRequestDTO) {
|
||||
boolean success = userService.resetPasswordByPhone(resetPasswordRequestDTO);
|
||||
return Result.success(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/vip-benefit")
|
||||
@RequestMapping({"/vip-benefit", "/api/vip-benefit"})
|
||||
@RequiredArgsConstructor
|
||||
public class VipBenefitController {
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/vip-info")
|
||||
@RequestMapping({"/vip-info", "/api/vip-info"})
|
||||
@RequiredArgsConstructor
|
||||
public class VipInfoController {
|
||||
|
||||
|
||||
@@ -2,9 +2,23 @@ package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 绑定邮箱请求 DTO
|
||||
* 用于用户绑定邮箱账号
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
public class BindEmailRequestDTO {
|
||||
|
||||
/**
|
||||
* 邮箱地址
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String code;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,23 @@ package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 绑定手机号请求 DTO
|
||||
* 用于用户绑定手机号
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
public class BindPhoneRequestDTO {
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String code;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,23 @@ package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 购物车 DTO
|
||||
* 用于购物车商品信息的传输
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
public class CartDTO {
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
}
|
||||
@@ -1,21 +1,36 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 登录请求 DTO
|
||||
* 用于用户账号密码登录
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-14
|
||||
*/
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class LoginRequestDTO {
|
||||
|
||||
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
private String account;
|
||||
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
|
||||
/**
|
||||
* 记住我标志
|
||||
*/
|
||||
private Boolean rememberMe;
|
||||
|
||||
|
||||
/**
|
||||
* 店铺ID
|
||||
*/
|
||||
private Long shopId;
|
||||
}
|
||||
@@ -2,7 +2,25 @@ package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单 DTO
|
||||
* 用于订单创建请求
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
public class OrderDTO {
|
||||
|
||||
/**
|
||||
* 优惠券ID
|
||||
*/
|
||||
private Long couponId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单商品列表
|
||||
*/
|
||||
private List<OrderItemDTO> items;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 订单商品项 DTO
|
||||
* 用于订单中的单个商品信息
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
public class OrderItemDTO {
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 商品数量
|
||||
*/
|
||||
private Integer quantity;
|
||||
|
||||
/**
|
||||
* 美甲师ID
|
||||
*/
|
||||
private Long artistId;
|
||||
}
|
||||
+5
-1
@@ -4,12 +4,16 @@ import lombok.Data;
|
||||
|
||||
/**
|
||||
* 刷新Token请求 DTO
|
||||
* 用于刷新访问令牌
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-02-14
|
||||
*/
|
||||
@Data
|
||||
public class RefreshTokenRequestDTO {
|
||||
|
||||
|
||||
/**
|
||||
* 刷新令牌
|
||||
*/
|
||||
private String refreshToken;
|
||||
}
|
||||
@@ -2,9 +2,28 @@ package com.xiaowang.yuminailcore.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 更换手机号请求 DTO
|
||||
* 用于用户更换绑定的手机号
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
public class UpdatePhoneRequestDTO {
|
||||
|
||||
/**
|
||||
* 原手机号
|
||||
*/
|
||||
private String oldPhone;
|
||||
|
||||
/**
|
||||
* 新手机号
|
||||
*/
|
||||
private String newPhone;
|
||||
|
||||
/**
|
||||
* 验证码
|
||||
*/
|
||||
private String verificationCode;
|
||||
}
|
||||
@@ -3,10 +3,33 @@ package com.xiaowang.yuminailcore.dto;
|
||||
import com.xiaowang.yuminailcore.vo.ProductVO;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 收藏夹 DTO
|
||||
* 用于收藏夹商品信息的传输
|
||||
*
|
||||
* @author xiaowang
|
||||
* @date 2026-03-12
|
||||
*/
|
||||
@Data
|
||||
public class WishlistDTO {
|
||||
|
||||
/**
|
||||
* 收藏记录ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Long productId;
|
||||
|
||||
/**
|
||||
* 商品详细信息
|
||||
*/
|
||||
private ProductVO product;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.time.LocalDateTime;
|
||||
public class OrderDO extends BaseEntity {
|
||||
private String orderNo;
|
||||
private Long userId;
|
||||
private Long shopId;
|
||||
private BigDecimal totalAmount;
|
||||
private BigDecimal actualAmount;
|
||||
private Long couponId;
|
||||
|
||||
@@ -13,6 +13,7 @@ public class OrderItemDO extends BaseEntity {
|
||||
private Long productId;
|
||||
private Integer quantity;
|
||||
private BigDecimal price;
|
||||
private Long artistId;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Integer isDelete;
|
||||
|
||||
@@ -5,7 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
@@ -15,8 +16,9 @@ import lombok.EqualsAndHashCode;
|
||||
* @author xiaowang
|
||||
* @date 2026-02-13
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_user")
|
||||
public class UserDO extends BaseEntity {
|
||||
|
||||
|
||||
@@ -15,4 +15,10 @@ public interface OrderMapper extends BaseMapper<OrderDO> {
|
||||
|
||||
@Select("SELECT * FROM t_order WHERE order_no = #{orderNo}")
|
||||
OrderDO selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
|
||||
@Select("SELECT DISTINCT o.* FROM t_order o " +
|
||||
"INNER JOIN t_order_item oi ON o.id = oi.order_id " +
|
||||
"WHERE oi.artist_id = #{artistId} AND o.is_delete = 0 " +
|
||||
"ORDER BY o.create_time DESC")
|
||||
List<OrderDO> selectByArtistId(@Param("artistId") Long artistId);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import java.util.List;
|
||||
public interface CartService {
|
||||
void addToCart(Long userId, CartDTO cartDTO);
|
||||
void removeFromCart(Long userId, Long productId);
|
||||
void batchRemoveFromCart(Long userId, List<Long> cartItemIds);
|
||||
void updateCartQuantity(Long userId, CartDTO cartDTO);
|
||||
List<CartVO> getCartList(Long userId);
|
||||
void clearCart(Long userId);
|
||||
|
||||
@@ -12,4 +12,5 @@ public interface OrderService {
|
||||
void cancelOrder(Long orderId, Long userId);
|
||||
void processOrder(Long orderId, Integer status);
|
||||
List<OrderVO> getAllOrders();
|
||||
List<OrderVO> getOrdersByArtistId(Long artistId);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.xiaowang.yuminailcore.dto.BindPhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.LoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.PhoneLoginRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.RegisterRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.ResetPasswordRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UpdatePhoneRequestDTO;
|
||||
import com.xiaowang.yuminailcore.dto.UserDTO;
|
||||
import com.xiaowang.yuminailcore.entity.UserDO;
|
||||
@@ -52,6 +53,8 @@ public interface UserService extends IService<UserDO> {
|
||||
boolean bindEmail(Long userId, BindEmailRequestDTO bindEmailRequestDTO);
|
||||
|
||||
boolean resetPassword(Long targetUserId, Long currentUserId);
|
||||
|
||||
boolean resetPasswordByPhone(ResetPasswordRequestDTO resetPasswordRequestDTO);
|
||||
|
||||
PageResultVO<UserVO> pageUsers(Integer page, Integer size, String keyword, Long shopId, Integer type);
|
||||
|
||||
|
||||
+13
@@ -61,6 +61,19 @@ public class CartServiceImpl implements CartService {
|
||||
cartMapper.delete(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void batchRemoveFromCart(Long userId, List<Long> cartItemIds) {
|
||||
if (cartItemIds == null || cartItemIds.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QueryWrapper<CartDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("user_id", userId)
|
||||
.in("id", cartItemIds)
|
||||
.eq("is_delete", 0);
|
||||
cartMapper.delete(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateCartQuantity(Long userId, CartDTO cartDTO) {
|
||||
|
||||
+87
-22
@@ -2,6 +2,7 @@ package com.xiaowang.yuminailcore.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.xiaowang.yuminailcore.dto.OrderDTO;
|
||||
import com.xiaowang.yuminailcore.dto.OrderItemDTO;
|
||||
import com.xiaowang.yuminailcore.entity.*;
|
||||
import com.xiaowang.yuminailcore.mapper.*;
|
||||
import com.xiaowang.yuminailcore.service.OrderService;
|
||||
@@ -38,38 +39,79 @@ public class OrderServiceImpl implements OrderService {
|
||||
@Resource
|
||||
private UserCouponMapper userCouponMapper;
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public OrderVO createOrder(Long userId, OrderDTO orderDTO) {
|
||||
// 获取购物车商品
|
||||
List<CartDO> cartList = cartMapper.selectByUserId(userId);
|
||||
if (cartList.isEmpty()) {
|
||||
throw new RuntimeException("购物车为空");
|
||||
// 获取订单项列表
|
||||
List<OrderItemDTO> orderItemDTOs = orderDTO.getItems();
|
||||
if (orderItemDTOs == null || orderItemDTOs.isEmpty()) {
|
||||
throw new RuntimeException("订单项不能为空");
|
||||
}
|
||||
|
||||
// 计算总金额
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
List<OrderItemDO> orderItems = new ArrayList<>();
|
||||
Long shopId = null;
|
||||
|
||||
for (CartDO cart : cartList) {
|
||||
if (cart.getIsDelete() == 0) {
|
||||
ProductDO product = productMapper.selectById(cart.getProductId());
|
||||
if (product != null && product.getIsDelete() == 0) {
|
||||
BigDecimal itemTotal = product.getPrice().multiply(new BigDecimal(cart.getQuantity()));
|
||||
totalAmount = totalAmount.add(itemTotal);
|
||||
|
||||
// 创建订单商品
|
||||
OrderItemDO orderItem = new OrderItemDO();
|
||||
orderItem.setProductId(product.getId());
|
||||
orderItem.setQuantity(cart.getQuantity());
|
||||
orderItem.setPrice(product.getPrice());
|
||||
orderItems.add(orderItem);
|
||||
}
|
||||
for (OrderItemDTO orderItemDTO : orderItemDTOs) {
|
||||
ProductDO product = productMapper.selectById(orderItemDTO.getProductId());
|
||||
if (product == null || product.getIsDelete() == 1) {
|
||||
throw new RuntimeException("商品不存在或已下架");
|
||||
}
|
||||
|
||||
// 验证美甲师
|
||||
if (orderItemDTO.getArtistId() != null) {
|
||||
UserDO artist = userMapper.selectById(orderItemDTO.getArtistId());
|
||||
if (artist == null || artist.getIsDelete() == 1) {
|
||||
throw new RuntimeException("美甲师不存在或已删除");
|
||||
}
|
||||
if (artist.getType() != 3) {
|
||||
throw new RuntimeException("指定的用户不是美甲师");
|
||||
}
|
||||
if (artist.getStatus() == 0) {
|
||||
throw new RuntimeException("美甲师已被禁用");
|
||||
}
|
||||
|
||||
// 验证商品是否可以被该美甲师预约
|
||||
if (product.getBookableArtists() != null && !product.getBookableArtists().isEmpty()) {
|
||||
String[] artistIds = product.getBookableArtists().split(",");
|
||||
boolean isBookable = false;
|
||||
for (String artistId : artistIds) {
|
||||
if (artistId.trim().equals(orderItemDTO.getArtistId().toString())) {
|
||||
isBookable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isBookable) {
|
||||
throw new RuntimeException("该美甲师无法预约此商品");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("请为每个商品选择美甲师");
|
||||
}
|
||||
|
||||
// 设置店铺ID(从第一个商品获取)
|
||||
if (shopId == null) {
|
||||
shopId = product.getShopId();
|
||||
}
|
||||
|
||||
BigDecimal itemTotal = product.getPrice().multiply(new BigDecimal(orderItemDTO.getQuantity()));
|
||||
totalAmount = totalAmount.add(itemTotal);
|
||||
|
||||
// 创建订单商品
|
||||
OrderItemDO orderItem = new OrderItemDO();
|
||||
orderItem.setProductId(product.getId());
|
||||
orderItem.setQuantity(orderItemDTO.getQuantity());
|
||||
orderItem.setPrice(product.getPrice());
|
||||
orderItem.setArtistId(orderItemDTO.getArtistId());
|
||||
orderItems.add(orderItem);
|
||||
}
|
||||
|
||||
if (totalAmount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
throw new RuntimeException("购物车商品无效");
|
||||
throw new RuntimeException("订单金额无效");
|
||||
}
|
||||
|
||||
// 处理优惠券
|
||||
@@ -117,6 +159,7 @@ public class OrderServiceImpl implements OrderService {
|
||||
OrderDO order = new OrderDO();
|
||||
order.setOrderNo(orderNo);
|
||||
order.setUserId(userId);
|
||||
order.setShopId(shopId);
|
||||
order.setTotalAmount(totalAmount);
|
||||
order.setActualAmount(actualAmount);
|
||||
order.setCouponId(couponId);
|
||||
@@ -131,9 +174,6 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderItemMapper.insert(item);
|
||||
}
|
||||
|
||||
// 清空购物车
|
||||
cartMapper.delete(new QueryWrapper<CartDO>().eq("user_id", userId).eq("is_delete", 0));
|
||||
|
||||
// 构建返回对象
|
||||
return buildOrderVO(order);
|
||||
}
|
||||
@@ -258,10 +298,24 @@ public class OrderServiceImpl implements OrderService {
|
||||
return orderVOList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderVO> getOrdersByArtistId(Long artistId) {
|
||||
List<OrderDO> orderList = orderMapper.selectByArtistId(artistId);
|
||||
List<OrderVO> orderVOList = new ArrayList<>();
|
||||
|
||||
for (OrderDO order : orderList) {
|
||||
orderVOList.add(buildOrderVO(order));
|
||||
}
|
||||
|
||||
return orderVOList;
|
||||
}
|
||||
|
||||
private OrderVO buildOrderVO(OrderDO order) {
|
||||
OrderVO orderVO = new OrderVO();
|
||||
orderVO.setId(order.getId());
|
||||
orderVO.setOrderNo(order.getOrderNo());
|
||||
orderVO.setUserId(order.getUserId());
|
||||
orderVO.setShopId(order.getShopId());
|
||||
orderVO.setTotalAmount(order.getTotalAmount());
|
||||
orderVO.setActualAmount(order.getActualAmount());
|
||||
orderVO.setCouponId(order.getCouponId());
|
||||
@@ -311,6 +365,17 @@ public class OrderServiceImpl implements OrderService {
|
||||
itemVO.setQuantity(item.getQuantity());
|
||||
itemVO.setPrice(item.getPrice());
|
||||
itemVO.setTotalPrice(item.getPrice().multiply(new BigDecimal(item.getQuantity())));
|
||||
|
||||
// 设置美甲师信息
|
||||
if (item.getArtistId() != null) {
|
||||
itemVO.setArtistId(item.getArtistId());
|
||||
UserDO artist = userMapper.selectById(item.getArtistId());
|
||||
if (artist != null) {
|
||||
itemVO.setArtistName(artist.getNickname());
|
||||
itemVO.setArtistAvatar(artist.getAvatar());
|
||||
}
|
||||
}
|
||||
|
||||
orderItemVOs.add(itemVO);
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -794,4 +794,32 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resetPasswordByPhone(ResetPasswordRequestDTO resetPasswordRequestDTO) {
|
||||
String phone = resetPasswordRequestDTO.getPhone();
|
||||
String verificationCode = resetPasswordRequestDTO.getVerificationCode();
|
||||
String newPassword = resetPasswordRequestDTO.getNewPassword();
|
||||
|
||||
// 验证验证码
|
||||
String redisKey = "verification_code:" + phone;
|
||||
String storedCode = redisTemplate.opsForValue().get(redisKey);
|
||||
if (storedCode == null || !storedCode.equals(verificationCode)) {
|
||||
throw new RuntimeException("验证码错误");
|
||||
}
|
||||
|
||||
// 根据手机号查找用户
|
||||
LambdaQueryWrapper<UserDO> wrapper = Wrappers.lambdaQuery(UserDO.class);
|
||||
wrapper.eq(UserDO::getPhone, phone);
|
||||
UserDO userDO = userMapper.selectOne(wrapper);
|
||||
|
||||
if (userDO == null) {
|
||||
throw new RuntimeException("未绑定手机号,请联系店员");
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
userDO.setPassword(passwordEncoder.encode(newPassword));
|
||||
userDO.setUpdateTime(LocalDateTime.now());
|
||||
return userMapper.updateById(userDO) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,7 @@ public class OrderItemVO {
|
||||
private Integer quantity;
|
||||
private BigDecimal price;
|
||||
private BigDecimal totalPrice;
|
||||
private Long artistId;
|
||||
private String artistName;
|
||||
private String artistAvatar;
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import java.util.List;
|
||||
public class OrderVO {
|
||||
private Long id;
|
||||
private String orderNo;
|
||||
private Long userId;
|
||||
private Long shopId;
|
||||
private BigDecimal totalAmount;
|
||||
private BigDecimal actualAmount;
|
||||
private Long couponId;
|
||||
|
||||
@@ -655,4 +655,7 @@ CREATE TABLE t_product_like (
|
||||
) COMMENT '商品点赞记录表';
|
||||
|
||||
CREATE INDEX idx_user_id_like ON t_product_like (user_id) COMMENT '按用户查询点赞的索引';
|
||||
CREATE INDEX idx_product_id_like ON t_product_like (product_id) COMMENT '按商品查询点赞的索引';
|
||||
CREATE INDEX idx_product_id_like ON t_product_like (product_id) COMMENT '按商品查询点赞的索引';
|
||||
|
||||
|
||||
ALTER TABLE t_order_item ADD COLUMN artist_id BIGINT UNSIGNED DEFAULT NULL COMMENT '关联美甲师ID' AFTER price;
|
||||
Reference in New Issue
Block a user