SM2-兴业对接基础
This commit is contained in:
parent
38d08cb91e
commit
69287cfbde
|
@ -4,10 +4,14 @@ import (
|
||||||
"github.com/ahmetb/go-linq/v3"
|
"github.com/ahmetb/go-linq/v3"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"qteam/app/constants/common"
|
"qteam/app/constants/common"
|
||||||
|
"qteam/app/constants/errorcode"
|
||||||
"qteam/app/http/controllers"
|
"qteam/app/http/controllers"
|
||||||
"qteam/app/http/entities/front"
|
"qteam/app/http/entities/front"
|
||||||
"qteam/app/models/ordermodel"
|
"qteam/app/models/ordermodel"
|
||||||
"qteam/app/services"
|
"qteam/app/services"
|
||||||
|
"qteam/app/third/market"
|
||||||
|
"qteam/app/utils"
|
||||||
|
"qteam/config"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,21 +41,36 @@ func OrderQuery(c *gin.Context) {
|
||||||
order := ordermodel.Order{OrderNo: request.OrderNo}
|
order := ordermodel.Order{OrderNo: request.OrderNo}
|
||||||
has, err := services.OrderDetailService(&order)
|
has, err := services.OrderDetailService(&order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
controllers.Error500(c)
|
controllers.Error(c, 500, "订单查询失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if has {
|
if has {
|
||||||
var state string
|
var state string
|
||||||
if order.State != common.ORDER_STATUS_PAY {
|
if order.State < common.ORDER_STATUS_PAY {
|
||||||
_, rsp := services.OrderXyQuery(request.OrderNo)
|
_, rsp := services.OrderXyQuery(request.OrderNo)
|
||||||
|
utils.Log(nil, "三方订单查询", rsp)
|
||||||
if rsp.OrderInfo.TxnStatus == "00" {
|
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)
|
|
||||||
}
|
}
|
||||||
|
state = strconv.Itoa(order.State)
|
||||||
controllers.Success(c, gin.H{"state": state}, "请求成功")
|
controllers.Success(c, gin.H{"state": state}, "请求成功")
|
||||||
} else {
|
} else {
|
||||||
controllers.Error404(c)
|
controllers.HandCodeRes(c, nil, errorcode.NotFound)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ func (p *OrderQueryResponse) ResponseFromDb(l ordermodel.Order) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrdersUpdateRequest struct {
|
type OrdersUpdateRequest struct {
|
||||||
Id int `json:"id" validate:"required" form:"id" validate:"required" example:"1"`
|
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作废)'
|
Status int `json:"status" form:"status" validate:"oneof=1 2 3 4" example:"1"` // '状态(1/待支付,2/已支付,3/已完成4/取消5作废)'
|
||||||
|
VoucherLink string `json:"voucher_link"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,16 +91,26 @@ func OrderDetailService(order *ordermodel.Order) (has bool, err error) {
|
||||||
repo := ordermodel.GetInstance().GetDb()
|
repo := ordermodel.GetInstance().GetDb()
|
||||||
conn := builder.NewCond()
|
conn := builder.NewCond()
|
||||||
if order.Id != 0 {
|
if order.Id != 0 {
|
||||||
conn = conn.And(builder.Eq{"Id": order.Id})
|
conn = conn.And(builder.Eq{"id": order.Id})
|
||||||
}
|
}
|
||||||
if order.OrderNo != "" {
|
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)
|
return repo.Where(conn).Get(order)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OrdersUpdateService(req front.OrdersUpdateRequest) (err error) {
|
func OrdersUpdateService(req front.OrdersUpdateRequest) (err error) {
|
||||||
repo := ordermodel.GetInstance().GetDb()
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue