From 3a819e4f668c15e8b77b188b322470da12bb7a43 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期五, 25 四月 2025 13:35:59 +0800
Subject: [PATCH] 会员管理

---
 src/main/java/com/mzl/flower/service/customer/CustomerService.java |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/mzl/flower/service/customer/CustomerService.java b/src/main/java/com/mzl/flower/service/customer/CustomerService.java
index 3c04fc6..91f59f1 100644
--- a/src/main/java/com/mzl/flower/service/customer/CustomerService.java
+++ b/src/main/java/com/mzl/flower/service/customer/CustomerService.java
@@ -26,12 +26,14 @@
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.Random;
 
 @Service
 @Transactional
@@ -47,6 +49,10 @@
 
     @Resource
     private BaseService baseService;
+
+    private static final String CHARACTERS = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
+
+    private final Random random = new Random();
 
     public CustomerService(CustomerMapper customerMapper, PartnerMapper partnerMapper) {
         this.customerMapper = customerMapper;
@@ -87,6 +93,8 @@
 
             customer.create(SecurityUtils.getUserId());
             customer.setIsEnabled(true);
+            customer.setIntervialcode(generateCode());
+            customer.setReintervialcode(dto.getRegesterCode());
             customer.setLevelId(Long.valueOf(Constants.DEFAULT_MEMBER_ID));
             customerMapper.insert(customer);
         } else {//重新修改
@@ -132,6 +140,11 @@
 
     private boolean checkExist(String userId) {
         return customerMapper.selectCount(new LambdaQueryWrapper<Customer>().eq(Customer::getUserId, userId)) > 0;
+    }
+
+    //验证邀请码是否有效
+    public boolean checkCode(String code) {
+        return customerMapper.findCustomerByInvitationCode(code) == null;
     }
 
     public Page<CustomerDTO> queryCustomer(QueryCustomerDTO dto, Page page) {
@@ -264,4 +277,43 @@
         customerByPhone.setContactTel(phone);
         return customerByPhone;
     }
+    public Customer getByUserId(String userId) {
+        List<Customer> customers = customerMapper.selectList(new LambdaQueryWrapper<Customer>().eq(Customer::getUserId, userId).eq(Customer::getDeleted, TrueOrFalseEnum.FALSE.isFlag()));
+        if(!CollectionUtils.isEmpty(customers)){
+            return customers.get(0);
+        }
+        return null;
+    }
+
+    public void updateMemberInfo(Customer customer) {
+        customerMapper.updateById(customer);
+    }
+
+    public void checkVipExpireTime() {
+        // 获取当天日期之前,且is_member=1的用户,设置为is_member=0并且将member_overtime设置为null
+        customerMapper.checkVipExpireTime();
+    }
+
+    //生成邀请码
+    private String generateCode() {
+        StringBuilder sb = new StringBuilder(4);
+        for (int i = 0; i < 4; i++) {
+            sb.append(CHARACTERS.charAt(random.nextInt(CHARACTERS.length())));
+        }
+        return sb.toString();
+    }
+
+    public void updateMemberInfoByUserId(Customer customer) {
+        if(null!= customer && StringUtils.isNotBlank(customer.getUserId())){
+            Customer byUserId = getByUserId(customer.getUserId());
+            if(null !=byUserId){
+                byUserId.setName(customer.getName());
+                byUserId.setCover(customer.getCover());
+                customerMapper.updateById(byUserId);
+            }else{
+                throw new ValidationException("用户不存在");
+            }
+
+        }
+    }
 }

--
Gitblit v1.9.3