1、订单头/** 订单类别头 */
private static final String ORDER_CODE = "1";
/** 退货类别头 */
private static final String RETURN_ORDER = "2";
/** 退款类别头 */
private static final String REFUND_ORDER = "3";
/** 未付款重新支付别头 */
private static final String AGAIN_ORDER = "4";
/** 随即编码 */
private static final int[] r = new int[] { 7, 9, 6, 2, 8, 1, 3, 0, 5, 4 };
/** 用户id和随机数总长度 */
private static final int maxLength = 14;
2、根据id进行加密+加随机数组成固定长度编码private static String toCode(Long id) {
String idStr = id.toString();
StringBuilder idsbs = new StringBuilder();
for (int i = idStr.length() - 1; i >= 0; i--) {
idsbs.append(r[idStr.charAt(i) - '0']);
}
return idsbs.append(getRandom(maxLength - idStr.length())).toString();
}
3、生成固定随机码private static long getRandom(long n) {
long min = 1, max = 9;
for (int i = 1; i
min *= 10;
max *= 10;
}
long rangeLong = (((long) (new Random().nextDouble() * (max - min)))) + min;
return rangeLong;
}
4、生成退货单号编码public static String getReturnCode(Long userId) {
return RETURN_ORDER + getCode(userId);
}
完成代码下载:
链接:https://pan.baidu.com/s/15iG4c-cQLIKKN445MhuVxA
您需要先赞赏10元 才能查看以下内容!立即赞赏