156 lines
4.4 KiB
Go
156 lines
4.4 KiB
Go
package gateway
|
|
|
|
import (
|
|
"fmt"
|
|
"gateway/internal/config"
|
|
"gateway/internal/models/merchant"
|
|
"gateway/internal/models/order"
|
|
"gateway/internal/models/response"
|
|
"gateway/internal/otelTrace"
|
|
"gateway/internal/schema/query"
|
|
"gateway/internal/service"
|
|
"gateway/internal/utils"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/beego/beego/v2/server/web"
|
|
"github.com/bytedance/sonic"
|
|
)
|
|
|
|
type OrderController struct {
|
|
web.Controller
|
|
}
|
|
|
|
func (c *OrderController) OrderQuery() {
|
|
bankOrderId := c.GetString("bankOrderId")
|
|
otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("获取订单信息:%s", bankOrderId), zap.String("bankOrderId", bankOrderId))
|
|
qy := query.SupplierOrderQueryResult(c.Ctx.Request.Context(), bankOrderId)
|
|
c.Ctx.WriteString(qy)
|
|
return
|
|
}
|
|
|
|
func (c *OrderController) OrderUpdate() {
|
|
bankOrderId := c.GetString("bankOrderId")
|
|
solveType := c.GetString("solveType")
|
|
orderInfo := order.GetOrderByBankOrderId(c.Ctx.Request.Context(), bankOrderId)
|
|
orderInfo.Operator = c.GetString("operator")
|
|
|
|
flag := false
|
|
|
|
if orderInfo.BankOrderId == "" {
|
|
otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error(fmt.Sprintf("该订单不存在, bankOrderId", bankOrderId), zap.String("bankOrderId", bankOrderId))
|
|
} else {
|
|
switch solveType {
|
|
case config.SUCCESS:
|
|
flag = service.SolvePaySuccess(c.Ctx.Request.Context(), bankOrderId, orderInfo.FactAmount, orderInfo.BankTransId, "手动修正至成功")
|
|
case config.FAIL:
|
|
flag = service.SolvePayFail(c.Ctx.Request.Context(), bankOrderId, orderInfo.BankTransId, "手动修正至失败")
|
|
case config.FREEZE_AMOUNT:
|
|
// 将这笔订单进行冻结
|
|
flag = service.SolveOrderFreeze(c.Ctx.Request.Context(), bankOrderId)
|
|
case config.UNFREEZE_AMOUNT:
|
|
// 将这笔订单金额解冻
|
|
flag = service.SolveOrderUnfreeze(c.Ctx.Request.Context(), bankOrderId)
|
|
case config.REFUND:
|
|
if orderInfo.Status == config.SUCCESS {
|
|
flag = service.SolveRefund(c.Ctx.Request.Context(), bankOrderId)
|
|
}
|
|
case config.ORDERROLL:
|
|
if orderInfo.Status == config.SUCCESS {
|
|
flag = service.SolveOrderRoll(c.Ctx.Request.Context(), bankOrderId)
|
|
}
|
|
default:
|
|
otelTrace.Logger.WithContext(c.Ctx.Request.Context()).Error("不存在这样的处理类型")
|
|
}
|
|
if flag {
|
|
c.Ctx.WriteString(config.SUCCESS)
|
|
} else {
|
|
c.Ctx.WriteString(config.FAIL)
|
|
}
|
|
}
|
|
c.StopRun()
|
|
}
|
|
|
|
func (c *OrderController) MerchantQuery() {
|
|
appKey := strings.TrimSpace(c.GetString("appKey"))
|
|
orderNo := strings.TrimSpace(c.GetString("orderNo"))
|
|
timestamp := strings.TrimSpace(c.GetString("timestamp"))
|
|
sign := strings.TrimSpace(c.GetString("sign"))
|
|
if appKey == "" || orderNo == "" || timestamp == "" || sign == "" {
|
|
resp := response.Resp{
|
|
Code: -1,
|
|
Msg: "参数错误",
|
|
}
|
|
_ = c.JSONResp(resp)
|
|
_ = c.ServeJSON()
|
|
return
|
|
}
|
|
merchantInfo := merchant.GetMerchantByPasskey(c.Ctx.Request.Context(), appKey)
|
|
if merchantInfo.Id == 0 {
|
|
resp := response.Resp{
|
|
Code: -1,
|
|
Msg: "key错误",
|
|
}
|
|
_ = c.JSONResp(resp)
|
|
_ = c.ServeJSON()
|
|
return
|
|
}
|
|
tmpSign := utils.GetMD5SignMF(map[string]any{
|
|
"appKey": appKey,
|
|
"orderNo": orderNo,
|
|
"timestamp": timestamp,
|
|
}, merchantInfo.MerchantSecret)
|
|
tmpSign2 := utils.GetMD5Sign(map[string]any{
|
|
"appKey": appKey,
|
|
"orderNo": orderNo,
|
|
"timestamp": timestamp,
|
|
}, []string{"appKey", "orderNo", "timestamp"}, merchantInfo.MerchantSecret)
|
|
if tmpSign != sign && tmpSign2 != sign {
|
|
resp := response.Resp{
|
|
Code: -1,
|
|
Msg: "签名错误",
|
|
}
|
|
_ = c.JSONResp(resp)
|
|
_ = c.ServeJSON()
|
|
return
|
|
}
|
|
orderInfo := order.GetOrderByMerchantOrderId(c.Ctx.Request.Context(), orderNo)
|
|
if orderInfo.Id == 0 {
|
|
resp := response.Resp{
|
|
Code: -1,
|
|
Msg: "订单不存在",
|
|
}
|
|
_ = c.JSONResp(resp)
|
|
_ = c.ServeJSON()
|
|
return
|
|
}
|
|
exValue, err := sonic.GetFromString(orderInfo.ExValue)
|
|
if err != nil {
|
|
resp := response.Resp{
|
|
Code: -1,
|
|
Msg: "内部错误",
|
|
}
|
|
_ = c.JSONResp(resp)
|
|
_ = c.ServeJSON()
|
|
return
|
|
}
|
|
cardNo, _ := exValue.Get("cardNo").String()
|
|
cardPwd, _ := exValue.Get("data").String()
|
|
_ = c.JSONResp(response.Resp{
|
|
Code: 0,
|
|
Msg: "订单获取成功",
|
|
Data: response.OrderQueryResp{
|
|
OrderNo: orderInfo.BankOrderId,
|
|
CardNo: cardNo,
|
|
CardPwd: cardPwd,
|
|
Status: orderInfo.Status,
|
|
FaceVal: orderInfo.FactAmount,
|
|
CardReturnData: orderInfo.CardReturnData,
|
|
Amount: strconv.FormatFloat(orderInfo.ShowAmount, 'f', -1, 64),
|
|
},
|
|
})
|
|
_ = c.ServeJSON()
|
|
}
|