package com.bohuikeji.delivery.backstage.util;

import com.bohuikeji.delivery.backstage.entity.TOrder;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import com.bohuikeji.frame.module.admin.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.regex.Pattern;

/**
 * @author ：mmzs
 * @date ：Created in 2021/3/8 12:18
 * @description：手机号工具类
 * @modified By：
 * @version: 1$
 */
@Slf4j
public class PhoneUtils {


    /**
     * 验证手机号格式
     * @param phone
     * @return
     */
    public static boolean isVerify(String phone) {
        //手机号码
        String phoneNumber="^(\\+86|86)?1((3[0-9])|(4[5|7])|(5([0-3]|[5-9]))|(8[0,5-9]))\\d{8}$";
        //座机号码
        String LandlineNumber="(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)";
        if(Pattern.matches(phoneNumber, phone)){
            return true;
        }
        if(Pattern.matches(LandlineNumber, phone)){
            return true;
        }
        return false;
    }

    /**
     * 手机号处理
     * @param phone
     * @return
     */
    public static String getPhone(String phone) {
        //座机号码--处理
        String LandlineNumber="(?:(\\(\\+?86\\))(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)|(?:(86-?)?(0[0-9]{2,3}\\-?)?([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?)";
        if(phone.contains("转")){
            phone = phone.replace("转","#");
        }
        if(phone.contains("_")){
            phone = phone.replace("_","#");
        }
        if(Pattern.matches(LandlineNumber, phone)){
            StringBuilder sb = new StringBuilder(phone);
            if(phone.substring(0, 3).matches("^0\\d{2}$")){
                phone = sb.insert(3,"-").toString();
            }else {
                phone = sb.insert(4,"-").toString();
            }
        }
        return phone;
    }

}
