SM2-基础完成

This commit is contained in:
wuchao 2024-06-13 14:50:26 +08:00
parent 1e7fc212b6
commit 09fe158216
6 changed files with 97 additions and 1 deletions

View File

@ -6,4 +6,11 @@ const (
FRONT_API_V1 = "/v1"
FRONT_API_V1_Auth = "/v1/auth"
ADMIN_V1 = "/admin/api/v1"
// 订单状态 1-待支付 2-已支付 3 充值完成 4充值异常 5卷链核销
ORDER_STATUS_DEFAULT = 1
ORDER_STATUS_PAY = 2
ORDER_STATUS_FINISH = 3
ORDER_STATUS_FAIL = 4
ORDER_STATUS_OFFSET = 5
)

View File

@ -0,0 +1,40 @@
package front
import (
"github.com/gin-gonic/gin"
"qteam/app/constants/common"
"qteam/app/http/controllers"
"qteam/app/http/entities/front"
"qteam/app/models/ordermodel"
"qteam/app/services"
)
func MarketCallback(c *gin.Context) {
req := controllers.GetRequest(c).(*front.MarketApiRequest)
response := front.MarketApiResponse{TradeNo: req.TradeNo}
order := ordermodel.Order{OrderNo: req.TradeNo}
has, err := services.OrderDetailService(&order)
if err != nil {
c.JSON(200, response)
return
}
if !has {
response.Msg = "订单不存在"
c.JSON(200, response)
return
}
if req.CnclSt == "4" {
update := front.OrdersUpdateRequest{
Id: order.Id,
Status: common.ORDER_STATUS_OFFSET,
}
err = services.OrdersUpdateService(update)
if err != nil {
c.JSON(200, response)
return
}
response.Code = "0000"
}
c.JSON(200, response)
}

View File

@ -0,0 +1,25 @@
package front
type MarketApiRequest struct {
TradeNo string `json:"tradeNo" validate:"required"` // 交易流水号
VoucherId string `json:"voucherId"` // 制码批次号
VoucherCode string `json:"voucherCode"` // 串码
CnclSt string `json:"cnclSt"` // 核销状态4-已核销
RedeemResult string `json:"redeemResult"` // 核销结果00-成功09- 失败
MrchntNo string `json:"mrchntNo"` // 商户号
}
type MarketApiResponse struct {
Code string `json:"code"` // 结果状态码: 0000-成功
Msg string `json:"msg"` // 错误信息
TradeNo string `json:"tradeNo"` // 交易流水号
}
type OpenApiRequest struct {
MerchantId int `form:"merchantId" validate:"required"`
OutTradeNo string `form:"outTradeNo" validate:"required"`
Status string `form:"status" validate:"required"`
RechargeAccount string `form:"rechargeAccount"`
CardCode string `form:"cardCode"`
Sign string `form:"sign" validate:"required"`
}

View File

@ -33,3 +33,8 @@ func (p *OrderQueryResponse) ResponseFromDb(l ordermodel.Order) {
utils.EntityCopy(p, &l)
p.CreateTime = l.CreateTime.Format("2006-01-02 15:04:05")
}
type OrdersUpdateRequest struct {
Id int `json:"id" validate:"required" form:"id" validate:"required" example:"1"`
Status int `json:"status" form:"status" validate:"oneof=1 2 3 4" example:"1"` // '状态(1/待支付,2/已支付,3/已完成4/取消5作废)'
}

View File

@ -13,7 +13,7 @@ var (
// 实体
type Order struct {
Id string `xorm:"'id' UNSIGNED INT pk autoincr"`
Id int `xorm:"'id' UNSIGNED INT pk autoincr"`
OrderNo string `xorm:"'order_no' varchar(50)"`
UserId int `xorm:"'user_id' int(0)"`
UserName string `xorm:"'user_name' varchar(11)"`

View File

@ -12,6 +12,7 @@ import (
"qteam/config"
"strconv"
"time"
"xorm.io/builder"
)
func CreateOrderService(userId int, productId int) (code int) {
@ -80,3 +81,21 @@ func OrderQueryService(userId int, OrderRequest *front.OrderQueryRequest) (code
code = handErr(err)
return
}
func OrderDetailService(order *ordermodel.Order) (has bool, err error) {
repo := ordermodel.GetInstance().GetDb()
conn := builder.NewCond()
if order.Id != 0 {
conn = conn.And(builder.Eq{"Id": order.Id})
}
if order.OrderNo != "" {
conn = conn.And(builder.Eq{"OrderNo": order.OrderNo})
}
return repo.Where(conn).Get(order)
}
func OrdersUpdateService(req front.OrdersUpdateRequest) (err error) {
repo := ordermodel.GetInstance().GetDb()
_, err = repo.Where("Id = ?", req.Id).Update(&ordermodel.Order{State: req.Status})
return
}