Browse Source

Merge branch 'dev'

licailing 3 years ago
parent
commit
368e0d1e38

+ 1 - 1
src/main/java/com/izouma/nineth/domain/UserProperty.java

@@ -8,7 +8,7 @@ import org.springframework.data.redis.core.RedisHash;
 
 import javax.persistence.Id;
 
-@RedisHash(value = "UserProperty", timeToLive = 86400L)
+@RedisHash(value = "UserProperty")
 @Data
 @AllArgsConstructor
 @NoArgsConstructor

+ 3 - 1
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -178,7 +178,9 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
 
     List<User> findAllByCollectionIdAndCollectionInvitor(Long collectionId, Long collectionInvitor);
 
-    int countAllByCollectionIdAndCollectionInvitor(Long collectionId, Long collectionInvitor);
+    List<User> findAllByCollectionIdAndCollectionInvitorAndSettleAccountIdIsNotNull(Long collectionId, Long collectionInvitor);
+
+    int countAllByCollectionIdAndCollectionInvitorAndSettleAccountIdIsNotNull(Long collectionId, Long collectionInvitor);
 
     long countAllByDelFalse();
 

+ 15 - 15
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -386,11 +386,11 @@ public class OrderService {
                 notifyOrder(order.getId(), PayMethod.WEIXIN, null);
             }
 
-            if (usePoint > 0) {
-                // 扣除积分
-                userRepo.addVipPoint(userId, -usePoint);
-                cacheService.clearUserMy(userId);
-            }
+//            if (usePoint > 0) {
+//                // 扣除积分
+//                userRepo.addVipPoint(userId, -usePoint);
+//                cacheService.clearUserMy(userId);
+//            }
 
             if (ObjectUtils.isNotEmpty(showroomId)) {
                 //通过展厅的购买数量
@@ -407,16 +407,16 @@ public class OrderService {
             return order;
         } catch (Exception e) {
             collectionService.increaseStock(collectionId, qty);
-            if (usePoint > 0) {
-                // 扣除积分
-                userRepo.addVipPoint(userId, usePoint);
-                cacheService.clearUserMy(userId);
-                log.info("订单失败加积分用户ID:{}, 积分:{}", userId, usePoint);
-            }
-            if (vip) {
-                collectionService.decreaseQuota(collectionId, 1);
-                log.info("订单失败加藏品额度CollectionId:{}", collectionId);
-            }
+//            if (usePoint > 0) {
+//                // 扣除积分
+//                userRepo.addVipPoint(userId, usePoint);
+//                cacheService.clearUserMy(userId);
+//                log.info("订单失败加积分用户ID:{}, 积分:{}", userId, usePoint);
+//            }
+//            if (vip) {
+//                collectionService.decreaseQuota(collectionId, 1);
+//                log.info("订单失败加藏品额度CollectionId:{}", collectionId);
+//            }
             throw e;
         }
     }

+ 3 - 17
src/main/java/com/izouma/nineth/service/ShowroomService.java

