package com.fzm.mall.server.admin.util;

import java.util.Random;

/**
 * @author lyz
 * @mail lyz@disanbo.com
 * @create 2018/7/17 10:36
 * @description
 */
public final class CodeUtil {

	public static final String getAcctUid() {
		return genRandomCode(false, 10);
	}

	public static final String getTranSeqNo() {
		return genRandomCode(false, 22);
	}

	/**
	 * 生成手机短信验证码
	 * 
	 * @return 短信验证码
	 */
	public static final String genValidateCode() {
		return genRandomCode(true, 4);
	}

	/**
	 * 生成对外展示id
	 * 
	 * @return 对外展示id
	 */
	public static final String genOutId() {
		return genRandomCode(true, 8);
	}

	/**
	 * 生成系统用户邀请码
	 * 
	 * @return 用户邀请码
	 */
	public static final String genInviteCode() {
		return genRandomCode(false, 6);
	}

	public static final String genThreeRandomCode() {
		return genRandomCode(false, 3);
	}

	public static final String getOid() {
		return genRandomCode(false, 18);
	}

	private static final String genRandomCode(boolean numOnly, int length) {
		String orginStr = numOnly ? "0123456789" : "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		if (length < 1) {
			return null;
		}

		StringBuilder code = new StringBuilder();
		Random r = new Random();
		while (length > 0) {
			code.append(orginStr.charAt(r.nextInt(orginStr.length())));
			--length;
		}
		return code.toString();
	}

	public static String getWithDrawOid() {
		return genRandomCode(false, 6);
	}

	public static String getPayId() {
		// TODO Auto-generated method stub
		return genRandomCode(true, 18);
	}

}
