Kaynağa Gözat

优化代码

jinshihui 1 gün önce
ebeveyn
işleme
c21bcacaf5

+ 5 - 0
nightFragrance-admin/src/main/java/com/ylx/web/controller/point/UserPointController.java

@@ -32,6 +32,11 @@ public class UserPointController extends BaseController {
     @Resource
     private IPointUserActivityTaskCompletionService pointUserActivityTaskCompletionService;
 
+    /**
+     * 获取当前用户的积分信息
+     * @param cityCode
+     * @return R<UserPointInfoVO>
+     */
     @ApiOperation("获取当前用户的积分信息")
     @GetMapping
     public R<UserPointInfoVO> getUserPointInfo(@RequestParam String cityCode) {

+ 1 - 2
nightFragrance-framework/src/main/java/com/ylx/framework/security/handle/AuthenticationEntryPointImpl.java

@@ -24,8 +24,7 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
     private static final long serialVersionUID = -8970718410437077606L;
 
     @Override
-    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
-            throws IOException {
+    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException {
         int code = HttpStatus.UNAUTHORIZED;
         String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI());
         ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));

+ 3 - 3
nightFragrance-massage/src/main/java/com/ylx/massage/domain/dto/ProductOrderCreateRequest.java

@@ -70,17 +70,17 @@ public class ProductOrderCreateRequest implements Serializable {
     private Integer payType;
 
     /**
-     * 运费(分)
+     * 运费
      */
     private BigDecimal freightAmount;
 
     /**
-     * 总金额(分)
+     * 总金额
      */
     private BigDecimal totalAmount;
 
     /**
-     * 支付金额(分)
+     * 支付金额
      */
     private BigDecimal payAmount;
 

+ 28 - 7
nightFragrance-massage/src/main/java/com/ylx/massage/service/impl/ProductOrderInfoServiceImpl.java

@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ylx.common.constant.HttpStatus;
 import com.ylx.common.constant.MassageConstants;
 import com.ylx.common.core.domain.R;
 import com.ylx.common.core.domain.model.WxLoginUser;
@@ -86,6 +87,11 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String createProductOrder(ProductOrderCreateRequest request) {
+        // 当前登录用户信息
+        WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
+        // 设置用户ID
+        request.setOpenId(wxLoginUser.getCOpenid());
+
         // 1. 参数校验
         validateRequest(request);
 
@@ -124,16 +130,13 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
         if (request == null) {
             throw new ServiceException("订单请求不能为空");
         }
-        if (request.getOpenId() == null || request.getOpenId().trim().isEmpty()) {
-            throw new ServiceException("用户ID不能为空");
-        }
-        if (request.getUserName() == null) {
+        if (StringUtils.isBlank(request.getUserName())) {
             throw new ServiceException("用户姓名不能为空");
         }
-        if (request.getUserPhone() == null) {
+        if (StringUtils.isBlank(request.getUserPhone())) {
             throw new ServiceException("用户电话不能为空");
         }
-        if (request.getUserAddress() == null) {
+        if (StringUtils.isBlank(request.getUserAddress())) {
             throw new ServiceException("用户地址不能为空");
         }
         if (request.getProductId() == null) {
@@ -148,6 +151,18 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
         if (request.getSkuId() == null) {
             throw new ServiceException("SKU ID不能为空");
         }
+
+        // 校验SKU是否存在
+        ProductSku sku = productSkuMapper.selectById(request.getSkuId());
+        if (sku == null) {
+            throw new ServiceException("skuId不存在");
+        }
+        //校验skuId是否正确
+        if (!sku.getProductId().equals(request.getProductId())) {
+            throw new ServiceException("skuId不正确");
+        }
+
+        // 校验购买数量是否大于0
         if (request.getQuantity() == null || request.getQuantity() <= 0) {
             throw new ServiceException("购买数量必须大于0");
         }
@@ -497,8 +512,14 @@ public class ProductOrderInfoServiceImpl extends ServiceImpl<ProductOrderInfoMap
      */
     @Override
     public R<?> cancelOrder(ProductOrderCancelRequest request) {
+        // 当前登录用户信息
+        WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
+        if (wxLoginUser == null) {
+            throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
+        }
+
         String orderNo = request.getOrderNo();
-        String openId = request.getOpenId();
+        String openId = wxLoginUser.getCOpenid();
         String cancelReason = request.getCancelReason();
         log.info("取消商品订单,订单号:{},openId:{},取消原因:{}", orderNo, openId, cancelReason);
 

+ 15 - 0
nightFragrance-massage/src/main/java/com/ylx/point/domain/vo/UserPointInfoVO.java

@@ -10,18 +10,33 @@ import java.math.BigDecimal;
 @ApiModel("用户积分信息")
 public class UserPointInfoVO {
 
+    /**
+     * 总积分
+     */
     @ApiModelProperty("总积分")
     private BigDecimal totalPoints;
 
+    /**
+     * 本月即将到期积分
+     */
     @ApiModelProperty("本月即将到期积分")
     private BigDecimal expirePoints;
 
+    /**
+     * 本月新获取积分
+     */
     @ApiModelProperty("本月新获取积分")
     private BigDecimal earnedPoints;
 
+    /**
+     * 已完成的任务
+     */
     @ApiModelProperty("已完成的任务")
     private Integer completedTask;
 
+    /**
+     * 待完成任务
+     */
     @ApiModelProperty("待完成任务")
     private Integer pendingTasks;