Przeglądaj źródła

Merge remote-tracking branch 'origin/dev' into dev

jinshihui 1 tydzień temu
rodzic
commit
02c6b75d25

+ 2 - 6
nightFragrance-admin/src/main/java/com/ylx/web/controller/point/UserPointController.java

@@ -17,12 +17,14 @@ import com.ylx.point.service.IPointUserActivityTaskCompletionService;
 import com.ylx.point.service.IPointUserLogService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.List;
 
+@PreAuthorize("@customerAuth.isCustomer()")
 @RestController
 @RequestMapping("/user/point")
 @Api(tags = {"用户积分"})
@@ -37,12 +39,6 @@ public class UserPointController extends BaseController {
     @Resource
     private IPointAccountService pointAccountService;
 
-    /**
-     * 获取当前用户的积分信息
-     *
-     * @param cityCode
-     * @return R<UserPointInfoVO>
-     */
     @ApiOperation("获取当前用户的积分信息")
     @GetMapping
     public R<UserPointInfoVO> getUserPointInfo(@RequestParam String cityCode) {

+ 20 - 0
nightFragrance-common/src/main/java/com/ylx/common/component/CustomerAuth.java

@@ -0,0 +1,20 @@
+package com.ylx.common.component;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.ylx.common.utils.SecurityUtils;
+import org.springframework.stereotype.Component;
+
+/**
+ * 自定义客户权限校验类
+ */
+@Component("customerAuth")
+public class CustomerAuth {
+
+    private static final Integer CUSTOMER = 0;
+
+    public boolean isCustomer() {
+        Integer role = SecurityUtils.getWxLoginUser().getRole();
+        return ObjectUtil.equals(CUSTOMER, role);
+    }
+
+}

+ 20 - 0
nightFragrance-common/src/main/java/com/ylx/common/component/MerchantAuth.java

@@ -0,0 +1,20 @@
+package com.ylx.common.component;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.ylx.common.utils.SecurityUtils;
+import org.springframework.stereotype.Component;
+
+/**
+ * 自定义商家权限校验类
+ */
+@Component("merchantAuth")
+public class MerchantAuth {
+
+    private static final Integer MERCHANT = 1;
+
+    public boolean isMerchant() {
+        Integer role = SecurityUtils.getWxLoginUser().getRole();
+        return ObjectUtil.equals(MERCHANT, role);
+    }
+
+}

+ 9 - 4
nightFragrance-massage/src/main/java/com/ylx/point/service/impl/PointAccountServiceImpl.java

@@ -56,6 +56,8 @@ public class PointAccountServiceImpl implements IPointAccountService {
     @Resource
     private TWxUserService wxUserService;
 
+    private static final Integer ZERO_BALANCE = 0;
+
     /**
      * 增加用户积分(无账户表版本)
      */
@@ -283,6 +285,12 @@ public class PointAccountServiceImpl implements IPointAccountService {
             // 1. 获取当前余额 (变动前)
             Integer currentBalance = getBalance(openId);
 
+            // 计算变动后余额 (快照)
+            Integer newBalance = currentBalance + points;
+            if (ObjectUtil.equals(ZERO_BALANCE, newBalance)) {
+                return;
+            }
+
             // 2. 写入积分流水表 (point_user_log)
             PointUserLog log = new PointUserLog();
             log.setOpenId(openId);
@@ -292,9 +300,6 @@ public class PointAccountServiceImpl implements IPointAccountService {
             log.setIsExpired(0);
             log.setActivityName(TaskNameEnum.LOCAL_LIVE_LOTTERY.getInfo());
             log.setMonth(DateUtil.format(new Date(), "yyyyMM"));
-
-            // 计算变动后余额 (快照)
-            Integer newBalance = currentBalance + points;
             log.setBalanceAfter(newBalance);
 
             boolean saveSuccess = pointUserLogService.save(log);
@@ -413,7 +418,7 @@ public class PointAccountServiceImpl implements IPointAccountService {
 
             log.info("成功获取广誉源领取积分,数量: {}", points);
 
-            return points;
+            return ObjectUtil.defaultIfNull(points, 0);
 
         } catch (ServiceException e) {
             // 透传业务异常,不要重复包装