This commit is contained in:
Ashang
2022-04-04 16:01:36 +08:00
commit 20c576b9bc
72 changed files with 4680 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
package comm
import "github.com/assimon/luuu/controller"
var Ctrl = &BaseCommController{}
type BaseCommController struct {
controller.BaseController
}
+24
View File
@@ -0,0 +1,24 @@
package comm
import (
"github.com/assimon/luuu/model/request"
"github.com/assimon/luuu/model/service"
"github.com/assimon/luuu/util/constant"
"github.com/labstack/echo/v4"
)
// CreateTransaction 创建交易
func (c *BaseCommController) CreateTransaction(ctx echo.Context) (err error) {
req := new(request.CreateTransactionRequest)
if err = ctx.Bind(req); err != nil {
return c.FailJson(ctx, constant.ParamsMarshalErr)
}
if err = c.ValidateStruct(ctx, req); err != nil {
return c.FailJson(ctx, err)
}
resp, err := service.CreateTransaction(req)
if err != nil {
return c.FailJson(ctx, err)
}
return c.SucJson(ctx, resp)
}
+39
View File
@@ -0,0 +1,39 @@
package comm
import (
"fmt"
"github.com/assimon/luuu/config"
"github.com/assimon/luuu/model/response"
"github.com/assimon/luuu/model/service"
"github.com/labstack/echo/v4"
"html/template"
"net/http"
)
// CheckoutCounter 收银台
func (c *BaseCommController) CheckoutCounter(ctx echo.Context) (err error) {
tradeId := ctx.Param("trade_id")
resp, err := service.GetCheckoutCounterByTradeId(tradeId)
if err != nil {
return ctx.String(http.StatusOK, err.Error())
}
tmpl, err := template.ParseFiles(fmt.Sprintf(".%s/%s", config.StaticPath, "index.html"))
if err != nil {
return ctx.String(http.StatusOK, err.Error())
}
return tmpl.Execute(ctx.Response(), resp)
}
// CheckStatus 支付状态检测
func (c *BaseCommController) CheckStatus(ctx echo.Context) (err error) {
tradeId := ctx.Param("trade_id")
order, err := service.GetOrderInfoByTradeId(tradeId)
if err != nil {
return c.FailJson(ctx, err)
}
resp := response.CheckStatusResponse{
TradeId: order.TradeId,
Status: order.Status,
}
return c.SucJson(ctx, resp)
}