@@ -289,24 +289,10 @@ public class ShowroomService {
 
     public String getStatus(Collection collection) {
         boolean salable = collection.isSalable();
-        if (collection.getSaleTime() != null) {
-            if (collection.getSaleTime().isAfter(LocalDateTime.now())) {
-                return "仅展示";
-            }
-        }
-        if (!salable) {
-            return "仅展示";
-        }
-        if (collection.getSoldOut() > 1) {
-            return "寄售中";
-        }
-        if (collection.isNoSoldOut()) {
-            return "仅展示";
-        }
-        if (collection.getSoldOut() != 1 & collection.getStock() == 0) {
-            return "仅展示";
+        if (salable) {
+            return "售卖中";
         }
-        return "寄售中";
+        return "仅展示";
     }
 
     public String getStatusById(Long collectionId) {

+ 3 - 0
src/main/java/com/izouma/nineth/service/UserBankCardService.java

@@ -70,6 +70,9 @@ public class UserBankCardService {
         if (user != null) {
             user.setSettleAccountId(request.getBindCardId());
             userService.save(user);
+            log.info("绑卡成功,加积分{}", user.getId());
+            //加积分加限购
+            userService.savePoint(user);
         }
         userBalanceRepo.unlock(Long.parseLong(request.getUserId()));
     }

+ 52 - 0
src/main/java/com/izouma/nineth/service/UserService.java

@@ -118,6 +118,7 @@ public class UserService {
     private ShowCollectionRepo            showCollectionRepo;
     private ShowroomService               showroomService;
     private NewsLikeRepo                  newsLikeRepo;
+    private UserPropertyRepo              userPropertyRepo;
 
     public User update(User user) {
         if (!SecurityUtils.hasRole(AuthorityName.ROLE_ADMIN)) {
@@ -1169,4 +1170,55 @@ public class UserService {
         }
 
     }
+
+    public void savePoint(User user) {
+        //给积分
+        Long invitor = user.getCollectionInvitor();
+        if (ObjectUtils.isEmpty(user.getCollectionId()) || ObjectUtils.isEmpty(invitor)) {
+            return;
+        }
+        Collection collection = collectionRepo.findById(user.getCollectionId()).orElse(null);
+        if (collection == null) {
+            return;
+        }
+        if (user.getVipPoint() < 1) {
+            //有效新用户1个限购
+            user.setVipPoint(100);
+            userRepo.save(user);
+            cacheService.clearUserMy(user.getId());
+            cacheService.clearUser(user.getId());
+        }
+
+        //指标数量
+        int assignment = collection.getAssignment();
+        if (assignment < 1) {
+            return;
+        }
+        int inviteNum = userRepo.countAllByCollectionIdAndCollectionInvitorAndSettleAccountIdIsNotNull(
+                user.getCollectionId(), invitor);
+
+        int point = inviteNum / assignment;
+        log.info("邀请数量,{}-{}", invitor, inviteNum);
+        if (point < 1) {
+            return;
+        }
+        User parent = userRepo.findById(invitor).orElse(null);
+        if (parent == null) {
+            return;
+        }
+        if (parent.getVipPoint() < 1) {
+            //老用户可有一个限购
+            parent.setVipPoint(100);
+            userRepo.save(parent);
+            cacheService.clearUserMy(user.getId());
+            cacheService.clearUser(user.getId());
+        }
+        log.info("修改限购{}", invitor);
+        UserProperty userProperty = userPropertyRepo.findById(invitor).orElse(new UserProperty(invitor, 0));
+        if (userProperty.getMaxCount() < 10 && userProperty.getMaxCount() != point) {
+            userProperty.setMaxCount(point);
+            userPropertyRepo.save(userProperty);
+            log.info("邀请绑卡限购+1,{}", invitor);
+        }
+    }
 }

+ 2 - 2
src/main/java/com/izouma/nineth/web/UserController.java

@@ -297,8 +297,8 @@ public class UserController extends BaseController {
 
     @GetMapping("/collectionInvite")
     public List<User> collectionInvite(@RequestParam Long collectionId) {
-        return userRepo.findAllByCollectionIdAndCollectionInvitor(collectionId, SecurityUtils.getAuthenticatedUser()
-                .getId());
+        return userRepo.findAllByCollectionIdAndCollectionInvitorAndSettleAccountIdIsNotNull(collectionId,
+                SecurityUtils.getAuthenticatedUser().getId());
     }
 
     @PreAuthorize("hasAnyRole('ADMIN')")

+ 6 - 0
src/test/java/com/izouma/nineth/service/UserServiceTest.java

@@ -210,4 +210,10 @@ public class UserServiceTest extends ApplicationTests {
     public void checkauth() throws AlipayApiException {
         userService.checkFaceAuth("7160e6a875cb67648bc7a3cce6e5397e");
     }
+
+    @Test
+    public void testSavePoint() {
+        User user = userRepo.findById(7962245L).orElse(null);
+        userService.savePoint(user);
+    }
 }