SM2-兴业对接基础

This commit is contained in:
wuchao 2024-06-14 10:06:05 +08:00
parent 38d08cb91e
commit 69287cfbde
3 changed files with 41 additions and 11 deletions

View File

@ -4,10 +4,14 @@ import (
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
"qteam/app/constants/common"
"qteam/app/constants/errorcode"
"qteam/app/http/controllers"
"qteam/app/http/entities/front"
"qteam/app/models/ordermodel"
"qteam/app/services"
"qteam/app/third/market"
"qteam/app/utils"
"qteam/config"
"strconv"
)
@ -37,21 +41,36 @@ func OrderQuery(c *gin.Context) {
order := ordermodel.Order{OrderNo: request.OrderNo}
has, err := services.OrderDetailService(&order)
if err != nil {
controllers.Error500(c)
controllers.Error(c, 500, "订单查询失败")
return
}
if has {
var state string
if order.State != common.ORDER_STATUS_PAY {
if order.State < common.ORDER_STATUS_PAY {
_, rsp := services.OrderXyQuery(request.OrderNo)
utils.Log(nil, "三方订单查询", rsp)
if rsp.OrderInfo.TxnStatus == "00" {
state = strconv.Itoa(common.ORDER_STATUS_FINISH)
client := market.NewMarketClient(config.GetConf().OpenApiMarketConfig)
data, err := client.MarketSend(order.OrderNo, strconv.Itoa(order.VoucherId), "", "1")
if err != nil {
controllers.Error(c, 500, "三方订单查询失败")
return
}
if data.ErrCode == "00" {
err := services.OrdersUpdateService(front.OrdersUpdateRequest{Id: order.Id, Status: common.ORDER_STATUS_PAY, VoucherLink: data.Data.ShortUrl})
if err != nil {
controllers.Error(c, 500, "订单更新失败")
utils.Log(nil, "营销系统下单失败", data)
return
}
}
state = strconv.Itoa(common.ORDER_STATUS_PAY)
}
}
} else {
state = strconv.Itoa(order.State)
}
controllers.Success(c, gin.H{"state": state}, "请求成功")
} else {
controllers.Error404(c)
controllers.HandCodeRes(c, nil, errorcode.NotFound)
return
}
}

View File

@ -41,4 +41,5 @@ func (p *OrderQueryResponse) ResponseFromDb(l ordermodel.Order) {
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作废)'
VoucherLink string `json:"voucher_link"`
}

View File

@ -91,16 +91,26 @@ 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})
conn = conn.And(builder.Eq{"id": order.Id})
}
if order.OrderNo != "" {
conn = conn.And(builder.Eq{"OrderNo": order.OrderNo})
conn = conn.And(builder.Eq{"order_no": 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})
var order ordermodel.Order
if req.Id != 0 {
order.Id = req.Id
}
if req.Status != 0 {
order.State = req.Status
}
if req.VoucherLink != "" {
order.VoucherLink = req.VoucherLink
}
_, err = repo.Where("Id = ?", req.Id).Update(&order)
return
}