xiaoyong931011
2022-03-04 2e2eeeb8291415706f4941e55270a0b23e76bf23
src/main/java/com/xcong/excoin/common/system/service/impl/CommonServiceImpl.java
@@ -1,5 +1,7 @@
package com.xcong.excoin.common.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.system.service.CommonService;
@@ -8,6 +10,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
/**
 * @author wzy
@@ -22,11 +25,62 @@
    @Override
    public boolean verifyCode(String account, String code) {
        if(StrUtil.isBlank(code)){
            return false;
        }
        String cacheCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + account);
        if (StrUtil.isBlank(cacheCode)) {
            return false;
        }
        if (code.equals(cacheCode)) {
            redisUtils.del(AppContants.VERIFY_CODE_PREFIX + account);
            return true;
        } else {
            return false;
        }
    }
        return code.equals(cacheCode);
    @Override
    public boolean mutiVerifyCode(String email, String emailCode, String phone, String phoneCode) {
        if (StrUtil.isBlank(emailCode) || StrUtil.isBlank(phoneCode)) {
            return false;
        }
        String cacheEmailCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + email);
        String cachePhoneCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + phone);
        if (StrUtil.isBlank(cacheEmailCode) || StrUtil.isBlank(cachePhoneCode)) {
            return false;
        }
        if (emailCode.equals(cacheEmailCode) && phoneCode.equals(cachePhoneCode)) {
            redisUtils.del(AppContants.VERIFY_CODE_PREFIX + email);
            redisUtils.del(AppContants.VERIFY_CODE_PREFIX + phone);
            return true;
        }
        return false;
    }
    @Override
    public String generateOrderNo(Long mid) {
        StringBuilder orderNo = new StringBuilder();
        String date = DateUtil.format(new Date(), "yyyyMMdd");
        orderNo.append(date);
        orderNo.append(mid);
        orderNo.append(RandomUtil.randomNumbers(2));
        Object countObj = redisUtils.get(date);
        if (countObj == null) {
            countObj = 0;
        }
        int count = (int) countObj;
        count++;
        redisUtils.set(date, count, 24 * 60 * 60);
        int size = 4;
        for (int i = 0; i < size - String.valueOf(count).length(); i++) {
            orderNo.append("0");
        }
        orderNo.append(count);
        return orderNo.toString();
    }
}