tj
2025-04-11 f71719bf3e2b433b790cfaa83265611faf1f1a1c
src/main/java/com/mzl/flower/service/customer/CustomerService.java
@@ -13,6 +13,7 @@
import com.mzl.flower.dto.request.menber.UserGrowthRecordDTO;
import com.mzl.flower.dto.response.customer.CustomerDTO;
import com.mzl.flower.dto.response.partner.PartnerDTO;
import com.mzl.flower.dto.response.supplier.SupplierDTO;
import com.mzl.flower.entity.customer.Customer;
import com.mzl.flower.entity.partner.Partner;
import com.mzl.flower.enums.TrueOrFalseEnum;
@@ -25,10 +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
@@ -44,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;
@@ -84,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 {//重新修改
@@ -129,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) {
@@ -252,4 +268,52 @@
        return null;
    }
    public CustomerDTO findCustomerByPhone(String phone) {
        CustomerDTO customerByPhone = customerMapper.findCustomerByPhone(phone);
        if (customerByPhone != null && customerByPhone.getMemberOvertime() != null) {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            customerByPhone.setMemberOverDate(customerByPhone.getMemberOvertime().format(formatter));
        }
        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("用户不存在");
            }
        }
    }
}