1.为了同步10/19号之前的数据,新增了excel导入相关接口;

2.删除回调通知,和第三方渠道方接口;
This commit is contained in:
chenlin 2024-10-30 15:26:55 +08:00
parent 2381e1c4e4
commit f7ccec1f92
4 changed files with 64 additions and 666 deletions

View File

@ -1,380 +0,0 @@
package migumanage
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/logger"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
"net/http"
"time"
)
// 以下接口是封装转发后对外的接口
// SendCaptchaEx 下单接口(下发验证码)
// @Summary 下单接口(下发验证码)
// @Tags 2024-咪咕(对外)-下单
// @Produce json
// @Accept json
// @Param request body models.SendCaptchaReqEx true "下单接口(下发验证码)"
// @Success 200 {object} models.SendCaptchaResp
// @Router /api/v1/coupon_provider/send_captcha [post]
func (e MiGuDeployService) SendCaptchaEx(c *gin.Context) {
fmt.Println("SendCaptcha-start")
logger.Info("SendCaptcha-start")
err := e.MakeContext(c).MakeOrm().Errors
if err != nil {
fmt.Println("MakeContext err:", err)
e.Logger.Error(err)
app.MiGuError(c, http.StatusInternalServerError, err, "初始化失败")
return
}
req := &models.SendCaptchaReqEx{}
if c.ShouldBindJSON(req) != nil {
logger.Errorf("SendCaptcha para err")
app.MiGuError(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
return
}
logger.Info("SendCaptcha req:", req)
// 判断渠道订单号是否过长
if len(req.OutTradeNo) > 64 {
app.MiGuError(c, http.StatusBadRequest, errors.New("outTradeNo length exceeded the limit64"), "length exceeded the limit64")
return
}
// 判断渠道编号
if !models.IsValidChannelEx(req.Channel, e.Orm) {
app.MiGuError(c, http.StatusBadRequest, errors.New("invalid channel"), "invalid channel")
return
}
// 判断skuCode
if !models.IsValidSkuCodeEx(req.SkuCode, e.Orm) {
app.MiGuError(c, http.StatusBadRequest, errors.New("invalid skuCode"), "invalid skuCode")
return
}
// 通过子渠道编号和sku查询主渠道编号及其sku
channel, sku, err := models.GetMainChannelCodeAndSkuCode(req.Channel, req.SkuCode, e.Orm)
if err != nil {
app.MiGuError(c, http.StatusBadRequest, err, "channel or skuCode err")
return
}
outTradeNo := models.GetOrderSerial(e.Orm)
miGuReq := &models.MiGuSendCaptchaReq{
Phone: req.Phone,
Channel: channel.MainChannelCode,
SkuCode: sku.SkuName,
OutTradeNo: outTradeNo,
}
resp, err := models.MiGuCaptchaRequest(miGuReq)
if err != nil {
logger.Errorf("SendCaptcha MiGuCaptchaRequest err:", err.Error())
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
var reason string
if resp.Msg != "" && resp.Data.LinkId != "" {
reason = fmt.Sprintf("%s;%s", resp.Msg, resp.Data.LinkId)
} else if resp.Msg != "" {
reason = resp.Msg
}
// 记录数据库
var sendLog models.MgTransactionLog
sendLog.ProductID = models.ProductID
sendLog.ChannelCode = req.Channel
sendLog.OutTradeNo = outTradeNo
sendLog.PhoneNumber = req.Phone
sendLog.LinkId = resp.Data.LinkId
sendLog.Result = resp.Code
sendLog.Reason = reason
sendLog.ChannelTradeNo = req.OutTradeNo
err = e.Orm.Create(&sendLog).Error
if err != nil {
logger.Info("Create MgTransactionLog err:", err)
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
if resp.Data.LinkId != "" {
resp.Data.LinkId = outTradeNo
}
fmt.Println("SendCaptcha-end")
logger.Info("SendCaptcha-end")
app.MiGuOK(c, resp)
}
// SubmitOrderEx 提交接口(提交验证码)
// @Summary 提交接口(提交验证码)
// @Tags 2024-咪咕(对外)-下单
// @Produce json
// @Accept json
// @Param request body models.SubmitOrderReqEx true "提交接口(提交验证码)"
// @Success 200 {object} models.SubmitOrderResp
// @Router /api/v1/coupon_provider/submit_order [post]
func (e MiGuDeployService) SubmitOrderEx(c *gin.Context) {
fmt.Println("SubmitOrder-start")
logger.Info("SubmitOrder-start")
err := e.MakeContext(c).MakeOrm().Errors
if err != nil {
fmt.Println("SubmitOrder MakeContext err:", err)
e.Logger.Error(err)
app.MiGuError(c, http.StatusInternalServerError, err, "初始化失败")
return
}
req := &models.SubmitOrderReqEx{}
if c.ShouldBindJSON(req) != nil {
logger.Errorf("SendCaptcha para err")
app.MiGuError(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
return
}
logger.Info("SubmitOrder req:", req)
// 判断渠道订单号是否过长
if len(req.OutTradeNo) > 64 {
app.MiGuError(c, http.StatusBadRequest, errors.New("outTradeNo length exceeded the limit64"), "length exceeded the limit64")
return
}
// 判断渠道编号
if !models.IsValidChannelEx(req.Channel, e.Orm) {
app.MiGuError(c, http.StatusBadRequest, errors.New("invalid channel"), "invalid channel")
return
}
// 判断skuCode
if !models.IsValidSkuCodeEx(req.SkuCode, e.Orm) {
app.MiGuError(c, http.StatusBadRequest, errors.New("invalid skuCode"), "invalid skuCode")
return
}
// 查询是否有记录
var logInfo models.MgTransactionLog
err = e.Orm.Table("mg_transaction_log").Where("out_trade_no = ?", req.LinkId).First(&logInfo).Error
if err != nil {
logger.Errorf("SubmitOrder query mg_transaction_log err:", err.Error())
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
if logInfo.LinkId == "" {
app.MiGuError(c, http.StatusBadRequest, errors.New("linkId is invalid"), "linkId is invalid")
return
}
// 通过子渠道编号和sku查询主渠道编号及其sku
channel, sku, err := models.GetMainChannelCodeAndSkuCode(req.Channel, req.SkuCode, e.Orm)
if err != nil {
app.MiGuError(c, http.StatusBadRequest, err, "channel or skuCode err")
return
}
outTradeNo := logInfo.OutTradeNo
if logInfo.OutTradeNo == "" {
outTradeNo = models.GetOrderSerial(e.Orm)
}
miGuReq := &models.MiGuSubmitOrderReq{
LinkId: logInfo.LinkId,
SmsCode: req.SmsCode,
Phone: req.Phone,
Channel: channel.MainChannelCode,
SkuCode: sku.SkuName,
OutTradeNo: outTradeNo,
}
resp, err := models.MiGuCaptchaSubmit(miGuReq)
if err != nil {
logger.Errorf("SubmitOrder MiGuCaptchaSubmit err:", err.Error())
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
var reason string
if resp.Msg != "" && resp.Data.LinkId != "" {
reason = fmt.Sprintf("%s;%s", resp.Msg, resp.Data.LinkId)
} else if resp.Msg != "" {
reason = resp.Msg
}
// 记录交易流水
var sendLog models.MgTransactionLog
sendLog.ProductID = models.ProductID
sendLog.ChannelCode = req.Channel
sendLog.OutTradeNo = outTradeNo
sendLog.LinkId = resp.Data.LinkId
sendLog.PhoneNumber = req.Phone
sendLog.Result = resp.Code
sendLog.Reason = reason
sendLog.VerificationCode = req.SmsCode
orderTime := time.Now()
sendLog.OrderTime = &orderTime
sendLog.ChannelTradeNo = req.OutTradeNo
err = e.Orm.Create(&sendLog).Error
if err != nil {
logger.Info("Create MgTransactionLog err:", err)
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
if resp.Data.LinkId != "" { // 提交订阅成功则记录到订单表
// 记录到订单列表
var orderInfo models.MgOrder
orderInfo.ProductID = models.ProductID
orderInfo.ChannelCode = req.Channel
orderInfo.OrderSerial = logInfo.OutTradeNo
nowTime := time.Now()
orderInfo.SubscribeTime = &nowTime
orderInfo.PhoneNumber = req.Phone
orderInfo.SM4PhoneNumber, _ = tools.SM4Encrypt(models.SM4KEy, req.Phone)
orderInfo.ExternalOrderID = resp.Data.LinkId // 外部平台订单号咪咕返回的linkId)
orderInfo.ChannelTradeNo = req.OutTradeNo // 渠道订单号
err = e.Orm.Create(&orderInfo).Error
if err != nil {
logger.Info("Create MgTransactionLog err:", err)
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
resp.Data.LinkId = outTradeNo
}
fmt.Println("SubmitOrder-end")
logger.Info("SubmitOrder-end")
app.MiGuOK(c, resp)
}
// CheckOrderEx 查询是否已经退订接口
// @Summary 查询是否已经退订接口
// @Tags 2024-咪咕(对外)-下单
// @Produce json
// @Accept json
// @Param request body models.CheckOrderReqEx true "查询是否已经退订接口"
// @Success 200 {object} models.CheckOrderResp
// @Router /api/v1/coupon_provider/order/check [post]
func (e MiGuDeployService) CheckOrderEx(c *gin.Context) {
fmt.Println("CheckOrderEx-start")
logger.Info("CheckOrderEx-start")
err := e.MakeContext(c).MakeOrm().Errors
if err != nil {
fmt.Println("CheckOrderEx MakeContext err:", err)
e.Logger.Error(err)
app.MiGuError(c, http.StatusInternalServerError, err, "初始化失败")
return
}
req := &models.CheckOrderReqEx{}
if c.ShouldBindJSON(req) != nil {
logger.Errorf("CheckOrderEx para err")
app.MiGuError(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
return
}
logger.Info("CheckOrderEx req:", req)
var resp models.CheckOrderResp
resp.Code = "0" //未退订
resp.Msg = "success"
// 查询是否有记录
var orderInfo models.MgOrder
err = e.Orm.Table("mg_order").Where("order_serial = ?", req.LinkId).First(&orderInfo).Error
if err != nil {
logger.Errorf("CheckOrderEx query mg_order err:", err.Error())
resp.Code = "404" // 没记录
app.MiGuOK(c, resp)
return
}
if orderInfo.State == 2 { // 已退订
resp.Code = "-1"
}
fmt.Println("CheckOrderEx-end")
logger.Info("CheckOrderEx-end")
app.MiGuOK(c, resp)
}
// CheckRightsInfoEx 查询是否已经退订接口(咪咕)
// @Summary 查询是否已经退订接口(咪咕)
// @Tags 2024-咪咕(对外)-下单
// @Produce json
// @Accept json
// @Param request body models.QueryRightsInfoReqEx true "查询是否已经退订接口(咪咕)"
// @Success 200 {object} models.QueryRightsInfoResp
// @Router /api/v1/coupon_provider/order/check_rights_info [post]
func (e MiGuDeployService) CheckRightsInfoEx(c *gin.Context) {
fmt.Println("CheckRightsInfoEx-start")
logger.Info("CheckRightsInfoEx-start")
err := e.MakeContext(c).MakeOrm().Errors
if err != nil {
fmt.Println("CheckOrderEx MakeContext err:", err)
e.Logger.Error(err)
app.MiGuError(c, http.StatusInternalServerError, err, "初始化失败")
return
}
req := &models.QueryRightsInfoReqEx{}
if c.ShouldBindJSON(req) != nil {
logger.Errorf("CheckRightsInfoEx para err")
app.MiGuError(c, http.StatusBadRequest, errors.New("para err"), "参数错误")
return
}
logger.Info("CheckRightsInfoEx req:", req)
// 判断渠道编号
if !models.IsValidChannelEx(req.Channel, e.Orm) {
app.MiGuError(c, http.StatusBadRequest, errors.New("invalid channel"), "invalid channel")
return
}
// 判断skuCode
if !models.IsValidSkuCodeEx(req.SkuCode, e.Orm) {
app.MiGuError(c, http.StatusBadRequest, errors.New("invalid skuCode"), "invalid skuCode")
return
}
// 通过子渠道编号和sku查询主渠道编号及其sku
_, sku, err := models.GetMainChannelCodeAndSkuCode(req.Channel, req.SkuCode, e.Orm)
if err != nil {
app.MiGuError(c, http.StatusBadRequest, err, "channel or skuCode err")
return
}
reqQuery := models.QueryRightsInfoReq{
Mobile: req.Phone,
}
reqQuery.AppChannelList = append(reqQuery.AppChannelList, sku.ChannelCode)
resp, err := models.MiGuQueryRightsInfo(&reqQuery)
if err != nil {
logger.Errorf("CheckRightsInfoEx MiGuQueryRightsInfo err:", err.Error())
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
fmt.Println("CheckRightsInfoEx-end")
logger.Info("CheckRightsInfoEx-end")
app.MiGuOK(c, resp)
}

View File

@ -1,264 +0,0 @@
package migumanage
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/go-admin-team/go-admin-core/logger"
"go-admin/app/admin/models"
"go-admin/tools"
"go-admin/tools/app"
"gorm.io/gorm"
"net/http"
"time"
)
// 以下接口是回调接口
// SubscribeNotice 订购成功通知接口
// @Summary 订购成功通知接口
// @Tags 2024-咪咕-回调
// @Produce json
// @Accept json
// @Param request body models.NewSendDataReq true "订购成功通知接口"
// @Success 200 {object} models.OppoSendDataResp
// @Router /api/v1/notice/subscribe [get]
func (e MiGuDeployService) SubscribeNotice(c *gin.Context) {
fmt.Println("SubscribeNotice-start")
logger.Info("订购成功通知-start")
fmt.Println("URL:", c.Request.URL.String())
orderId := c.Query("orderId") // 对应linkId
extData := c.Query("extData") // 对应outTradeNo
status := c.Query("status") // status: 1成功 不存在status也认为是订购成功通知
fmt.Println("orderId:", orderId)
fmt.Println("extData:", extData)
fmt.Println("status:", status)
logger.Info(fmt.Sprintf("orderId is:%s, extData is:%s, status is:%s", orderId, extData, status))
if orderId == "" { // 没有返回linkId
logger.Error("orderId is null")
app.MiGuNoticeOK(c, "failed")
return
}
if !(status == "1" || status == "") {
logger.Error("status is", status)
app.MiGuNoticeOK(c, fmt.Sprintf("failed,status is:%s", status))
return
}
err := e.MakeContext(c).MakeOrm().Errors
if err != nil {
fmt.Println("MakeContext err:", err)
e.Logger.Error(err)
app.MiGuNoticeOK(c, "failed")
return
}
var orderInfo models.MgOrder
for i := 0; i < 3; i++ {
// 查询订单表是否有记录
err = e.Orm.Table("mg_order").Where("external_order_id = ?", orderId).First(&orderInfo).Error
if err != nil && err.Error() != "record not found" {
logger.Errorf("SubscribeNotice query mg_order err:", err.Error())
app.MiGuNoticeOK(c, "failed")
return
}
if errors.Is(err, gorm.ErrRecordNotFound) { // 没有查询到记录循环查询3次
time.Sleep(800 * time.Millisecond)
} else if err == nil { // 查询到记录,则跳出循环
break
}
}
if errors.Is(err, gorm.ErrRecordNotFound) { // 订单表没有记录
// 查询交易流水表
var logInfo models.MgTransactionLog
err = e.Orm.Table("mg_transaction_log").
Where("link_id = ?", orderId).First(&logInfo).Error
if err != nil {
logger.Errorf("SubscribeNotice query mg_transaction_log err:", err.Error())
app.MiGuNoticeOK(c, "failed")
return
}
// 插入订单表
var inOrder models.MgOrder
inOrder.CreatedAt = logInfo.CreatedAt
inOrder.UpdatedAt = logInfo.UpdatedAt
inOrder.ProductID = logInfo.ProductID
inOrder.ChannelCode = logInfo.ChannelCode
inOrder.OrderSerial = logInfo.OutTradeNo
strTime := time.Now()
inOrder.SubscribeTime = &strTime
inOrder.PhoneNumber = logInfo.PhoneNumber
inOrder.SM4PhoneNumber, _ = tools.SM4Encrypt(models.SM4KEy, logInfo.PhoneNumber)
inOrder.ExternalOrderID = logInfo.LinkId
inOrder.ChannelTradeNo = logInfo.ChannelTradeNo
inOrder.State = models.SubscribeOK
err = e.Orm.Create(&inOrder).Error
if err != nil {
logger.Info("Create MgOrder err:", err)
app.MiGuError(c, http.StatusBadRequest, err, err.Error())
return
}
orderInfo.ChannelCode = inOrder.ChannelCode
} else { // 订单表有记录
if orderInfo.State != 1 {
err = e.Orm.Table("mg_order").Where("external_order_id = ?", orderId).Updates(map[string]interface{}{
"state": models.SubscribeOK,
"subscribe_time": time.Now(),
"updated_at": time.Now(),
}).Error
if err != nil {
logger.Errorf("SubscribeNotice update mg_order err:", err.Error())
app.MiGuNoticeOK(c, "failed")
return
}
}
}
// 判断是否为子渠道订购,是的话需要通知子渠道
if models.IsValidChannelEx(orderInfo.ChannelCode, e.Orm) {
channelInfo, err := models.GetChannelInfoByChannelCode(orderInfo.ChannelCode, e.Orm)
if err != nil {
fmt.Println("SubscribeNotice GetChannelInfoByChannelCode err:", err)
fmt.Println("SubscribeNotice sub_channel_code is:", orderInfo.ChannelCode)
logger.Errorf("SubscribeNotice GetChannelInfoByChannelCode err, sub_channel_code is:", orderInfo.ChannelCode)
}
if channelInfo.SubscribeURL != "" {
for i := 0; i < 3; i++ {
resp, err := models.NoticeSubChannel(channelInfo.SubscribeURL, orderInfo.OrderSerial,
orderInfo.ChannelTradeNo, "1")
if err != nil {
fmt.Println("NoticeSubChannel err:", err)
fmt.Println("i is:", i)
continue
}
if resp != "success" {
continue
} else {
break
}
}
} else {
fmt.Println("SubscribeNotice SubscribeURL is null, sub_channel_code is:", orderInfo.ChannelCode)
logger.Error("SubscribeNotice SubscribeURL is null, sub_channel_code is:", orderInfo.ChannelCode)
}
}
fmt.Println("SubscribeNotice-end")
logger.Info("订购成功通知-end")
app.MiGuNoticeOK(c, "success")
return
}
// UnsubscribeNotice 退订通知接口
// @Summary 退订通知接口
// @Tags 2024-咪咕-回调
// @Produce json
// @Accept json
// @Param request body models.NewSendDataReq true "退订通知接口"
// @Success 200 {object} models.OppoSendDataResp
// @Router /api/v1/notice/unsubscribe [get]
func (e MiGuDeployService) UnsubscribeNotice(c *gin.Context) {
fmt.Println("UnsubscribeNotice-start")
logger.Info("退订通知-start")
fmt.Println("URL:", c.Request.URL.String())
orderId := c.Query("orderId") // 对应linkId
extData := c.Query("extData") // 对应outTradeNo
status := c.Query("status") // status: 1成功 不存在status也认为是订购成功通知
fmt.Println("orderId:", orderId)
fmt.Println("extData:", extData)
fmt.Println("status:", status)
logger.Info(fmt.Sprintf("orderId is:%s, extData is:%s, status is:%s", orderId, extData, status))
if orderId == "" { // 没有返回linkId
logger.Error("orderId is null")
app.MiGuNoticeOK(c, "failed")
return
}
if !(status == "2") {
logger.Error("status is", status)
app.MiGuNoticeOK(c, fmt.Sprintf("failed,status is:%s", status))
return
}
err := e.MakeContext(c).MakeOrm().Errors
if err != nil {
fmt.Println("MakeContext err:", err)
e.Logger.Error(err)
app.MiGuNoticeOK(c, "failed")
return
}
// 查询是否有记录
var orderInfo models.MgOrder
err = e.Orm.Table("mg_order").Where("external_order_id = ?", orderId).First(&orderInfo).Error
if err != nil {
logger.Errorf("UnsubscribeNotice query mg_order err:", err.Error())
app.MiGuNoticeOK(c, "failed")
return
}
if orderInfo.State != 2 { // 订单不是退订状态才更新
err = e.Orm.Table("mg_order").Where("external_order_id = ?", orderId).Updates(map[string]interface{}{
"state": models.UnsubscribeOK,
"unsubscribe_time": time.Now(),
"updated_at": time.Now(),
}).Error
if err != nil {
logger.Errorf("UnsubscribeNotice update mg_order err:", err.Error())
app.MiGuNoticeOK(c, "failed")
return
}
}
// 判断是否为子渠道订购,是的话需要通知子渠道
if models.IsValidChannelEx(orderInfo.ChannelCode, e.Orm) {
channelInfo, err := models.GetChannelInfoByChannelCode(orderInfo.ChannelCode, e.Orm)
if err != nil {
fmt.Println("UnsubscribeNotice GetChannelInfoByChannelCode err:", err)
fmt.Println("UnsubscribeNotice sub_channel_code is:", orderInfo.ChannelCode)
logger.Errorf("UnsubscribeNotice GetChannelInfoByChannelCode err, sub_channel_code is:", orderInfo.ChannelCode)
}
if channelInfo.SubscribeURL != "" {
for i := 0; i < 3; i++ {
resp, err := models.NoticeSubChannel(channelInfo.SubscribeURL, orderInfo.OrderSerial,
orderInfo.ChannelTradeNo, "2")
if err != nil {
continue
}
if resp != "success" {
continue
} else {
break
}
}
} else {
fmt.Println("UnsubscribeNotice SubscribeURL is null, sub_channel_code is:", orderInfo.ChannelCode)
logger.Error("UnsubscribeNotice SubscribeURL is null, sub_channel_code is:", orderInfo.ChannelCode)
}
}
fmt.Println("UnsubscribeNotice-end")
logger.Info("退订通知-end")
app.MiGuNoticeOK(c, "success")
return
}

View File

@ -71,6 +71,21 @@ type MgOrder struct {
IsOneHourCancel int `json:"is_one_hour_cancel"` // 是否1小时内退订 1-是 其他-否
}
type MgOrderCopy struct {
Model
ProductID int64 `json:"product_id"` // 产品ID
ChannelCode string `gorm:"size:255" json:"channel_code"` // 渠道编码
OrderSerial string `gorm:"size:255;not null" json:"order_serial"` // 订单流水号
SubscribeTime *time.Time `json:"subscribe_time"` // 订阅时间
PhoneNumber string `gorm:"size:20;not null" json:"phone_number"` // 手机号
SM4PhoneNumber string `gorm:"size:255" json:"sm4_phone_number"` // SM4加密手机号
ExternalOrderID string `gorm:"size:255" json:"external_order_id"` // 外部平台订单号(如咪咕等)
ChannelTradeNo string `gorm:"size:255" json:"channel_trade_no"` // 渠道订单号
State int `gorm:"size:255" json:"state"` // 用户订阅状态 1-订阅成功 2-已取消订阅
UnsubscribeTime *time.Time `json:"unsubscribe_time"` // 取消订阅时间
IsOneHourCancel int `json:"is_one_hour_cancel"` // 是否1小时内退订 1-是 其他-否
}
// MgChannel 渠道列表
type MgChannel struct {
Model
@ -811,6 +826,38 @@ func GetOrderSerial(db *gorm.DB) string {
return "" // 返回空字符串,如果在最大重试次数后仍未找到唯一编号
}
// GetExcelOrderSerial generates a unique inventory serial number based on subscribeTime
func GetExcelOrderSerial(db *gorm.DB, subscribeTime time.Time) string {
const maxRetries = 5
mu.Lock()
defer mu.Unlock()
for retryCount := 0; retryCount < maxRetries; retryCount++ {
// 使用 subscribeTime 的日期部分生成订单号
datePart := subscribeTime.Format("060102") // 格式为 YYMMDD
// 生成13位随机数
nowTime := time.Now()
rand.Seed(nowTime.UnixNano() + int64(retryCount)) // 确保每次生成不同的随机数
randomNum := rand.Int63n(1e13) // 生成范围为0到9999999999999的随机数
randomPart := fmt.Sprintf("%013d", randomNum) // 确保随机数是13位前面补零
// 拼接日期部分和随机数部分
sn := fmt.Sprintf("%s%s", datePart, randomPart)
// 查询订单号是否已存在
exist, err := QueryRecordExist(fmt.Sprintf("SELECT * FROM mg_transaction_log WHERE out_trade_no='%s'", sn), db)
if err != nil {
logger.Error("sn err:", err)
continue
}
if !exist {
return sn
}
}
return "" // 在最大重试次数后仍未找到唯一编号则返回空字符串
}
// IsValidChannel 判断渠道号是否为 12, 13, 14
func IsValidChannel(channel string) bool {
return channel == "0012" || channel == "0013" || channel == "0014"
@ -1198,3 +1245,16 @@ func ExportOrderListToExcel(orderList []MgOrder, db *gorm.DB) (string, error) {
return url, nil
}
// ConvertStringToTime 将日期字符串转换为时间格式
func ConvertStringToTime(dateStr string) (string, error) {
// 解析输入字符串为时间
t, err := time.Parse("20060102", dateStr)
if err != nil {
return "", err // 返回错误
}
// 格式化为所需的时间格式
formattedTime := t.Format("2006-01-02 15:04:05")
return formattedTime, nil
}

View File

@ -29,31 +29,13 @@ func registerMiGuControlManageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.Gi
api.POST("sys_channel/list", apiMiGu.SysChannelList) // 查询系统所有渠道编码
api.POST("home/data", apiMiGu.HomepageDataSummary) // 查询首页汇总数据
api.POST("home/revenue_analysis", apiMiGu.CalculateRevenueAnalysis) // 查询不同日期的留存月份
//api.POST("order/import", apiMiGu.ImportExcelToMgOrderHandler) // 通过excel导入订单数据
//api.POST("order/import_update", apiMiGu.ImportExcelToMgOrderHandlerUpdate) // 通过excel导入订单退订数据
}
}
// registerMiGuControlManageUnAuthRouter 无需认证的路由代码
func registerMiGuControlManageUnAuthRouter(v1 *gin.RouterGroup) {
//apiMiGu := migumanage.MiGuDeployService{}
//api := v1.Group("/notice")
//{
// api.GET("subscribe", apiMiGu.SubscribeNotice) // 订购成功通知
// api.GET("unsubscribe", apiMiGu.UnsubscribeNotice) // 退订通知
//}
//
//apiPost := v1.Group("/migu")
//{
// apiPost.POST("send_captcha", apiMiGu.SendCaptcha) // 下单接口(下发验证码)
// apiPost.POST("submit_order", apiMiGu.SubmitOrder) // 提交接口(提交验证码)
// apiPost.POST("order/check", apiMiGu.CheckOrder) // 查询是否已经退订接口
// apiPost.POST("order/check_rights_info", apiMiGu.CheckRightsInfo) // 查询是否已经退订接口(咪咕)
//}
//
//apiEx := v1.Group("/coupon_provider")
//{
// apiEx.POST("send_captcha", apiMiGu.SendCaptchaEx) // 下单接口(下发验证码)-对外
// apiEx.POST("submit_order", apiMiGu.SubmitOrderEx) // 提交接口(提交验证码)-对外
// apiEx.POST("order/check", apiMiGu.CheckOrderEx) // 查询是否已经退订接口-对外
// apiEx.POST("order/check_rights_info", apiMiGu.CheckRightsInfoEx) // 查询是否已经退订接口(咪咕)-对外
//}
}