From c697ed09cb1e257bc54603213b304e0f156326a6 Mon Sep 17 00:00:00 2001
From: 44323 <443237572@qq.com>
Date: 星期四, 02 十一月 2023 10:34:07 +0800
Subject: [PATCH] 支付会员送券功能补充 运营商权限bug修改
---
cloud-server-competition/src/main/java/com/dsh/competition/util/CodeGenerateUtils.java | 74 +++++++++++++++++++++++++++++++++++++
1 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/cloud-server-competition/src/main/java/com/dsh/competition/util/CodeGenerateUtils.java b/cloud-server-competition/src/main/java/com/dsh/competition/util/CodeGenerateUtils.java
index e69de29..62ac104 100644
--- a/cloud-server-competition/src/main/java/com/dsh/competition/util/CodeGenerateUtils.java
+++ b/cloud-server-competition/src/main/java/com/dsh/competition/util/CodeGenerateUtils.java
@@ -0,0 +1,74 @@
+package com.dsh.competition.util;
+
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+/**
+ * @Description
+ * @Author xiaochen
+ * @Date 2021/7/28 10:26
+ */
+public class CodeGenerateUtils {
+
+ /**
+ * @return
+ * @Description 获取商品编码
+ * 商品编码规则:nanoTime(后5位)*5位随机数(10000~99999)
+ * @Author xiaochen
+ */
+ public static String generateProductCode() {
+ long nanoPart = System.nanoTime() % 100000L;
+ if (nanoPart < 10000L) {
+ nanoPart += 10000L;
+ }
+ long randomPart = (long) (Math.random() * (90000) + 10000);
+ String code = "0" + new BigDecimal(nanoPart).multiply(new BigDecimal(randomPart));
+ return code.substring(code.length() - 10);
+ }
+
+ /**
+ * @return
+ * @Description 生成订单编号 10位
+ * 订单编号规则:(10位):(年末尾*月,取后2位)+(用户ID%3.33*日取整后2位)+(timestamp*10000以内随机数,取后6位)
+ * @Author xiaochen
+ */
+ public static String generateOrderSn() {
+ Calendar calendar = Calendar.getInstance();
+ int year = calendar.get(Calendar.YEAR);
+ year = year % 10;
+ if (year == 0) year = 10;
+ int month = calendar.get(Calendar.MONTH) + 1;
+ int yearMonth = year * month;
+ String yearMonthPart = "0" + yearMonth;
+ yearMonthPart = yearMonthPart.substring(yearMonthPart.length() - 2);
+
+ int day = calendar.get(Calendar.DAY_OF_MONTH);
+ double v = Math.random() * 10000;
+ int dayNum = (int) ((v % 3.33) * day);
+ String dayPart = "0" + dayNum;
+ dayPart = dayPart.substring(dayPart.length() - 2);
+
+ String timestampPart = "" + (Math.random() * 10000) * (System.currentTimeMillis() / 10000);
+ timestampPart = timestampPart.replace(".", "").replace("E", "");
+ timestampPart = timestampPart.substring(0, 6);
+ return yearMonthPart + dayPart + timestampPart;
+ }
+
+ /**
+ * @return
+ * @Description 生成统一支付单号 规则:年(2)月(2)日(2)时(2)分(2)+timestamp*5位随机整数取后5位
+ * @Author xiaochen
+ */
+ public static String generateVolumeSn() {
+ Calendar calendar = Calendar.getInstance();
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
+ String dateTime = dateFormat.format(calendar.getTime());
+ dateTime = dateTime.substring(2);
+ String timestampPart = "" + (Math.random() * 10000) * (System.currentTimeMillis() / 10000);
+ timestampPart = timestampPart.replace(".", "").replace("E", "");
+ timestampPart = timestampPart.substring(0, 5);
+ return dateTime + timestampPart;
+ }
+
+}
--
Gitblit v1.7.1