From 09fe15821621b0df4a2e873cdc652413c05da294 Mon Sep 17 00:00:00 2001 From: wuchao <1272174216@qq.com> Date: Thu, 13 Jun 2024 14:50:26 +0800 Subject: [PATCH] =?UTF-8?q?SM2-=E5=9F=BA=E7=A1=80=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/constants/common/common.go | 7 ++++ .../controllers/front/OpenapiController.go | 40 +++++++++++++++++++ app/http/entities/front/openapi.go | 25 ++++++++++++ app/http/entities/front/order.go | 5 +++ app/models/ordermodel/order.go | 2 +- app/services/OrderService.go | 19 +++++++++ 6 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 app/http/controllers/front/OpenapiController.go create mode 100644 app/http/entities/front/openapi.go diff --git a/app/constants/common/common.go b/app/constants/common/common.go index 55584f5..5ee4cfb 100644 --- a/app/constants/common/common.go +++ b/app/constants/common/common.go @@ -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 ) diff --git a/app/http/controllers/front/OpenapiController.go b/app/http/controllers/front/OpenapiController.go new file mode 100644 index 0000000..ca5542a --- /dev/null +++ b/app/http/controllers/front/OpenapiController.go @@ -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) +} diff --git a/app/http/entities/front/openapi.go b/app/http/entities/front/openapi.go new file mode 100644 index 0000000..b0d631f --- /dev/null +++ b/app/http/entities/front/openapi.go @@ -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"` +} diff --git a/app/http/entities/front/order.go b/app/http/entities/front/order.go index 9e4f47d..b79d205 100644 --- a/app/http/entities/front/order.go +++ b/app/http/entities/front/order.go @@ -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作废)' +} diff --git a/app/models/ordermodel/order.go b/app/models/ordermodel/order.go index 7a0e9ec..1d41d40 100644 --- a/app/models/ordermodel/order.go +++ b/app/models/ordermodel/order.go @@ -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)"` diff --git a/app/services/OrderService.go b/app/services/OrderService.go index 7abcd76..2afd786 100644 --- a/app/services/OrderService.go +++ b/app/services/OrderService.go @@ -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 +}