Skip to content

Commit

Permalink
style: rename some func
Browse files Browse the repository at this point in the history
  • Loading branch information
v03413 committed Dec 18, 2024
1 parent 1e49233 commit 4df2fc0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app

// Version 版本号说明 1.0.0 代表主版本号.功能版本号.修订号
const Version = "1.14.1"
const Version = "1.14.2"
4 changes: 2 additions & 2 deletions app/web/epay.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"net/http"
)

// EpaySubmit 【兼容】易支付提交
func EpaySubmit(ctx *gin.Context) {
// epaySubmit 【兼容】易支付提交
func epaySubmit(ctx *gin.Context) {
if err := ctx.Request.ParseForm(); err != nil {
ctx.String(200, "参数解析错误:"+err.Error())

Expand Down
16 changes: 8 additions & 8 deletions app/web/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"time"
)

// CreateTransaction 创建订单
func CreateTransaction(ctx *gin.Context) {
// createTransaction 创建订单
func createTransaction(ctx *gin.Context) {
_data, _ := ctx.Get("data")
data := _data.(map[string]any)
orderId, ok1 := data["order_id"].(string)
Expand All @@ -29,7 +29,7 @@ func CreateTransaction(ctx *gin.Context) {
// ---
if !ok1 || !ok2 || !ok3 || !ok4 {
log.Warn("参数错误", data)
ctx.JSON(200, RespFailJson(fmt.Errorf("参数错误")))
ctx.JSON(200, respFailJson(fmt.Errorf("参数错误")))
return
}

Expand All @@ -41,13 +41,13 @@ func CreateTransaction(ctx *gin.Context) {

var order, err = buildOrder(money, model.OrderApiTypeEpusdt, orderId, tradeType, redirectUrl, notifyUrl, orderId)
if err != nil {
ctx.JSON(200, RespFailJson(fmt.Errorf("订单创建失败:%w", err)))
ctx.JSON(200, respFailJson(fmt.Errorf("订单创建失败:%w", err)))

return
}

// 返回响应数据
ctx.JSON(200, RespSuccJson(gin.H{
ctx.JSON(200, respSuccJson(gin.H{
"trade_id": order.TradeId,
"order_id": orderId,
"amount": money,
Expand Down Expand Up @@ -116,7 +116,7 @@ func buildOrder(money float64, apiType, orderId, tradeType, redirectUrl, notifyU
return tradeOrder, nil
}

func CheckoutCounter(ctx *gin.Context) {
func checkoutCounter(ctx *gin.Context) {
var tradeId = ctx.Param("trade_id")
var order, ok = model.GetTradeOrder(tradeId)
if !ok {
Expand Down Expand Up @@ -144,11 +144,11 @@ func CheckoutCounter(ctx *gin.Context) {
})
}

func CheckStatus(ctx *gin.Context) {
func checkStatus(ctx *gin.Context) {
var tradeId = ctx.Param("trade_id")
var order, ok = model.GetTradeOrder(tradeId)
if !ok {
ctx.JSON(200, RespFailJson(fmt.Errorf("订单不存在")))
ctx.JSON(200, respFailJson(fmt.Errorf("订单不存在")))

return
}
Expand Down
23 changes: 5 additions & 18 deletions app/web/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,12 @@ package web

import "github.com/gin-gonic/gin"

type Response struct {
StatusCode int `json:"status_code"`
Message string `json:"message"`
Data interface{} `json:"data"`
RequestID string `json:"request_id"`
}
func respFailJson(err error) gin.H {

func RespFailJson(err error) gin.H {
return gin.H{
"status_code": 400,
"message": err.Error(),
}
return gin.H{"status_code": 400, "message": err.Error()}
}

func RespSuccJson(data interface{}) gin.H {
return gin.H{
"status_code": 200,
"message": "success",
"data": data,
"request_id": "",
}
func respSuccJson(data interface{}) gin.H {

return gin.H{"status_code": 200, "message": "success", "data": data, "request_id": ""}
}
8 changes: 4 additions & 4 deletions app/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func Start() {
payRoute := r.Group("/pay")
{
// 收银台
payRoute.GET("/checkout-counter/:trade_id", CheckoutCounter)
payRoute.GET("/checkout-counter/:trade_id", checkoutCounter)
// 状态检测
payRoute.GET("/check-status/:trade_id", CheckStatus)
payRoute.GET("/check-status/:trade_id", checkStatus)
}

// 创建订单
Expand Down Expand Up @@ -75,11 +75,11 @@ func Start() {

ctx.Set("data", m)
})
orderRoute.POST("/create-transaction", CreateTransaction)
orderRoute.POST("/create-transaction", createTransaction)
}

// 易支付兼容
r.POST("/submit.php", EpaySubmit)
r.POST("/submit.php", epaySubmit)

log.Info("WEB尝试启动 Listen: ", listen)
go func() {
Expand Down

0 comments on commit 4df2fc0

Please sign in to comment.