feat: 添加otel支持
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# 对接文档
|
||||
|
||||
> AppKey:**{{.payKey}}**
|
||||
> PayKey:**{{.payKey}}**
|
||||
> AppSecret:**{{.paySecret}}**
|
||||
|
||||
## 请求支付页面
|
||||
|
||||
8
go.mod
8
go.mod
@@ -17,10 +17,10 @@ require (
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
|
||||
github.com/rs/xid v1.6.0
|
||||
github.com/samber/slog-multi v1.4.0
|
||||
github.com/shopspring/decimal v1.4.0
|
||||
github.com/widuu/gojson v0.0.0-20170212122013-7da9d2cd949b
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.9.0
|
||||
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0
|
||||
go.opentelemetry.io/otel v1.34.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.10.0
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.34.0
|
||||
@@ -31,6 +31,7 @@ require (
|
||||
go.opentelemetry.io/otel/sdk/log v0.10.0
|
||||
go.opentelemetry.io/otel/sdk/metric v1.34.0
|
||||
go.opentelemetry.io/otel/trace v1.34.0
|
||||
go.uber.org/zap v1.27.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -41,6 +42,7 @@ require (
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/felixge/httpsnoop v1.0.4 // indirect
|
||||
github.com/go-logr/logr v1.4.2 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
|
||||
@@ -56,13 +58,13 @@ require (
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.62.0 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/samber/lo v1.49.1 // indirect
|
||||
github.com/shiena/ansicolor v0.0.0-20230509054315-a9deabde6e02 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.34.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
golang.org/x/arch v0.14.0 // indirect
|
||||
golang.org/x/crypto v0.33.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
|
||||
|
||||
18
go.sum
18
go.sum
@@ -30,6 +30,8 @@ github.com/duke-git/lancet/v2 v2.3.4 h1:8XGI7P9w+/GqmEBEXYaH/XuNiM0f4/90Ioti0IvY
|
||||
github.com/duke-git/lancet/v2 v2.3.4/go.mod h1:zGa2R4xswg6EG9I6WnyubDbFO/+A/RROxIbXcwryTsc=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
|
||||
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
@@ -91,10 +93,6 @@ github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/rs/xid v1.6.0 h1:fV591PaemRlL6JfRxGDEPl69wICngIQ3shQtzfy2gxU=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
|
||||
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
|
||||
github.com/samber/slog-multi v1.4.0 h1:pwlPMIE7PrbTHQyKWDU+RIoxP1+HKTNOujk3/kdkbdg=
|
||||
github.com/samber/slog-multi v1.4.0/go.mod h1:FsQ4Uv2L+E/8TZt+/BVgYZ1LoDWCbfCU21wVIoMMrO8=
|
||||
github.com/shiena/ansicolor v0.0.0-20230509054315-a9deabde6e02 h1:v9ezJDHA1XGxViAUSIoO/Id7Fl63u6d0YmsAm+/p2hs=
|
||||
github.com/shiena/ansicolor v0.0.0-20230509054315-a9deabde6e02/go.mod h1:RF16/A3L0xSa0oSERcnhd8Pu3IXSDZSK2gmGIMsttFE=
|
||||
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
|
||||
@@ -117,8 +115,10 @@ github.com/widuu/gojson v0.0.0-20170212122013-7da9d2cd949b/go.mod h1:9W1pyetRkwX
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.9.0 h1:N+78eXSlu09kii5nkiM+01YbtWe01oZLPPLhNlEKhus=
|
||||
go.opentelemetry.io/contrib/bridges/otelslog v0.9.0/go.mod h1:/2KhfLAhtQpgnhIk1f+dftA3fuuMcZjiz//Dc9yfaEs=
|
||||
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0 h1:f+xpAfhQTjR8beiSMe1bnT/25PkeyWmOcI+SjXWguNw=
|
||||
go.opentelemetry.io/contrib/bridges/otelzap v0.9.0/go.mod h1:T1Z1jyS5FttgQoF6UcGhnM+gF9wU32B4lHO69nXw4FE=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I=
|
||||
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
|
||||
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.10.0 h1:q/heq5Zh8xV1+7GoMGJpTxM2Lhq5+bFxB29tshuRuw0=
|
||||
@@ -143,6 +143,12 @@ go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC
|
||||
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
|
||||
go.opentelemetry.io/proto/otlp v1.5.0 h1:xJvq7gMzB31/d406fB8U5CBdyQGw4P399D1aQWU/3i4=
|
||||
go.opentelemetry.io/proto/otlp v1.5.0/go.mod h1:keN8WnHxOy8PG0rQZjJJ5A2ebUoafqWp0eVQ4yIXvJ4=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||
golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
|
||||
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
||||
@@ -6,13 +6,15 @@ import (
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/models/response"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/schema/query"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
@@ -23,8 +25,8 @@ type OrderController struct {
|
||||
|
||||
func (c *OrderController) OrderQuery() {
|
||||
bankOrderId := c.GetString("bankOrderId")
|
||||
logs.Debug(fmt.Sprintf("获取到boss后台的银行id = %s", bankOrderId))
|
||||
qy := query.SupplierOrderQueryResult(bankOrderId)
|
||||
otel.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
|
||||
}
|
||||
@@ -32,35 +34,35 @@ func (c *OrderController) OrderQuery() {
|
||||
func (c *OrderController) OrderUpdate() {
|
||||
bankOrderId := c.GetString("bankOrderId")
|
||||
solveType := c.GetString("solveType")
|
||||
orderInfo := order.GetOrderByBankOrderId(bankOrderId)
|
||||
orderInfo := order.GetOrderByBankOrderId(c.Ctx.Request.Context(), bankOrderId)
|
||||
orderInfo.Operator = c.GetString("operator")
|
||||
|
||||
flag := false
|
||||
|
||||
if orderInfo.BankOrderId == "" {
|
||||
logs.Error("该订单不存在,bankOrderId=", bankOrderId)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error(fmt.Sprintf("该订单不存在, bankOrderId", bankOrderId), zap.String("bankOrderId", bankOrderId))
|
||||
} else {
|
||||
switch solveType {
|
||||
case config.SUCCESS:
|
||||
flag = service.SolvePaySuccess(bankOrderId, orderInfo.FactAmount, orderInfo.BankTransId, "手动修正至成功")
|
||||
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(bankOrderId)
|
||||
flag = service.SolveOrderFreeze(c.Ctx.Request.Context(), bankOrderId)
|
||||
case config.UNFREEZE_AMOUNT:
|
||||
// 将这笔订单金额解冻
|
||||
flag = service.SolveOrderUnfreeze(bankOrderId)
|
||||
flag = service.SolveOrderUnfreeze(c.Ctx.Request.Context(), bankOrderId)
|
||||
case config.REFUND:
|
||||
if orderInfo.Status == config.SUCCESS {
|
||||
flag = service.SolveRefund(bankOrderId)
|
||||
flag = service.SolveRefund(c.Ctx.Request.Context(), bankOrderId)
|
||||
}
|
||||
case config.ORDERROLL:
|
||||
if orderInfo.Status == config.SUCCESS {
|
||||
flag = service.SolveOrderRoll(bankOrderId)
|
||||
flag = service.SolveOrderRoll(c.Ctx.Request.Context(), bankOrderId)
|
||||
}
|
||||
default:
|
||||
logs.Error("不存在这样的处理类型")
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("不存在这样的处理类型")
|
||||
}
|
||||
if flag {
|
||||
c.Ctx.WriteString(config.SUCCESS)
|
||||
@@ -85,7 +87,7 @@ func (c *OrderController) MerchantQuery() {
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
merchantInfo := merchant.GetMerchantByPasskey(appKey)
|
||||
merchantInfo := merchant.GetMerchantByPasskey(c.Ctx.Request.Context(), appKey)
|
||||
if merchantInfo.Id == 0 {
|
||||
resp := response.Resp{
|
||||
Code: -1,
|
||||
@@ -114,7 +116,7 @@ func (c *OrderController) MerchantQuery() {
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
orderInfo := order.GetOrderByMerchantOrderId(orderNo)
|
||||
orderInfo := order.GetOrderByMerchantOrderId(c.Ctx.Request.Context(), orderNo)
|
||||
if orderInfo.Id == 0 {
|
||||
resp := response.Resp{
|
||||
Code: -1,
|
||||
|
||||
@@ -9,9 +9,10 @@ import (
|
||||
"gateway/internal/schema/response"
|
||||
"gateway/internal/service/pay_for"
|
||||
"gateway/internal/service/supplier/third_party"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
@@ -37,7 +38,7 @@ func (c *PayForGateway) PayFor() {
|
||||
payForResponse.ResultCode = "01"
|
||||
payForResponse.ResultMsg = msg
|
||||
} else {
|
||||
payForResponse = pay_for.AutoPayFor(params, config.SELF_API)
|
||||
payForResponse = pay_for.AutoPayFor(c.Ctx.Request.Context(), params, config.SELF_API)
|
||||
}
|
||||
c.Data["json"] = payForResponse
|
||||
_ = c.ServeJSON()
|
||||
@@ -51,28 +52,28 @@ func (c *PayForGateway) PayForQuery() {
|
||||
"merchantOrderId": strings.TrimSpace(c.GetString("merchantOrderId")),
|
||||
"sign": strings.TrimSpace(c.GetString("sign")),
|
||||
}
|
||||
c.Data["json"] = pay_for.PayForResultQuery(params)
|
||||
c.Data["json"] = pay_for.PayForResultQuery(c.Ctx.Request.Context(), params)
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// QuerySupplierPayForResult 查询上游的代付结果
|
||||
func (c *PayForGateway) QuerySupplierPayForResult() {
|
||||
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
|
||||
p := payfor.GetPayForByBankOrderId(bankOrderId)
|
||||
p := payfor.GetPayForByBankOrderId(c.Ctx.Request.Context(), bankOrderId)
|
||||
if p.RoadUid == "" {
|
||||
// 向上游查询订单结果
|
||||
orderInfo := order.GetOrderByBankOrderId(bankOrderId)
|
||||
orderInfo := order.GetOrderByBankOrderId(c.Ctx.Request.Context(), bankOrderId)
|
||||
|
||||
if orderInfo.BankOrderId == "" {
|
||||
c.Ctx.WriteString("fail")
|
||||
return
|
||||
}
|
||||
|
||||
roadInfo := road.GetRoadInfoByRoadUid(p.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(c.Ctx.Request.Context(), p.RoadUid)
|
||||
supplier := third_party.GetPaySupplierByCode(roadInfo.ProductUid)
|
||||
supplier.PayQuery(orderInfo, roadInfo)
|
||||
} else {
|
||||
roadInfo := road.GetRoadInfoByRoadUid(p.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(c.Ctx.Request.Context(), p.RoadUid)
|
||||
supplier := third_party.GetPaySupplierByCode(roadInfo.ProductUid)
|
||||
res := supplier.PayFor(p)
|
||||
logs.Debug("代付查询结果:", res)
|
||||
@@ -85,15 +86,15 @@ func (c *PayForGateway) SolvePayForResult() {
|
||||
resultType := strings.TrimSpace(c.GetString("resultType"))
|
||||
bankOrderId := strings.TrimSpace(c.GetString("bankOrderId"))
|
||||
|
||||
p := payfor.GetPayForByBankOrderId(bankOrderId)
|
||||
p := payfor.GetPayForByBankOrderId(c.Ctx.Request.Context(), bankOrderId)
|
||||
if p.BankOrderId == "" {
|
||||
c.Ctx.WriteString(config.FAIL)
|
||||
}
|
||||
|
||||
if resultType == config.PAYFOR_FAIL {
|
||||
pay_for.PayForFail(p)
|
||||
pay_for.PayForFail(c.Ctx.Request.Context(), p)
|
||||
} else if resultType == config.PAYFOR_SUCCESS {
|
||||
pay_for.PayForSuccess(p)
|
||||
pay_for.PayForSuccess(c.Ctx.Request.Context(), p)
|
||||
}
|
||||
|
||||
c.Ctx.WriteString(config.SUCCESS)
|
||||
@@ -113,7 +114,7 @@ func (c *PayForGateway) Balance() {
|
||||
balanceResponse.ResultMsg = msg
|
||||
c.Data["json"] = balanceResponse
|
||||
} else {
|
||||
c.Data["json"] = pay_for.BalanceQuery(params)
|
||||
c.Data["json"] = pay_for.BalanceQuery(c.Ctx.Request.Context(), params)
|
||||
}
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"gateway/internal/models/merchant_deploy"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/schema/request"
|
||||
"gateway/internal/schema/response"
|
||||
"gateway/internal/service"
|
||||
@@ -20,17 +21,19 @@ import (
|
||||
"gateway/internal/service/supplier/t_mall_game"
|
||||
"gateway/internal/service/supplier/third_party"
|
||||
"gateway/internal/utils"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/allegro/bigcache/v3"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/core/validation"
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/random"
|
||||
"github.com/duke-git/lancet/v2/structs"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -46,7 +49,7 @@ type ScanController struct {
|
||||
func (c *ScanController) Scan() {
|
||||
// 获取所有请求参数
|
||||
// 获取客户端的ip
|
||||
p := service.GetMerchantInfo(map[string]any{
|
||||
p := service.GetMerchantInfo(c.Ctx.Request.Context(), map[string]any{
|
||||
"exValue": strings.TrimSpace(c.GetString("exValue")),
|
||||
"orderNo": strings.TrimSpace(c.GetString("orderNo")),
|
||||
"orderPeriod": strings.TrimSpace(c.GetString("orderPeriod")),
|
||||
@@ -59,10 +62,18 @@ func (c *ScanController) Scan() {
|
||||
"ip": strings.TrimSpace(c.GetString("ip")),
|
||||
"deviceId": strings.TrimSpace(c.GetString("deviceId")),
|
||||
})
|
||||
ctx, cancel := otel.Span(c.Ctx.Request.Context(), "页面订单", "ScanController", trace.WithAttributes(
|
||||
attribute.String("exValue", p.Params["exValue"].(string)),
|
||||
attribute.String("orderNo", p.Params["orderNo"].(string)),
|
||||
attribute.String("productCode", p.Params["productCode"].(string)),
|
||||
attribute.String("sign", p.Params["sign"].(string)),
|
||||
))
|
||||
defer cancel()
|
||||
c.Ctx.Request = c.Ctx.Request.WithContext(ctx)
|
||||
p.ClientIP = strings.TrimSpace(c.GetString("ip"))
|
||||
cacheId, _ := idCache.Get(strings.TrimSpace(c.GetString("orderNo")))
|
||||
if len(cacheId) != 0 {
|
||||
logs.Info("订单已经提交,订单信息:%v", p)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("订单已经提交,订单信息:id=%s", p.Params["orderNo"]), zap.Any("orderInfo", p.Params))
|
||||
p.Msg = "订单已经提交~"
|
||||
p.Code = -1
|
||||
c.SolveFailJSON(p)
|
||||
@@ -78,22 +89,22 @@ func (c *ScanController) Scan() {
|
||||
c.SolveFailJSON(p)
|
||||
return
|
||||
}
|
||||
slog.InfoContext(c.Ctx.Request.Context(), "【BaseGateway】获取商户请求过来的参数:", p.Params)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】获取商户请求过来的参数", zap.Any("params", p.Params))
|
||||
// 签名验证
|
||||
if !utils.Md5MFVerify(p.Params, p.MerchantInfo.MerchantSecret) &&
|
||||
!utils.Md5TMPMFVerify(p.Params, p.MerchantInfo.MerchantSecret) &&
|
||||
if !utils.Md5MFVerify(c.Ctx.Request.Context(), p.Params, p.MerchantInfo.MerchantSecret) &&
|
||||
!utils.Md5TMPMFVerify(c.Ctx.Request.Context(), p.Params, p.MerchantInfo.MerchantSecret) &&
|
||||
!utils.Md5Verify(p.Params, p.MerchantInfo.MerchantSecret) {
|
||||
p.Code = -1
|
||||
p.Msg = "签名异常"
|
||||
c.SolveFailJSON(p)
|
||||
return
|
||||
}
|
||||
p = service.ChooseRoadV2(p)
|
||||
p = service.ChooseRoadV2(c.Ctx.Request.Context(), p)
|
||||
if p.Code == -1 {
|
||||
c.SolveFailJSON(p)
|
||||
return
|
||||
}
|
||||
mt := merchant_deploy.GetMerchantDeployByUidAndRoadUid(p.MerchantInfo.MerchantUid, p.RoadInfo.RoadUid)
|
||||
mt := merchant_deploy.GetMerchantDeployByUidAndRoadUid(c.Ctx.Request.Context(), p.MerchantInfo.MerchantUid, p.RoadInfo.RoadUid)
|
||||
if mt.Id == 0 {
|
||||
p.Msg = "当前用户没有开通该通道"
|
||||
c.SolveFailJSON(p)
|
||||
@@ -106,7 +117,7 @@ func (c *ScanController) Scan() {
|
||||
c.SolveFailJSON(p)
|
||||
return
|
||||
}
|
||||
pm, err := mt.GetShowMMValue(orderPrice)
|
||||
pm, err := mt.GetShowMMValue(c.Ctx.Request.Context(), orderPrice)
|
||||
if err != nil {
|
||||
p.Code = -1
|
||||
p.Msg = fmt.Sprintf("获取展示比例失败:%v", err.Error())
|
||||
@@ -121,7 +132,7 @@ func (c *ScanController) Scan() {
|
||||
return
|
||||
}
|
||||
// TODO: 生成订单记录
|
||||
orderInfo, _, err := service.GenerateRecord(p)
|
||||
orderInfo, _, err := service.GenerateRecord(c.Ctx.Request.Context(), p)
|
||||
if err != nil {
|
||||
p.Msg = fmt.Sprintf("生成订单失败:%v", err.Error())
|
||||
c.SolveFailJSON(p)
|
||||
@@ -132,7 +143,7 @@ func (c *ScanController) Scan() {
|
||||
return
|
||||
}
|
||||
|
||||
hiddenCfg := service.GetOrderHidden(&orderInfo)
|
||||
hiddenCfg := service.GetOrderHidden(c.Ctx.Request.Context(), &orderInfo)
|
||||
if hiddenCfg != nil {
|
||||
hiddenCfg.Strategy = int(random.RandFromGivenSlice([]consts.StealRuleType{
|
||||
consts.StealRuleTypeStealDelay,
|
||||
@@ -142,13 +153,13 @@ func (c *ScanController) Scan() {
|
||||
delayDuration := random.RandInt(hiddenCfg.DelayDurationMin, hiddenCfg.DelayDurationMax)
|
||||
//1. 新的空白记录
|
||||
if hiddenCfg.Strategy == int(consts.StealRuleTypeStealBlank) {
|
||||
newBankOrderId, err2 := service.CreateHiddenBlankOrder(&orderInfo, int64(delayDuration))
|
||||
newBankOrderId, err2 := service.CreateHiddenBlankOrder(c.Ctx.Request.Context(), &orderInfo, int64(delayDuration))
|
||||
if err2 != nil {
|
||||
slog.ErrorContext(c.Ctx.Request.Context(), "添加订单关联失败【偷卡】:%v", err2.Error())
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡1】", zap.Error(err2))
|
||||
}
|
||||
//添加订单关联
|
||||
if err2 = service.CreateRelateHideOrderRecord(newBankOrderId, &orderInfo, hiddenCfg, delayDuration); err2 != nil {
|
||||
slog.ErrorContext(c.Ctx.Request.Context(), "添加订单关联失败【偷卡】:%v", err2.Error())
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡2】", zap.Error(err2))
|
||||
}
|
||||
//错误订单回调上游
|
||||
//oldBankOrderId := orderInfo.BankOrderId
|
||||
@@ -160,45 +171,48 @@ func (c *ScanController) Scan() {
|
||||
}
|
||||
//2.新的错误记录
|
||||
if hiddenCfg.Strategy == int(consts.StealRuleTypeStealDelay) {
|
||||
newBankOrderId, err2 := service.CreateHiddenErrorOrder(&orderInfo, int64(delayDuration))
|
||||
newBankOrderId, err2 := service.CreateHiddenErrorOrder(c.Ctx.Request.Context(), &orderInfo, int64(delayDuration))
|
||||
if err2 != nil {
|
||||
slog.ErrorContext(c.Ctx.Request.Context(), "添加订单关联失败【偷卡】:%v", err2.Error())
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡1】", zap.Error(err2))
|
||||
}
|
||||
//添加订单关联
|
||||
if err2 = service.CreateRelateHideOrderRecord(newBankOrderId, &orderInfo, hiddenCfg, delayDuration); err2 != nil {
|
||||
slog.ErrorContext(c.Ctx.Request.Context(), "添加订单关联失败【偷卡】:%v", err2.Error())
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("添加订单关联失败【偷卡2】", zap.Error(err2))
|
||||
}
|
||||
oldBankOrderId := orderInfo.BankOrderId
|
||||
//错误订单回调上游
|
||||
delayPool.Go(func() {
|
||||
delayPool.CtxGo(c.Ctx.Request.Context(), func() {
|
||||
time.Sleep(time.Duration(delayDuration) * time.Second)
|
||||
//已有的订单回调为失败
|
||||
service.SolvePayFail(c.Ctx.Request.Context(), oldBankOrderId, orderInfo.BankTransId, hiddenCfg.ExtraReturnInfo)
|
||||
// 创建一个5分钟超时的上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(c.Ctx.Request.Context(), 5*time.Minute)
|
||||
defer cancel()
|
||||
service.SolvePayFail(timeoutCtx, oldBankOrderId, orderInfo.BankTransId, hiddenCfg.ExtraReturnInfo)
|
||||
})
|
||||
orderInfo.BankOrderId = newBankOrderId
|
||||
}
|
||||
}
|
||||
slog.Info("请求订单信息,订单信息:%+v", orderInfo)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】生成订单记录", zap.Any("orderInfo", orderInfo))
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err = json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("格式化数据失败", zap.Error(err), zap.String("ExValue", orderInfo.ExValue))
|
||||
p.Msg = fmt.Sprintf("格式化数据失败:%v", orderInfo.ExValue)
|
||||
c.SolveFailJSON(p)
|
||||
}
|
||||
|
||||
isAllowed, err := backend.GetIPIsRestricted(p.ClientIP, mt.Id, orderInfo.BankOrderId, cdata.Data, convertor.ToString(p.Params["deviceId"]))
|
||||
order.UpdateIpRestricted(orderInfo.BankOrderId, isAllowed)
|
||||
isAllowed, err := backend.GetIPIsRestricted(c.Ctx.Request.Context(), p.ClientIP, mt.Id, orderInfo.BankOrderId, cdata.Data, convertor.ToString(p.Params["deviceId"]))
|
||||
order.UpdateIpRestricted(c.Ctx.Request.Context(), orderInfo.BankOrderId, isAllowed)
|
||||
|
||||
logs.Info("IP是否允许:%v", isAllowed)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("IP是否允许", zap.Bool("isAllowed", isAllowed))
|
||||
// otel.Logger.WithContext(c.Ctx.Request.Context()).Info("IP是否允许:%v", isAllowed)
|
||||
if !isAllowed {
|
||||
logs.Info("IP被限制,无法兑换", p.ClientIP)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info(fmt.Sprintf("IP被限制,无法兑换 %s", p.ClientIP), zap.String("ClientIP", p.ClientIP))
|
||||
c.Data["json"] = response.CommonErr(-1, errors.New("提交失败").Error())
|
||||
service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "IP限制,无法兑换")
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
slog.Info("获取商户部署信息:%+v", mt)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】生成订单记录", zap.Any("orderInfo", orderInfo))
|
||||
if mt.AutoSettle == config.NO {
|
||||
params := map[string]any{
|
||||
"orderNo": orderInfo.BankOrderId,
|
||||
@@ -224,14 +238,14 @@ func (c *ScanController) Scan() {
|
||||
if supplierByCode == nil {
|
||||
// 插入处理失败的动账通知
|
||||
service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "")
|
||||
slog.ErrorContext(c.Ctx.Request.Context(), "获取上游渠道失败,请联系客服:%v", supplierCode)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("获取上游渠道失败,请联系客服", zap.String("supplierCode", supplierCode))
|
||||
c.Data["json"] = response.CommonErr(-1, errors.New("获取上游渠道失败,请联系客服").Error())
|
||||
_ = c.ServeJSON()
|
||||
c.StopRun()
|
||||
return
|
||||
}
|
||||
slog.ErrorContext(c.Ctx.Request.Context(), "获取供应商信息:%+v", supplierByCode)
|
||||
scanData := supplierByCode.Scan(orderInfo, p.RoadInfo, p.MerchantInfo)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("【BaseGateway】获取到对应的上游", zap.Any("supplierByCode", supplierByCode))
|
||||
scanData := supplierByCode.Scan(c.Ctx.Request.Context(), orderInfo, p.RoadInfo, p.MerchantInfo)
|
||||
order.InsertCardReturnData(scanData.BankNo, scanData.ReturnData)
|
||||
if scanData.Status == "00" {
|
||||
scanSuccessData := service.GenerateSuccessData(scanData, p)
|
||||
@@ -275,14 +289,14 @@ func (c *ScanController) GetAllowedMM() {
|
||||
c.StopRun()
|
||||
}
|
||||
|
||||
merchantInfo, err := service.GetMerchantInfoByPayKey(payKey)
|
||||
merchantInfo, err := service.GetMerchantInfoByPayKey(c.Ctx.Request.Context(), payKey)
|
||||
if err != nil || merchantInfo.Id == 0 {
|
||||
c.Data["json"] = response.CommonErr(-1, "获取面额失败,获取商户信息出错")
|
||||
_ = c.ServeJSON()
|
||||
c.StopRun()
|
||||
}
|
||||
|
||||
merchantDeployInfo := service.GerMerchantDeployInfoByUidAndProductCode(merchantInfo.MerchantUid, productCode)
|
||||
merchantDeployInfo := service.GerMerchantDeployInfoByUidAndProductCode(c.Ctx.Request.Context(), merchantInfo.MerchantUid, productCode)
|
||||
if merchantDeployInfo.Id == 0 {
|
||||
res := response.CommonErr(-1, "获取面额失败,当前通道不存在")
|
||||
c.Data["json"] = res
|
||||
@@ -290,7 +304,7 @@ func (c *ScanController) GetAllowedMM() {
|
||||
return
|
||||
}
|
||||
|
||||
profitMarginList, err := merchantDeployInfo.GetFactMMValue(showMMValue)
|
||||
profitMarginList, err := merchantDeployInfo.GetFactMMValue(c.Ctx.Request.Context(), showMMValue)
|
||||
if err != nil {
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
@@ -305,7 +319,7 @@ func (c *ScanController) GetAllowedMM() {
|
||||
IsLinkSingle bool `json:"isLinkSingle" description:"链接是否单独放置"`
|
||||
LinkID string `json:"linkID" description:"链接"`
|
||||
}
|
||||
logs.Info("当前请求面额数据:%+v", profitMarginList)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("当前请求面额数据", zap.Any("profitMarginList", profitMarginList))
|
||||
resData := make([]*profitMarginStruct, 0)
|
||||
for _, v := range profitMarginList {
|
||||
if v.ShowLabel != 0 || v.FactLabel != 0 {
|
||||
@@ -319,7 +333,7 @@ func (c *ScanController) GetAllowedMM() {
|
||||
})
|
||||
}
|
||||
}
|
||||
logs.Info("转换后的面额数据:%+v", resData)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("当前请求面额数据", zap.Any("profitMarginList", profitMarginList))
|
||||
c.Data["json"] = response.Ok(resData)
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
@@ -328,34 +342,41 @@ func (c *ScanController) GetAllowedMM() {
|
||||
func (c *ScanController) CreateOrder() {
|
||||
createdOrder := request.CreatedOrder{}
|
||||
_ = c.Bind(&createdOrder)
|
||||
logs.Info("创建订单:%+v", createdOrder)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单:", zap.Any("createdOrder", createdOrder))
|
||||
valid := validation.Validation{}
|
||||
b, err := valid.Valid(&createdOrder)
|
||||
if err != nil || !b {
|
||||
logs.Error("创建订单错误:", err)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误:", zap.Error(err))
|
||||
res := response.CommonErr(-1, "创建订单失败,参数错误")
|
||||
c.Data["json"] = res
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
ctx, cancel := otel.Span(c.Ctx.Request.Context(), "API订单", "ScanController", trace.WithAttributes(
|
||||
attribute.String("PayKey", createdOrder.PayKey),
|
||||
attribute.String("ProductCode", createdOrder.ProductCode),
|
||||
attribute.String("productCode", createdOrder.Sign),
|
||||
))
|
||||
defer cancel()
|
||||
c.Ctx.Request = c.Ctx.Request.WithContext(ctx)
|
||||
|
||||
merchantInfo := merchant.GetMerchantByPasskey(createdOrder.PayKey)
|
||||
merchantInfo := merchant.GetMerchantByPasskey(c.Ctx.Request.Context(), createdOrder.PayKey)
|
||||
if merchantInfo.Id == 0 {
|
||||
logs.Error("创建订单错误:", err)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误:", zap.Error(err))
|
||||
c.Data["json"] = response.CommonErr(-1, "创建订单错误,商户不存在")
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
if !utils.Md5MFVerify(createdOrder.ToMap(), merchantInfo.MerchantSecret) && !utils.Md5Verify(createdOrder.ToMap(), merchantInfo.MerchantSecret) {
|
||||
logs.Info("创建订单错误,sign校验失败", err)
|
||||
if !utils.Md5MFVerify(c.Ctx.Request.Context(), createdOrder.ToMap(), merchantInfo.MerchantSecret) && !utils.Md5Verify(createdOrder.ToMap(), merchantInfo.MerchantSecret) {
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("创建订单错误,sign校验失败")
|
||||
c.Data["json"] = response.CommonErr(-1, "sign验证错误")
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
orderInfo := order.GetOrderByMerchantOrderId(createdOrder.OrderNo)
|
||||
roadInfo := road.GetRoadInfoByProductCode(createdOrder.ProductCode)
|
||||
orderInfo := order.GetOrderByMerchantOrderId(c.Ctx.Request.Context(), createdOrder.OrderNo)
|
||||
roadInfo := road.GetRoadInfoByProductCode(c.Ctx.Request.Context(), createdOrder.ProductCode)
|
||||
if orderInfo.Id != 0 {
|
||||
res := response.Ok(struct {
|
||||
ProductCode string `json:"productCode"`
|
||||
@@ -382,7 +403,7 @@ func (c *ScanController) CreateOrder() {
|
||||
supplierByCode := third_party.GetPaySupplierByCode(supplierCode)
|
||||
if supplierByCode == nil {
|
||||
// 插入处理失败的动账通知
|
||||
logs.Error("获取上游渠道失败,请联系客服", supplierCode)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("获取上游渠道失败,请联系客服", zap.String("supplierCode", supplierCode))
|
||||
err = errors.New("获取上游渠道失败,请联系客服")
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
@@ -390,21 +411,20 @@ func (c *ScanController) CreateOrder() {
|
||||
}
|
||||
|
||||
// 创建订单记录
|
||||
orderInfo, err = service.CreateOrderInfoAndOrderProfitInfo(createdOrder, merchantInfo)
|
||||
orderInfo, err = service.CreateOrderInfoAndOrderProfitInfo(c.Ctx.Request.Context(), createdOrder, merchantInfo)
|
||||
if err != nil {
|
||||
res := response.CommonErr(-1, "创建订单失败,创建订单记录失败")
|
||||
logs.Info("创建订单错误:", err)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("创建订单错误:", zap.Error(err))
|
||||
c.Data["json"] = res
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
logs.Info("获取供应商信息:%+v", supplierCode)
|
||||
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Info("获取供应商信息", zap.Any("supplierCode", supplierCode))
|
||||
payUrl := ""
|
||||
bankTransId := ""
|
||||
//TODO: 区分自有渠道和三方渠道
|
||||
if supplierByCode.HasDependencyHTML() {
|
||||
scanData := supplierByCode.Scan(orderInfo, roadInfo, merchantInfo)
|
||||
scanData := supplierByCode.Scan(c.Ctx.Request.Context(), orderInfo, roadInfo, merchantInfo)
|
||||
payUrl = scanData.PayUrl
|
||||
bankTransId = scanData.UpStreamOrderNo
|
||||
} else {
|
||||
@@ -421,7 +441,7 @@ func (c *ScanController) CreateOrder() {
|
||||
}
|
||||
|
||||
if err = order.UpdatePayUrlAndTime(orderInfo.BankOrderId, payUrl, bankTransId, ""); err != nil {
|
||||
logs.Error("更新订单支付链接失败:", err)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("更新订单支付链接失败:", zap.Error(err))
|
||||
c.Data["json"] = response.CommonErr(-1, "更新订单支付链接失败")
|
||||
return
|
||||
}
|
||||
@@ -445,7 +465,7 @@ func (c *ScanController) CreateOrder() {
|
||||
}
|
||||
respMap, err := structs.New(resp).ToMap()
|
||||
if err != nil {
|
||||
logs.Info("创建订单错误:", err)
|
||||
otel.Logger.WithContext(c.Ctx.Request.Context()).Error("创建订单错误:", zap.Error(err))
|
||||
c.Data["json"] = response.CommonErr(-1, err.Error())
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestScanController_Scan(t *testing.T) {
|
||||
cacheValue, err := idCache.Get("123456")
|
||||
logs.Info(cacheValue, err)
|
||||
err2 := idCache.Set("123456", []byte("123456"))
|
||||
logs.Info(err2)
|
||||
cacheValue, err = idCache.Get("123456")
|
||||
logs.Info(cacheValue, err)
|
||||
}
|
||||
@@ -3,13 +3,14 @@ package dto
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
_ "github.com/beego/beego/v2/server/web"
|
||||
"github.com/duke-git/lancet/v2/formatter"
|
||||
"gateway/internal/otel"
|
||||
"sort"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "github.com/beego/beego/v2/server/web"
|
||||
"github.com/duke-git/lancet/v2/formatter"
|
||||
)
|
||||
|
||||
func TestParams_Encrypt(t *testing.T) {
|
||||
@@ -23,7 +24,7 @@ func TestParams_Encrypt(t *testing.T) {
|
||||
// NotifyUrl: "http://121.37.253.228:12307/",
|
||||
//}
|
||||
//p, _ := formatter.Pretty(orderParams)
|
||||
//logs.Info(p, "https://shop.kkknametrans.buzz/?sign="+orderParams.Encrypt())
|
||||
//otel.Logger.WithContext(c.Ctx.Request.Context()).Info(p, "https://shop.kkknametrans.buzz/?sign="+orderParams.Encrypt())
|
||||
|
||||
main()
|
||||
}
|
||||
@@ -43,7 +44,7 @@ func main() {
|
||||
params["amount"] = "100"
|
||||
|
||||
result, _ := formatter.Pretty(params)
|
||||
logs.Info(result)
|
||||
otel.Logger.WithContext(otel.InitCtx).Info(result)
|
||||
|
||||
strArr := SortMap(params)
|
||||
signStr := ""
|
||||
@@ -57,10 +58,10 @@ func main() {
|
||||
}
|
||||
signStr += appSecret
|
||||
h := md5.New()
|
||||
logs.Info(signStr)
|
||||
otel.Logger.WithContext(otel.InitCtx).Info(signStr)
|
||||
h.Write([]byte(signStr))
|
||||
result = hex.EncodeToString(h.Sum(nil))
|
||||
logs.Info(result)
|
||||
otel.Logger.WithContext(otel.InitCtx).Info(result)
|
||||
}
|
||||
|
||||
// SortMap 对map的key值进行排序
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AccountInfo struct {
|
||||
@@ -24,28 +27,28 @@ type AccountInfo struct {
|
||||
|
||||
const ACCOUNT_INFO = "account_info"
|
||||
|
||||
func InsetAcount(account AccountInfo) bool {
|
||||
func InsetAcount(ctx context.Context, account AccountInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&account)
|
||||
if err != nil {
|
||||
logs.Error("insert account fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert account fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetAccountByUid(accountUid string) AccountInfo {
|
||||
func GetAccountByUid(ctx context.Context, accountUid string) AccountInfo {
|
||||
o := orm.NewOrm()
|
||||
var account AccountInfo
|
||||
_, err := o.QueryTable(ACCOUNT_INFO).Filter("account_uid", accountUid).Limit(1).All(&account)
|
||||
if err != nil {
|
||||
logs.Error("get account by uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get account by uid fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return account
|
||||
}
|
||||
|
||||
func GetAccountLenByMap(params map[string]string) int {
|
||||
func GetAccountLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(ACCOUNT_INFO)
|
||||
for k, v := range params {
|
||||
@@ -55,12 +58,12 @@ func GetAccountLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Limit(-1).OrderBy("-update_time").Count()
|
||||
if err != nil {
|
||||
logs.Error("get account len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get account len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetAccountByMap(params map[string]string, displayCount, offset int) []AccountInfo {
|
||||
func GetAccountByMap(ctx context.Context, params map[string]string, displayCount, offset int) []AccountInfo {
|
||||
o := orm.NewOrm()
|
||||
var accountList []AccountInfo
|
||||
qs := o.QueryTable(ACCOUNT_INFO)
|
||||
@@ -72,38 +75,38 @@ func GetAccountByMap(params map[string]string, displayCount, offset int) []Accou
|
||||
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&accountList)
|
||||
if err != nil {
|
||||
logs.Error("get account by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get account by map fail: ", zap.Error(err))
|
||||
}
|
||||
return accountList
|
||||
}
|
||||
|
||||
func GetAllAccount() []AccountInfo {
|
||||
func GetAllAccount(ctx context.Context) []AccountInfo {
|
||||
o := orm.NewOrm()
|
||||
var accountList []AccountInfo
|
||||
|
||||
_, err := o.QueryTable(ACCOUNT_INFO).Limit(-1).All(&accountList)
|
||||
if err != nil {
|
||||
logs.Error("get all account fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get all account fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return accountList
|
||||
}
|
||||
|
||||
func UpdateAccount(account AccountInfo) bool {
|
||||
func UpdateAccount(ctx context.Context, account AccountInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&account)
|
||||
if err != nil {
|
||||
logs.Error("update account fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update account fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func DeleteAccountByUid(accountUid string) bool {
|
||||
func DeleteAccountByUid(ctx context.Context, accountUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(ACCOUNT_INFO).Filter("account_uid", accountUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete account fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete account fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AccountHistoryInfo struct {
|
||||
@@ -20,17 +23,17 @@ type AccountHistoryInfo struct {
|
||||
|
||||
const AccountHistoryInfoName = "account_history_info"
|
||||
|
||||
func InsertAccountHistory(accountHistory AccountHistoryInfo) bool {
|
||||
func InsertAccountHistory(ctx context.Context, accountHistory AccountHistoryInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(accountHistory)
|
||||
if err != nil {
|
||||
logs.Error("insert account history fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert account history fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetAccountHistoryLenByMap(params map[string]string) int {
|
||||
func GetAccountHistoryLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(AccountHistoryInfoName)
|
||||
for k, v := range params {
|
||||
@@ -40,12 +43,12 @@ func GetAccountHistoryLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get account history len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get account history len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetAccountHistoryByMap(params map[string]string, displayCount, offset int) []AccountHistoryInfo {
|
||||
func GetAccountHistoryByMap(ctx context.Context, params map[string]string, displayCount, offset int) []AccountHistoryInfo {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(AccountHistoryInfoName)
|
||||
var accountHistoryList []AccountHistoryInfo
|
||||
@@ -56,7 +59,7 @@ func GetAccountHistoryByMap(params map[string]string, displayCount, offset int)
|
||||
}
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&accountHistoryList)
|
||||
if err != nil {
|
||||
logs.Error("get account history by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get account history by map fail: ", zap.Error(err))
|
||||
}
|
||||
return accountHistoryList
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type AgentInfo struct {
|
||||
@@ -41,40 +44,40 @@ func IsEixstByAgentPhone(agentPhone string) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func InsertAgentInfo(agentInfo AgentInfo) bool {
|
||||
func InsertAgentInfo(ctx context.Context, agentInfo AgentInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&agentInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert agent info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert agent info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func GetAgentInfoByAgentUid(agentUid string) AgentInfo {
|
||||
func GetAgentInfoByAgentUid(ctx context.Context, agentUid string) AgentInfo {
|
||||
o := orm.NewOrm()
|
||||
var agentInfo AgentInfo
|
||||
_, err := o.QueryTable(AGENT_INFO).Filter("agent_uid", agentUid).Limit(1).All(&agentInfo)
|
||||
if err != nil {
|
||||
logs.Error("get agent info by agentUid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get agent info by agentUid fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return agentInfo
|
||||
}
|
||||
|
||||
func GetAgentInfoByPhone(phone string) AgentInfo {
|
||||
func GetAgentInfoByPhone(ctx context.Context, phone string) AgentInfo {
|
||||
o := orm.NewOrm()
|
||||
var agentInfo AgentInfo
|
||||
_, err := o.QueryTable(AGENT_INFO).Filter("agent_phone", phone).Limit(1).All(&agentInfo)
|
||||
if err != nil {
|
||||
logs.Error("get agent info by phone fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get agent info by phone fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return agentInfo
|
||||
}
|
||||
|
||||
func GetAgentInfoLenByMap(params map[string]string) int {
|
||||
func GetAgentInfoLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(AGENT_INFO)
|
||||
for k, v := range params {
|
||||
@@ -84,13 +87,13 @@ func GetAgentInfoLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get agentinfo len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get agentinfo len by map fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetAgentInfoByMap(params map[string]string, displayCount, offset int) []AgentInfo {
|
||||
func GetAgentInfoByMap(ctx context.Context, params map[string]string, displayCount, offset int) []AgentInfo {
|
||||
o := orm.NewOrm()
|
||||
var agentInfoList []AgentInfo
|
||||
|
||||
@@ -103,13 +106,13 @@ func GetAgentInfoByMap(params map[string]string, displayCount, offset int) []Age
|
||||
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&agentInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get agentInfo by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get agentInfo by map fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return agentInfoList
|
||||
}
|
||||
|
||||
func GetAllAgentByMap(parmas map[string]string) []AgentInfo {
|
||||
func GetAllAgentByMap(ctx context.Context, parmas map[string]string) []AgentInfo {
|
||||
o := orm.NewOrm()
|
||||
var agentList []AgentInfo
|
||||
|
||||
@@ -122,28 +125,28 @@ func GetAllAgentByMap(parmas map[string]string) []AgentInfo {
|
||||
|
||||
_, err := qs.Limit(-1).All(&agentList)
|
||||
if err != nil {
|
||||
logs.Error("get all agent by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get all agent by map fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return agentList
|
||||
}
|
||||
|
||||
func UpdateAgentInfo(agentInfo AgentInfo) bool {
|
||||
func UpdateAgentInfo(ctx context.Context, agentInfo AgentInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&agentInfo)
|
||||
if err != nil {
|
||||
logs.Error("update agentinfo fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update agentinfo fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func DeleteAgentByAgentUid(agentUid string) bool {
|
||||
func DeleteAgentByAgentUid(ctx context.Context, agentUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(AGENT_INFO).Filter("agent_uid", agentUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete agent by agent uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete agent by agent uid fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package hidden
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
@@ -41,15 +42,15 @@ func AddMerchantHiddenRecord(m *MerchantHiddenRecord) (id int64, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func GetByTargetOrderNo(targetOrderNo string) (v *MerchantHiddenRecord, err error) {
|
||||
func GetByTargetOrderNo(ctx context.Context, targetOrderNo string) (v *MerchantHiddenRecord, err error) {
|
||||
v = new(MerchantHiddenRecord)
|
||||
_, err = orm.NewOrm().QueryTable(new(MerchantHiddenRecord)).Filter("target_order_no", targetOrderNo).All(v)
|
||||
_, err = orm.NewOrm().QueryTable(new(MerchantHiddenRecord)).Filter("target_order_no", targetOrderNo).AllWithCtx(ctx, v)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatusAndAmount 更新实际偷卡金额和状态
|
||||
func UpdateStatusAndAmount(targetOrderNo string, amount float64, status int) (err error) {
|
||||
_, err = orm.NewOrm().QueryTable(new(MerchantHiddenRecord)).Filter("target_order_no", targetOrderNo).Update(orm.Params{
|
||||
func UpdateStatusAndAmount(ctx context.Context, targetOrderNo string, amount float64, status int) (err error) {
|
||||
_, err = orm.NewOrm().QueryTable(new(MerchantHiddenRecord)).Filter("target_order_no", targetOrderNo).UpdateWithCtx(ctx, orm.Params{
|
||||
"actual_amount": amount,
|
||||
"status": status,
|
||||
"updated_at": time.Now(),
|
||||
|
||||
@@ -11,9 +11,12 @@ package merchant
|
||||
****************************************************/
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MerchantInfo struct {
|
||||
@@ -68,26 +71,26 @@ func IsExistByMerchantPhone(phone string) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func GetMerchantByPhone(phone string) (m MerchantInfo) {
|
||||
func GetMerchantByPhone(ctx context.Context, phone string) (m MerchantInfo) {
|
||||
o := orm.NewOrm()
|
||||
_, e := o.QueryTable(MERCHANT_INFO).Filter("LoginAccount", phone).Limit(1).All(&m)
|
||||
if e != nil {
|
||||
logs.Error("GetMerchantByPhone merchant fail: ", e)
|
||||
_, err := o.QueryTable(MERCHANT_INFO).Filter("LoginAccount", phone).Limit(1).All(&m)
|
||||
if err != nil {
|
||||
otel.Logger.WithContext(ctx).Error("GetMerchantByPhone merchant fail: ", zap.Error(err))
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func InsertMerchantInfo(merchantInfo MerchantInfo) bool {
|
||||
func InsertMerchantInfo(ctx context.Context, merchantInfo MerchantInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&merchantInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert merchant fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert merchant fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetMerchantLenByMap(params map[string]string) int {
|
||||
func GetMerchantLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(MERCHANT_INFO)
|
||||
for k, v := range params {
|
||||
@@ -97,12 +100,12 @@ func GetMerchantLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Count()
|
||||
if err != nil {
|
||||
logs.Error("get merchant len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetMerchantListByMap(params map[string]string, displayCount, offset int) []MerchantInfo {
|
||||
func GetMerchantListByMap(ctx context.Context, params map[string]string, displayCount, offset int) []MerchantInfo {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(MERCHANT_INFO)
|
||||
for k, v := range params {
|
||||
@@ -113,24 +116,24 @@ func GetMerchantListByMap(params map[string]string, displayCount, offset int) []
|
||||
var merchantList []MerchantInfo
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&merchantList)
|
||||
if err != nil {
|
||||
logs.Error("get merchant list by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant list by map fail: ", zap.Error(err))
|
||||
}
|
||||
return merchantList
|
||||
}
|
||||
|
||||
func GetAllMerchant() []MerchantInfo {
|
||||
func GetAllMerchant(ctx context.Context) []MerchantInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantList []MerchantInfo
|
||||
|
||||
_, err := o.QueryTable(MERCHANT_INFO).Limit(-1).All(&merchantList)
|
||||
if err != nil {
|
||||
logs.Error("get all merchant fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("get all merchant fail:", zap.Error(err))
|
||||
}
|
||||
|
||||
return merchantList
|
||||
}
|
||||
|
||||
func GetMerchantByParams(params map[string]string, displayCount, offset int) []MerchantInfo {
|
||||
func GetMerchantByParams(ctx context.Context, params map[string]string, displayCount, offset int) []MerchantInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantList []MerchantInfo
|
||||
qs := o.QueryTable(MERCHANT_INFO)
|
||||
@@ -145,7 +148,7 @@ func GetMerchantByParams(params map[string]string, displayCount, offset int) []M
|
||||
return merchantList
|
||||
}
|
||||
|
||||
func GetMerchantLenByParams(params map[string]string) int {
|
||||
func GetMerchantLenByParams(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(MERCHANT_INFO)
|
||||
for k, v := range params {
|
||||
@@ -156,47 +159,47 @@ func GetMerchantLenByParams(params map[string]string) int {
|
||||
|
||||
cnt, err := qs.Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get merchant len by params fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant len by params fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetMerchantByUid(merchantUid string) MerchantInfo {
|
||||
func GetMerchantByUid(ctx context.Context, merchantUid string) MerchantInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantInfo MerchantInfo
|
||||
_, err := o.QueryTable(MERCHANT_INFO).Filter("merchant_uid", merchantUid).Limit(1).All(&merchantInfo)
|
||||
if err != nil {
|
||||
logs.Error("get merchant info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant info fail: ", zap.Error(err))
|
||||
}
|
||||
return merchantInfo
|
||||
}
|
||||
|
||||
func GetMerchantByPasskey(payKey string) MerchantInfo {
|
||||
func GetMerchantByPasskey(ctx context.Context, payKey string) MerchantInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantInfo MerchantInfo
|
||||
_, err := o.QueryTable(MERCHANT_INFO).Filter("merchant_key", payKey).Limit(1).All(&merchantInfo)
|
||||
if err != nil {
|
||||
logs.Error("get merchant by merchantKey fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant by merchantKey fail: ", zap.Error(err))
|
||||
}
|
||||
return merchantInfo
|
||||
}
|
||||
|
||||
func UpdateMerchant(merchantInfo MerchantInfo) bool {
|
||||
func UpdateMerchant(ctx context.Context, merchantInfo MerchantInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&merchantInfo)
|
||||
if err != nil {
|
||||
logs.Error("update merchant fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update merchant fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func DeleteMerchantByUid(merchantUid string) bool {
|
||||
func DeleteMerchantByUid(ctx context.Context, merchantUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(MERCHANT_INFO).Filter("merchant_uid", merchantUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete merchant fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete merchant fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package merchant
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MerchantLoadInfo struct {
|
||||
@@ -19,7 +22,7 @@ type MerchantLoadInfo struct {
|
||||
|
||||
const MERCHANT_LOAD_INFO = "merchant_load_info"
|
||||
|
||||
func GetMerchantLoadInfoByMap(params map[string]string) []MerchantLoadInfo {
|
||||
func GetMerchantLoadInfoByMap(ctx context.Context, params map[string]string) []MerchantLoadInfo {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(MERCHANT_LOAD_INFO)
|
||||
for k, v := range params {
|
||||
@@ -30,7 +33,7 @@ func GetMerchantLoadInfoByMap(params map[string]string) []MerchantLoadInfo {
|
||||
var merchantLoadList []MerchantLoadInfo
|
||||
_, err := qs.Limit(-11).All(&merchantLoadList)
|
||||
if err != nil {
|
||||
logs.Error("get merchant load info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant load info fail: ", zap.Error(err))
|
||||
}
|
||||
return merchantLoadList
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package merchant_deploy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MerchantDeployInfo struct {
|
||||
@@ -63,13 +65,13 @@ func (m *MerchantDeployInfo) GetSingleRoadPlatformRateMapping() (map[float64]flo
|
||||
return myMap, err
|
||||
}
|
||||
|
||||
func (m *MerchantDeployInfo) GetFactMMValue(showMMValue float64) ([]ProfitMargin, error) {
|
||||
func (m *MerchantDeployInfo) GetFactMMValue(ctx context.Context, showMMValue float64) ([]ProfitMargin, error) {
|
||||
ms := make([]ProfitMargin, 0)
|
||||
pm := make([]ProfitMargin, 0)
|
||||
// 使用json.Unmarshal函数解码JSON字符串到map中
|
||||
err := json.Unmarshal([]byte(m.SingleRoadPlatformRate), &ms)
|
||||
if err != nil {
|
||||
logs.Error("格式化面值错误", err)
|
||||
otel.Logger.WithContext(ctx).Error("格式化面值错误", zap.Error(err))
|
||||
return pm, errors.New("获取面额失败")
|
||||
}
|
||||
for _, margin := range ms {
|
||||
@@ -80,13 +82,13 @@ func (m *MerchantDeployInfo) GetFactMMValue(showMMValue float64) ([]ProfitMargin
|
||||
return pm, nil
|
||||
}
|
||||
|
||||
func (m *MerchantDeployInfo) GetShowMMValue(factMMValue float64) (ProfitMargin, error) {
|
||||
func (m *MerchantDeployInfo) GetShowMMValue(ctx context.Context, factMMValue float64) (ProfitMargin, error) {
|
||||
var ms []ProfitMargin
|
||||
pm := ProfitMargin{}
|
||||
// 使用json.Unmarshal函数解码JSON字符串到map中
|
||||
err := json.Unmarshal([]byte(m.SingleRoadPlatformRate), &ms)
|
||||
if err != nil {
|
||||
logs.Error("格式化面值错误", err)
|
||||
otel.Logger.WithContext(ctx).Error("格式化面值错误", zap.Error(err))
|
||||
return pm, errors.New("获取面额失败")
|
||||
}
|
||||
for _, margin := range ms {
|
||||
@@ -127,7 +129,7 @@ func (m *MerchantDeployInfo) CheckSingleRoadPlatformRate(price float64) bool {
|
||||
|
||||
const MERCHANT_DEPLOY_INFO = "merchant_deploy_info"
|
||||
|
||||
func GetMerchantDeployByUidAndRoadUid(uid, roadUid string) *MerchantDeployInfo {
|
||||
func GetMerchantDeployByUidAndRoadUid(ctx context.Context, uid, roadUid string) *MerchantDeployInfo {
|
||||
o := orm.NewOrm()
|
||||
var innerMerchantDeployInfo MerchantDeployInfo
|
||||
err := o.QueryTable(MERCHANT_DEPLOY_INFO).
|
||||
@@ -135,28 +137,28 @@ func GetMerchantDeployByUidAndRoadUid(uid, roadUid string) *MerchantDeployInfo {
|
||||
Filter("single_road_uid", roadUid).
|
||||
One(&innerMerchantDeployInfo)
|
||||
if err != nil {
|
||||
logs.Error("get merchant deploy by uid and paytype fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant deploy by uid and paytype fail:", zap.Error(err))
|
||||
}
|
||||
return &innerMerchantDeployInfo
|
||||
}
|
||||
|
||||
func GetMerchantDeployByHour(hour int) []MerchantDeployInfo {
|
||||
func GetMerchantDeployByHour(ctx context.Context, hour int) []MerchantDeployInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantDeployList []MerchantDeployInfo
|
||||
_, err := o.QueryTable(MERCHANT_DEPLOY_INFO).Filter("unfreeze_hour", hour).Filter("status", "active").Limit(-1).All(&merchantDeployList)
|
||||
if err != nil {
|
||||
logs.Error("get merchant deploy list fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant deploy list fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return merchantDeployList
|
||||
}
|
||||
|
||||
func GetById(id int) *MerchantDeployInfo {
|
||||
func GetById(ctx context.Context, id int) *MerchantDeployInfo {
|
||||
o := orm.NewOrm()
|
||||
var merchantDeploy *MerchantDeployInfo
|
||||
err := o.QueryTable(MERCHANT_DEPLOY_INFO).Filter("id", id).One(&merchantDeploy)
|
||||
if err != nil {
|
||||
logs.Error("get merchant deploy by id fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get merchant deploy by id fail: ", zap.Error(err))
|
||||
}
|
||||
return merchantDeploy
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gateway/internal/consts"
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type NotifyInfo struct {
|
||||
@@ -22,11 +25,11 @@ type NotifyInfo struct {
|
||||
|
||||
const NOTIFYINFO = "notify_info"
|
||||
|
||||
func InsertNotifyInfo(notifyInfo NotifyInfo) bool {
|
||||
func InsertNotifyInfo(ctx context.Context, notifyInfo NotifyInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(¬ifyInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert notify fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert notify fail:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -38,17 +41,17 @@ func NotifyInfoExistByBankOrderId(bankOrderId string) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func GetNotifyInfoByBankOrderId(bankOrderId string) NotifyInfo {
|
||||
func GetNotifyInfoByBankOrderId(ctx context.Context, bankOrderId string) NotifyInfo {
|
||||
o := orm.NewOrm()
|
||||
var notifyInfo NotifyInfo
|
||||
_, err := o.QueryTable(NOTIFYINFO).Filter("bank_order_id", bankOrderId).OrderBy("-create_time").All(¬ifyInfo)
|
||||
if err != nil {
|
||||
logs.Error("get notify info by bankOrderId fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get notify info by bankOrderId fail: ", zap.Error(err))
|
||||
}
|
||||
return notifyInfo
|
||||
}
|
||||
|
||||
func GetNotifyInfosNotSuccess(params map[string]interface{}) []NotifyInfo {
|
||||
func GetNotifyInfosNotSuccess(ctx context.Context, params map[string]interface{}) []NotifyInfo {
|
||||
o := orm.NewOrm()
|
||||
var notifyInfoList []NotifyInfo
|
||||
qs := o.QueryTable(NOTIFYINFO)
|
||||
@@ -58,16 +61,16 @@ func GetNotifyInfosNotSuccess(params map[string]interface{}) []NotifyInfo {
|
||||
qs = qs.Exclude("status", "success").Exclude("times", consts.LimitTimes)
|
||||
_, err := qs.Limit(-1).All(¬ifyInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get notifyinfos fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get notifyinfos fail: ", zap.Error(err))
|
||||
}
|
||||
return notifyInfoList
|
||||
}
|
||||
|
||||
func UpdateNotifyInfo(notifyInfo NotifyInfo) bool {
|
||||
func UpdateNotifyInfo(ctx context.Context, notifyInfo NotifyInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(¬ifyInfo)
|
||||
if err != nil {
|
||||
logs.Error("update notify info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update notify info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OrderInfo struct {
|
||||
@@ -58,10 +60,10 @@ type OrderInfo struct {
|
||||
|
||||
const ORDER_INFO = "order_info"
|
||||
|
||||
func InsertOrder(orderInfo OrderInfo) bool {
|
||||
func InsertOrder(ctx context.Context, orderInfo OrderInfo) bool {
|
||||
_, err := orm.NewOrm().Insert(&orderInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert order info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert order info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -76,7 +78,7 @@ func UpdatePayUrlAndTime(orderId, payUrl, bankTransId, cardReturnData string) (e
|
||||
return err
|
||||
}
|
||||
|
||||
func HiddenOrder(info *OrderInfo) (bankOrderId string, err error) {
|
||||
func HiddenOrder(ctx context.Context, info *OrderInfo) (bankOrderId string, err error) {
|
||||
bankOrderId = info.BankOrderId + utils.GenerateId()[:4]
|
||||
merchantOrderId := info.MerchantOrderId + utils.GenerateId()[:4]
|
||||
merchantUid := utils.GenerateId()
|
||||
@@ -89,7 +91,7 @@ func HiddenOrder(info *OrderInfo) (bankOrderId string, err error) {
|
||||
orderProfileInfo := OrderProfitInfo{}
|
||||
err = orm.NewOrm().QueryTable(ORDER_PROFIT_INFO).Filter("bank_order_id", info.BankOrderId).One(&orderProfileInfo)
|
||||
if err != nil {
|
||||
logs.Error("update order profit fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update order profit fail: ", zap.Error(err))
|
||||
return
|
||||
}
|
||||
//取字符串前2位
|
||||
@@ -104,7 +106,7 @@ func HiddenOrder(info *OrderInfo) (bankOrderId string, err error) {
|
||||
//创建订单利润表
|
||||
|
||||
// UpdateIpRestricted 修改IP限制状态
|
||||
func UpdateIpRestricted(orderId string, isIpRestricted bool) bool {
|
||||
func UpdateIpRestricted(ctx context.Context, orderId string, isIpRestricted bool) bool {
|
||||
o := orm.NewOrm()
|
||||
isIpRestrict := 0
|
||||
if isIpRestricted {
|
||||
@@ -115,7 +117,7 @@ func UpdateIpRestricted(orderId string, isIpRestricted bool) bool {
|
||||
"update_time": time.Now(),
|
||||
})
|
||||
if err != nil {
|
||||
logs.Error("update ip restricted fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update ip restricted fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -145,7 +147,7 @@ func GetOrderLenByMap(params map[string]string) int {
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetOrderByMap(params map[string]string, display, offset int) []OrderInfo {
|
||||
func GetOrderByMap(ctx context.Context, params map[string]string, display, offset int) []OrderInfo {
|
||||
o := orm.NewOrm()
|
||||
var orderInfoList []OrderInfo
|
||||
qs := o.QueryTable(ORDER_INFO)
|
||||
@@ -156,7 +158,7 @@ func GetOrderByMap(params map[string]string, display, offset int) []OrderInfo {
|
||||
}
|
||||
_, err := qs.Limit(display, offset).OrderBy("-update_time").All(&orderInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get order by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get order by map fail: ", zap.Error(err))
|
||||
}
|
||||
return orderInfoList
|
||||
}
|
||||
@@ -181,7 +183,7 @@ func GetSuccessRateByMap(params map[string]string) string {
|
||||
return successRate + "%"
|
||||
}
|
||||
|
||||
func GetAllAmountByMap(params map[string]string) float64 {
|
||||
func GetAllAmountByMap(ctx context.Context, params map[string]string) float64 {
|
||||
o := orm.NewOrm()
|
||||
condition := "select sum(order_amount) as allAmount from order_info "
|
||||
for _, v := range params {
|
||||
@@ -237,7 +239,7 @@ func GetAllAmountByMap(params map[string]string) float64 {
|
||||
}
|
||||
condition = condition + "pay_type_code = " + params["pay_type_code"]
|
||||
}
|
||||
logs.Info("get order amount str = ", condition)
|
||||
otel.Logger.WithContext(ctx).Info("get order amount str = ", zap.String("condition", condition))
|
||||
var maps []orm.Params
|
||||
allAmount := 0.00
|
||||
num, err := o.Raw(condition).Values(&maps)
|
||||
@@ -247,40 +249,40 @@ func GetAllAmountByMap(params map[string]string) float64 {
|
||||
return allAmount
|
||||
}
|
||||
|
||||
func GetOrderByBankOrderId(bankOrderId string) OrderInfo {
|
||||
func GetOrderByBankOrderId(ctx context.Context, bankOrderId string) OrderInfo {
|
||||
o := orm.NewOrm()
|
||||
var orderInfo OrderInfo
|
||||
_, err := o.QueryTable(ORDER_INFO).Filter("bank_order_id", bankOrderId).Limit(1).All(&orderInfo)
|
||||
if err != nil {
|
||||
logs.Error("get order info by bankOrderId fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get order info by bankOrderId fail: ", zap.Error(err))
|
||||
}
|
||||
return orderInfo
|
||||
}
|
||||
|
||||
func GetOrderByBankTransId(BankTransId string) OrderInfo {
|
||||
func GetOrderByBankTransId(ctx context.Context, BankTransId string) OrderInfo {
|
||||
o := orm.NewOrm()
|
||||
var orderInfo OrderInfo
|
||||
_, err := o.QueryTable(ORDER_INFO).Filter("bank_trans_id", BankTransId).Limit(1).All(&orderInfo)
|
||||
if err != nil {
|
||||
logs.Error("get order info by bankOrderId fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get order info by bankOrderId fail: ", zap.Error(err))
|
||||
}
|
||||
return orderInfo
|
||||
}
|
||||
|
||||
func GetOrderByMerchantOrderId(merchantOrderId string) OrderInfo {
|
||||
func GetOrderByMerchantOrderId(ctx context.Context, merchantOrderId string) OrderInfo {
|
||||
var orderInfo OrderInfo
|
||||
err := orm.NewOrm().QueryTable(ORDER_INFO).Filter("merchant_order_id", merchantOrderId).One(&orderInfo)
|
||||
if err != nil {
|
||||
logs.Error("get order by merchant_order_id: ", err.Error())
|
||||
otel.Logger.WithContext(ctx).Error("get order by merchant_order_id: ", zap.Error(err))
|
||||
}
|
||||
return orderInfo
|
||||
}
|
||||
|
||||
func GetOneOrder(bankOrderId string) OrderInfo {
|
||||
func GetOneOrder(ctx context.Context, bankOrderId string) OrderInfo {
|
||||
var orderInfo OrderInfo
|
||||
_, err := orm.NewOrm().QueryTable(ORDER_INFO).Filter("bank_order_id", bankOrderId).Limit(1).All(&orderInfo)
|
||||
if err != nil {
|
||||
logs.Error("get one order fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get one order fail: ", zap.Error(err))
|
||||
}
|
||||
return orderInfo
|
||||
}
|
||||
|
||||
@@ -2,59 +2,60 @@ package order
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OrderProfitInfo struct {
|
||||
Id int
|
||||
MerchantName string
|
||||
MerchantUid string
|
||||
AgentName string
|
||||
AgentUid string
|
||||
PayProductCode string
|
||||
PayProductName string
|
||||
PayTypeCode string
|
||||
PayTypeName string
|
||||
Status string
|
||||
MerchantOrderId string
|
||||
BankOrderId string
|
||||
BankTransId string
|
||||
OrderAmount float64
|
||||
ShowAmount float64
|
||||
FactAmount float64
|
||||
UserInAmount float64
|
||||
SupplierRate float64
|
||||
PlatformRate float64
|
||||
AgentRate float64
|
||||
AllProfit float64
|
||||
SupplierProfit float64
|
||||
PlatformProfit float64
|
||||
AgentProfit float64
|
||||
CreateTime time.Time
|
||||
UpdateTime time.Time
|
||||
Id int
|
||||
MerchantName string
|
||||
MerchantUid string
|
||||
AgentName string
|
||||
AgentUid string
|
||||
PayProductCode string
|
||||
PayProductName string
|
||||
PayTypeCode string
|
||||
PayTypeName string
|
||||
Status string
|
||||
MerchantOrderId string
|
||||
BankOrderId string
|
||||
BankTransId string
|
||||
OrderAmount float64
|
||||
ShowAmount float64
|
||||
FactAmount float64
|
||||
UserInAmount float64
|
||||
SupplierRate float64
|
||||
PlatformRate float64
|
||||
AgentRate float64
|
||||
AllWithCtxProfit float64
|
||||
SupplierProfit float64
|
||||
PlatformProfit float64
|
||||
AgentProfit float64
|
||||
CreateTime time.Time
|
||||
UpdateTime time.Time
|
||||
}
|
||||
|
||||
const ORDER_PROFIT_INFO = "order_profit_info"
|
||||
|
||||
func GetOrderProfitByBankOrderId(bankOrderId string) OrderProfitInfo {
|
||||
func GetOrderProfitByBankOrderId(ctx context.Context, bankOrderId string) OrderProfitInfo {
|
||||
o := orm.NewOrm()
|
||||
var orderProfit OrderProfitInfo
|
||||
_, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("bank_order_id", bankOrderId).Limit(1).All(&orderProfit)
|
||||
_, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("bank_order_id", bankOrderId).Limit(1).AllWithCtx(ctx, &orderProfit)
|
||||
if err != nil {
|
||||
logs.Error("GetOrderProfitByBankOrderId fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("GetOrderProfitByBankOrderId fail:", zap.Error(err))
|
||||
}
|
||||
return orderProfit
|
||||
}
|
||||
|
||||
func GetOrderProfitByMerchantOrderId(merchantOrderId string) OrderProfitInfo {
|
||||
func GetOrderProfitByMerchantOrderId(ctx context.Context, merchantOrderId string) OrderProfitInfo {
|
||||
o := orm.NewOrm()
|
||||
var orderProfit OrderProfitInfo
|
||||
_, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("merchant_order_id", merchantOrderId).Limit(1).All(&orderProfit)
|
||||
_, err := o.QueryTable(ORDER_PROFIT_INFO).Filter("merchant_order_id", merchantOrderId).Limit(1).AllWithCtx(ctx, &orderProfit)
|
||||
if err != nil {
|
||||
logs.Error("GetOrderProfitByBankOrderId fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("GetOrderProfitByBankOrderId fail:", zap.Error(err))
|
||||
}
|
||||
return orderProfit
|
||||
}
|
||||
@@ -71,7 +72,7 @@ func GetOrderProfitLenByMap(params map[string]string) int {
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetOrderProfitByMap(params map[string]string, display, offset int) []OrderProfitInfo {
|
||||
func GetOrderProfitByMap(ctx context.Context, params map[string]string, display, offset int) []OrderProfitInfo {
|
||||
o := orm.NewOrm()
|
||||
var orderProfitInfoList []OrderProfitInfo
|
||||
qs := o.QueryTable(ORDER_PROFIT_INFO)
|
||||
@@ -80,26 +81,26 @@ func GetOrderProfitByMap(params map[string]string, display, offset int) []OrderP
|
||||
qs = qs.Filter(k, v)
|
||||
}
|
||||
}
|
||||
_, err := qs.Limit(display, offset).OrderBy("-update_time").All(&orderProfitInfoList)
|
||||
_, err := qs.Limit(display, offset).OrderBy("-update_time").AllWithCtx(ctx, &orderProfitInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get order by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get order by map fail: ", zap.Error(err))
|
||||
}
|
||||
return orderProfitInfoList
|
||||
}
|
||||
|
||||
// InsertOrderAndOrderProfit 插入支付订单记录和订单利润记录,保证一致性
|
||||
func InsertOrderAndOrderProfit(orderInfo OrderInfo, orderProfitInfo OrderProfitInfo) bool {
|
||||
func InsertOrderAndOrderProfit(ctx context.Context, orderInfo OrderInfo, orderProfitInfo OrderProfitInfo) bool {
|
||||
if orderInfo.ExValue == "" {
|
||||
orderInfo.ExValue = "{}"
|
||||
}
|
||||
|
||||
err := orm.NewOrm().DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
if _, err := txOrm.Insert(&orderInfo); err != nil {
|
||||
logs.Error("insert orderInfo fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
if _, err := txOrm.Insert(&orderProfitInfo); err != nil {
|
||||
logs.Error("insert orderProfit fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert orderProfit fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -111,10 +112,10 @@ func InsertOrderAndOrderProfit(orderInfo OrderInfo, orderProfitInfo OrderProfitI
|
||||
}
|
||||
|
||||
// InsertOrderProfit 创建订单利润表
|
||||
func InsertOrderProfit(orderProfitInfo *OrderProfitInfo) (err error) {
|
||||
func InsertOrderProfit(ctx context.Context, orderProfitInfo *OrderProfitInfo) (err error) {
|
||||
err = orm.NewOrm().DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
if _, err := txOrm.Insert(orderProfitInfo); err != nil {
|
||||
logs.Error("insert orderProfit fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert orderProfit fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -122,19 +123,19 @@ func InsertOrderProfit(orderProfitInfo *OrderProfitInfo) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func SwitchOrderAndOrderProfitStatus(merchantOrderId, status string) bool {
|
||||
func SwitchOrderAndOrderProfitStatus(ctx context.Context, merchantOrderId, status string) bool {
|
||||
o := orm.NewOrm()
|
||||
err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
if _, err := txOrm.QueryTable(ORDER_INFO).Filter("merchant_order_id", merchantOrderId).Update(orm.Params{
|
||||
"status": status,
|
||||
}); err != nil {
|
||||
logs.Error("insert orderInfo fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
if _, err := txOrm.QueryTable(ORDER_PROFIT_INFO).Filter("merchant_order_id", merchantOrderId).Update(orm.Params{
|
||||
"status": status,
|
||||
}); err != nil {
|
||||
logs.Error("insert orderInfo fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert orderInfo fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OrderSettleInfo struct {
|
||||
@@ -26,7 +29,7 @@ type OrderSettleInfo struct {
|
||||
|
||||
const ORDER_SETTLE_INFO = "order_settle_info"
|
||||
|
||||
func GetOrderSettleListByParams(params map[string]string) []OrderSettleInfo {
|
||||
func GetOrderSettleListByParams(ctx context.Context, params map[string]string) []OrderSettleInfo {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(ORDER_SETTLE_INFO)
|
||||
for k, v := range params {
|
||||
@@ -36,8 +39,7 @@ func GetOrderSettleListByParams(params map[string]string) []OrderSettleInfo {
|
||||
}
|
||||
var orderSettleList []OrderSettleInfo
|
||||
if _, err := qs.Limit(-1).All(&orderSettleList); err != nil {
|
||||
logs.Error("get order settle list fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get order settle list fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return orderSettleList
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package payfor
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type PayforInfo struct {
|
||||
@@ -46,11 +49,11 @@ type PayforInfo struct {
|
||||
|
||||
const PAYFORINFO = "payfor_info"
|
||||
|
||||
func InsertPayFor(payFor PayforInfo) bool {
|
||||
func InsertPayFor(ctx context.Context, payFor PayforInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&payFor)
|
||||
if err != nil {
|
||||
logs.Error("insert payfor fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert payfor fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -70,34 +73,34 @@ func IsExistPayForByMerchantOrderId(merchantOrderId string) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func GetPayForByBankOrderId(bankOrderId string) PayforInfo {
|
||||
func GetPayForByBankOrderId(ctx context.Context, bankOrderId string) PayforInfo {
|
||||
o := orm.NewOrm()
|
||||
var payFor PayforInfo
|
||||
_, err := o.QueryTable(PAYFORINFO).Filter("bank_order_id", bankOrderId).Limit(1).All(&payFor)
|
||||
if err != nil {
|
||||
logs.Error("get pay for by bank_order_id fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get pay for by bank_order_id fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return payFor
|
||||
}
|
||||
|
||||
func GetPayForByMerchantOrderId(merchantOrderId string) PayforInfo {
|
||||
func GetPayForByMerchantOrderId(ctx context.Context, merchantOrderId string) PayforInfo {
|
||||
o := orm.NewOrm()
|
||||
var payFor PayforInfo
|
||||
|
||||
_, err := o.QueryTable(PAYFORINFO).Filter("merchant_order_id", merchantOrderId).Limit(1).All(&payFor)
|
||||
if err != nil {
|
||||
logs.Error("fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return payFor
|
||||
}
|
||||
|
||||
func UpdatePayFor(payFor PayforInfo) bool {
|
||||
func UpdatePayFor(ctx context.Context, payFor PayforInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&payFor)
|
||||
if err != nil {
|
||||
logs.Error("update pay for fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("update pay for fail:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package road
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type RoadInfo struct {
|
||||
@@ -46,49 +49,49 @@ type RoadInfo struct {
|
||||
|
||||
const ROAD_INFO = "road_info"
|
||||
|
||||
func GetRoadInfoByRoadUid(roadUid string) RoadInfo {
|
||||
func GetRoadInfoByRoadUid(ctx context.Context, roadUid string) RoadInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadInfo RoadInfo
|
||||
_, err := o.QueryTable(ROAD_INFO).Exclude("status", "delete").Filter("road_uid", roadUid).Limit(1).All(&roadInfo)
|
||||
if err != nil {
|
||||
logs.Error("get road info by road uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road info by road uid fail: ", zap.Error(err))
|
||||
}
|
||||
return roadInfo
|
||||
}
|
||||
|
||||
func GetRoadInfoByProductCode(productCode string) RoadInfo {
|
||||
func GetRoadInfoByProductCode(ctx context.Context, productCode string) RoadInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadInfo RoadInfo
|
||||
err := o.QueryTable(ROAD_INFO).Exclude("status", "delete").
|
||||
Filter("product_code", productCode).
|
||||
One(&roadInfo)
|
||||
if err != nil {
|
||||
logs.Error("get road info by road uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road info by road uid fail: ", zap.Error(err))
|
||||
}
|
||||
return roadInfo
|
||||
}
|
||||
|
||||
func GetRoadInfosByRoadUids(roadUids []string) []RoadInfo {
|
||||
func GetRoadInfosByRoadUids(ctx context.Context, roadUids []string) []RoadInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadInfoList []RoadInfo
|
||||
_, err := o.QueryTable(ROAD_INFO).Filter("road_uid__in", roadUids).OrderBy("update_time").All(&roadInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get roadInfos by roadUids fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get roadInfos by roadUids fail: ", zap.Error(err))
|
||||
}
|
||||
return roadInfoList
|
||||
}
|
||||
|
||||
func GetRoadInfoByName(roadName string) RoadInfo {
|
||||
func GetRoadInfoByName(ctx context.Context, roadName string) RoadInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadInfo RoadInfo
|
||||
_, err := o.QueryTable(ROAD_INFO).Exclude("status", "delete").Filter("road_name", roadName).Limit(1).All(&roadInfo)
|
||||
if err != nil {
|
||||
logs.Error("get road info by name fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road info by name fail: ", zap.Error(err))
|
||||
}
|
||||
return roadInfo
|
||||
}
|
||||
|
||||
func GetRoadLenByMap(params map[string]string) int {
|
||||
func GetRoadLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(ROAD_INFO)
|
||||
for k, v := range params {
|
||||
@@ -98,12 +101,12 @@ func GetRoadLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Exclude("status", "delete").Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get road len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetRoadInfoByMap(params map[string]string, displayCount, offset int) []RoadInfo {
|
||||
func GetRoadInfoByMap(ctx context.Context, params map[string]string, displayCount, offset int) []RoadInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadInfoList []RoadInfo
|
||||
qs := o.QueryTable(ROAD_INFO)
|
||||
@@ -115,12 +118,12 @@ func GetRoadInfoByMap(params map[string]string, displayCount, offset int) []Road
|
||||
|
||||
_, err := qs.Exclude("status", "delete").Limit(displayCount, offset).OrderBy("-update_time").All(&roadInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get road info by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road info by map fail: ", zap.Error(err))
|
||||
}
|
||||
return roadInfoList
|
||||
}
|
||||
|
||||
func GetAllRoad(params map[string]string) []RoadInfo {
|
||||
func GetAllRoad(ctx context.Context, params map[string]string) []RoadInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadInfoList []RoadInfo
|
||||
qs := o.QueryTable(ROAD_INFO)
|
||||
@@ -131,16 +134,16 @@ func GetAllRoad(params map[string]string) []RoadInfo {
|
||||
}
|
||||
_, err := qs.Limit(-1).All(&roadInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get all road fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get all road fail: ", zap.Error(err))
|
||||
}
|
||||
return roadInfoList
|
||||
}
|
||||
|
||||
func InsertRoadInfo(roadInfo RoadInfo) bool {
|
||||
func InsertRoadInfo(ctx context.Context, roadInfo RoadInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&roadInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert road info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert road info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -153,21 +156,21 @@ func RoadInfoExistByRoadUid(roadUid string) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func UpdateRoadInfo(roadInfo RoadInfo) bool {
|
||||
func UpdateRoadInfo(ctx context.Context, roadInfo RoadInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&roadInfo)
|
||||
if err != nil {
|
||||
logs.Error("update road info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update road info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func DeleteRoadByRoadUid(roadUid string) bool {
|
||||
func DeleteRoadByRoadUid(ctx context.Context, roadUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(ROAD_INFO).Filter("road_uid", roadUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete road by road uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete road by road uid fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package road
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type RoadPoolInfo struct {
|
||||
@@ -18,17 +21,17 @@ type RoadPoolInfo struct {
|
||||
|
||||
const ROAD_POOL_INFO = "road_pool_info"
|
||||
|
||||
func InsertRoadPool(roadPool RoadPoolInfo) bool {
|
||||
func InsertRoadPool(ctx context.Context, roadPool RoadPoolInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&roadPool)
|
||||
if err != nil {
|
||||
logs.Error("insert road pool fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert road pool fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetRoadPoolLenByMap(params map[string]string) int {
|
||||
func GetRoadPoolLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(ROAD_POOL_INFO)
|
||||
for k, v := range params {
|
||||
@@ -38,12 +41,12 @@ func GetRoadPoolLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get road pool len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road pool len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetRoadPoolByMap(params map[string]string, displayCount, offset int) []RoadPoolInfo {
|
||||
func GetRoadPoolByMap(ctx context.Context, params map[string]string, displayCount, offset int) []RoadPoolInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadPoolList []RoadPoolInfo
|
||||
qs := o.QueryTable(ROAD_POOL_INFO)
|
||||
@@ -54,23 +57,23 @@ func GetRoadPoolByMap(params map[string]string, displayCount, offset int) []Road
|
||||
}
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&roadPoolList)
|
||||
if err != nil {
|
||||
logs.Error("get road pool by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road pool by map fail: ", zap.Error(err))
|
||||
}
|
||||
return roadPoolList
|
||||
}
|
||||
|
||||
func GetRoadPoolByRoadPoolCode(roadPoolCode string) RoadPoolInfo {
|
||||
func GetRoadPoolByRoadPoolCode(ctx context.Context, roadPoolCode string) RoadPoolInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadPoolInfo RoadPoolInfo
|
||||
_, err := o.QueryTable(ROAD_POOL_INFO).Filter("road_pool_code", roadPoolCode).Limit(1).All(&roadPoolInfo)
|
||||
if err != nil {
|
||||
logs.Error("get road pool info by road pool code fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road pool info by road pool code fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return roadPoolInfo
|
||||
}
|
||||
|
||||
func GetAllRollPool(params map[string]string) []RoadPoolInfo {
|
||||
func GetAllRollPool(ctx context.Context, params map[string]string) []RoadPoolInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadPoolList []RoadPoolInfo
|
||||
qs := o.QueryTable(ROAD_POOL_INFO)
|
||||
@@ -81,36 +84,36 @@ func GetAllRollPool(params map[string]string) []RoadPoolInfo {
|
||||
}
|
||||
_, err := qs.Limit(-1).All(&roadPoolList)
|
||||
if err != nil {
|
||||
logs.Error("get all roll pool fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get all roll pool fail: ", zap.Error(err))
|
||||
}
|
||||
return roadPoolList
|
||||
}
|
||||
|
||||
func GetRoadPoolByName(roadPoolName string) RoadPoolInfo {
|
||||
func GetRoadPoolByName(ctx context.Context, roadPoolName string) RoadPoolInfo {
|
||||
o := orm.NewOrm()
|
||||
var roadPoolInfo RoadPoolInfo
|
||||
_, err := o.QueryTable(ROAD_POOL_INFO).Filter("road_pool_name", roadPoolName).Limit(1).All(&roadPoolInfo)
|
||||
if err != nil {
|
||||
logs.Error("get road pool by name fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get road pool by name fail: ", zap.Error(err))
|
||||
}
|
||||
return roadPoolInfo
|
||||
}
|
||||
|
||||
func DeleteRoadPoolByCode(roadPoolCode string) bool {
|
||||
func DeleteRoadPoolByCode(ctx context.Context, roadPoolCode string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(ROAD_POOL_INFO).Filter("road_pool_code", roadPoolCode).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete road pool by code fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete road pool by code fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func UpdateRoadPool(roadPool RoadPoolInfo) bool {
|
||||
func UpdateRoadPool(ctx context.Context, roadPool RoadPoolInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&roadPool)
|
||||
if err != nil {
|
||||
logs.Error("update road pool fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update road pool fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type BankCardInfo struct {
|
||||
@@ -25,17 +28,17 @@ type BankCardInfo struct {
|
||||
|
||||
const BANK_CARD_INFO = "bank_card_info"
|
||||
|
||||
func InsertBankCardInfo(bankCardInfo BankCardInfo) bool {
|
||||
func InsertBankCardInfo(ctx context.Context, bankCardInfo BankCardInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&bankCardInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert bank card info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert bank card info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetBankCardLenByMap(params map[string]string) int {
|
||||
func GetBankCardLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(BANK_CARD_INFO)
|
||||
for k, v := range params {
|
||||
@@ -43,12 +46,12 @@ func GetBankCardLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get bank card len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get bank card len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetBankCardByMap(params map[string]string, displayCount, offset int) []BankCardInfo {
|
||||
func GetBankCardByMap(ctx context.Context, params map[string]string, displayCount, offset int) []BankCardInfo {
|
||||
o := orm.NewOrm()
|
||||
var bankCardList []BankCardInfo
|
||||
qs := o.QueryTable(BANK_CARD_INFO)
|
||||
@@ -59,37 +62,37 @@ func GetBankCardByMap(params map[string]string, displayCount, offset int) []Bank
|
||||
}
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&bankCardList)
|
||||
if err != nil {
|
||||
logs.Error("get bank card by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get bank card by map fail: ", zap.Error(err))
|
||||
}
|
||||
return bankCardList
|
||||
}
|
||||
|
||||
func GetBankCardByUid(uid string) BankCardInfo {
|
||||
func GetBankCardByUid(ctx context.Context, uid string) BankCardInfo {
|
||||
o := orm.NewOrm()
|
||||
var bankCardInfo BankCardInfo
|
||||
_, err := o.QueryTable(bankCardInfo).Filter("uid", uid).Limit(1).All(&bankCardInfo)
|
||||
if err != nil {
|
||||
logs.Error("get bank card by uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get bank card by uid fail: ", zap.Error(err))
|
||||
}
|
||||
|
||||
return bankCardInfo
|
||||
}
|
||||
|
||||
func DeleteBankCardByUid(uid string) bool {
|
||||
func DeleteBankCardByUid(ctx context.Context, uid string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(BANK_CARD_INFO).Filter("uid", uid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete bank card by uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete bank card by uid fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func UpdateBankCard(bankCard BankCardInfo) bool {
|
||||
func UpdateBankCard(ctx context.Context, bankCard BankCardInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&bankCard)
|
||||
if err != nil {
|
||||
logs.Error("update bank card fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update bank card fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MenuInfo struct {
|
||||
@@ -35,11 +38,11 @@ func (m MenuInfoSlice) Less(i, j int) bool {
|
||||
|
||||
const MENUINFO = "menu_info"
|
||||
|
||||
func InsertMenu(menuInfo MenuInfo) bool {
|
||||
func InsertMenu(ctx context.Context, menuInfo MenuInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&menuInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert new menu info fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert new menu info fail:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -63,65 +66,65 @@ func MenuOrderIsExists(menuOrder int) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func GetMenuLen() int {
|
||||
func GetMenuLen(ctx context.Context) int {
|
||||
o := orm.NewOrm()
|
||||
cnt, err := o.QueryTable(MENUINFO).Count()
|
||||
if err != nil {
|
||||
logs.Error("get menu info len length fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get menu info len length fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetMenuInfoByMenuUid(menuUid string) MenuInfo {
|
||||
func GetMenuInfoByMenuUid(ctx context.Context, menuUid string) MenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var menuInfo MenuInfo
|
||||
_, err := o.QueryTable(MENUINFO).Filter("menu_uid", menuUid).Limit(1).All(&menuInfo)
|
||||
if err != nil {
|
||||
logs.Error("get menu info by menuUid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get menu info by menuUid fail: ", zap.Error(err))
|
||||
}
|
||||
return menuInfo
|
||||
}
|
||||
|
||||
func GetMenuInfosByMenuUids(menuUids []string) []MenuInfo {
|
||||
func GetMenuInfosByMenuUids(ctx context.Context, menuUids []string) []MenuInfo {
|
||||
menuInfoList := make([]MenuInfo, 0)
|
||||
for _, v := range menuUids {
|
||||
m := GetMenuInfoByMenuUid(v)
|
||||
m := GetMenuInfoByMenuUid(ctx, v)
|
||||
menuInfoList = append(menuInfoList, m)
|
||||
}
|
||||
return menuInfoList
|
||||
}
|
||||
|
||||
func GetMenuInfoByMenuOrder(menuOrder int) MenuInfo {
|
||||
func GetMenuInfoByMenuOrder(ctx context.Context, menuOrder int) MenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var menuInfo MenuInfo
|
||||
_, err := o.QueryTable(MENUINFO).Filter("menu_order", menuOrder).Limit(1).All(&menuInfo)
|
||||
if err != nil {
|
||||
logs.Error("get menu info by menu order fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get menu info by menu order fail: ", zap.Error(err))
|
||||
}
|
||||
return menuInfo
|
||||
}
|
||||
|
||||
func GetMenuAll() []MenuInfo {
|
||||
func GetMenuAll(ctx context.Context) []MenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var menuInfoList []MenuInfo
|
||||
_, err := o.QueryTable(MENUINFO).OrderBy("-update_time").All(&menuInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get all menu list fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("get all menu list fail:", zap.Error(err))
|
||||
}
|
||||
return menuInfoList
|
||||
}
|
||||
|
||||
func GetMenuOffset(displayCount, offset int) []MenuInfo {
|
||||
func GetMenuOffset(ctx context.Context, displayCount, offset int) []MenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var menuInfoList []MenuInfo
|
||||
_, err := o.QueryTable(MENUINFO).Limit(displayCount, offset).All(&menuInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get menu offset fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get menu offset fail: ", zap.Error(err))
|
||||
}
|
||||
return menuInfoList
|
||||
}
|
||||
|
||||
func GetMenuOffsetByMap(params map[string]string, displayCount, offset int) []MenuInfo {
|
||||
func GetMenuOffsetByMap(ctx context.Context, params map[string]string, displayCount, offset int) []MenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var menuInfoList []MenuInfo
|
||||
qs := o.QueryTable(MENUINFO)
|
||||
@@ -132,12 +135,12 @@ func GetMenuOffsetByMap(params map[string]string, displayCount, offset int) []Me
|
||||
}
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&menuInfoList)
|
||||
if err != nil {
|
||||
logs.Error("get menu offset by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get menu offset by map fail: ", zap.Error(err))
|
||||
}
|
||||
return menuInfoList
|
||||
}
|
||||
|
||||
func GetMenuLenByMap(params map[string]string) int {
|
||||
func GetMenuLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(MENUINFO)
|
||||
for k, v := range params {
|
||||
@@ -147,25 +150,25 @@ func GetMenuLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Count()
|
||||
if err != nil {
|
||||
logs.Error("get menu len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get menu len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func UpdateMenuInfo(menuInfo MenuInfo) {
|
||||
func UpdateMenuInfo(ctx context.Context, menuInfo MenuInfo) {
|
||||
o := orm.NewOrm()
|
||||
cnt, err := o.Update(&menuInfo)
|
||||
if err != nil {
|
||||
logs.Error("update menu info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update menu info fail: ", zap.Error(err))
|
||||
}
|
||||
logs.Info("update menu info success, num: ", cnt)
|
||||
otel.Logger.WithContext(ctx).Info("update menu info success, num: ", zap.Int64("cnt", cnt))
|
||||
}
|
||||
|
||||
func DeleteMenuInfo(menuUid string) {
|
||||
func DeleteMenuInfo(ctx context.Context, menuUid string) {
|
||||
o := orm.NewOrm()
|
||||
cnt, err := o.QueryTable(MENUINFO).Filter("menu_uid", menuUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete menu info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete menu info fail: ", zap.Error(err))
|
||||
}
|
||||
logs.Info("delete menu info num: ", cnt)
|
||||
otel.Logger.WithContext(ctx).Info("delete menu info num: ", zap.Int64("cnt", cnt))
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type PowerInfo struct {
|
||||
@@ -41,46 +44,46 @@ func PowerUidExists(powerUid string) bool {
|
||||
return exists
|
||||
}
|
||||
|
||||
func InsertPowerInfo(powerInfo PowerInfo) bool {
|
||||
func InsertPowerInfo(ctx context.Context, powerInfo PowerInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&powerInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert power info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert power info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetPower() []PowerInfo {
|
||||
func GetPower(ctx context.Context) []PowerInfo {
|
||||
o := orm.NewOrm()
|
||||
var powerInfo []PowerInfo
|
||||
_, err := o.QueryTable(POWER_INFO).Limit(-1).All(&powerInfo)
|
||||
if err != nil {
|
||||
logs.Error("get power fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get power fail: ", zap.Error(err))
|
||||
}
|
||||
return powerInfo
|
||||
}
|
||||
|
||||
func GetPowerById(powerId string) PowerInfo {
|
||||
func GetPowerById(ctx context.Context, powerId string) PowerInfo {
|
||||
o := orm.NewOrm()
|
||||
var powerInfo PowerInfo
|
||||
_, err := o.QueryTable(POWER_INFO).Filter("power_id", powerId).Limit(1).All(&powerInfo)
|
||||
if err != nil {
|
||||
logs.Error("get power by id fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get power by id fail: ", zap.Error(err))
|
||||
}
|
||||
return powerInfo
|
||||
}
|
||||
|
||||
func GetPowerByIds(powerIds []string) []PowerInfo {
|
||||
func GetPowerByIds(ctx context.Context, powerIds []string) []PowerInfo {
|
||||
var powerInfoList []PowerInfo
|
||||
for _, v := range powerIds {
|
||||
m := GetPowerById(v)
|
||||
m := GetPowerById(ctx, v)
|
||||
powerInfoList = append(powerInfoList, m)
|
||||
}
|
||||
return powerInfoList
|
||||
}
|
||||
|
||||
func GetPowerItemLenByMap(params map[string]string) int {
|
||||
func GetPowerItemLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(POWER_INFO)
|
||||
for k, v := range params {
|
||||
@@ -90,12 +93,12 @@ func GetPowerItemLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get power item len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get power item len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetPowerItemByMap(params map[string]string, displpay, offset int) []PowerInfo {
|
||||
func GetPowerItemByMap(ctx context.Context, params map[string]string, displpay, offset int) []PowerInfo {
|
||||
o := orm.NewOrm()
|
||||
var powerItemList []PowerInfo
|
||||
qs := o.QueryTable(POWER_INFO)
|
||||
@@ -107,26 +110,26 @@ func GetPowerItemByMap(params map[string]string, displpay, offset int) []PowerIn
|
||||
|
||||
_, err := qs.Limit(displpay, offset).OrderBy("-update_time").All(&powerItemList)
|
||||
if err != nil {
|
||||
logs.Error("get power item by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get power item by map fail: ", zap.Error(err))
|
||||
}
|
||||
return powerItemList
|
||||
}
|
||||
|
||||
func DeletePowerItemByPowerID(powerID string) bool {
|
||||
func DeletePowerItemByPowerID(ctx context.Context, powerID string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(POWER_INFO).Filter("power_id", powerID).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete power item by powerID fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete power item by powerID fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func DeletePowerBySecondUid(secondUid string) bool {
|
||||
func DeletePowerBySecondUid(ctx context.Context, secondUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(POWER_INFO).Filter("second_menu_uid", secondUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete power by second menu uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete power by second menu uid fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type RoleInfo struct {
|
||||
@@ -25,7 +28,7 @@ type RoleInfo struct {
|
||||
|
||||
const ROLE_INFO = "role_info"
|
||||
|
||||
func GetRoleLenByMap(params map[string]string) int {
|
||||
func GetRoleLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(ROLE_INFO)
|
||||
for k, v := range params {
|
||||
@@ -35,22 +38,22 @@ func GetRoleLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Count()
|
||||
if err != nil {
|
||||
logs.Error("get role len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get role len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetRole() []RoleInfo {
|
||||
func GetRole(ctx context.Context) []RoleInfo {
|
||||
o := orm.NewOrm()
|
||||
var roleInfo []RoleInfo
|
||||
_, err := o.QueryTable(ROLE_INFO).Limit(-1).OrderBy("-update_time").All(&roleInfo)
|
||||
if err != nil {
|
||||
logs.Error("get all role fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get all role fail: ", zap.Error(err))
|
||||
}
|
||||
return roleInfo
|
||||
}
|
||||
|
||||
func GetRoleByMap(params map[string]string, display, offset int) []RoleInfo {
|
||||
func GetRoleByMap(ctx context.Context, params map[string]string, display, offset int) []RoleInfo {
|
||||
o := orm.NewOrm()
|
||||
var roleInfo []RoleInfo
|
||||
qs := o.QueryTable(ROLE_INFO)
|
||||
@@ -61,52 +64,52 @@ func GetRoleByMap(params map[string]string, display, offset int) []RoleInfo {
|
||||
}
|
||||
_, err := qs.Limit(display, offset).OrderBy("-update_time").All(&roleInfo)
|
||||
if err != nil {
|
||||
logs.Error("get role by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get role by map fail: ", zap.Error(err))
|
||||
}
|
||||
return roleInfo
|
||||
}
|
||||
|
||||
func GetRoleByRoleUid(roleUid string) RoleInfo {
|
||||
func GetRoleByRoleUid(ctx context.Context, roleUid string) RoleInfo {
|
||||
o := orm.NewOrm()
|
||||
var roleInfo RoleInfo
|
||||
_, err := o.QueryTable(ROLE_INFO).Filter("role_uid", roleUid).Limit(1).All(&roleInfo)
|
||||
if err != nil {
|
||||
logs.Error("get role by role uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get role by role uid fail: ", zap.Error(err))
|
||||
}
|
||||
return roleInfo
|
||||
}
|
||||
|
||||
func RoleNameExists(roleName string) bool {
|
||||
func RoleNameExists(ctx context.Context, roleName string) bool {
|
||||
o := orm.NewOrm()
|
||||
exists := o.QueryTable(ROLE_INFO).Filter("role_name", roleName).Exist()
|
||||
return exists
|
||||
}
|
||||
|
||||
func InsertRole(roleInfo RoleInfo) bool {
|
||||
func InsertRole(ctx context.Context, roleInfo RoleInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&roleInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert role fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert role fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func DeleteRoleByRoleUid(roleUid string) bool {
|
||||
func DeleteRoleByRoleUid(ctx context.Context, roleUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(ROLE_INFO).Filter("role_uid", roleUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete role by role uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete role by role uid fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func UpdateRoleInfo(roleInfo RoleInfo) bool {
|
||||
func UpdateRoleInfo(ctx context.Context, roleInfo RoleInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&roleInfo)
|
||||
if err != nil {
|
||||
logs.Error("update role info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update role info fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const SECOND_MENU_INFO = "second_menu_info"
|
||||
@@ -40,74 +43,74 @@ func (sm SecondMenuSlice) Less(i, j int) bool {
|
||||
return sm[i].FirstMenuOrder < sm[j].FirstMenuOrder
|
||||
}
|
||||
|
||||
func GetSecondMenuLen() int {
|
||||
func GetSecondMenuLen(ctx context.Context) int {
|
||||
o := orm.NewOrm()
|
||||
cnt, err := o.QueryTable(SECOND_MENU_INFO).Count()
|
||||
if err != nil {
|
||||
logs.Error("get second meun len fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get second meun len fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetSecondMenuInfoByMenuOrder(menuOrder int, firstMenuUid string) SecondMenuInfo {
|
||||
func GetSecondMenuInfoByMenuOrder(ctx context.Context, menuOrder int, firstMenuUid string) SecondMenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var secondMenuInfo SecondMenuInfo
|
||||
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Filter("menu_order", menuOrder).Limit(1).All(&secondMenuInfo)
|
||||
if err != nil {
|
||||
logs.Error("get second menu info by menu order fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get second menu info by menu order fail: ", zap.Error(err))
|
||||
}
|
||||
return secondMenuInfo
|
||||
}
|
||||
|
||||
func GetSecondMenuLenByFirstMenuUid(firstMenuUid string) int {
|
||||
func GetSecondMenuLenByFirstMenuUid(ctx context.Context, firstMenuUid string) int {
|
||||
o := orm.NewOrm()
|
||||
cnt, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Count()
|
||||
if err != nil {
|
||||
logs.Error("get second menu len by first menu uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get second menu len by first menu uid fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetSecondMenuList() []SecondMenuInfo {
|
||||
func GetSecondMenuList(ctx context.Context) []SecondMenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var secondMenuList []SecondMenuInfo
|
||||
_, err := o.QueryTable(SECOND_MENU_INFO).Limit(-1).OrderBy("-update_time").All(&secondMenuList)
|
||||
if err != nil {
|
||||
logs.Error("get second menu list fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get second menu list fail: ", zap.Error(err))
|
||||
}
|
||||
return secondMenuList
|
||||
}
|
||||
|
||||
func GetSecondMenuInfoBySecondMenuUid(secondMenuUid string) SecondMenuInfo {
|
||||
func GetSecondMenuInfoBySecondMenuUid(ctx context.Context, secondMenuUid string) SecondMenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var secondMenuInfo SecondMenuInfo
|
||||
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondMenuUid).Limit(1).All(&secondMenuInfo)
|
||||
if err != nil {
|
||||
logs.Error("get scond menu info by second menu uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get scond menu info by second menu uid fail: ", zap.Error(err))
|
||||
}
|
||||
return secondMenuInfo
|
||||
}
|
||||
|
||||
func GetSecondMenuInfoBySecondMenuUids(secondMenuUids []string) []SecondMenuInfo {
|
||||
func GetSecondMenuInfoBySecondMenuUids(ctx context.Context, secondMenuUids []string) []SecondMenuInfo {
|
||||
secondMenuInfoList := make([]SecondMenuInfo, 0)
|
||||
for _, v := range secondMenuUids {
|
||||
sm := GetSecondMenuInfoBySecondMenuUid(v)
|
||||
sm := GetSecondMenuInfoBySecondMenuUid(ctx, v)
|
||||
secondMenuInfoList = append(secondMenuInfoList, sm)
|
||||
}
|
||||
return secondMenuInfoList
|
||||
}
|
||||
|
||||
func GetSecondMenuListByFirstMenuUid(firstMenuUid string) []SecondMenuInfo {
|
||||
func GetSecondMenuListByFirstMenuUid(ctx context.Context, firstMenuUid string) []SecondMenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var secondMenuList []SecondMenuInfo
|
||||
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Limit(-1).OrderBy("-update_time").All(&secondMenuList)
|
||||
if err != nil {
|
||||
logs.Error("get second menu list by first menu uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get second menu list by first menu uid fail: ", zap.Error(err))
|
||||
}
|
||||
return secondMenuList
|
||||
}
|
||||
|
||||
func GetSecondMenuLenByMap(params map[string]string) int {
|
||||
func GetSecondMenuLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(SECOND_MENU_INFO)
|
||||
for k, v := range params {
|
||||
@@ -115,12 +118,12 @@ func GetSecondMenuLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Limit(-1).Count()
|
||||
if err != nil {
|
||||
logs.Error("get second menu len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get second menu len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func GetSecondMenuByMap(params map[string]string, displayCount, offset int) []SecondMenuInfo {
|
||||
func GetSecondMenuByMap(ctx context.Context, params map[string]string, displayCount, offset int) []SecondMenuInfo {
|
||||
o := orm.NewOrm()
|
||||
var secondMenuList []SecondMenuInfo
|
||||
qs := o.QueryTable(SECOND_MENU_INFO)
|
||||
@@ -131,16 +134,16 @@ func GetSecondMenuByMap(params map[string]string, displayCount, offset int) []Se
|
||||
}
|
||||
_, err := qs.Limit(displayCount, offset).OrderBy("-update_time").All(&secondMenuList)
|
||||
if err != nil {
|
||||
logs.Error("get second menu by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get second menu by map fail: ", zap.Error(err))
|
||||
}
|
||||
return secondMenuList
|
||||
}
|
||||
|
||||
func InsertSecondMenu(secondMenuInfo SecondMenuInfo) bool {
|
||||
func InsertSecondMenu(ctx context.Context, secondMenuInfo SecondMenuInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&secondMenuInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert second menu fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert second menu fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -164,46 +167,46 @@ func SecondRouterExists(secondRouter string) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func DeleteSecondMenuByFirstMenuUid(firstMenuUid string) bool {
|
||||
func DeleteSecondMenuByFirstMenuUid(ctx context.Context, firstMenuUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
num, err := o.QueryTable(SECOND_MENU_INFO).Filter("first_menu_uid", firstMenuUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete second menu by first menu uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete second menu by first menu uid fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
logs.Info("delete second menu by first menu uid success, num: ", num)
|
||||
otel.Logger.WithContext(ctx).Info("delete second menu by first menu uid success, num: ", zap.Int64("num", num))
|
||||
return true
|
||||
}
|
||||
|
||||
func DeleteSecondMenuBySecondMenuUid(secondMenuUid string) bool {
|
||||
func DeleteSecondMenuBySecondMenuUid(ctx context.Context, secondMenuUid string) bool {
|
||||
o := orm.NewOrm()
|
||||
num, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondMenuUid).Delete()
|
||||
if err != nil {
|
||||
logs.Error("delete second menu by second menu uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete second menu by second menu uid fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
logs.Info("delete second menu by second menu uid success, num: ", num)
|
||||
otel.Logger.WithContext(ctx).Info("delete second menu by second menu uid success, num: ", zap.Int64("num", num))
|
||||
return true
|
||||
}
|
||||
|
||||
func UpdateSecondMenuOrderBySecondUid(secondUid string, order int) {
|
||||
func UpdateSecondMenuOrderBySecondUid(ctx context.Context, secondUid string, order int) {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(SECOND_MENU_INFO).Filter("second_menu_uid", secondUid).Update(orm.Params{"menu_order": order})
|
||||
if err != nil {
|
||||
logs.Error("update second menu order by second menu uid fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update second menu order by second menu uid fail: ", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateSecondMenu(secondMenu SecondMenuInfo) {
|
||||
func UpdateSecondMenu(ctx context.Context, secondMenu SecondMenuInfo) {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Update(&secondMenu)
|
||||
if err != nil {
|
||||
logs.Error("update second menu for first order fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update second menu for first order fail: ", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
func SecondMenuExistByMenuOrder(menuOrder int) bool {
|
||||
func SecondMenuExistByMenuOrder(ctx context.Context, menuOrder int) bool {
|
||||
o := orm.NewOrm()
|
||||
exist := o.QueryTable(SECOND_MENU_INFO).Filter("menu_order", menuOrder).Exist()
|
||||
exist := o.QueryTable(SECOND_MENU_INFO).Filter("menu_order", menuOrder).ExistWithCtx(ctx)
|
||||
return exist
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -24,17 +27,17 @@ type UserInfo struct {
|
||||
UpdateTime time.Time
|
||||
}
|
||||
|
||||
func GetUserInfoByUserID(userID string) UserInfo {
|
||||
func GetUserInfoByUserID(ctx context.Context, userID string) UserInfo {
|
||||
o := orm.NewOrm()
|
||||
var userInfo UserInfo
|
||||
err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userID).One(&userInfo)
|
||||
if err != nil {
|
||||
logs.Error("get user info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get user info fail: ", zap.Error(err))
|
||||
}
|
||||
return userInfo
|
||||
}
|
||||
|
||||
func GetOperatorByMap(params map[string]string, displayCount, offset int) []UserInfo {
|
||||
func GetOperatorByMap(ctx context.Context, params map[string]string, displayCount, offset int) []UserInfo {
|
||||
o := orm.NewOrm()
|
||||
var userInfo []UserInfo
|
||||
qs := o.QueryTable(USERINFO)
|
||||
@@ -45,12 +48,12 @@ func GetOperatorByMap(params map[string]string, displayCount, offset int) []User
|
||||
}
|
||||
_, err := qs.Exclude("status", "delete").Limit(displayCount, offset).OrderBy("-update_time").All(&userInfo)
|
||||
if err != nil {
|
||||
logs.Error("get operator by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get operator by map fail: ", zap.Error(err))
|
||||
}
|
||||
return userInfo
|
||||
}
|
||||
|
||||
func GetOperatorLenByMap(params map[string]string) int {
|
||||
func GetOperatorLenByMap(ctx context.Context, params map[string]string) int {
|
||||
o := orm.NewOrm()
|
||||
qs := o.QueryTable(USERINFO)
|
||||
for k, v := range params {
|
||||
@@ -58,45 +61,45 @@ func GetOperatorLenByMap(params map[string]string) int {
|
||||
}
|
||||
cnt, err := qs.Exclude("status", "delete").Count()
|
||||
if err != nil {
|
||||
logs.Error("get operator len by map fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("get operator len by map fail: ", zap.Error(err))
|
||||
}
|
||||
return int(cnt)
|
||||
}
|
||||
|
||||
func UpdateUserInfoIP(userInfo UserInfo) {
|
||||
func UpdateUserInfoIP(ctx context.Context, userInfo UserInfo) {
|
||||
o := orm.NewOrm()
|
||||
num, err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userInfo.UserId).Update(orm.Params{"ip": userInfo.Ip})
|
||||
if err != nil {
|
||||
logs.Error("%s update user info ip fail: %v", userInfo.UserId, err)
|
||||
otel.Logger.WithContext(ctx).Error("%s update user info ip fail: %v", zap.String("UserId", userInfo.UserId), zap.Error(err))
|
||||
} else {
|
||||
logs.Info("%s update user info ip success, num: %d", userInfo.UserId, num)
|
||||
otel.Logger.WithContext(ctx).Info("%s update user info ip success, num: %d", zap.String("UserId", userInfo.UserId), zap.Int64("num", num))
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateUserInfoPassword(userInfo UserInfo) {
|
||||
func UpdateUserInfoPassword(ctx context.Context, userInfo UserInfo) {
|
||||
o := orm.NewOrm()
|
||||
num, err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userInfo.UserId).Update(orm.Params{"passwd": userInfo.Passwd})
|
||||
if err != nil {
|
||||
logs.Error("%s update user info password fail: %v", userInfo.UserId, err)
|
||||
otel.Logger.WithContext(ctx).Error("%s update user info password fail: %v", zap.String("UserId", userInfo.UserId), zap.Error(err))
|
||||
} else {
|
||||
logs.Info("%s update user info password success, update num: %d", userInfo.UserId, num)
|
||||
otel.Logger.WithContext(ctx).Info("%s update user info password success, update num: %d", zap.String("UserId", userInfo.UserId), zap.Int64("num", num))
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateUserInfo(userInfo UserInfo) {
|
||||
func UpdateUserInfo(ctx context.Context, userInfo UserInfo) {
|
||||
o := orm.NewOrm()
|
||||
if num, err := o.Update(&userInfo); err != nil {
|
||||
logs.Error("update user info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update user info fail: ", zap.Error(err))
|
||||
} else {
|
||||
logs.Info("update user info success, num: ", num)
|
||||
otel.Logger.WithContext(ctx).Info("update user info success, num: ", zap.Int64("num", num))
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateStauts(status, userId string) bool {
|
||||
func UpdateStauts(ctx context.Context, status, userId string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(USERINFO).Filter("user_id", userId).Update(orm.Params{"status": status})
|
||||
if err != nil {
|
||||
logs.Error("update status fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("update status fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -114,21 +117,21 @@ func NickIsExist(nick string) bool {
|
||||
return exist
|
||||
}
|
||||
|
||||
func InsertUser(userInfo UserInfo) bool {
|
||||
func InsertUser(ctx context.Context, userInfo UserInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.Insert(&userInfo)
|
||||
if err != nil {
|
||||
logs.Error("insert user fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("insert user fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func DeleteUserByUserId(userId string) bool {
|
||||
func DeleteUserByUserId(ctx context.Context, userId string) bool {
|
||||
o := orm.NewOrm()
|
||||
_, err := o.QueryTable(USERINFO).Exclude("status", "delete").Filter("user_id", userId).Update(orm.Params{"status": "delete"})
|
||||
if err != nil {
|
||||
logs.Error("delete user by userId fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("delete user by userId fail: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -2,10 +2,13 @@ package otel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
beecontext "github.com/beego/beego/v2/server/web/context"
|
||||
slogmulti "github.com/samber/slog-multi"
|
||||
"go.opentelemetry.io/contrib/bridges/otelslog"
|
||||
"go.opentelemetry.io/contrib/bridges/otelzap"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp"
|
||||
@@ -18,17 +21,46 @@ import (
|
||||
sdkMetric "go.opentelemetry.io/otel/sdk/metric"
|
||||
"go.opentelemetry.io/otel/sdk/resource"
|
||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 初始化ctx
|
||||
var (
|
||||
InitCtx = context.Background()
|
||||
)
|
||||
|
||||
type LoggerStruct struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// WithContext 为日志记录器添加上下文信息。
|
||||
// 如果上下文中包含跟踪 id,则将其添加到日志中以增强可追踪性。
|
||||
func (l *LoggerStruct) WithContext(ctx context.Context) *zap.Logger {
|
||||
// 如果上下文为空,直接返回日志记录器,不进行任何修改。
|
||||
if ctx == nil {
|
||||
return l.logger
|
||||
}
|
||||
// 从 context 中获取 span
|
||||
// 从 context 中获取 span
|
||||
span := trace.SpanFromContext(ctx)
|
||||
if !span.SpanContext().IsValid() {
|
||||
return l.logger
|
||||
}
|
||||
return l.logger.With(
|
||||
zap.String("trace_id", span.SpanContext().TraceID().String()),
|
||||
zap.String("span_id", span.SpanContext().SpanID().String()),
|
||||
)
|
||||
}
|
||||
|
||||
var (
|
||||
serviceName = "网关服务"
|
||||
collectorURL = "otel-collector.kkknametrans.buzz"
|
||||
Logger *LoggerStruct // 添加全局 logger
|
||||
)
|
||||
|
||||
func InitTracer() (func(context.Context) error, func(context.Context) error, func(context.Context) error) {
|
||||
@@ -109,27 +141,76 @@ func InitTracer() (func(context.Context) error, func(context.Context) error, fun
|
||||
sdklog.WithResource(resources),
|
||||
)
|
||||
global.SetLoggerProvider(loggerProvider)
|
||||
slog.SetDefault(slog.New(
|
||||
slogmulti.Fanout(
|
||||
otelslog.NewHandler(serviceName, otelslog.WithLoggerProvider(loggerProvider)),
|
||||
slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
||||
AddSource: true,
|
||||
Level: slog.LevelDebug,
|
||||
}),
|
||||
|
||||
// 自定义日志格式配置
|
||||
encoderConfig := zapcore.EncoderConfig{
|
||||
TimeKey: "time",
|
||||
LevelKey: "level",
|
||||
NameKey: "logger",
|
||||
CallerKey: "caller",
|
||||
FunctionKey: zapcore.OmitKey,
|
||||
MessageKey: "msg",
|
||||
StacktraceKey: "stacktrace",
|
||||
LineEnding: zapcore.DefaultLineEnding,
|
||||
EncodeLevel: zapcore.CapitalLevelEncoder, // 使用大写字母记录日志级别
|
||||
EncodeTime: zapcore.TimeEncoderOfLayout(time.DateTime), // ISO8601 时间格式
|
||||
EncodeDuration: zapcore.SecondsDurationEncoder,
|
||||
EncodeCaller: zapcore.ShortCallerEncoder, // 短路径编码器
|
||||
}
|
||||
|
||||
// 创建核心
|
||||
core := zapcore.NewTee(
|
||||
otelzap.NewCore(serviceName, otelzap.WithLoggerProvider(loggerProvider)),
|
||||
zapcore.NewCore(
|
||||
zapcore.NewConsoleEncoder(encoderConfig),
|
||||
// zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
|
||||
zapcore.NewMultiWriteSyncer(
|
||||
zapcore.AddSync(os.Stdout),
|
||||
),
|
||||
zap.InfoLevel,
|
||||
),
|
||||
))
|
||||
)
|
||||
logger := zap.New(core,
|
||||
zap.AddCaller(),
|
||||
// zap.AddCallerSkip(1),
|
||||
zap.AddStacktrace(zap.ErrorLevel),
|
||||
)
|
||||
// zap设置标准输出流
|
||||
// 设置全局 logger
|
||||
Logger = &LoggerStruct{
|
||||
logger: logger,
|
||||
}
|
||||
// 确保设置 TextMapPropagator
|
||||
otel.SetTextMapPropagator(
|
||||
propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}),
|
||||
)
|
||||
return traceExporter.Shutdown, metricExporter.Shutdown, logExporter.Shutdown
|
||||
}
|
||||
|
||||
// 从请求头中提取上游的 trace context
|
||||
// 并将其注入到当前的 context 中
|
||||
// 这样下游的服务就可以从 context 中获取到上游的 trace context
|
||||
// 这样就可以在日志中看到上游的 trace Context
|
||||
func Middleware(ctx *beecontext.Context, next web.FilterFunc) {
|
||||
req := ctx.Request
|
||||
// 从请求头中提取上游的 trace context
|
||||
propagator := otel.GetTextMapPropagator()
|
||||
parentCtx := propagator.Extract(req.Context(), propagation.HeaderCarrier(req.Header))
|
||||
routeTrace := otel.Tracer("router")
|
||||
// 提取跟踪上下文
|
||||
spanCtx := otel.GetTextMapPropagator().Extract(req.Context(), propagation.HeaderCarrier(req.Header))
|
||||
spanCtx, span := routeTrace.Start(spanCtx, req.URL.Path,
|
||||
spanCtx, span := routeTrace.Start(parentCtx, req.URL.Path,
|
||||
trace.WithAttributes(
|
||||
attribute.String("http.method", req.Method),
|
||||
attribute.String("http.url", req.URL.String()),
|
||||
attribute.String("peer.hostname", req.Host),
|
||||
attribute.String("http.scheme", getScheme(req)),
|
||||
attribute.String("component", "beego"),
|
||||
attribute.String("peer.address", req.RemoteAddr),
|
||||
attribute.String("span.kind", "server"),
|
||||
attribute.String("peer.service", serviceName),
|
||||
attribute.String("http.flavor", req.Proto),
|
||||
attribute.String("http.user_agent", req.UserAgent()),
|
||||
attribute.String("http.server_name", serviceName),
|
||||
attribute.String("http.target", req.URL.Path),
|
||||
),
|
||||
)
|
||||
//添加slog
|
||||
@@ -140,19 +221,14 @@ func Middleware(ctx *beecontext.Context, next web.FilterFunc) {
|
||||
span.SetAttributes(attribute.Int("http.status_code", ctx.Request.Response.StatusCode))
|
||||
}
|
||||
}()
|
||||
span.SetAttributes(attribute.String("http.method", ctx.Request.Method))
|
||||
span.SetAttributes(attribute.String("peer.hostname", ctx.Request.Host))
|
||||
span.SetAttributes(attribute.String("http.scheme", getScheme(ctx.Request)))
|
||||
span.SetAttributes(attribute.String("component", "beego"))
|
||||
ctx.Request = ctx.Request.WithContext(spanCtx)
|
||||
next(ctx)
|
||||
}
|
||||
|
||||
// Span 抽象span
|
||||
func Span(ctx context.Context, spanName string) func() {
|
||||
//tracer :=
|
||||
_, span := otel.Tracer("service").Start(ctx, spanName)
|
||||
return func() {
|
||||
func Span(ctx context.Context, traceName, spanName string, attr ...trace.SpanStartOption) (context.Context, func()) {
|
||||
ctx, span := otel.Tracer("").Start(ctx, spanName, attr...)
|
||||
return ctx, func() {
|
||||
defer span.End()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/utils"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type MerchantQueryController struct {
|
||||
@@ -23,7 +25,7 @@ type OrderQueryFailData struct {
|
||||
}
|
||||
|
||||
// OrderQuery 改接口是为下游商户提供订单查询
|
||||
func (c *MerchantQueryController) OrderQuery() {
|
||||
func (c *MerchantQueryController) OrderQuery(ctx context.Context) {
|
||||
orderNo := strings.TrimSpace(c.GetString("orderNo"))
|
||||
payKey := strings.TrimSpace(c.GetString("payKey"))
|
||||
sign := strings.TrimSpace(c.GetString("sign"))
|
||||
@@ -35,11 +37,11 @@ func (c *MerchantQueryController) OrderQuery() {
|
||||
failData.StatusCode = "01"
|
||||
failData.PayKey = payKey
|
||||
|
||||
merchantInfo := merchant.GetMerchantByPasskey(payKey)
|
||||
merchantInfo := merchant.GetMerchantByPasskey(ctx, payKey)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
failData.Msg = "商户不存在,请核对payKey字段"
|
||||
}
|
||||
orderInfo := order.GetOrderByMerchantOrderId(orderNo)
|
||||
orderInfo := order.GetOrderByMerchantOrderId(ctx, orderNo)
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
failData.Msg = "不存在这样的订单,请核对orderNo字段"
|
||||
}
|
||||
@@ -67,7 +69,7 @@ func (c *MerchantQueryController) OrderQuery() {
|
||||
p["sign"] = utils.GetMD5Sign(p, keys, paySercet)
|
||||
s, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
logs.Error("json marshal fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("json marshal fail: ", zap.Error(err))
|
||||
}
|
||||
c.Data["json"] = s
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/message"
|
||||
"gateway/internal/service/pay_for"
|
||||
"gateway/internal/service/supplier/third_party"
|
||||
"gateway/internal/utils"
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
|
||||
"github.com/go-stomp/stomp/v3"
|
||||
)
|
||||
|
||||
@@ -37,11 +39,11 @@ var (
|
||||
payForQueryConsumerPool = gopool.NewPool("PayForQueryConsumer", 20, gopool.NewConfig())
|
||||
)
|
||||
|
||||
func PayForQueryTimer(task PayForQueryTask) {
|
||||
func PayForQueryTimer(ctx context.Context, task PayForQueryTask) {
|
||||
for {
|
||||
select {
|
||||
case <-task.Delay.C:
|
||||
PayForSupplier(task)
|
||||
PayForSupplier(ctx, task)
|
||||
task.Delay.Stop()
|
||||
return
|
||||
// 70分钟没有执行该协程,那么退出协程
|
||||
@@ -51,48 +53,51 @@ func PayForQueryTimer(task PayForQueryTask) {
|
||||
}
|
||||
}
|
||||
|
||||
func PayForSupplier(task PayForQueryTask) {
|
||||
logs.Info(fmt.Sprintf("执行代付查询任务:%+v", task))
|
||||
payFor := payfor.GetPayForByBankOrderId(task.BankOrderId)
|
||||
func PayForSupplier(ctx context.Context, task PayForQueryTask) {
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("执行代付查询任务:%+v", task))
|
||||
payFor := payfor.GetPayForByBankOrderId(ctx, task.BankOrderId)
|
||||
|
||||
roadInfo := road.GetRoadInfoByRoadUid(payFor.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, payFor.RoadUid)
|
||||
supplier := third_party.GetPaySupplierByCode(roadInfo.ProductUid)
|
||||
if supplier == nil {
|
||||
logs.Error("代付查询返回supplier为空")
|
||||
otel.Logger.WithContext(ctx).Error("代付查询返回supplier为空")
|
||||
return
|
||||
}
|
||||
res, _ := supplier.PayForQuery(payFor)
|
||||
if res == config.PAYFOR_SUCCESS {
|
||||
// 代付成功了
|
||||
pay_for.PayForSuccess(payFor)
|
||||
pay_for.PayForSuccess(ctx, payFor)
|
||||
} else if res == config.PAYFOR_FAIL {
|
||||
// 代付失败
|
||||
pay_for.PayForFail(payFor)
|
||||
pay_for.PayForFail(ctx, payFor)
|
||||
} else if res == config.PAYFOR_BANKING {
|
||||
// 银行处理中,那么就继续执行查询,直到次数超过最大次数
|
||||
if task.QueryTimes <= task.LimitTimes {
|
||||
task.QueryTimes += 1
|
||||
task.Delay = time.NewTimer(time.Duration(PayForQueryInterval) * time.Minute)
|
||||
PayForQueryPool.Go(func() {
|
||||
PayForQueryTimer(task)
|
||||
PayForQueryPool.CtxGo(ctx, func() {
|
||||
// 创建一个5分钟超时的上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
PayForQueryTimer(timeoutCtx, task)
|
||||
})
|
||||
} else {
|
||||
logs.Info(fmt.Sprintf("该代付订单已经超过最大查询次数,bankOrderId = %s", task.BankOrderId))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("该代付订单已经超过最大查询次数,bankOrderId = %s", task.BankOrderId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func payForQueryConsumer(bankOrderId string) {
|
||||
func payForQueryConsumer(ctx context.Context, bankOrderId string) {
|
||||
exist := payfor.IsExistPayForByBankOrderId(bankOrderId)
|
||||
if !exist {
|
||||
logs.Error(fmt.Sprintf("代付记录不存在,bankOrderId = %s", bankOrderId))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("代付记录不存在,bankOrderId = %s", bankOrderId))
|
||||
return
|
||||
}
|
||||
|
||||
payFor := payfor.GetPayForByBankOrderId(bankOrderId)
|
||||
payFor := payfor.GetPayForByBankOrderId(ctx, bankOrderId)
|
||||
|
||||
if payFor.Status != config.PAYFOR_BANKING {
|
||||
logs.Info(fmt.Sprintf("代付状态不是银行处理中,不需要去查询,bankOrderId = %s", bankOrderId))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付状态不是银行处理中,不需要去查询,bankOrderId = %s", bankOrderId))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,21 +111,23 @@ func payForQueryConsumer(bankOrderId string) {
|
||||
Status: payFor.Status,
|
||||
}
|
||||
PayForQueryPool.Go(func() {
|
||||
PayForQueryTimer(payForQueryTask)
|
||||
PayForQueryTimer(ctx, payForQueryTask)
|
||||
})
|
||||
}
|
||||
|
||||
// CreatePayForQueryConsumer 创建代付查询的消费者
|
||||
func CreatePayForQueryConsumer() {
|
||||
func CreatePayForQueryConsumer(ctx context.Context) {
|
||||
ctx, cancel := otel.Span(ctx, "CreatePayForQueryConsumer", "CreatePayForQueryConsumer")
|
||||
defer cancel()
|
||||
// 启动定时任务
|
||||
conn := message.GetActiveMQConn()
|
||||
if conn == nil {
|
||||
logs.Error("启动消息队列消费者失败....")
|
||||
otel.Logger.WithContext(ctx).Error("启动消息队列消费者失败....")
|
||||
os.Exit(1)
|
||||
}
|
||||
payForQuery, err := conn.Subscribe(config.MqPayForQuery, stomp.AckClient)
|
||||
if err != nil {
|
||||
logs.Error("订阅代付查询失败......")
|
||||
otel.Logger.WithContext(ctx).Error("订阅代付查询失败......")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@@ -129,13 +136,16 @@ func CreatePayForQueryConsumer() {
|
||||
case v := <-payForQuery.C:
|
||||
if v != nil {
|
||||
bankOrderId := string(v.Body)
|
||||
payForQueryConsumerPool.Go(func() {
|
||||
payForQueryConsumer(bankOrderId)
|
||||
payForQueryConsumerPool.CtxGo(ctx, func() {
|
||||
// 创建一个5分钟超时的上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
payForQueryConsumer(timeoutCtx, bankOrderId)
|
||||
})
|
||||
// 应答,重要
|
||||
err := conn.Ack(v)
|
||||
if err != nil {
|
||||
logs.Error("消息应答失败!")
|
||||
otel.Logger.WithContext(ctx).Error("消息应答失败!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/message"
|
||||
"gateway/internal/service/supplier/third_party"
|
||||
"os"
|
||||
@@ -26,15 +28,15 @@ const (
|
||||
LimitTimes = 5 // 最多查询5次
|
||||
)
|
||||
|
||||
func SupplierOrderQueryResult(bankOrderId string) supply_model.MsgModel {
|
||||
orderInfo := order.GetOrderByBankOrderId(bankOrderId)
|
||||
func SupplierOrderQueryResult(ctx context.Context, bankOrderId string) supply_model.MsgModel {
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, bankOrderId)
|
||||
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("不存在这样的订单,订单查询结束")
|
||||
otel.Logger.WithContext(ctx).Error("不存在这样的订单,订单查询结束")
|
||||
return supply_model.OrderNotExist
|
||||
}
|
||||
if orderInfo.Status != "" && orderInfo.Status != "wait" {
|
||||
logs.Error(fmt.Sprintf("该订单=%s,已经处理完毕,", bankOrderId))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("该订单=%s,已经处理完毕,", bankOrderId))
|
||||
return supply_model.OrderFinished
|
||||
}
|
||||
|
||||
@@ -42,27 +44,27 @@ func SupplierOrderQueryResult(bankOrderId string) supply_model.MsgModel {
|
||||
supplier_ := third_party.GetPaySupplierByCode(supplierCode)
|
||||
|
||||
if supplier_ == nil {
|
||||
logs.Error("不存在这样的订单,订单查询结束")
|
||||
otel.Logger.WithContext(ctx).Error("不存在这样的订单,订单查询结束")
|
||||
return supply_model.OrderNotExist
|
||||
}
|
||||
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
result := supplier_.PayQueryV2(orderInfo, roadInfo)
|
||||
return result
|
||||
}
|
||||
|
||||
// 该接口是查询上游的订单
|
||||
func solveSupplierOrderQuery(task OrderQueryTask) {
|
||||
func solveSupplierOrderQuery(ctx context.Context, task OrderQueryTask) {
|
||||
bankOrderId := task.BankOrderId
|
||||
|
||||
flag := SupplierOrderQueryResult(bankOrderId)
|
||||
flag := SupplierOrderQueryResult(ctx, bankOrderId)
|
||||
if flag == supply_model.RemoteSuccess || flag == supply_model.RemoteDataHealingErr {
|
||||
logs.Info("订单查询成功, bankOrderId:", bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("订单查询成功, bankOrderId:%s", bankOrderId))
|
||||
} else {
|
||||
if task.Times <= LimitTimes {
|
||||
task.Times += 1
|
||||
task.OrderQueryTimer = time.NewTimer(time.Duration(5) * time.Minute)
|
||||
DelayOrderQueryQueue(task)
|
||||
DelayOrderQueryQueue(ctx, task)
|
||||
} else {
|
||||
logs.Notice(fmt.Sprintf("订单id=%s, 已经查询超过次数", bankOrderId))
|
||||
}
|
||||
@@ -70,12 +72,12 @@ func solveSupplierOrderQuery(task OrderQueryTask) {
|
||||
}
|
||||
|
||||
// DelayOrderQueryQueue 延时队列
|
||||
func DelayOrderQueryQueue(task OrderQueryTask) {
|
||||
func DelayOrderQueryQueue(ctx context.Context, task OrderQueryTask) {
|
||||
for {
|
||||
select {
|
||||
case <-task.OrderQueryTimer.C:
|
||||
logs.Info(fmt.Sprintf("订单id=%s,执行第:%d 次查询", task.BankOrderId, task.Times))
|
||||
solveSupplierOrderQuery(task)
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("订单id=%s,执行第:%d 次查询", task.BankOrderId, task.Times))
|
||||
solveSupplierOrderQuery(ctx, task)
|
||||
return
|
||||
case <-time.After(time.Duration(2*DelayTime) * time.Minute):
|
||||
return
|
||||
@@ -84,10 +86,12 @@ func DelayOrderQueryQueue(task OrderQueryTask) {
|
||||
}
|
||||
|
||||
// CreateSupplierOrderQueryCuConsumer 启动消息订单查询的消息队列消费者
|
||||
func CreateSupplierOrderQueryCuConsumer() {
|
||||
func CreateSupplierOrderQueryCuConsumer(ctx context.Context) {
|
||||
ctx, cancel := otel.Span(ctx, "CreateSupplierOrderQueryCuConsumer", "CreateSupplierOrderQueryCuConsumer")
|
||||
defer cancel()
|
||||
conn := message.GetActiveMQConn()
|
||||
if conn == nil {
|
||||
logs.Error("supply order query consumer fail")
|
||||
otel.Logger.WithContext(ctx).Error("supply order query consumer fail")
|
||||
os.Exit(1)
|
||||
}
|
||||
logs.Notice("启动订单查询的消费者成功.....")
|
||||
@@ -98,13 +102,13 @@ func CreateSupplierOrderQueryCuConsumer() {
|
||||
case v := <-orderQuerySub.C:
|
||||
if v != nil {
|
||||
bankOrderId := string(v.Body)
|
||||
logs.Info("消费者正在处理订单查询: " + bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Info("消费者正在处理订单查询: " + bankOrderId)
|
||||
task := OrderQueryTask{BankOrderId: bankOrderId, OrderQueryTimer: time.NewTimer(time.Second * 1), Times: 1}
|
||||
DelayOrderQueryQueue(task)
|
||||
DelayOrderQueryQueue(ctx, task)
|
||||
// 应答,重要
|
||||
err := conn.Ack(v)
|
||||
if err != nil {
|
||||
logs.Error("消息应答失败!")
|
||||
otel.Logger.WithContext(ctx).Error("消息应答失败!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,15 @@ package backend
|
||||
import (
|
||||
"context"
|
||||
"gateway/internal/config"
|
||||
"github.com/carlmjohnson/requests"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/carlmjohnson/requests"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
)
|
||||
|
||||
func GetIPIsRestricted(ip string, merchantDeployId int, orderNo, cardPass, deviceId string) (isAllowed bool, err error) {
|
||||
func GetIPIsRestricted(ctx context.Context, ip string, merchantDeployId int, orderNo, cardPass, deviceId string) (isAllowed bool, err error) {
|
||||
response := struct {
|
||||
Code int `json:"code"`
|
||||
Data struct {
|
||||
@@ -28,6 +31,6 @@ func GetIPIsRestricted(ip string, merchantDeployId int, orderNo, cardPass, devic
|
||||
"cardPass": {cardPass},
|
||||
"deviceId": {deviceId},
|
||||
"merchantDeployID": {strconv.Itoa(merchantDeployId)},
|
||||
}).ToJSON(&response).Fetch(context.Background())
|
||||
}).Transport(otelhttp.NewTransport(http.DefaultTransport)).ToJSON(&response).Fetch(context.Background())
|
||||
return response.Data.IsAllowed, err
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetIPIsRestricted(t *testing.T) {
|
||||
isAllowed, _ := GetIPIsRestricted("123.123.123.123", 1)
|
||||
logs.Info(isAllowed)
|
||||
// isAllowed, _ := GetIPIsRestricted(context.Background(), "123.123.123.123", 1)
|
||||
// otel.Logger.WithContext(c.Ctx.Request.Context()).Info(isAllowed)
|
||||
}
|
||||
|
||||
@@ -5,21 +5,23 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/schema/response"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"strconv"
|
||||
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// GetMerchantInfoByUID 获取商户信息
|
||||
func GetMerchantInfoByUID(params map[string]any) *response.PayBaseResp {
|
||||
func GetMerchantInfoByUID(ctx context.Context, params map[string]any) *response.PayBaseResp {
|
||||
c := new(response.PayBaseResp)
|
||||
c.Params = make(map[string]any)
|
||||
c.Params = params
|
||||
merchantInfo := merchant.GetMerchantByUid(convertor.ToString(params["MerchantUid"]))
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, convertor.ToString(params["MerchantUid"]))
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
c.Code = -1
|
||||
c.Msg = "商户不存在,或者paykey有误,请联系管理员"
|
||||
@@ -33,8 +35,8 @@ func GetMerchantInfoByUID(params map[string]any) *response.PayBaseResp {
|
||||
}
|
||||
|
||||
// GetMerchantInfoByPayKey 通过payKey获取商户信息
|
||||
func GetMerchantInfoByPayKey(payKey string) (merchantInfo merchant.MerchantInfo, err error) {
|
||||
merchantInfo = merchant.GetMerchantByPasskey(payKey)
|
||||
func GetMerchantInfoByPayKey(ctx context.Context, payKey string) (merchantInfo merchant.MerchantInfo, err error) {
|
||||
merchantInfo = merchant.GetMerchantByPasskey(ctx, payKey)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
err = errors.New("商户不存在,请联系商户")
|
||||
return
|
||||
@@ -46,11 +48,11 @@ func GetMerchantInfoByPayKey(payKey string) (merchantInfo merchant.MerchantInfo,
|
||||
}
|
||||
|
||||
// GetMerchantInfo 获取商户信息
|
||||
func GetMerchantInfo(params map[string]any) *response.PayBaseResp {
|
||||
func GetMerchantInfo(ctx context.Context, params map[string]any) *response.PayBaseResp {
|
||||
c := new(response.PayBaseResp)
|
||||
c.Params = make(map[string]any)
|
||||
c.Params = params
|
||||
merchantInfo := merchant.GetMerchantByPasskey(convertor.ToString(params["payKey"]))
|
||||
merchantInfo := merchant.GetMerchantByPasskey(ctx, convertor.ToString(params["payKey"]))
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
c.Code = -1
|
||||
c.Msg = "商户不存在,或者paykey有误,请联系管理员"
|
||||
@@ -80,7 +82,7 @@ func ExValueIsValid(ctx context.Context, c *response.PayBaseResp) *response.PayB
|
||||
isRedeemValid := true
|
||||
exRedeemValue := supplier.RedeemCardInfo{}
|
||||
if err := json.Unmarshal([]byte(convertor.ToString(c.Params["exValue"])), &exRedeemValue); err != nil {
|
||||
logs.Error("提交卡密格式错误,请检查", c.Params["exValue"], err)
|
||||
otel.Logger.WithContext(ctx).Error("提交卡密格式错误,请检查", zap.Any("exValue", c.Params["exValue"]), zap.Error(err))
|
||||
isRedeemValid = false
|
||||
}
|
||||
if exRedeemValue.Data == "" || len(exRedeemValue.Data) == 0 {
|
||||
@@ -159,7 +161,7 @@ func OrderPriceIsValid(ctx context.Context, c *response.PayBaseResp) *response.P
|
||||
|
||||
a, err := strconv.ParseFloat(convertor.ToString(c.Params["orderPrice"]), 64)
|
||||
if err != nil {
|
||||
logs.Error("order price is invalid: ", c.Params["orderPrice"])
|
||||
otel.Logger.WithContext(ctx).Error("order price is invalid: ", zap.Any("orderPrice", c.Params["orderPrice"]), zap.Error(err))
|
||||
c.Code = -1
|
||||
c.Msg = "订单金额非法"
|
||||
}
|
||||
|
||||
@@ -1,30 +1,34 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gateway/internal/consts"
|
||||
"gateway/internal/models/hidden"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/setting"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/datetime"
|
||||
"github.com/duke-git/lancet/v2/pointer"
|
||||
"github.com/duke-git/lancet/v2/random"
|
||||
"github.com/duke-git/lancet/v2/slice"
|
||||
"github.com/duke-git/lancet/v2/validator"
|
||||
"github.com/mohae/deepcopy"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// GetOrderLock 定义一个锁
|
||||
var GetOrderLock = sync.Mutex{}
|
||||
|
||||
// GetOrderHidden 判断当前订单是否偷卡
|
||||
func GetOrderHidden(orderNo *order.OrderInfo) (cfg *hidden.MerchantHiddenConfig) {
|
||||
func GetOrderHidden(ctx context.Context, orderNo *order.OrderInfo) (cfg *hidden.MerchantHiddenConfig) {
|
||||
//加锁
|
||||
GetOrderLock.Lock()
|
||||
defer GetOrderLock.Unlock()
|
||||
@@ -44,7 +48,7 @@ func GetOrderHidden(orderNo *order.OrderInfo) (cfg *hidden.MerchantHiddenConfig)
|
||||
var amountRule []int
|
||||
err = json.Unmarshal([]byte(config.AmountRule), &amountRule)
|
||||
if err != nil {
|
||||
logs.Error("偷卡规则查询失败:%v", err)
|
||||
otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
//匹配条件:当前订单金额在配置金额规则中 && 当前订单面额小于等于配置面额
|
||||
@@ -52,14 +56,14 @@ func GetOrderHidden(orderNo *order.OrderInfo) (cfg *hidden.MerchantHiddenConfig)
|
||||
continue
|
||||
}
|
||||
|
||||
roadInfo := road.GetRoadInfoByRoadUid(config.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, config.RoadUid)
|
||||
if pointer.IsNil(roadInfo) || roadInfo.Id == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
record, err2 := hidden.GetLatestOneRecordByHiddenConfigId(config.Id, []int{int(consts.StealRuleStatusSuccess), int(consts.StealRuleStatusWaiting)})
|
||||
if err2 != nil {
|
||||
logs.Error("偷卡规则查询失败:%v", err2)
|
||||
otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err2))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -67,7 +71,7 @@ func GetOrderHidden(orderNo *order.OrderInfo) (cfg *hidden.MerchantHiddenConfig)
|
||||
if record.IsFinish == 1 || record.Id == 0 {
|
||||
orderInfos, err := order.GetByUidAndRoadUidAndTime(config.MerchantUid, config.RoadUid, datetime.Max(record.UpdatedAt, *cardConfig.UpdatedAt))
|
||||
if err != nil || len(orderInfos) == 0 {
|
||||
logs.Error("偷卡规则查询失败:%v", err)
|
||||
otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -90,7 +94,7 @@ func GetOrderHidden(orderNo *order.OrderInfo) (cfg *hidden.MerchantHiddenConfig)
|
||||
// 获取最后一轮偷卡数据
|
||||
records, err := hidden.GetRecordByConfigId(record.MerchantHiddenConfigId, []int{int(consts.StealRuleStatusSuccess), int(consts.StealRuleStatusWaiting)}, lastSucceedRecord.CreatedAt)
|
||||
if err != nil {
|
||||
logs.Error("偷卡规则查询失败:%v", err)
|
||||
otel.Logger.WithContext(ctx).Error("偷卡规则查询失败:%v", zap.Error(err))
|
||||
return
|
||||
}
|
||||
recordTotal := slice.ReduceBy(records, 0, func(index int, item *hidden.MerchantHiddenRecord, agg int) int {
|
||||
@@ -107,22 +111,22 @@ func GetOrderHidden(orderNo *order.OrderInfo) (cfg *hidden.MerchantHiddenConfig)
|
||||
}
|
||||
|
||||
// CreateHiddenBlankOrder 创建新的空白订单
|
||||
func CreateHiddenBlankOrder(orderInfo *order.OrderInfo, duration int64) (bankOrderId string, err error) {
|
||||
bankOrderId, err = order.HiddenOrder(orderInfo)
|
||||
logs.Info("创建新的假订单:%v", orderInfo.BankOrderId, bankOrderId)
|
||||
func CreateHiddenBlankOrder(ctx context.Context, orderInfo *order.OrderInfo, duration int64) (bankOrderId string, err error) {
|
||||
bankOrderId, err = order.HiddenOrder(ctx, orderInfo)
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("创建新的假订单:%v", orderInfo.BankOrderId, bankOrderId), zap.String("bankOrderId", bankOrderId), zap.String("orderInfo.BankOrderId", orderInfo.BankOrderId))
|
||||
|
||||
//复制到一个新的对象中
|
||||
newOrderInfo := deepcopy.Copy(*orderInfo).(order.OrderInfo)
|
||||
// 创建一个新的失败订单
|
||||
newOrderInfo.ExValue = "{}"
|
||||
newOrderInfo.Id = 0
|
||||
order.InsertOrder(newOrderInfo)
|
||||
order.InsertOrder(ctx, newOrderInfo)
|
||||
// 去掉现有订单的关联数据
|
||||
return
|
||||
}
|
||||
|
||||
func CreateHiddenErrorOrder(orderInfo *order.OrderInfo, duration int64) (bankOrderId string, err error) {
|
||||
bankOrderId, _ = order.HiddenOrder(orderInfo)
|
||||
func CreateHiddenErrorOrder(ctx context.Context, orderInfo *order.OrderInfo, duration int64) (bankOrderId string, err error) {
|
||||
bankOrderId, _ = order.HiddenOrder(ctx, orderInfo)
|
||||
//创建利润表
|
||||
|
||||
//复制到一个新的对象中
|
||||
@@ -138,7 +142,7 @@ func CreateHiddenErrorOrder(orderInfo *order.OrderInfo, duration int64) (bankOrd
|
||||
newOrderInfo.Id = 0
|
||||
exValue.Data = ReplaceNumberOrLetter(exValue.Data, len(exValue.Data))
|
||||
exValue.CardNo = ReplaceNumberOrLetter(exValue.CardNo, len(exValue.CardNo))
|
||||
order.InsertOrder(newOrderInfo)
|
||||
order.InsertOrder(ctx, newOrderInfo)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -157,8 +161,8 @@ func CreateRelateHideOrderRecord(targetOrderBankId string, orderInfo *order.Orde
|
||||
return
|
||||
}
|
||||
|
||||
func GetRelateRecordByTargetOrderNo(targetOrderBankId string) (record *hidden.MerchantHiddenRecord, err error) {
|
||||
record, err = hidden.GetByTargetOrderNo(targetOrderBankId)
|
||||
func GetRelateRecordByTargetOrderNo(ctx context.Context, targetOrderBankId string) (record *hidden.MerchantHiddenRecord, err error) {
|
||||
record, err = hidden.GetByTargetOrderNo(ctx, targetOrderBankId)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -171,7 +175,7 @@ func GetRelateRecordByTargetOrderNo(targetOrderBankId string) (record *hidden.Me
|
||||
// targetStr := random.RandFromGivenSlice(list)
|
||||
// if !pointer.IsNil(targetStr) && targetStr != "" {
|
||||
// index := random.RandFromGivenSlice(FindAllIndex(str, targetStr))
|
||||
// logs.Info(str, FindAllIndex(str, targetStr))
|
||||
// otel.Logger.WithContext(ctx).Info(str, FindAllIndex(str, targetStr))
|
||||
// if index != -1 {
|
||||
// if validator.IsIntStr(targetStr) {
|
||||
// //去掉当前数字
|
||||
@@ -255,25 +259,25 @@ func FindAllIndex(str string, char string) []int {
|
||||
}
|
||||
|
||||
// UpdateRelateRecordStatus 更新偷卡状态和偷卡金额
|
||||
func UpdateRelateRecordStatus(orderBankId string, amount float64, status int) (err error) {
|
||||
err = hidden.UpdateStatusAndAmount(orderBankId, amount, status)
|
||||
func UpdateRelateRecordStatus(ctx context.Context, orderBankId string, amount float64, status int) (err error) {
|
||||
err = hidden.UpdateStatusAndAmount(ctx, orderBankId, amount, status)
|
||||
return
|
||||
}
|
||||
|
||||
var UpdateStealRecordLock = sync.Mutex{}
|
||||
|
||||
func UpdateRelateRecordSucceedStatus(orderBankId string, amount float64) (err error) {
|
||||
func UpdateRelateRecordSucceedStatus(ctx context.Context, orderBankId string, amount float64) (err error) {
|
||||
UpdateStealRecordLock.Lock()
|
||||
defer UpdateStealRecordLock.Unlock()
|
||||
|
||||
logs.Info("【偷卡】更新偷卡记录", orderBankId, amount)
|
||||
otel.Logger.WithContext(ctx).Info("【偷卡】更新偷卡记录", zap.String(orderBankId, "orderBankId"), zap.Float64("amount", amount))
|
||||
//查询本次偷卡记录
|
||||
record, err := GetRelateRecordByTargetOrderNo(orderBankId)
|
||||
record, err := GetRelateRecordByTargetOrderNo(ctx, orderBankId)
|
||||
if err != nil || pointer.IsNil(record) || record.Id == 0 {
|
||||
return
|
||||
}
|
||||
//更新本次偷卡金额和状态
|
||||
err = UpdateRelateRecordStatus(orderBankId, amount, int(consts.StealRuleStatusSuccess))
|
||||
err = UpdateRelateRecordStatus(ctx, orderBankId, amount, int(consts.StealRuleStatusSuccess))
|
||||
//根据id查找配置
|
||||
cfg, err := hidden.GetMerchantHiddenConfigById(record.MerchantHiddenConfigId)
|
||||
if err != nil || pointer.IsNil(cfg) || cfg.Id == 0 {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReplaceNumberOrLetter(t *testing.T) {
|
||||
result := ReplaceNumberOrLetter("1111111111", len("1111111111"))
|
||||
logs.Info(result)
|
||||
otel.Logger.WithContext(context.Background()).Info(result)
|
||||
}
|
||||
|
||||
@@ -23,10 +23,8 @@ func init() {
|
||||
address := config.GetMQAddress()
|
||||
conn, err := stomp.Dial("tcp", address, options...)
|
||||
if err != nil {
|
||||
logs.Error("链接MQ失败:", err.Error())
|
||||
// os.Exit(1)
|
||||
logs.Info("链接MQ失败:", err.Error())
|
||||
}
|
||||
|
||||
activeConn = conn
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gateway/internal/otel"
|
||||
"os"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func SendMessage(topic, message string) {
|
||||
func SendMessage(ctx context.Context, topic, message string) {
|
||||
conn := GetActiveMQConn()
|
||||
if conn == nil {
|
||||
logs.Error("send message get Active mq fail")
|
||||
otel.Logger.WithContext(ctx).Error("send message get Active mq fail")
|
||||
os.Exit(1)
|
||||
}
|
||||
err := conn.Send(topic, "text/plain", []byte(message))
|
||||
|
||||
if err != nil {
|
||||
logs.Error("发送消息给activeMQ失败, message=", message)
|
||||
otel.Logger.WithContext(ctx).Error("发送消息给activeMQ失败, message=", zap.String("message", message))
|
||||
} else {
|
||||
logs.Info("发送消息给activeMQ成功,message=", message)
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("发送消息给activeMQ成功,message="), zap.String("message", message))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/consts"
|
||||
"gateway/internal/models/notify"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/message"
|
||||
"gateway/internal/utils"
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/go-stomp/stomp/v3"
|
||||
@@ -33,15 +37,15 @@ var (
|
||||
)
|
||||
|
||||
// SendOrderNotify 给商户发送订单结果
|
||||
func SendOrderNotify(bankOrderId string) {
|
||||
func SendOrderNotify(ctx context.Context, bankOrderId string) {
|
||||
if !notify.NotifyInfoExistByBankOrderId(bankOrderId) {
|
||||
logs.Error("该订单不存在回调内容,bankOrderId= " + bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("该订单不存在回调内容,bankOrderId= " + bankOrderId)
|
||||
return
|
||||
}
|
||||
|
||||
notifyInfo := notify.GetNotifyInfoByBankOrderId(bankOrderId)
|
||||
notifyInfo := notify.GetNotifyInfoByBankOrderId(ctx, bankOrderId)
|
||||
if notifyInfo.Status == "success" {
|
||||
logs.Info(fmt.Sprintf("该订单= %s,已经回调", bankOrderId))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("该订单= %s,已经回调", bankOrderId))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -50,15 +54,15 @@ func SendOrderNotify(bankOrderId string) {
|
||||
|
||||
req := httplib.Get(notifyInfo.Url)
|
||||
response, err := req.String()
|
||||
logs.Info(fmt.Sprintf("bankOrderId = %s, 回调结果为:%s", bankOrderId, response))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("bankOrderId = %s, 回调结果为:%s", bankOrderId, response))
|
||||
|
||||
if err == nil && ("success" == response || "SUCCESS" == response) {
|
||||
if strings.Contains(strings.ToLower(response), "success") {
|
||||
notifyInfo.Status = "success"
|
||||
if notify.UpdateNotifyInfo(notifyInfo) {
|
||||
logs.Info("订单回调成功, bankOrderId=", bankOrderId)
|
||||
if notify.UpdateNotifyInfo(ctx, notifyInfo) {
|
||||
otel.Logger.WithContext(ctx).Info("订单回调成功, bankOrderId=", zap.String("bankOrderId", bankOrderId))
|
||||
} else {
|
||||
logs.Error("订单回调成功,但是更新数据库失败, bankOrderId=", bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("订单回调成功,但是更新数据库失败, bankOrderId=", zap.String("bankOrderId", bankOrderId))
|
||||
}
|
||||
} else {
|
||||
logs.Notice("订单已经回调,商户已经收到了回调通知,但是返回值错误: ", response)
|
||||
@@ -68,7 +72,7 @@ func SendOrderNotify(bankOrderId string) {
|
||||
logs.Notice(fmt.Sprintf("该订单= %s,已经超过了回调次数", bankOrderId))
|
||||
} else {
|
||||
minute := GetOrderNotifyMinute(notifyInfo.Times)
|
||||
logs.Info(fmt.Sprintf("bankOrderId = %s, 进行第 %d 次回调,本次延时时间为:%d", notifyInfo.BankOrderId, notifyInfo.Times, minute))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("bankOrderId = %s, 进行第 %d 次回调,本次延时时间为:%d", notifyInfo.BankOrderId, notifyInfo.Times, minute))
|
||||
task := OrderNotifyTask{
|
||||
Delay: time.NewTimer(time.Duration(minute) * time.Minute),
|
||||
MerchantOrderId: notifyInfo.MerchantOrderId,
|
||||
@@ -76,11 +80,14 @@ func SendOrderNotify(bankOrderId string) {
|
||||
FirstNotifyTime: notifyInfo.CreateTime.Format("2006-12-20 12:43:34"),
|
||||
NotifyTimes: notifyInfo.Times, LimitTimes: consts.LimitTimes, Status: notifyInfo.Status,
|
||||
}
|
||||
notifyPool.Go(func() {
|
||||
OrderNotifyTimer(task)
|
||||
notifyPool.CtxGo(ctx, func() {
|
||||
// 创建一个5分钟超时的上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
OrderNotifyTimer(timeoutCtx, task)
|
||||
})
|
||||
if !notify.UpdateNotifyInfo(notifyInfo) {
|
||||
logs.Error("订单回调失败,数据库更新失败:" + bankOrderId)
|
||||
if !notify.UpdateNotifyInfo(ctx, notifyInfo) {
|
||||
otel.Logger.WithContext(ctx).Error("订单回调失败,数据库更新失败:" + bankOrderId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,11 +121,11 @@ func GetOrderNotifyMinute(times int) int {
|
||||
return cur
|
||||
}
|
||||
|
||||
func OrderNotifyTimer(task OrderNotifyTask) {
|
||||
func OrderNotifyTimer(ctx context.Context, task OrderNotifyTask) {
|
||||
for {
|
||||
select {
|
||||
case <-task.Delay.C:
|
||||
SendOrderNotify(task.BankOrderId)
|
||||
SendOrderNotify(ctx, task.BankOrderId)
|
||||
return
|
||||
case <-time.After(time.Minute * 70):
|
||||
logs.Notice("订单回调延时执行,70分钟没有执行")
|
||||
@@ -128,11 +135,11 @@ func OrderNotifyTimer(task OrderNotifyTask) {
|
||||
}
|
||||
|
||||
// CreateOrderDelayQueue 读取一小时之内,未发送成功,并且还没有到达回调限制次数的记录读取,存入延迟队列
|
||||
func CreateOrderDelayQueue() {
|
||||
func CreateOrderDelayQueue(ctx context.Context) {
|
||||
params := make(map[string]interface{})
|
||||
params["times__lte"] = consts.LimitTimes
|
||||
params["create_time__gte"] = utils.GetDateTimeBeforeHours(48)
|
||||
notifyList := notify.GetNotifyInfosNotSuccess(params)
|
||||
notifyList := notify.GetNotifyInfosNotSuccess(ctx, params)
|
||||
for _, nf := range notifyList {
|
||||
minute := GetOrderNotifyMinute(nf.Times)
|
||||
task := OrderNotifyTask{
|
||||
@@ -145,24 +152,27 @@ func CreateOrderDelayQueue() {
|
||||
Status: nf.Status,
|
||||
}
|
||||
notifyPool.Go(func() {
|
||||
OrderNotifyTimer(task)
|
||||
OrderNotifyTimer(ctx, task)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// CreateOrderNotifyConsumer 创建订单回调消费者
|
||||
func CreateOrderNotifyConsumer() {
|
||||
CreateOrderDelayQueue()
|
||||
func CreateOrderNotifyConsumer(ctx context.Context) {
|
||||
ctx, cancel := otel.Span(ctx, "CreateOrderNotifyConsumer", "CreateOrderNotifyConsumer")
|
||||
defer cancel()
|
||||
|
||||
CreateOrderDelayQueue(ctx)
|
||||
// 启动定时任务
|
||||
conn := message.GetActiveMQConn()
|
||||
if conn == nil {
|
||||
logs.Error("启动消息队列消费者失败....")
|
||||
otel.Logger.WithContext(ctx).Error("启动消息队列消费者失败....")
|
||||
os.Exit(1)
|
||||
}
|
||||
logs.Notice("订单回调消息队列启动成功......")
|
||||
orderNotify, err := conn.Subscribe(config.MqOrderNotify, stomp.AckClient)
|
||||
if err != nil {
|
||||
logs.Error("订阅订单回调失败......")
|
||||
otel.Logger.WithContext(ctx).Error("订阅订单回调失败......")
|
||||
os.Exit(1)
|
||||
}
|
||||
for {
|
||||
@@ -170,13 +180,15 @@ func CreateOrderNotifyConsumer() {
|
||||
case v := <-orderNotify.C:
|
||||
if v != nil {
|
||||
bankOrderId := string(v.Body)
|
||||
sendNotifyPool.Go(func() {
|
||||
SendOrderNotify(bankOrderId)
|
||||
sendNotifyPool.CtxGo(ctx, func() {
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, time.Hour)
|
||||
defer cancel()
|
||||
SendOrderNotify(timeoutCtx, bankOrderId)
|
||||
})
|
||||
// 应答,重要
|
||||
err := conn.Ack(v)
|
||||
if err != nil {
|
||||
logs.Error("消息应答失败!")
|
||||
otel.Logger.WithContext(ctx).Error("消息应答失败!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,32 +10,35 @@ import (
|
||||
"gateway/internal/models/merchant_deploy"
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/schema/response"
|
||||
"gateway/internal/service/message"
|
||||
"gateway/internal/service/supplier/third_party"
|
||||
"gateway/internal/utils"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
// AutoPayFor 程序自动代付
|
||||
func AutoPayFor(params map[string]any, giveType string) *response.PayForResponse {
|
||||
func AutoPayFor(ctx context.Context, params map[string]any, giveType string) *response.PayForResponse {
|
||||
payForResponse := new(response.PayForResponse)
|
||||
|
||||
merchantInfo := merchant.GetMerchantByPasskey(convertor.ToString(params["merchantKey"]))
|
||||
merchantInfo := merchant.GetMerchantByPasskey(ctx, convertor.ToString(params["merchantKey"]))
|
||||
if !utils.Md5Verify(params, merchantInfo.MerchantSecret) {
|
||||
logs.Error(fmt.Sprintf("下游商户代付请求,签名失败,商户信息: %+v", merchantInfo))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("下游商户代付请求,签名失败,商户信息: %+v", merchantInfo))
|
||||
payForResponse.ResultCode = "01"
|
||||
payForResponse.ResultMsg = "下游商户代付请求,签名失败。"
|
||||
return payForResponse
|
||||
} else {
|
||||
res, msg := checkSettAmount(convertor.ToString(params["amount"]))
|
||||
res, msg := checkSettAmount(ctx, convertor.ToString(params["amount"]))
|
||||
if !res {
|
||||
payForResponse.ResultCode = "01"
|
||||
payForResponse.ResultMsg = msg
|
||||
@@ -45,7 +48,7 @@ func AutoPayFor(params map[string]any, giveType string) *response.PayForResponse
|
||||
|
||||
exist := payfor.IsExistPayForByMerchantOrderId(convertor.ToString(params["merchantOrderId"]))
|
||||
if exist {
|
||||
logs.Error(fmt.Sprintf("代付订单号重复:merchantOrderId = %s", params["merchantOrderId"]))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("代付订单号重复:merchantOrderId = %s", params["merchantOrderId"]))
|
||||
payForResponse.ResultMsg = "商户订单号重复"
|
||||
payForResponse.ResultCode = "01"
|
||||
|
||||
@@ -54,7 +57,7 @@ func AutoPayFor(params map[string]any, giveType string) *response.PayForResponse
|
||||
|
||||
settAmount, err := strconv.ParseFloat(convertor.ToString(params["amount"]), 64)
|
||||
if err != nil {
|
||||
logs.Error("代付的金额错误:", err)
|
||||
otel.Logger.WithContext(ctx).Error("代付的金额错误:", zap.Error(err))
|
||||
payForResponse.ResultMsg = "代付金额错误"
|
||||
payForResponse.ResultCode = "01"
|
||||
return payForResponse
|
||||
@@ -81,10 +84,10 @@ func AutoPayFor(params map[string]any, giveType string) *response.PayForResponse
|
||||
}
|
||||
|
||||
// 获取银行编码和银行名称
|
||||
p.BankCode = utils.GetBankCodeByBankCardNo(p.BankAccountNo)
|
||||
p.BankCode = utils.GetBankCodeByBankCardNo(ctx, p.BankAccountNo)
|
||||
p.BankName = utils.GetBankNameByCode(p.BankCode)
|
||||
|
||||
if !payfor.InsertPayFor(p) {
|
||||
if !payfor.InsertPayFor(ctx, p) {
|
||||
payForResponse.ResultCode = "01"
|
||||
payForResponse.ResultMsg = "代付记录插入失败"
|
||||
} else {
|
||||
@@ -93,9 +96,9 @@ func AutoPayFor(params map[string]any, giveType string) *response.PayForResponse
|
||||
payForResponse.SettAmount = convertor.ToString(params["amount"])
|
||||
payForResponse.MerchantOrderId = convertor.ToString(params["MerchantOrderId"])
|
||||
|
||||
p = payfor.GetPayForByBankOrderId(p.BankOrderId)
|
||||
p = payfor.GetPayForByBankOrderId(ctx, p.BankOrderId)
|
||||
|
||||
if findPayForRoad(p) {
|
||||
if findPayForRoad(ctx, p) {
|
||||
payForResponse.ResultCode = "00"
|
||||
payForResponse.ResultMsg = "银行处理中"
|
||||
} else {
|
||||
@@ -112,63 +115,63 @@ func AutoPayFor(params map[string]any, giveType string) *response.PayForResponse
|
||||
/**
|
||||
* 返回1表示需要手动打款,返回0表示银行已经受理,-1表示系统处理失败
|
||||
*/
|
||||
func findPayForRoad(p payfor.PayforInfo) bool {
|
||||
m := merchant.GetMerchantByUid(p.MerchantUid)
|
||||
func findPayForRoad(ctx context.Context, p payfor.PayforInfo) bool {
|
||||
m := merchant.GetMerchantByUid(ctx, p.MerchantUid)
|
||||
|
||||
md := merchant_deploy.GetMerchantDeployByUidAndRoadUid(m.MerchantUid, p.RoadUid)
|
||||
md := merchant_deploy.GetMerchantDeployByUidAndRoadUid(ctx, m.MerchantUid, p.RoadUid)
|
||||
|
||||
// 检查商户是否设置了自动代付
|
||||
if md.AutoPayfor == config.NO || md.AutoPayfor == "" {
|
||||
logs.Notice(fmt.Sprintf("该商户uid=%s, 没有开通自动代付功能", p.MerchantUid))
|
||||
p.Type = config.PAYFOR_HAND
|
||||
payfor.UpdatePayFor(p)
|
||||
payfor.UpdatePayFor(ctx, p)
|
||||
} else {
|
||||
if m.SinglePayForRoadUid != "" {
|
||||
p.RoadUid = m.SinglePayForRoadUid
|
||||
p.RoadName = m.SinglePayForRoadName
|
||||
} else {
|
||||
roadPoolInfo := road.GetRoadPoolByRoadPoolCode(m.RollPayForRoadCode)
|
||||
roadPoolInfo := road.GetRoadPoolByRoadPoolCode(ctx, m.RollPayForRoadCode)
|
||||
roadUids := strings.Split(roadPoolInfo.RoadUidPool, "||")
|
||||
roadInfoList := road.GetRoadInfosByRoadUids(roadUids)
|
||||
roadInfoList := road.GetRoadInfosByRoadUids(ctx, roadUids)
|
||||
if len(roadUids) == 0 || len(roadInfoList) == 0 {
|
||||
logs.Error(fmt.Sprintf("通道轮询池=%s, 没有配置通道", m.RollPayForRoadCode))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("通道轮询池=%s, 没有配置通道", m.RollPayForRoadCode))
|
||||
} else {
|
||||
p.RoadUid = roadInfoList[0].RoadUid
|
||||
p.RoadName = roadInfoList[0].RoadName
|
||||
}
|
||||
}
|
||||
|
||||
if !payfor.UpdatePayFor(p) {
|
||||
if !payfor.UpdatePayFor(ctx, p) {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(p.RoadUid) > 0 {
|
||||
roadInfo := road.GetRoadInfoByRoadUid(p.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, p.RoadUid)
|
||||
p.PayforFee = roadInfo.SettleFee
|
||||
p.PayforTotalAmount = p.PayforFee + p.PayforAmount
|
||||
|
||||
if m.PayforFee > config.ZERO {
|
||||
logs.Info(fmt.Sprintf("商户uid=%s,有单独的代付手续费。", m.MerchantUid))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("商户uid=%s,有单独的代付手续费。", m.MerchantUid))
|
||||
p.PayforFee = m.PayforFee
|
||||
p.PayforTotalAmount = p.PayforFee + p.PayforAmount
|
||||
}
|
||||
|
||||
if !payfor.UpdatePayFor(p) {
|
||||
if !payfor.UpdatePayFor(ctx, p) {
|
||||
return false
|
||||
}
|
||||
|
||||
if p.GiveType == config.SELF_HELP {
|
||||
if !MerchantSelf(p) {
|
||||
if !MerchantSelf(ctx, p) {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if !SendPayFor(p) {
|
||||
if !SendPayFor(ctx, p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p.Status = config.PAYFOR_FAIL
|
||||
if !payfor.UpdatePayFor(p) {
|
||||
if !payfor.UpdatePayFor(ctx, p) {
|
||||
return false
|
||||
}
|
||||
p.ResponseContent = "没有设置代付通道"
|
||||
@@ -179,10 +182,10 @@ func findPayForRoad(p payfor.PayforInfo) bool {
|
||||
}
|
||||
|
||||
// MerchantSelf 商户自己体现
|
||||
func MerchantSelf(p payfor.PayforInfo) bool {
|
||||
func MerchantSelf(ctx context.Context, p payfor.PayforInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
if err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
p.UpdateTime = time.Now()
|
||||
p.Status = config.PAYFOR_BANKING
|
||||
p.RequestTime = time.Now()
|
||||
@@ -191,7 +194,7 @@ func MerchantSelf(p payfor.PayforInfo) bool {
|
||||
return err
|
||||
}
|
||||
|
||||
RequestPayFor(p)
|
||||
RequestPayFor(ctx, p)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
@@ -200,13 +203,13 @@ func MerchantSelf(p payfor.PayforInfo) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func SendPayFor(p payfor.PayforInfo) bool {
|
||||
func SendPayFor(ctx context.Context, p payfor.PayforInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
var account accounts.AccountInfo
|
||||
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", p.MerchantUid).QueryRow(&account); err != nil || account.AccountUid == "" {
|
||||
logs.Error("send payfor select account fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("send payfor select account fail:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -226,7 +229,7 @@ func SendPayFor(p payfor.PayforInfo) bool {
|
||||
account.PayforAmount = account.PayforAmount + p.PayforAmount + p.PayforFee
|
||||
|
||||
if _, err := txOrm.Update(&account); err != nil {
|
||||
logs.Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更新账户表出错, err: %s", p.MerchantUid, err))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更新账户表出错, err: %s", p.MerchantUid, err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -237,11 +240,11 @@ func SendPayFor(p payfor.PayforInfo) bool {
|
||||
p.UpdateTime = time.Now()
|
||||
|
||||
if _, err := txOrm.Update(&p); err != nil {
|
||||
logs.Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更代付列表出错, err:%s", p.MerchantUid, err))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,在发送代付给上游的处理中,更代付列表出错, err:%s", p.MerchantUid, err))
|
||||
return err
|
||||
}
|
||||
|
||||
RequestPayFor(p)
|
||||
RequestPayFor(ctx, p)
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
@@ -250,31 +253,31 @@ func SendPayFor(p payfor.PayforInfo) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func RequestPayFor(p payfor.PayforInfo) {
|
||||
func RequestPayFor(ctx context.Context, p payfor.PayforInfo) {
|
||||
if p.RoadUid == "" {
|
||||
return
|
||||
}
|
||||
p.Type = config.PAYFOR_ROAD
|
||||
roadInfo := road.GetRoadInfoByRoadUid(p.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, p.RoadUid)
|
||||
supplierCode := roadInfo.ProductUid
|
||||
supplier := third_party.GetPaySupplierByCode(supplierCode)
|
||||
res := supplier.PayFor(p)
|
||||
logs.Info(fmt.Sprintf("代付uid=%s,上游处理结果为:%s", p.PayforUid, res))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,上游处理结果为:%s", p.PayforUid, res))
|
||||
// 将代付订单号发送到消息队列
|
||||
message.SendMessage(config.MqPayForQuery, p.BankOrderId)
|
||||
message.SendMessage(ctx, config.MqPayForQuery, p.BankOrderId)
|
||||
}
|
||||
|
||||
// PayForResultQuery 代付结果查询
|
||||
func PayForResultQuery(params map[string]any) string {
|
||||
func PayForResultQuery(ctx context.Context, params map[string]any) string {
|
||||
query := make(map[string]any)
|
||||
query["merchantOrderId"] = params["merchantOrderId"]
|
||||
merchantInfo := merchant.GetMerchantByPasskey(convertor.ToString(params["merchantKey"]))
|
||||
merchantInfo := merchant.GetMerchantByPasskey(ctx, convertor.ToString(params["merchantKey"]))
|
||||
if !utils.Md5Verify(params, merchantInfo.MerchantSecret) {
|
||||
query["resultMsg"] = "签名错误"
|
||||
query["settStatus"] = "03"
|
||||
query["sign"] = utils.GetMD5Sign(params, utils.SortMap(params), merchantInfo.MerchantSecret)
|
||||
} else {
|
||||
payForInfo := payfor.GetPayForByMerchantOrderId(convertor.ToString(params["merchantOrderId"]))
|
||||
payForInfo := payfor.GetPayForByMerchantOrderId(ctx, convertor.ToString(params["merchantOrderId"]))
|
||||
if payForInfo.BankOrderId == "" {
|
||||
query["resultMsg"] = "不存在这样的代付订单"
|
||||
query["settStatus"] = "03"
|
||||
@@ -305,7 +308,7 @@ func PayForResultQuery(params map[string]any) string {
|
||||
|
||||
mJson, err := json.Marshal(query)
|
||||
if err != nil {
|
||||
logs.Error("PayForQuery json marshal fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("PayForQuery json marshal fail:", zap.Error(err))
|
||||
return fmt.Sprintf("PayForQuery json marshal fail:%s", err.Error())
|
||||
} else {
|
||||
return string(mJson)
|
||||
@@ -313,17 +316,17 @@ func PayForResultQuery(params map[string]any) string {
|
||||
}
|
||||
|
||||
// BalanceQuery 商户查询余额
|
||||
func BalanceQuery(params map[string]any) string {
|
||||
func BalanceQuery(ctx context.Context, params map[string]any) string {
|
||||
balanceResponse := new(response.BalanceResponse)
|
||||
str := ""
|
||||
merchantInfo := merchant.GetMerchantByPasskey(convertor.ToString(params["merchantKey"]))
|
||||
merchantInfo := merchant.GetMerchantByPasskey(ctx, convertor.ToString(params["merchantKey"]))
|
||||
if !utils.Md5Verify(params, merchantInfo.MerchantSecret) {
|
||||
balanceResponse.ResultCode = "-1"
|
||||
balanceResponse.ResultMsg = "签名错误"
|
||||
mJson, _ := json.Marshal(balanceResponse)
|
||||
str = string(mJson)
|
||||
} else {
|
||||
accountInfo := accounts.GetAccountByUid(merchantInfo.MerchantUid)
|
||||
accountInfo := accounts.GetAccountByUid(ctx, merchantInfo.MerchantUid)
|
||||
tmp := make(map[string]any)
|
||||
tmp["resultCode"] = "00"
|
||||
tmp["balance"] = strconv.FormatFloat(accountInfo.Balance, 'f', 2, 64)
|
||||
@@ -341,10 +344,10 @@ func BalanceQuery(params map[string]any) string {
|
||||
return str
|
||||
}
|
||||
|
||||
func checkSettAmount(settAmount string) (bool, string) {
|
||||
func checkSettAmount(ctx context.Context, settAmount string) (bool, string) {
|
||||
_, err := strconv.ParseFloat(settAmount, 64)
|
||||
if err != nil {
|
||||
logs.Error(fmt.Sprintf("代付金额有误,settAmount = %s", settAmount))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("代付金额有误,settAmount = %s", settAmount))
|
||||
return false, "代付金额有误"
|
||||
}
|
||||
return true, ""
|
||||
|
||||
@@ -7,33 +7,34 @@ import (
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/models/accounts"
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/otel"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func PayForFail(p payfor.PayforInfo) bool {
|
||||
func PayForFail(ctx context.Context, p payfor.PayforInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
if err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
var tmpForPay payfor.PayforInfo
|
||||
if err := txOrm.Raw(
|
||||
"select * from payfor_info where bank_order_id = ? for update", p.BankOrderId).
|
||||
QueryRow(&tmpForPay); err != nil || tmpForPay.PayforUid == "" {
|
||||
|
||||
logs.Error("solve pay fail select fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve pay fail select fail:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if tmpForPay.Status == config.PAYFOR_FAIL || tmpForPay.Status == config.PAYFOR_SUCCESS {
|
||||
logs.Error(fmt.Sprintf("该代付订单uid=%s,状态已经是最终结果", tmpForPay.PayforUid))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("该代付订单uid=%s,状态已经是最终结果", tmpForPay.PayforUid))
|
||||
return errors.New("状态已经是最终结果")
|
||||
}
|
||||
// 更新payfor记录的状态
|
||||
tmpForPay.Status = config.PAYFOR_FAIL
|
||||
tmpForPay.UpdateTime = time.Now()
|
||||
if _, err := txOrm.Update(&tmpForPay); err != nil {
|
||||
logs.Error("PayForFail update payfor_info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("PayForFail update payfor_info fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -43,20 +44,20 @@ func PayForFail(p payfor.PayforInfo) bool {
|
||||
tmpForPay.MerchantUid).
|
||||
QueryRow(&account); err != nil || account.AccountUid == "" {
|
||||
|
||||
logs.Error("payfor select account fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("payfor select account fail:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
account.UpdateTime = time.Now()
|
||||
if account.PayforAmount < tmpForPay.PayforTotalAmount {
|
||||
logs.Error(fmt.Sprintf("商户uid=%s,账户中待代付金额小于代付记录的金额", tmpForPay.MerchantUid))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,账户中待代付金额小于代付记录的金额", tmpForPay.MerchantUid))
|
||||
return errors.New("账户中待代付金额小于代付记录的金额")
|
||||
}
|
||||
// 将正在打款中的金额减去
|
||||
account.PayforAmount = account.PayforAmount - tmpForPay.PayforTotalAmount
|
||||
|
||||
if _, err := txOrm.Update(&account); err != nil {
|
||||
logs.Error("PayForFail update account fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("PayForFail update account fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -67,19 +68,19 @@ func PayForFail(p payfor.PayforInfo) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func PayForSuccess(p payfor.PayforInfo) bool {
|
||||
func PayForSuccess(ctx context.Context, p payfor.PayforInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
var tmpPayFor payfor.PayforInfo
|
||||
if err := txOrm.Raw("select * from payfor_info where bank_order_id = ? for update",
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from payfor_info where bank_order_id = ? for update",
|
||||
p.BankOrderId).
|
||||
QueryRow(&tmpPayFor); err != nil || tmpPayFor.PayforUid == "" {
|
||||
logs.Error("payfor success select payfor fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("payfor success select payfor fail:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
if tmpPayFor.Status == config.PAYFOR_FAIL || tmpPayFor.Status == config.PAYFOR_SUCCESS {
|
||||
logs.Error(fmt.Sprintf("该代付订单uid=#{payFor.PayforUid},已经是最终结果,不需要处理"))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("该代付订单uid=#{payFor.PayforUid},已经是最终结果,不需要处理"))
|
||||
return errors.New("已经是最终结果,不需要处理")
|
||||
}
|
||||
|
||||
@@ -87,22 +88,21 @@ func PayForSuccess(p payfor.PayforInfo) bool {
|
||||
tmpPayFor.Status = config.PAYFOR_SUCCESS
|
||||
_, err := txOrm.Update(&tmpPayFor)
|
||||
if err != nil {
|
||||
logs.Error("PayForSuccess update payfor fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("PayForSuccess update payfor fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
var account accounts.AccountInfo
|
||||
if err := txOrm.Raw(
|
||||
"select * from account_info where account_uid = ? for update",
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from account_info where account_uid = ? for update",
|
||||
tmpPayFor.MerchantUid).
|
||||
QueryRow(&account); err != nil || account.AccountUid == "" {
|
||||
logs.Error("payfor success select account fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("payfor success select account fail:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
account.UpdateTime = time.Now()
|
||||
if account.PayforAmount < tmpPayFor.PayforTotalAmount {
|
||||
logs.Error(fmt.Sprintf("商户uid=#{payFor.MerchantUid},账户中待代付金额小于代付记录的金额"))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=#{payFor.MerchantUid},账户中待代付金额小于代付记录的金额"))
|
||||
return errors.New("账户中待代付金额小于代付记录的金额")
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ func PayForSuccess(p payfor.PayforInfo) bool {
|
||||
account.SettleAmount = account.SettleAmount - tmpPayFor.PayforTotalAmount
|
||||
|
||||
if _, err := txOrm.Update(&account); err != nil {
|
||||
logs.Error("PayForSuccess update account fail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("PayForSuccess update account fail:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func PayForSuccess(p payfor.PayforInfo) bool {
|
||||
}
|
||||
|
||||
if _, err := txOrm.Insert(&accountHistory); err != nil {
|
||||
logs.Error("PayForSuccess insert account history fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("PayForSuccess insert account history fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
@@ -13,36 +15,37 @@ import (
|
||||
"gateway/internal/schema/request"
|
||||
"gateway/internal/schema/response"
|
||||
"gateway/internal/utils"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// ChooseRoadV2 选择通道,通过productCode选择对应的通道
|
||||
func ChooseRoadV2(c *response.PayBaseResp) *response.PayBaseResp {
|
||||
func ChooseRoadV2(ctx context.Context, c *response.PayBaseResp) *response.PayBaseResp {
|
||||
orderPrice, err := strconv.ParseFloat(convertor.ToString(c.Params["orderPrice"]), 64)
|
||||
if err != nil {
|
||||
c.Code = -1
|
||||
c.Msg = "输入金额错误!"
|
||||
return c
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByProductCode(convertor.ToString(c.Params["productCode"]))
|
||||
roadInfo := road.GetRoadInfoByProductCode(ctx, convertor.ToString(c.Params["productCode"]))
|
||||
if roadInfo.Id == 0 {
|
||||
c.Code = -1
|
||||
c.Msg = "未配置支付通道!"
|
||||
return c
|
||||
}
|
||||
if msg, ok := RoadIsValid(roadInfo, c); !ok {
|
||||
if msg, ok := RoadIsValid(ctx, roadInfo, c); !ok {
|
||||
c.Code = -1
|
||||
c.Msg = msg
|
||||
return c
|
||||
}
|
||||
merchantUid := c.MerchantInfo.MerchantUid
|
||||
// 通道配置信息
|
||||
deployInfo := merchant_deploy.GetMerchantDeployByUidAndRoadUid(merchantUid, roadInfo.RoadUid)
|
||||
deployInfo := merchant_deploy.GetMerchantDeployByUidAndRoadUid(ctx, merchantUid, roadInfo.RoadUid)
|
||||
if deployInfo.MerchantUid == "" {
|
||||
c.Code = -1
|
||||
c.Msg = "该商户没有配置通道信息"
|
||||
@@ -62,12 +65,12 @@ func ChooseRoadV2(c *response.PayBaseResp) *response.PayBaseResp {
|
||||
c.RoadInfo = roadInfo
|
||||
c.PlatformRate = rate
|
||||
c.AgentRate = deployInfo.SingleRoadAgentRate
|
||||
c.RoadPoolInfo = road.GetRoadPoolByRoadPoolCode(deployInfo.RollRoadCode)
|
||||
c.RoadPoolInfo = road.GetRoadPoolByRoadPoolCode(ctx, deployInfo.RollRoadCode)
|
||||
return c
|
||||
}
|
||||
|
||||
// RoadIsValid 判断通道是否是合法的
|
||||
func RoadIsValid(roadInfo road.RoadInfo, c *response.PayBaseResp) (string, bool) {
|
||||
func RoadIsValid(ctx context.Context, roadInfo road.RoadInfo, c *response.PayBaseResp) (string, bool) {
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
return "参数缺失", false
|
||||
}
|
||||
@@ -84,7 +87,7 @@ func RoadIsValid(roadInfo road.RoadInfo, c *response.PayBaseResp) (string, bool)
|
||||
return "当前未处在交易区间内", false
|
||||
}
|
||||
if roadInfo.SingleMinLimit > c.OrderAmount || roadInfo.SingleMaxLimit < c.OrderAmount {
|
||||
logs.Error(FORMAT + "订单金额超限制")
|
||||
otel.Logger.WithContext(ctx).Error(FORMAT + "订单金额超限制")
|
||||
return "订单金额超过交易限制", false
|
||||
}
|
||||
todayLimit := roadInfo.TodayLimit
|
||||
@@ -92,18 +95,18 @@ func RoadIsValid(roadInfo road.RoadInfo, c *response.PayBaseResp) (string, bool)
|
||||
todayIncome := roadInfo.TodayIncome
|
||||
totalIncome := roadInfo.TotalIncome
|
||||
if (todayIncome + c.OrderAmount) > todayLimit {
|
||||
logs.Error(FORMAT + "达到了每天金额上限")
|
||||
otel.Logger.WithContext(ctx).Error(FORMAT + "达到了每天金额上限")
|
||||
return "订单金额超过金额限制", false
|
||||
}
|
||||
if (totalIncome + c.OrderAmount) > totalLimit {
|
||||
logs.Error(FORMAT + "达到了总量限制")
|
||||
otel.Logger.WithContext(ctx).Error(FORMAT + "达到了总量限制")
|
||||
return "订单金额达到总量限制", false
|
||||
}
|
||||
// 如果通道被选中,那么总请求数+1
|
||||
roadInfo.RequestAll = roadInfo.RequestAll + 1
|
||||
roadInfo.TodayRequestAll = roadInfo.RequestAll + 1
|
||||
roadInfo.UpdateTime = time.Now()
|
||||
road.UpdateRoadInfo(roadInfo)
|
||||
road.UpdateRoadInfo(ctx, roadInfo)
|
||||
return "", true
|
||||
}
|
||||
|
||||
@@ -176,7 +179,7 @@ func CreateOrderInfo(createdOrder request.CreatedOrder, info merchant.MerchantIn
|
||||
}
|
||||
|
||||
// GenerateOrderProfit 计算收益,平台利润,代理利润
|
||||
func GenerateOrderProfit(orderInfo order.OrderInfo, c *response.PayBaseResp) order.OrderProfitInfo {
|
||||
func GenerateOrderProfit(ctx context.Context, orderInfo order.OrderInfo, c *response.PayBaseResp) order.OrderProfitInfo {
|
||||
// 因为所有的手续费率都是百分率,所以需要除以100
|
||||
supplierProfit := decimal.NewFromFloat(orderInfo.OrderAmount).
|
||||
Div(decimal.NewFromInt(100)).
|
||||
@@ -196,7 +199,7 @@ func GenerateOrderProfit(orderInfo order.OrderInfo, c *response.PayBaseResp) ord
|
||||
allProfit := supplierProfit.Add(platformProfit).Add(agentProfit)
|
||||
|
||||
if allProfit.GreaterThanOrEqual(decimal.NewFromFloat(orderInfo.OrderAmount)) {
|
||||
logs.Error("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId))
|
||||
c.Msg = "手续费已经超过了订单金额"
|
||||
c.Code = -1
|
||||
}
|
||||
@@ -210,20 +213,20 @@ func GenerateOrderProfit(orderInfo order.OrderInfo, c *response.PayBaseResp) ord
|
||||
OrderAmount: c.OrderAmount,
|
||||
FactAmount: c.OrderAmount,
|
||||
ShowAmount: c.OrderAmount,
|
||||
AllProfit: allProfit.InexactFloat64(),
|
||||
UserInAmount: decimal.NewFromFloat(orderInfo.OrderAmount).Sub(allProfit).InexactFloat64(),
|
||||
SupplierProfit: supplierProfit.InexactFloat64(),
|
||||
PlatformProfit: platformProfit.InexactFloat64(),
|
||||
AgentProfit: agentProfit.InexactFloat64(),
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
MerchantUid: c.MerchantInfo.MerchantUid,
|
||||
MerchantName: orderInfo.MerchantName,
|
||||
SupplierRate: c.RoadInfo.BasicFee,
|
||||
PlatformRate: c.PlatformRate,
|
||||
AgentRate: c.AgentRate,
|
||||
AgentName: orderInfo.AgentName,
|
||||
AgentUid: orderInfo.AgentUid,
|
||||
// AllProfit: allProfit.InexactFloat64(),
|
||||
UserInAmount: decimal.NewFromFloat(orderInfo.OrderAmount).Sub(allProfit).InexactFloat64(),
|
||||
SupplierProfit: supplierProfit.InexactFloat64(),
|
||||
PlatformProfit: platformProfit.InexactFloat64(),
|
||||
AgentProfit: agentProfit.InexactFloat64(),
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
MerchantUid: c.MerchantInfo.MerchantUid,
|
||||
MerchantName: orderInfo.MerchantName,
|
||||
SupplierRate: c.RoadInfo.BasicFee,
|
||||
PlatformRate: c.PlatformRate,
|
||||
AgentRate: c.AgentRate,
|
||||
AgentName: orderInfo.AgentName,
|
||||
AgentUid: orderInfo.AgentUid,
|
||||
}
|
||||
|
||||
// 如果该条订单设置了代理利率,并且设置了代理
|
||||
@@ -234,7 +237,7 @@ func GenerateOrderProfit(orderInfo order.OrderInfo, c *response.PayBaseResp) ord
|
||||
return orderProfit
|
||||
}
|
||||
|
||||
func CreateOrderProfitInfo(createdOrder request.CreatedOrder, merchantInfo merchant.MerchantInfo, merchantDeployInfo merchant_deploy.MerchantDeployInfo, orderInfo order.OrderInfo, roadInfo road.RoadInfo) (orderProfitInfo order.OrderProfitInfo, err error) {
|
||||
func CreateOrderProfitInfo(ctx context.Context, createdOrder request.CreatedOrder, merchantInfo merchant.MerchantInfo, merchantDeployInfo merchant_deploy.MerchantDeployInfo, orderInfo order.OrderInfo, roadInfo road.RoadInfo) (orderProfitInfo order.OrderProfitInfo, err error) {
|
||||
// 因为所有的手续费率都是百分率,所以需要除以100
|
||||
platFormRate, err := merchantDeployInfo.GetSingleRoadPlatformRateByPrice(createdOrder.OrderPrice)
|
||||
if err != nil {
|
||||
@@ -260,7 +263,7 @@ func CreateOrderProfitInfo(createdOrder request.CreatedOrder, merchantInfo merch
|
||||
allProfit := supplierProfit.Add(platformProfit).Add(agentProfit)
|
||||
|
||||
if allProfit.GreaterThanOrEqual(decimal.NewFromFloat(orderInfo.OrderAmount)) {
|
||||
logs.Error("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("手续费已经超过订单金额,bankOrderId = %s", orderInfo.BankOrderId))
|
||||
err = errors.New("手续费已经超过订单金额")
|
||||
return
|
||||
}
|
||||
@@ -274,44 +277,44 @@ func CreateOrderProfitInfo(createdOrder request.CreatedOrder, merchantInfo merch
|
||||
OrderAmount: orderInfo.OrderAmount,
|
||||
FactAmount: orderInfo.FactAmount,
|
||||
ShowAmount: orderInfo.ShowAmount,
|
||||
AllProfit: allProfit.InexactFloat64(),
|
||||
UserInAmount: decimal.NewFromFloat(orderInfo.OrderAmount).Sub(allProfit).InexactFloat64(),
|
||||
SupplierProfit: supplierProfit.InexactFloat64(),
|
||||
PlatformProfit: platformProfit.InexactFloat64(),
|
||||
AgentProfit: agentProfit.InexactFloat64(),
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
MerchantUid: merchantInfo.MerchantUid,
|
||||
MerchantName: orderInfo.MerchantName,
|
||||
SupplierRate: roadInfo.BasicFee,
|
||||
PlatformRate: platFormRate,
|
||||
AgentRate: merchantDeployInfo.SingleRoadAgentRate,
|
||||
AgentName: orderInfo.AgentName,
|
||||
AgentUid: orderInfo.AgentUid,
|
||||
// AllProfit: allProfit.InexactFloat64(),
|
||||
UserInAmount: decimal.NewFromFloat(orderInfo.OrderAmount).Sub(allProfit).InexactFloat64(),
|
||||
SupplierProfit: supplierProfit.InexactFloat64(),
|
||||
PlatformProfit: platformProfit.InexactFloat64(),
|
||||
AgentProfit: agentProfit.InexactFloat64(),
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
MerchantUid: merchantInfo.MerchantUid,
|
||||
MerchantName: orderInfo.MerchantName,
|
||||
SupplierRate: roadInfo.BasicFee,
|
||||
PlatformRate: platFormRate,
|
||||
AgentRate: merchantDeployInfo.SingleRoadAgentRate,
|
||||
AgentName: orderInfo.AgentName,
|
||||
AgentUid: orderInfo.AgentUid,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GenerateRecord 生成订单一系列的记录
|
||||
func GenerateRecord(c *response.PayBaseResp) (order.OrderInfo, order.OrderProfitInfo, error) {
|
||||
func GenerateRecord(ctx context.Context, c *response.PayBaseResp) (order.OrderInfo, order.OrderProfitInfo, error) {
|
||||
// 获取订单和订单利润表
|
||||
orderInfo := order.GetOrderByMerchantOrderId(convertor.ToString(c.Params["orderNo"]))
|
||||
orderProfitInfo := order.GetOrderProfitByMerchantOrderId(convertor.ToString(c.Params["orderNo"]))
|
||||
orderInfo := order.GetOrderByMerchantOrderId(ctx, convertor.ToString(c.Params["orderNo"]))
|
||||
orderProfitInfo := order.GetOrderProfitByMerchantOrderId(ctx, convertor.ToString(c.Params["orderNo"]))
|
||||
if orderProfitInfo.Id == 0 || orderInfo.MerchantOrderId == "" {
|
||||
//生成订单记录,订单利润利润
|
||||
orderInfo = GenerateOrderInfo(c)
|
||||
orderProfit := GenerateOrderProfit(orderInfo, c)
|
||||
orderProfit := GenerateOrderProfit(ctx, orderInfo, c)
|
||||
if c.Code == -1 {
|
||||
return orderInfo, orderProfit, errors.New("订单数据插入失败")
|
||||
}
|
||||
//插入订单记录和订单利润记录
|
||||
if !order.InsertOrderAndOrderProfit(orderInfo, orderProfit) {
|
||||
if !order.InsertOrderAndOrderProfit(ctx, orderInfo, orderProfit) {
|
||||
c.Code = -1
|
||||
return orderInfo, orderProfit, errors.New("订单数据插入失败")
|
||||
}
|
||||
orderInfo = order.GetOrderByMerchantOrderId(convertor.ToString(c.Params["orderNo"]))
|
||||
orderProfitInfo = order.GetOrderProfitByBankOrderId(orderProfitInfo.BankOrderId)
|
||||
logs.Info("插入支付订单记录和支付利润记录成功")
|
||||
orderInfo = order.GetOrderByMerchantOrderId(ctx, convertor.ToString(c.Params["orderNo"]))
|
||||
orderProfitInfo = order.GetOrderProfitByBankOrderId(ctx, orderProfitInfo.BankOrderId)
|
||||
otel.Logger.WithContext(ctx).Info("插入支付订单记录和支付利润记录成功")
|
||||
return orderInfo, orderProfit, nil
|
||||
}
|
||||
if orderInfo.Status != config.Created {
|
||||
@@ -330,13 +333,13 @@ func GenerateRecord(c *response.PayBaseResp) (order.OrderInfo, order.OrderProfit
|
||||
err := errors.New("订单数据插入失败")
|
||||
return orderInfo, orderProfitInfo, err
|
||||
}
|
||||
if !order.SwitchOrderAndOrderProfitStatus(convertor.ToString(c.Params["orderNo"]), config.WAIT) {
|
||||
if !order.SwitchOrderAndOrderProfitStatus(ctx, convertor.ToString(c.Params["orderNo"]), config.WAIT) {
|
||||
err := errors.New("订单状态转换失败")
|
||||
return orderInfo, orderProfitInfo, err
|
||||
}
|
||||
orderInfo = order.GetOrderByMerchantOrderId(convertor.ToString(c.Params["orderNo"]))
|
||||
orderProfitInfo = order.GetOrderProfitByBankOrderId(orderProfitInfo.BankOrderId)
|
||||
logs.Info("插入支付订单记录和支付利润记录成功")
|
||||
orderInfo = order.GetOrderByMerchantOrderId(ctx, convertor.ToString(c.Params["orderNo"]))
|
||||
orderProfitInfo = order.GetOrderProfitByBankOrderId(ctx, orderProfitInfo.BankOrderId)
|
||||
otel.Logger.WithContext(ctx).Info("插入支付订单记录和支付利润记录成功")
|
||||
return orderInfo, orderProfitInfo, nil
|
||||
}
|
||||
|
||||
@@ -364,14 +367,14 @@ func GenerateSuccessData(scanData supplier.ScanData, c *response.PayBaseResp) *r
|
||||
return scanSuccessData
|
||||
}
|
||||
|
||||
func CreateOrderInfoAndOrderProfitInfo(createdOrder request.CreatedOrder, info merchant.MerchantInfo) (orderInfo order.OrderInfo, err error) {
|
||||
roadInfo := road.GetRoadInfoByProductCode(createdOrder.ProductCode)
|
||||
func CreateOrderInfoAndOrderProfitInfo(ctx context.Context, createdOrder request.CreatedOrder, info merchant.MerchantInfo) (orderInfo order.OrderInfo, err error) {
|
||||
roadInfo := road.GetRoadInfoByProductCode(ctx, createdOrder.ProductCode)
|
||||
|
||||
if roadInfo.Id == 0 {
|
||||
err = errors.New("未配置支付方式")
|
||||
return
|
||||
}
|
||||
if msg, ok := RoadIsValid(roadInfo, &response.PayBaseResp{
|
||||
if msg, ok := RoadIsValid(ctx, roadInfo, &response.PayBaseResp{
|
||||
OrderAmount: createdOrder.OrderPrice,
|
||||
}); !ok {
|
||||
err = errors.New(msg)
|
||||
@@ -379,6 +382,7 @@ func CreateOrderInfoAndOrderProfitInfo(createdOrder request.CreatedOrder, info m
|
||||
}
|
||||
|
||||
merchantDeploy := merchant_deploy.GetMerchantDeployByUidAndRoadUid(
|
||||
ctx,
|
||||
info.MerchantUid,
|
||||
roadInfo.RoadUid,
|
||||
)
|
||||
@@ -387,7 +391,7 @@ func CreateOrderInfoAndOrderProfitInfo(createdOrder request.CreatedOrder, info m
|
||||
return
|
||||
}
|
||||
|
||||
roadPoolInfo := road.GetRoadPoolByRoadPoolCode(merchantDeploy.RollRoadCode)
|
||||
roadPoolInfo := road.GetRoadPoolByRoadPoolCode(ctx, merchantDeploy.RollRoadCode)
|
||||
if roadPoolInfo.Id == 0 {
|
||||
err = errors.New("当前用户未配置支付方式")
|
||||
return
|
||||
@@ -399,13 +403,13 @@ func CreateOrderInfoAndOrderProfitInfo(createdOrder request.CreatedOrder, info m
|
||||
return
|
||||
}
|
||||
|
||||
orderProfitInfo, err := CreateOrderProfitInfo(createdOrder, info, *merchantDeploy, orderInfo, roadInfo)
|
||||
orderProfitInfo, err := CreateOrderProfitInfo(ctx, createdOrder, info, *merchantDeploy, orderInfo, roadInfo)
|
||||
if err != nil {
|
||||
err = errors.Join(err, errors.New("创建订单失败"))
|
||||
return
|
||||
}
|
||||
|
||||
if !order.InsertOrderAndOrderProfit(orderInfo, orderProfitInfo) {
|
||||
if !order.InsertOrderAndOrderProfit(ctx, orderInfo, orderProfitInfo) {
|
||||
err = errors.Join(err, errors.New("创建订单失败"))
|
||||
return
|
||||
}
|
||||
@@ -413,8 +417,8 @@ func CreateOrderInfoAndOrderProfitInfo(createdOrder request.CreatedOrder, info m
|
||||
return
|
||||
}
|
||||
|
||||
func GerMerchantDeployInfoByUidAndProductCode(uid, productCode string) merchant_deploy.MerchantDeployInfo {
|
||||
roadInfo := road.GetRoadInfoByProductCode(productCode)
|
||||
merchantDeploy := merchant_deploy.GetMerchantDeployByUidAndRoadUid(uid, roadInfo.RoadUid)
|
||||
func GerMerchantDeployInfoByUidAndProductCode(ctx context.Context, uid, productCode string) merchant_deploy.MerchantDeployInfo {
|
||||
roadInfo := road.GetRoadInfoByProductCode(ctx, productCode)
|
||||
merchantDeploy := merchant_deploy.GetMerchantDeployByUidAndRoadUid(ctx, uid, roadInfo.RoadUid)
|
||||
return *merchantDeploy
|
||||
}
|
||||
|
||||
@@ -11,17 +11,21 @@ import (
|
||||
"gateway/internal/models/notify"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/message"
|
||||
"gateway/internal/utils"
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/pointer"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/pointer"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -30,52 +34,55 @@ var (
|
||||
)
|
||||
|
||||
// SolvePaySuccess 处理支付成功的加款等各项操作
|
||||
func SolvePaySuccess(bankOrderId string, factAmount float64, trxNo string, cardReturnData string) bool {
|
||||
|
||||
func SolvePaySuccess(ctx context.Context, bankOrderId string, factAmount float64, trxNo string, cardReturnData string) bool {
|
||||
ctx, cancel := otel.Span(ctx, "订单处理", "SolvePayFail", trace.WithAttributes(
|
||||
attribute.String("bankOrderId", bankOrderId),
|
||||
attribute.String("cardReturnData", cardReturnData),
|
||||
))
|
||||
defer cancel()
|
||||
o := orm.NewOrm()
|
||||
err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
// 查找订单
|
||||
var orderInfo order.OrderInfo
|
||||
if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from order_info where bank_order_id = ? for update", bankOrderId).
|
||||
QueryRow(&orderInfo); err != nil || orderInfo.BankOrderId == "" {
|
||||
logs.Error("不存在该订单,或者select for update出错")
|
||||
otel.Logger.WithContext(ctx).Error("不存在该订单,或者select for update出错")
|
||||
return err
|
||||
}
|
||||
if orderInfo.Status == config.SUCCESS {
|
||||
logs.Error("该订单已经处理,订单号=", bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("该订单已经处理,订单号=", zap.String("bankOrderId", bankOrderId))
|
||||
return errors.New(fmt.Sprintf("该订单已经处理,订单号= %s", bankOrderId))
|
||||
}
|
||||
|
||||
orderInfo.FactAmount = factAmount
|
||||
orderInfo.Status = config.SUCCESS
|
||||
orderInfo.BankTransId = trxNo
|
||||
orderInfo.CardReturnData = cardReturnData
|
||||
orderInfo.UpdateTime = time.Now()
|
||||
if _, err := txOrm.Update(&orderInfo); err != nil || orderInfo.BankOrderId == "" {
|
||||
logs.Error(fmt.Sprintf("solve pay success, update order info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
if _, err := txOrm.UpdateWithCtx(ctx, &orderInfo); err != nil || orderInfo.BankOrderId == "" {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update order info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
return err
|
||||
}
|
||||
|
||||
record, _ := GetRelateRecordByTargetOrderNo(bankOrderId)
|
||||
record, _ := GetRelateRecordByTargetOrderNo(ctx, bankOrderId)
|
||||
if !pointer.IsNil(record) && record.Id != 0 {
|
||||
// TODO: 判断是否偷卡(隐藏订单)
|
||||
if err2 := UpdateRelateRecordSucceedStatus(bankOrderId, factAmount); err2 != nil {
|
||||
logs.Error("【偷卡】更新偷卡记录失败", err2)
|
||||
if err2 := UpdateRelateRecordSucceedStatus(ctx, bankOrderId, factAmount); err2 != nil {
|
||||
otel.Logger.WithContext(ctx).Error("【偷卡】更新偷卡记录失败", zap.Error(err2))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 查找订单表
|
||||
var orderProfitInfo order.OrderProfitInfo
|
||||
if err := txOrm.Raw(
|
||||
if err := txOrm.RawWithCtx(ctx,
|
||||
"select * from order_profit_info where bank_order_id = ? for update",
|
||||
bankOrderId,
|
||||
).QueryRow(&orderProfitInfo); err != nil || orderProfitInfo.BankOrderId == "" {
|
||||
logs.Error("select order_profit_info for update fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("select order_profit_info for update fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
if orderProfitInfo.BankOrderId == "" {
|
||||
logs.Error("solve pay success, get orderProfit fail, bankOrderId = ", bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("solve pay success, get orderProfit fail, bankOrderId = ", zap.String("bankOrderId", bankOrderId))
|
||||
return errors.New(fmt.Sprintf("solve pay success, get orderProfit fail, bankOrderId = %s", bankOrderId))
|
||||
}
|
||||
|
||||
@@ -95,8 +102,8 @@ func SolvePaySuccess(bankOrderId string, factAmount float64, trxNo string, cardR
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
if _, err := txOrm.Insert(&orderSettleInfo); err != nil {
|
||||
logs.Error(
|
||||
if _, err := txOrm.InsertWithCtx(ctx, &orderSettleInfo); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error(
|
||||
fmt.Sprintf("solve pay success,insert order settle info fail: %s, bankOrderId = %s",
|
||||
err, bankOrderId),
|
||||
)
|
||||
@@ -104,16 +111,16 @@ func SolvePaySuccess(bankOrderId string, factAmount float64, trxNo string, cardR
|
||||
}
|
||||
// 做账户的加款操作,最重要的一步
|
||||
var accountInfo accounts.AccountInfo
|
||||
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(&accountInfo); err != nil || accountInfo.AccountUid == "" {
|
||||
logs.Error(fmt.Sprintf("solve pay success, raw account info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(&accountInfo); err != nil || accountInfo.AccountUid == "" {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, raw account info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
return err
|
||||
}
|
||||
if _, err := txOrm.QueryTable(accounts.ACCOUNT_INFO).Filter("account_uid", orderInfo.MerchantUid).
|
||||
Update((orm.Params{
|
||||
UpdateWithCtx(ctx, orm.Params{
|
||||
"balance": factAmount + accountInfo.Balance,
|
||||
"wait_amount": factAmount + accountInfo.WaitAmount,
|
||||
})); err != nil {
|
||||
logs.Error(fmt.Sprintf("solve pay success, update account info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
}); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update account info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
return err
|
||||
}
|
||||
// 添加一条动账记录
|
||||
@@ -127,12 +134,12 @@ func SolvePaySuccess(bankOrderId string, factAmount float64, trxNo string, cardR
|
||||
CreateTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
}
|
||||
if _, err := txOrm.Insert(&accountHistory); err != nil {
|
||||
logs.Error(fmt.Sprintf("solve pay success,insert account history fail:%s, bankOrderId = %s", err, bankOrderId))
|
||||
if _, err := txOrm.InsertWithCtx(ctx, &accountHistory); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success,insert account history fail:%s, bankOrderId = %s", err, bankOrderId))
|
||||
return err
|
||||
}
|
||||
// 更新通道信息
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
|
||||
roadInfo.RequestSuccess += 1
|
||||
roadInfo.TodayRequestSuccess += 1 // 今日成功
|
||||
@@ -141,90 +148,101 @@ func SolvePaySuccess(bankOrderId string, factAmount float64, trxNo string, cardR
|
||||
roadInfo.TodayProfit += orderProfitInfo.PlatformProfit + orderProfitInfo.AgentProfit
|
||||
roadInfo.TotalProfit += orderProfitInfo.PlatformProfit + orderProfitInfo.AgentProfit
|
||||
roadInfo.UpdateTime = time.Now()
|
||||
if _, err := txOrm.Update(&roadInfo); err != nil {
|
||||
logs.Error(fmt.Sprintf("solve pay success, update road info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
if _, err := txOrm.UpdateWithCtx(ctx, &roadInfo); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update road info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
return err
|
||||
}
|
||||
// 更新订单利润表
|
||||
orderProfitInfo.Status = config.SUCCESS
|
||||
orderProfitInfo.UpdateTime = time.Now()
|
||||
if _, err := txOrm.Update(&orderProfitInfo); err != nil {
|
||||
logs.Error(fmt.Sprintf("solve pay success, update order profit info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
if _, err := txOrm.UpdateWithCtx(ctx, &orderProfitInfo); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update order profit info fail: %s, bankOrderId = %s", err, bankOrderId))
|
||||
return err
|
||||
}
|
||||
// 给下游发送回调通知
|
||||
return nil
|
||||
})
|
||||
orderNotify.Go(func() {
|
||||
CreateOrderNotifyInfo(bankOrderId, config.SUCCESS)
|
||||
// 创建一个5分钟超时的上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
CreateOrderNotifyInfo(timeoutCtx, bankOrderId, config.SUCCESS)
|
||||
})
|
||||
if err != nil {
|
||||
logs.Error("SolvePaySuccess失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", zap.Error(err))
|
||||
return true
|
||||
}
|
||||
|
||||
logs.Info("SolvePaySuccess处理成功")
|
||||
otel.Logger.WithContext(ctx).Info("SolvePaySuccess处理成功")
|
||||
return true
|
||||
}
|
||||
|
||||
// SolvePayFail 处理支付失败
|
||||
func SolvePayFail(ctx context.Context, bankOrderId, transId string, cardReturnData string) bool {
|
||||
ctx, cancel := otel.Span(ctx, "订单处理", "SolvePayFail", trace.WithAttributes(
|
||||
attribute.String("bankOrderId", bankOrderId),
|
||||
attribute.String("cardReturnData", cardReturnData),
|
||||
))
|
||||
defer cancel()
|
||||
o := orm.NewOrm()
|
||||
err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
var orderTmp order.OrderInfo
|
||||
if err := txOrm.Raw("select * from order_info where bank_order_id = ?", bankOrderId).QueryRow(&orderTmp); err != nil || orderTmp.BankOrderId == "" {
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from order_info where bank_order_id = ?", bankOrderId).QueryRow(&orderTmp); err != nil || orderTmp.BankOrderId == "" {
|
||||
return err
|
||||
}
|
||||
if orderTmp.Status != config.WAIT {
|
||||
return nil
|
||||
// return errors.New("订单已经处理,不要重复加款")
|
||||
}
|
||||
if _, err := txOrm.QueryTable(order.ORDER_INFO).Filter("bank_order_id", bankOrderId).Update(orm.Params{
|
||||
if _, err := txOrm.QueryTable(order.ORDER_INFO).Filter("bank_order_id", bankOrderId).UpdateWithCtx(ctx, orm.Params{
|
||||
"status": config.FAIL,
|
||||
"card_return_data": cardReturnData,
|
||||
"bank_trans_id": transId,
|
||||
}); err != nil {
|
||||
logs.Error("更改订单状态失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("更改订单状态失败:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
if _, err := txOrm.QueryTable(order.ORDER_PROFIT_INFO).Filter("bank_order_id", bankOrderId).Update(orm.Params{"status": config.FAIL, "bank_trans_id": transId}); err != nil {
|
||||
logs.Error("更改订单状态失败:", err)
|
||||
if _, err := txOrm.QueryTable(order.ORDER_PROFIT_INFO).Filter("bank_order_id", bankOrderId).UpdateWithCtx(ctx, orm.Params{"status": config.FAIL, "bank_trans_id": transId}); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error("更改订单状态失败:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: 判断是否偷卡(隐藏订单)
|
||||
// 如果是偷卡,就不计算利润什么的,也不回调
|
||||
hiddenCfg, _ := GetRelateRecordByTargetOrderNo(bankOrderId)
|
||||
hiddenCfg, _ := GetRelateRecordByTargetOrderNo(ctx, bankOrderId)
|
||||
if !pointer.IsNil(hiddenCfg) && hiddenCfg.Id != 0 {
|
||||
_ = UpdateRelateRecordStatus(bankOrderId, 0, int(consts.StealRuleStatusFail))
|
||||
_ = UpdateRelateRecordStatus(ctx, bankOrderId, 0, int(consts.StealRuleStatusFail))
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
orderNotify.Go(func() {
|
||||
CreateOrderNotifyInfo(bankOrderId, config.FAIL)
|
||||
// 创建一个5分钟超时的上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
CreateOrderNotifyInfo(timeoutCtx, bankOrderId, config.FAIL)
|
||||
})
|
||||
if err != nil {
|
||||
logs.Error("SolvePayFail:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolvePayFail:", zap.Error(err))
|
||||
}
|
||||
logs.Info("SolvePayFail成功")
|
||||
otel.Logger.WithContext(ctx).Info("SolvePayFail成功")
|
||||
return true
|
||||
}
|
||||
|
||||
// SolveOrderFreeze 处理订单冻结
|
||||
func SolveOrderFreeze(bankOrderId string) bool {
|
||||
func SolveOrderFreeze(ctx context.Context, bankOrderId string) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
var orderInfo order.OrderInfo
|
||||
if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(&orderInfo); err != nil || orderInfo.BankOrderId == "" {
|
||||
logs.Error("solve order freeze 不存在这样的订单记录,bankOrderId = ", bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("solve order freeze 不存在这样的订单记录,bankOrderId = ", zap.String("bankOrderId", bankOrderId))
|
||||
return err
|
||||
}
|
||||
|
||||
// 如果订单不是失败或者成功状态,订单不能冻结
|
||||
if orderInfo.Status != config.SUCCESS && orderInfo.Status != config.FAIL {
|
||||
logs.Error("非成功或失败订单不能进行冻结")
|
||||
otel.Logger.WithContext(ctx).Error("非成功或失败订单不能进行冻结")
|
||||
return errors.New("非成功或失败订单不能进行冻结")
|
||||
}
|
||||
|
||||
@@ -233,23 +251,23 @@ func SolveOrderFreeze(bankOrderId string) bool {
|
||||
orderInfo.UpdateTime = time.Now()
|
||||
|
||||
if _, err := txOrm.Update(&orderInfo); err != nil {
|
||||
logs.Error("solve order freeze fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 账户的冻结金额里面加入相应的金额
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(bankOrderId)
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(ctx, bankOrderId)
|
||||
|
||||
var accountInfo accounts.AccountInfo
|
||||
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(&accountInfo); err != nil || accountInfo.AccountUid == "" {
|
||||
logs.Error(fmt.Sprintf("solve pay fail select acount fail:%s", err))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay fail select acount fail:%s", err))
|
||||
return err
|
||||
}
|
||||
|
||||
accountInfo.UpdateTime = time.Now()
|
||||
accountInfo.FreezeAmount = orderProfitInfo.UserInAmount + accountInfo.FreezeAmount
|
||||
if _, err := txOrm.Update(&accountInfo); err != nil {
|
||||
logs.Error("solve order freeze fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -266,30 +284,30 @@ func SolveOrderFreeze(bankOrderId string) bool {
|
||||
}
|
||||
|
||||
if _, err := txOrm.Insert(&accountHistoryInfo); err != nil {
|
||||
logs.Error("solve order freeze fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order freeze fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
logs.Error("SolveOrderFreeze:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolveOrderFreeze:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("SolveOrderFreeze")
|
||||
otel.Logger.WithContext(ctx).Info("SolveOrderFreeze")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// SolveOrderUnfreeze 订单解冻
|
||||
func SolveOrderUnfreeze(bankOrderId string) bool {
|
||||
func SolveOrderUnfreeze(ctx context.Context, bankOrderId string) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
orderInfo := new(order.OrderInfo)
|
||||
if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(orderInfo); err != nil || orderInfo.BankOrderId == "" {
|
||||
logs.Error("solve order unfreeze 不存在这样的订单记录,bankOrderId = ", bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("solve order unfreeze 不存在这样的订单记录,bankOrderId = ", zap.String("bankOrderId", bankOrderId))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -298,22 +316,22 @@ func SolveOrderUnfreeze(bankOrderId string) bool {
|
||||
orderInfo.UnfreezeTime = utils.GetBasicDateTime()
|
||||
orderInfo.UpdateTime = time.Now()
|
||||
if _, err := txOrm.Update(orderInfo); err != nil {
|
||||
logs.Error("solve order unfreeze fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order unfreeze fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(bankOrderId)
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(ctx, bankOrderId)
|
||||
|
||||
accountInfo := new(accounts.AccountInfo)
|
||||
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(accountInfo); err != nil || accountInfo.AccountUid == "" {
|
||||
logs.Error(fmt.Sprintf("unfreeze select account fail: %s", err))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("unfreeze select account fail: %s", err))
|
||||
return err
|
||||
}
|
||||
accountInfo.UpdateTime = time.Now()
|
||||
accountInfo.FreezeAmount = accountInfo.FreezeAmount - orderProfitInfo.UserInAmount
|
||||
|
||||
if _, err := txOrm.Update(accountInfo); err != nil {
|
||||
logs.Error("solve order unfreeze fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order unfreeze fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -334,19 +352,19 @@ func SolveOrderUnfreeze(bankOrderId string) bool {
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
logs.Error("SolveOrderUnfreeze失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolveOrderUnfreeze失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func SolveRefund(bankOrderId string) bool {
|
||||
func SolveRefund(ctx context.Context, bankOrderId string) bool {
|
||||
o := orm.NewOrm()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
orderInfo := new(order.OrderInfo)
|
||||
if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(orderInfo); err != nil || orderInfo.BankOrderId == "" {
|
||||
logs.Error("solve refund 不存在这样的订单,bankOrderId = " + bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("solve refund 不存在这样的订单,bankOrderId = " + bankOrderId)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -354,7 +372,7 @@ func SolveRefund(bankOrderId string) bool {
|
||||
orderInfo.Refund = config.YES
|
||||
orderInfo.RefundTime = utils.GetBasicDateTime()
|
||||
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(bankOrderId)
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(ctx, bankOrderId)
|
||||
account := new(accounts.AccountInfo)
|
||||
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(account); err != nil || account.AccountUid == "" {
|
||||
return err
|
||||
@@ -373,11 +391,11 @@ func SolveRefund(bankOrderId string) bool {
|
||||
}
|
||||
|
||||
if _, err := txOrm.Update(orderInfo); err != nil {
|
||||
logs.Error("solve order refund update order info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order refund update order info fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
if _, err := txOrm.Update(account); err != nil {
|
||||
logs.Error("solve order refund update account fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order refund update account fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -393,35 +411,35 @@ func SolveRefund(bankOrderId string) bool {
|
||||
}
|
||||
|
||||
if _, err := txOrm.Insert(&accountHistoryInfo); err != nil {
|
||||
logs.Error("solve order refund insert account history fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order refund insert account history fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
logs.Error("SolveRefund 成功:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolveRefund 成功:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func SolveOrderRoll(bankOrderId string) bool {
|
||||
func SolveOrderRoll(ctx context.Context, bankOrderId string) bool {
|
||||
o := orm.NewOrm()
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
orderInfo := new(order.OrderInfo)
|
||||
|
||||
if err := txOrm.Raw("select * from order_info where bank_order_id = ? for update", bankOrderId).QueryRow(orderInfo); err != nil {
|
||||
logs.Error("solve order roll fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order roll fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if orderInfo.Status != config.SUCCESS {
|
||||
logs.Error("solve order roll 订单不存在或者订单状态不是success, bankOrderId=", bankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("solve order roll 订单不存在或者订单状态不是success, bankOrderId=", zap.String("bankOrderId", bankOrderId))
|
||||
return errors.New("solve order roll failed")
|
||||
}
|
||||
orderInfo.UpdateTime = time.Now()
|
||||
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(bankOrderId)
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(ctx, bankOrderId)
|
||||
|
||||
account := new(accounts.AccountInfo)
|
||||
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", orderInfo.MerchantUid).QueryRow(account); err != nil || account.AccountUid == "" {
|
||||
@@ -436,11 +454,11 @@ func SolveOrderRoll(bankOrderId string) bool {
|
||||
}
|
||||
|
||||
if _, err := txOrm.Update(orderInfo); err != nil {
|
||||
logs.Error("solve order roll fail update order info fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order roll fail update order info fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
if _, err := txOrm.Update(account); err != nil {
|
||||
logs.Error("solve order roll update account fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order roll update account fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -456,13 +474,13 @@ func SolveOrderRoll(bankOrderId string) bool {
|
||||
}
|
||||
|
||||
if _, err := txOrm.Insert(&accountHistoryInfo); err != nil {
|
||||
logs.Error("solve order roll insert account history fail: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("solve order roll insert account history fail: ", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
logs.Error("SolveOrderRoll处理失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolveOrderRoll处理失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -486,12 +504,12 @@ func CompareOrderAndFactAmount(factAmount float64, orderInfo order.OrderInfo) in
|
||||
}
|
||||
|
||||
// CreateOrderNotifyInfo 支付完成后,处理给商户的回调信息
|
||||
func CreateOrderNotifyInfo(bankOrderId string, tradeStatus string) {
|
||||
orderInfo := order.GetOneOrder(bankOrderId)
|
||||
func CreateOrderNotifyInfo(ctx context.Context, bankOrderId string, tradeStatus string) {
|
||||
orderInfo := order.GetOneOrder(ctx, bankOrderId)
|
||||
if orderInfo.Status != config.SUCCESS && orderInfo.Status != config.FAIL {
|
||||
return
|
||||
}
|
||||
merchantInfo := merchant.GetMerchantByUid(orderInfo.MerchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, orderInfo.MerchantUid)
|
||||
statusCode := 0
|
||||
if tradeStatus == "success" {
|
||||
statusCode = 1
|
||||
@@ -511,7 +529,7 @@ func CreateOrderNotifyInfo(bankOrderId string, tradeStatus string) {
|
||||
for k, v := range params {
|
||||
u.Add(k, convertor.ToString(v))
|
||||
}
|
||||
if notify.InsertNotifyInfo(notify.NotifyInfo{
|
||||
if notify.InsertNotifyInfo(ctx, notify.NotifyInfo{
|
||||
Type: "order",
|
||||
BankOrderId: orderInfo.BankOrderId,
|
||||
MerchantOrderId: orderInfo.MerchantOrderId,
|
||||
@@ -521,12 +539,15 @@ func CreateOrderNotifyInfo(bankOrderId string, tradeStatus string) {
|
||||
UpdateTime: time.Now(),
|
||||
Url: orderInfo.NotifyUrl + "?" + u.Encode(),
|
||||
}) {
|
||||
logs.Info(fmt.Sprintf("订单bankOrderId=%s,已经将回调地址插入数据库", orderInfo.BankOrderId))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("订单bankOrderId=%s,已经将回调地址插入数据库", orderInfo.BankOrderId))
|
||||
} else {
|
||||
logs.Error(fmt.Sprintf("订单bankOrderId=%s,插入回调数据库失败", orderInfo.BankOrderId))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("订单bankOrderId=%s,插入回调数据库失败", orderInfo.BankOrderId))
|
||||
}
|
||||
// 将订单发送到消息队列,给下面的商户进行回调
|
||||
sendMessageNotify.Go(func() {
|
||||
message.SendMessage(config.MqOrderNotify, orderInfo.BankOrderId)
|
||||
sendMessageNotify.CtxGo(ctx, func() {
|
||||
// 创建一个5分钟超时的上下文
|
||||
timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Minute)
|
||||
defer cancel()
|
||||
message.SendMessage(timeoutCtx, config.MqOrderNotify, orderInfo.BankOrderId)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -17,6 +16,5 @@ func TestCreateOrderNotifyInfo(t *testing.T) {
|
||||
"statusCode": "01",
|
||||
"tradeStatus": "success",
|
||||
}
|
||||
sign := utils.GetMD5SignMF(params, "sssscu5go30gdv0c73fo7g90")
|
||||
logs.Info("签名结果:", sign)
|
||||
_ = utils.GetMD5SignMF(params, "sssscu5go30gdv0c73fo7g90")
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import (
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/merchant_deploy"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/utils"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/orm"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,42 +23,42 @@ const (
|
||||
)
|
||||
|
||||
// OrderSettle 订单结算,将那些支付成功的订单金额加入到商户账户的结算金额中
|
||||
func OrderSettle() {
|
||||
func OrderSettle(ctx context.Context) {
|
||||
params := make(map[string]string)
|
||||
params["is_allow_settle"] = config.YES
|
||||
params["is_complete_settle"] = config.NO
|
||||
orderSettleList := order.GetOrderSettleListByParams(params)
|
||||
orderSettleList := order.GetOrderSettleListByParams(ctx, params)
|
||||
for _, orderSettle := range orderSettleList {
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(orderSettle.BankOrderId)
|
||||
if !settle(orderSettle, orderProfitInfo) {
|
||||
logs.Error(fmt.Sprintf("结算订单bankOrderId = #{orderSettle.BankOrderId}, 执行失败"))
|
||||
orderProfitInfo := order.GetOrderProfitByBankOrderId(ctx, orderSettle.BankOrderId)
|
||||
if !settle(ctx, orderSettle, orderProfitInfo) {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("结算订单bankOrderId = #{orderSettle.BankOrderId}, 执行失败"))
|
||||
} else {
|
||||
logs.Info(fmt.Sprintf("结算订单bankOrderId= #{orderSettle.BankOrderId},执行成功"))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("结算订单bankOrderId= #{orderSettle.BankOrderId},执行成功"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo) bool {
|
||||
func settle(ctx context.Context, orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
if err := o.DoTxWithCtx(ctx, func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
tmpSettle := new(order.OrderSettleInfo)
|
||||
if err := txOrm.Raw("select * from order_settle_info where bank_order_id=? for update", orderSettle.BankOrderId).QueryRow(tmpSettle); err != nil || tmpSettle.BankOrderId == "" {
|
||||
logs.Error("获取tmpSettle失败,bankOrderId=%s", orderSettle.BankOrderId)
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from order_settle_info where bank_order_id=? for update", orderSettle.BankOrderId).QueryRow(tmpSettle); err != nil || tmpSettle.BankOrderId == "" {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("获取tmpSettle失败,bankOrderId=%s", orderSettle.BankOrderId), zap.String("BankOrderId", orderSettle.BankOrderId))
|
||||
return err
|
||||
}
|
||||
|
||||
tmpSettle.UpdateTime = time.Now()
|
||||
tmpSettle.IsCompleteSettle = config.YES
|
||||
if _, err := txOrm.Update(tmpSettle); err != nil {
|
||||
logs.Error("更新tmpSettle失败,错误:", err)
|
||||
if _, err := txOrm.UpdateWithCtx(ctx, tmpSettle); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error("更新tmpSettle失败,错误:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
accountInfo := new(accounts.AccountInfo)
|
||||
if err := txOrm.Raw("select * from account_info where account_uid= ? for update", orderSettle.MerchantUid).
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from account_info where account_uid= ? for update", orderSettle.MerchantUid).
|
||||
QueryRow(accountInfo); err != nil || accountInfo.UpdateTime.IsZero() {
|
||||
logs.Error("结算select account info失败,错误信息:", err)
|
||||
otel.Logger.WithContext(ctx).Error("结算select account info失败,错误信息:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
accountInfo.UpdateTime = time.Now()
|
||||
@@ -65,6 +66,7 @@ func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo
|
||||
// 商户有押款操作
|
||||
loadAmount := 0.0
|
||||
merchantDeployInfo := merchant_deploy.GetMerchantDeployByUidAndRoadUid(
|
||||
ctx,
|
||||
accountInfo.AccountUid,
|
||||
orderSettle.RoadUid,
|
||||
)
|
||||
@@ -87,32 +89,32 @@ func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo
|
||||
}
|
||||
|
||||
if _, err := txOrm.Insert(&tmp); err != nil {
|
||||
logs.Error("結算插入merchantLoad失敗,失败信息:", err)
|
||||
otel.Logger.WithContext(ctx).Error("結算插入merchantLoad失敗,失败信息:", zap.Error(err))
|
||||
return err
|
||||
} else {
|
||||
logs.Info("结算插入新的merchantLoad信息成功")
|
||||
otel.Logger.WithContext(ctx).Info("结算插入新的merchantLoad信息成功")
|
||||
}
|
||||
} else {
|
||||
merchantLoad := new(merchant.MerchantLoadInfo)
|
||||
if err := txOrm.Raw("select * from merchant_load_info where merchant_uid=? and road_uid=? and load_date=? for update", orderSettle.MerchantUid, orderSettle.RoadUid, date).
|
||||
if err := txOrm.RawWithCtx(ctx, "select * from merchant_load_info where merchant_uid=? and road_uid=? and load_date=? for update", orderSettle.MerchantUid, orderSettle.RoadUid, date).
|
||||
QueryRow(merchantLoad); err != nil || merchantLoad.UpdateTime.IsZero() {
|
||||
logs.Error(fmt.Sprintf("结算过程,select merchant load info失败,错误信息:%s", err))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("结算过程,select merchant load info失败,错误信息:%s", zap.Error(err)))
|
||||
return err
|
||||
} else {
|
||||
merchantLoad.UpdateTime = time.Now()
|
||||
merchantLoad.LoadAmount += loadAmount
|
||||
if _, err := txOrm.Update(merchantLoad); err != nil {
|
||||
logs.Error(fmt.Sprintf("结算过程,update merchant load info失败,失败信息:%s", err))
|
||||
if _, err := txOrm.UpdateWithCtx(ctx, merchantLoad); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("结算过程,update merchant load info失败,失败信息:%s", zap.Error(err)))
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logs.Info(fmt.Sprintf("结算过程中,该商户不需要押款,全款结算"))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("结算过程中,该商户不需要押款,全款结算"))
|
||||
}
|
||||
|
||||
if accountInfo.WaitAmount < orderProfit.UserInAmount {
|
||||
logs.Error("系统出现严重故障,账户的带结算金额小于订单结算金额")
|
||||
otel.Logger.WithContext(ctx).Error("系统出现严重故障,账户的带结算金额小于订单结算金额")
|
||||
return errors.New("系统出现严重故障,账户的带结算金额小于订单结算金额, 账户 = " + accountInfo.AccountName + "订单id = " + orderProfit.BankOrderId)
|
||||
}
|
||||
|
||||
@@ -122,8 +124,8 @@ func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo
|
||||
accountInfo.WaitAmount = accountInfo.WaitAmount - orderProfit.UserInAmount
|
||||
accountInfo.LoanAmount = accountInfo.LoanAmount + loadAmount
|
||||
|
||||
if _, err := txOrm.Update(accountInfo); err != nil {
|
||||
logs.Error("结算update account 失败,错误信息:", err)
|
||||
if _, err := txOrm.UpdateWithCtx(ctx, accountInfo); err != nil {
|
||||
otel.Logger.WithContext(ctx).Error("结算update account 失败,错误信息:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -135,11 +137,11 @@ func settle(orderSettle order.OrderSettleInfo, orderProfit order.OrderProfitInfo
|
||||
}
|
||||
|
||||
// MerchantLoadSolve 商户的押款释放处理,根据商户的押款时间进行处理
|
||||
func MerchantLoadSolve() {
|
||||
func MerchantLoadSolve(ctx context.Context) {
|
||||
hour := time.Now().Hour()
|
||||
merchantDeployList := merchant_deploy.GetMerchantDeployByHour(hour)
|
||||
merchantDeployList := merchant_deploy.GetMerchantDeployByHour(ctx, hour)
|
||||
for _, merchantDeploy := range merchantDeployList {
|
||||
logs.Info(fmt.Sprintf("开始执行商户uid=%s,进行解款操作", merchantDeploy.MerchantUid))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("开始执行商户uid=%s,进行解款操作", merchantDeploy.MerchantUid))
|
||||
|
||||
loadDate := utils.GetDateBeforeDays(merchantDeploy.LoanDays)
|
||||
params := make(map[string]string)
|
||||
@@ -147,13 +149,13 @@ func MerchantLoadSolve() {
|
||||
params["merchant_uid"] = merchantDeploy.MerchantUid
|
||||
params["load_date__lte"] = loadDate
|
||||
|
||||
merchantLoadList := merchant.GetMerchantLoadInfoByMap(params)
|
||||
merchantLoadList := merchant.GetMerchantLoadInfoByMap(ctx, params)
|
||||
for _, merchantLoad := range merchantLoadList {
|
||||
if MerchantAbleAmount(merchantLoad) {
|
||||
logs.Info(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道= %s, 解款成功",
|
||||
if MerchantAbleAmount(ctx, merchantLoad) {
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道= %s, 解款成功",
|
||||
merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid))
|
||||
} else {
|
||||
logs.Error(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道=%s, 解款失败",
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("商户uid=%s,押款金额=%f,押款通道=%s, 解款失败",
|
||||
merchantLoad.MerchantUid, merchantLoad.LoadAmount, merchantLoad.RoadUid))
|
||||
}
|
||||
}
|
||||
@@ -161,7 +163,7 @@ func MerchantLoadSolve() {
|
||||
}
|
||||
|
||||
// MerchantAbleAmount 对应的商户的账户可用金额进行调整操作
|
||||
func MerchantAbleAmount(merchantLoad merchant.MerchantLoadInfo) bool {
|
||||
func MerchantAbleAmount(ctx context.Context, merchantLoad merchant.MerchantLoadInfo) bool {
|
||||
o := orm.NewOrm()
|
||||
|
||||
if err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
@@ -169,25 +171,25 @@ func MerchantAbleAmount(merchantLoad merchant.MerchantLoadInfo) bool {
|
||||
if err := txOrm.Raw("select * from merchant_load_info where merchant_uid=? and road_uid=? and load_date=? for update",
|
||||
merchantLoad.MerchantUid, merchantLoad.RoadUid, merchantLoad.LoadDate).
|
||||
QueryRow(tmpLoad); err != nil || tmpLoad.MerchantUid == "" {
|
||||
logs.Error(fmt.Sprintf("解款操作获取商户押款信息失败,fail: %s", err))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("解款操作获取商户押款信息失败,fail: %s", zap.Error(err)))
|
||||
return err
|
||||
}
|
||||
if tmpLoad.Status != config.NO {
|
||||
logs.Error(fmt.Sprintf("押款信息merchantuid=%s,通道uid=%s, 押款日期=%s,已经解款过,不需要再进行处理了", tmpLoad.MerchantUid, tmpLoad.RoadUid, tmpLoad.LoadDate))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("押款信息merchantuid=%s,通道uid=%s, 押款日期=%s,已经解款过,不需要再进行处理了", tmpLoad.MerchantUid, tmpLoad.RoadUid, tmpLoad.LoadDate))
|
||||
return errors.New("已经解款过,不需要再进行处理了")
|
||||
}
|
||||
|
||||
tmpLoad.UpdateTime = time.Now()
|
||||
tmpLoad.Status = config.YES
|
||||
if _, err := txOrm.Update(tmpLoad); err != nil {
|
||||
logs.Error(fmt.Sprintf("解款操作更新merchant load info 失败:%s", err))
|
||||
otel.Logger.WithContext(ctx).Error("解款操作更新merchant load info 失败", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
accountInfo := new(accounts.AccountInfo)
|
||||
if err := txOrm.Raw("select * from account_info where account_uid = ? for update", merchantLoad.MerchantUid).
|
||||
QueryRow(accountInfo); err != nil || accountInfo.AccountUid == "" {
|
||||
logs.Error("结款操作获取账户信息失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("结款操作获取账户信息失败:", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
accountInfo.UpdateTime = time.Now()
|
||||
@@ -199,7 +201,7 @@ func MerchantAbleAmount(merchantLoad merchant.MerchantLoadInfo) bool {
|
||||
}
|
||||
|
||||
if _, err := txOrm.Update(accountInfo); err != nil {
|
||||
logs.Error(fmt.Sprintf("解款操作更新account info 失败:%s,账户uid=%s", err, accountInfo.AccountUid))
|
||||
otel.Logger.WithContext(ctx).Error(fmt.Sprintf("解款操作更新account info 失败:%s,账户uid=%s", err, accountInfo.AccountUid))
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -210,7 +212,9 @@ func MerchantAbleAmount(merchantLoad merchant.MerchantLoadInfo) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func OrderSettleInit() {
|
||||
func OrderSettleInit(ctx context.Context) {
|
||||
ctx, cancel := otel.Span(ctx, "OrderSettleInit", "OrderSettleInit")
|
||||
defer cancel()
|
||||
// 每隔5分钟,巡查有没有可以进行结算的订单
|
||||
settleTimer := time.NewTimer(time.Duration(Interval) * time.Minute)
|
||||
oneMinuteTimer := time.NewTimer(time.Duration(Minutes) * time.Minute)
|
||||
@@ -218,10 +222,10 @@ func OrderSettleInit() {
|
||||
select {
|
||||
case <-settleTimer.C:
|
||||
settleTimer = time.NewTimer(time.Duration(Interval) * time.Minute)
|
||||
OrderSettle()
|
||||
OrderSettle(ctx)
|
||||
case <-oneMinuteTimer.C:
|
||||
oneMinuteTimer = time.NewTimer(time.Duration(Minutes) * time.Minute)
|
||||
MerchantLoadSolve()
|
||||
MerchantLoadSolve(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package supplier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/models/payfor"
|
||||
@@ -24,7 +25,7 @@ type ScanData struct {
|
||||
}
|
||||
|
||||
type PayInterface interface {
|
||||
Scan(order.OrderInfo, road.RoadInfo, merchant.MerchantInfo) ScanData
|
||||
Scan(context.Context, order.OrderInfo, road.RoadInfo, merchant.MerchantInfo) ScanData
|
||||
PayNotify()
|
||||
PayQuery(order.OrderInfo, road.RoadInfo) bool
|
||||
PayQueryV2(order.OrderInfo, road.RoadInfo) supply_model.MsgModel
|
||||
|
||||
88
internal/service/supplier/third_party/apple.go
vendored
88
internal/service/supplier/third_party/apple.go
vendored
@@ -1,6 +1,7 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
@@ -11,15 +12,21 @@ import (
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/service/supplier"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -69,7 +76,7 @@ func (c *AppleCardImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *AppleCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
func (c *AppleCardImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
cfg := config.Config{}
|
||||
params := make(map[string]string)
|
||||
|
||||
@@ -87,26 +94,27 @@ func (c *AppleCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInf
|
||||
if err != nil {
|
||||
return false, "获取苹果卡密地址失败!"
|
||||
}
|
||||
req := httplib.Post(url)
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, url, "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
req.Retries(3)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
req.Header("tokenFrom", "iframe")
|
||||
response, err := req.String()
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
if err != nil {
|
||||
logs.Error("Apple GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("Apple GetToken 请求失败:", zap.Error(err))
|
||||
return false, ""
|
||||
}
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return false, ""
|
||||
}
|
||||
type AutoGenerated struct {
|
||||
@@ -120,7 +128,7 @@ func (c *AppleCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInf
|
||||
var resData AutoGenerated
|
||||
err = json.Unmarshal([]byte(response), &resData)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response))
|
||||
return false, "内部数据处理失败"
|
||||
}
|
||||
|
||||
@@ -142,14 +150,20 @@ func (c *AppleCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInf
|
||||
return false, response
|
||||
}
|
||||
|
||||
func (c *AppleCardImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *AppleCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "AppleCardImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
var scanData supplier.ScanData
|
||||
if !ok {
|
||||
scanData = supplier.ScanData{
|
||||
@@ -171,11 +185,11 @@ func (c *AppleCardImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo,
|
||||
|
||||
// KMEncrypt 加密卡密
|
||||
func (c *AppleCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
|
||||
block, err := aes.NewCipher([]byte(secret))
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher")
|
||||
return "", err
|
||||
}
|
||||
// 数据填充
|
||||
@@ -187,10 +201,11 @@ func (c *AppleCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *AppleCardImpl) PayNotify() {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
attach := strings.TrimSpace(c.GetString("attach"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【APPLE】回调的订单号不存在,订单号=", attach)
|
||||
otel.Logger.WithContext(ctx).Error("【APPLE】回调的订单号不存在,订单号=", zap.String("attach", attach))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
@@ -204,7 +219,7 @@ func (c *AppleCardImpl) PayNotify() {
|
||||
orderInfo.BankTransId = params["merchantId"]
|
||||
if params["status"] == "1" {
|
||||
// TODO 订单支付成功
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -212,7 +227,7 @@ func (c *AppleCardImpl) PayNotify() {
|
||||
}
|
||||
return
|
||||
}
|
||||
isOk := service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", params["remark"])
|
||||
isOk := service.SolvePayFail(ctx, orderInfo.BankOrderId, "", params["remark"])
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -222,6 +237,7 @@ func (c *AppleCardImpl) PayNotify() {
|
||||
}
|
||||
|
||||
func (c *AppleCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -246,23 +262,23 @@ func (c *AppleCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -286,6 +302,7 @@ func (c *AppleCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
}
|
||||
|
||||
func (c *AppleCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -310,12 +327,12 @@ func (c *AppleCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -325,7 +342,7 @@ func (c *AppleCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -367,6 +384,7 @@ func (c *AppleCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
params := map[string]string{}
|
||||
params["order_id"] = payFor.BankOrderId
|
||||
@@ -375,25 +393,25 @@ func (c *AppleCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -430,7 +448,7 @@ func (c *AppleCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
"net/http"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
@@ -15,12 +18,16 @@ import (
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -70,7 +77,7 @@ func (c *AppleCardSharkImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *AppleCardSharkImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
func (c *AppleCardSharkImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
cfg := config.Config{}
|
||||
|
||||
params := map[string]string{
|
||||
@@ -91,10 +98,11 @@ func (c *AppleCardSharkImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCa
|
||||
oriStr += s + "=" + s2 + "&"
|
||||
}
|
||||
oriStr += "key=12345"
|
||||
req := httplib.Post("http://haocai.just168.vip/api/newOrder")
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, "http://haocai.just168.vip/api/newOrder", "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
req.Header("Content-Type", "application/json")
|
||||
@@ -102,18 +110,24 @@ func (c *AppleCardSharkImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCa
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
req.Header("tokenFrom", "iframe")
|
||||
response, err := req.String()
|
||||
logs.Info(response)
|
||||
otel.Logger.WithContext(ctx).Info(response)
|
||||
return true, ""
|
||||
}
|
||||
|
||||
func (c *AppleCardSharkImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *AppleCardSharkImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "AppleCardSharkImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
var scanData supplier.ScanData
|
||||
if !ok {
|
||||
scanData = supplier.ScanData{
|
||||
@@ -134,12 +148,11 @@ func (c *AppleCardSharkImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadI
|
||||
}
|
||||
|
||||
// KMEncrypt 加密卡密
|
||||
func (c *AppleCardSharkImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
func (c *AppleCardSharkImpl) kMEncrypt(ctx context.Context, kf, appSecret string) (string, error) {
|
||||
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
|
||||
block, err := aes.NewCipher([]byte(secret))
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher")
|
||||
return "", err
|
||||
}
|
||||
// 数据填充
|
||||
@@ -151,23 +164,24 @@ func (c *AppleCardSharkImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *AppleCardSharkImpl) PayNotify() {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
attach := strings.TrimSpace(c.GetString("attach"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【APPLE】回调的订单号不存在,订单号=", attach)
|
||||
otel.Logger.WithContext(ctx).Error("【APPLE】回调的订单号不存在,订单号=", zap.String("attach", attach))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【APPLE】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【APPLE】支付通道已经关系或者删除,不进行回调")
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【APPLE】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【APPLE】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
@@ -181,14 +195,14 @@ func (c *AppleCardSharkImpl) PayNotify() {
|
||||
orderInfo.BankTransId = params["merchantId"]
|
||||
if params["status"] == "1" {
|
||||
// TODO 订单支付成功
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
}
|
||||
} else {
|
||||
isOk := service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "")
|
||||
isOk := service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -201,6 +215,7 @@ func (c *AppleCardSharkImpl) PayNotify() {
|
||||
|
||||
func (c *AppleCardSharkImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
params := map[string]any{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -223,23 +238,23 @@ func (c *AppleCardSharkImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.R
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -264,6 +279,7 @@ func (c *AppleCardSharkImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.R
|
||||
|
||||
func (c *AppleCardSharkImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
params := map[string]any{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -286,12 +302,12 @@ func (c *AppleCardSharkImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -301,7 +317,7 @@ func (c *AppleCardSharkImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -339,6 +355,8 @@ func (c *AppleCardSharkImpl) PayFor(info payfor.PayforInfo) string {
|
||||
|
||||
func (c *AppleCardSharkImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
cfg := config.Config{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
url, err := cfg.GetMFCardQueryUrl()
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
@@ -351,25 +369,25 @@ func (c *AppleCardSharkImpl) PayForQuery(payFor payfor.PayforInfo) (string, stri
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -406,7 +424,7 @@ func (c *AppleCardSharkImpl) PayForQuery(payFor payfor.PayforInfo) (string, stri
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gateway/internal/service/supplier"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAppleCardSharkImpl_SendCard(t *testing.T) {
|
||||
i := AppleCardSharkImpl{}
|
||||
i.SendCard("", supplier.RedeemCardInfo{
|
||||
i.SendCard(context.Background(), "", supplier.RedeemCardInfo{
|
||||
FaceType: "100",
|
||||
RecoveryType: "8",
|
||||
CardNo: "123456789",
|
||||
|
||||
65
internal/service/supplier/third_party/daili.go
vendored
65
internal/service/supplier/third_party/daili.go
vendored
@@ -1,19 +1,27 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/service/supplier"
|
||||
"gateway/internal/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"strconv"
|
||||
"strings"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/rs/xid"
|
||||
@@ -34,7 +42,13 @@ func (c *DaiLiImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *DaiLiImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *DaiLiImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "DaiLiImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
// 从boss后台获取数据
|
||||
service2 := gojson.Json(roadInfo.Params).Get("service2").Tostring()
|
||||
apiKey := gojson.Json(roadInfo.Params).Get("apikey").Tostring()
|
||||
@@ -55,17 +69,20 @@ func (c *DaiLiImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merc
|
||||
|
||||
request := URL + "?" + utils.MapToString(params)
|
||||
|
||||
logs.Info("代丽请求字符串 = " + request)
|
||||
otel.Logger.WithContext(ctx).Info("代丽请求字符串 = " + request)
|
||||
|
||||
var scanData supplier.ScanData
|
||||
scanData.Status = "00"
|
||||
response, err := httplib.Post(request).String()
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, request, "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
req.Retries(3)
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("代丽支付请求失败:" + err.Error())
|
||||
otel.Logger.WithContext(ctx).Error("代丽支付请求失败:" + err.Error())
|
||||
scanData.Status = "-1"
|
||||
scanData.Msg = "请求失败:" + err.Error()
|
||||
} else {
|
||||
/*logs.Info("代丽支付返回 = " + response)
|
||||
/*otel.Logger.WithContext(ctx).Info("代丽支付返回 = " + response)
|
||||
status := gojson.Json(response).Get("status").Tostring()
|
||||
message := gojson.Json(response).Get("message").Tostring()
|
||||
if "10000" != status {
|
||||
@@ -84,21 +101,23 @@ func (c *DaiLiImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merc
|
||||
}
|
||||
|
||||
func (c *DaiLiImpl) PayNotify() {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
orderNo := strings.TrimSpace(c.GetString("orderNo"))
|
||||
orderInfo := order.GetOrderByBankOrderId(orderNo)
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, orderNo)
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("快付回调的订单号不存在,订单号=", orderNo)
|
||||
otel.Logger.WithContext(ctx).Error("快付回调的订单号不存在,订单号=", zap.String("orderNo", orderNo))
|
||||
c.StopRun()
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("支付通道已经关系或者删除,不进行回调")
|
||||
c.StopRun()
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.StopRun()
|
||||
}
|
||||
paySecret := merchantInfo.MerchantSecret
|
||||
@@ -117,7 +136,7 @@ func (c *DaiLiImpl) PayNotify() {
|
||||
tmpSign := utils.GetMD5Sign(params, keys, paySecret)
|
||||
sign := strings.TrimSpace(c.GetString("sign"))
|
||||
if tmpSign != sign {
|
||||
logs.Error("代丽回调签名异常,回调失败")
|
||||
otel.Logger.WithContext(ctx).Error("代丽回调签名异常,回调失败")
|
||||
// c.StopRun()
|
||||
}
|
||||
// 实际支付金额
|
||||
@@ -131,37 +150,39 @@ func (c *DaiLiImpl) PayNotify() {
|
||||
|
||||
// paySolveController := new(service.PaySolveController)
|
||||
if tradeStatus == "FAILED" {
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "") {
|
||||
logs.Error("solve order fail fail")
|
||||
if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") {
|
||||
otel.Logger.WithContext(ctx).Error("solve order fail fail")
|
||||
}
|
||||
} else if tradeStatus == "CANCELED" {
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "") {
|
||||
logs.Error("solve order cancel fail")
|
||||
if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") {
|
||||
otel.Logger.WithContext(ctx).Error("solve order cancel fail")
|
||||
}
|
||||
} else if tradeStatus == "WAITING_PAYMENT" {
|
||||
logs.Notice("快付回调,该订单还处于等待支付,订单id=", orderNo)
|
||||
} else if tradeStatus == "SUCCESS" {
|
||||
// 订单支付成功,需要搞很多事情 TODO
|
||||
service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, c.GetString("trxNo"), "支付成功")
|
||||
service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, c.GetString("trxNo"), "支付成功")
|
||||
}
|
||||
c.Ctx.WriteString("success")
|
||||
}
|
||||
|
||||
func (c *DaiLiImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
tradeStatus := "SUCCESS"
|
||||
trxNo := orderInfo.BankOrderId
|
||||
factAmount := 100.00
|
||||
if tradeStatus == "SUCCESS" {
|
||||
// 调用支付成功的接口,做加款更新操作,需要把实际支付金额传入
|
||||
if !service.SolvePaySuccess(orderInfo.BankOrderId, factAmount, trxNo, "支付成功") {
|
||||
if !service.SolvePaySuccess(ctx, orderInfo.BankOrderId, factAmount, trxNo, "支付成功") {
|
||||
return false
|
||||
}
|
||||
} else if tradeStatus == "FAILED" {
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "") {
|
||||
if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
logs.Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId)
|
||||
otel.Logger.WithContext(ctx).Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
63
internal/service/supplier/third_party/fat_six.go
vendored
63
internal/service/supplier/third_party/fat_six.go
vendored
@@ -1,8 +1,10 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
@@ -11,7 +13,12 @@ import (
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/cryptor"
|
||||
@@ -21,11 +28,10 @@ import (
|
||||
"github.com/duke-git/lancet/v2/pointer"
|
||||
"github.com/duke-git/lancet/v2/structs"
|
||||
"github.com/widuu/gojson"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type FatSixImpl struct {
|
||||
@@ -67,7 +73,7 @@ type sendCardResp struct {
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
func (f *FatSixImpl) sendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string) (bool, *sendCardResp) {
|
||||
func (f *FatSixImpl) sendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, attach string) (bool, *sendCardResp) {
|
||||
response := &sendCardResp{}
|
||||
req := sendCardReq{
|
||||
Mid: gojson.Json(jsonStr).Get("mid").Tostring(),
|
||||
@@ -80,7 +86,7 @@ func (f *FatSixImpl) sendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
params["sign"] = sign(params, maputil.Keys(params), gojson.Json(jsonStr).Get("paySecret").Tostring())
|
||||
|
||||
pretty, _ := formatter.Pretty(params)
|
||||
logs.Info("请求参数:" + pretty)
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + pretty)
|
||||
|
||||
//urlParams := url.Values{}
|
||||
//for k, v := range params {
|
||||
@@ -88,7 +94,7 @@ func (f *FatSixImpl) sendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
//}
|
||||
body, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("解析参数失败", err)
|
||||
otel.Logger.WithContext(ctx).Error("解析参数失败", zap.Error(err))
|
||||
return false, response
|
||||
}
|
||||
header := http.Header{}
|
||||
@@ -101,20 +107,21 @@ func (f *FatSixImpl) sendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
Body: body,
|
||||
}
|
||||
httpClient := netutil.NewHttpClient()
|
||||
httpClient.Transport = otelhttp.NewTransport(http.DefaultTransport)
|
||||
resp, err := httpClient.SendRequest(request)
|
||||
|
||||
if err != nil || resp.StatusCode != 200 {
|
||||
logs.Error("发送数据失败", err)
|
||||
otel.Logger.WithContext(ctx).Error("发送数据失败", zap.Error(err))
|
||||
return false, response
|
||||
}
|
||||
err = httpClient.DecodeResponse(resp, &response)
|
||||
if err != nil || pointer.IsNil(response) {
|
||||
logs.Error("解析分解会结构失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("解析分解会结构失败", zap.Error(err), zap.Any("response", response))
|
||||
return false, response
|
||||
}
|
||||
|
||||
pretty, _ = formatter.Pretty(response)
|
||||
logs.Info("返回参数:" + pretty)
|
||||
otel.Logger.WithContext(ctx).Info("返回参数:" + pretty)
|
||||
if response.Status == 0 {
|
||||
return true, response
|
||||
}
|
||||
@@ -122,16 +129,22 @@ func (f *FatSixImpl) sendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
return false, response
|
||||
}
|
||||
|
||||
func (f *FatSixImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, info3 merchant.MerchantInfo) supplier.ScanData {
|
||||
func (f *FatSixImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, info3 merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "FatSixImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{
|
||||
FaceType: convertor.ToString(orderInfo.OrderAmount),
|
||||
}
|
||||
//err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
//if err != nil {
|
||||
// logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
// otel.Logger.WithContext(ctx).Error("格式化数据失败", orderInfo.ExValue)
|
||||
// return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
//}
|
||||
ok, response := f.sendCard(roadInfo.Params, cdata, orderInfo.BankOrderId)
|
||||
ok, response := f.sendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId)
|
||||
if !ok {
|
||||
return supplier.ScanData{
|
||||
Status: "-1",
|
||||
@@ -155,6 +168,8 @@ func (f *FatSixImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, inf
|
||||
}
|
||||
|
||||
func (f *FatSixImpl) PayNotify() {
|
||||
ctx := f.Ctx.Request.Context()
|
||||
|
||||
resp := struct {
|
||||
MerOrderTid string `json:"merOrderTid"`
|
||||
Tid string `json:"tid"`
|
||||
@@ -164,19 +179,19 @@ func (f *FatSixImpl) PayNotify() {
|
||||
}{}
|
||||
err := f.Bind(&resp)
|
||||
if err != nil {
|
||||
logs.Error("解析参数失败", err)
|
||||
otel.Logger.WithContext(ctx).Error("解析参数失败", zap.Error(err))
|
||||
f.Ctx.WriteString("fail")
|
||||
return
|
||||
}
|
||||
orderInfo := order.GetOrderByBankOrderId(resp.MerOrderTid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, resp.MerOrderTid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
|
||||
//解析token
|
||||
params, _ := structs.ToMap(resp)
|
||||
respSign := resp.Sign
|
||||
tmpSign := sign(params, maputil.Keys(params), gojson.Json(roadInfo.Params).Get("paySecret").Tostring())
|
||||
if tmpSign != respSign {
|
||||
logs.Error("签名错误", err)
|
||||
otel.Logger.WithContext(ctx).Error("签名错误", zap.Error(err))
|
||||
f.Ctx.WriteString("fail")
|
||||
return
|
||||
}
|
||||
@@ -184,10 +199,10 @@ func (f *FatSixImpl) PayNotify() {
|
||||
// TODO 订单支付成功
|
||||
money, err := convertor.ToFloat(resp.Money)
|
||||
if err != nil {
|
||||
logs.Error("金额转换失败", err)
|
||||
otel.Logger.WithContext(ctx).Error("金额转换失败", zap.Error(err))
|
||||
f.Ctx.WriteString("fail")
|
||||
}
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, money, resp.Tid, "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, money, resp.Tid, "支付成功")
|
||||
if isOk {
|
||||
f.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -210,6 +225,8 @@ func (f *FatSixImpl) PayQuery(info order.OrderInfo, info2 road.RoadInfo) bool {
|
||||
}
|
||||
|
||||
func (f *FatSixImpl) PayQueryV2(info order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
ctx := f.Ctx.Request.Context()
|
||||
|
||||
params := map[string]any{
|
||||
"mid": "",
|
||||
}
|
||||
@@ -226,7 +243,7 @@ func (f *FatSixImpl) PayQueryV2(info order.OrderInfo, roadInfo road.RoadInfo) su
|
||||
httpClient := netutil.NewHttpClient()
|
||||
resp, err := httpClient.SendRequest(request)
|
||||
if err != nil || resp.StatusCode != 200 {
|
||||
logs.Error("发送数据失败", err)
|
||||
otel.Logger.WithContext(ctx).Error("发送数据失败", zap.Error(err))
|
||||
return "发送数据失败"
|
||||
}
|
||||
response := struct {
|
||||
@@ -240,7 +257,7 @@ func (f *FatSixImpl) PayQueryV2(info order.OrderInfo, roadInfo road.RoadInfo) su
|
||||
}{}
|
||||
err = httpClient.DecodeResponse(resp, &response)
|
||||
if err != nil || pointer.IsNil(response) {
|
||||
logs.Error("解析分解会结构失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("解析分解会结构失败", zap.Error(err), zap.Any("response", response))
|
||||
return "解析分解会结构失败"
|
||||
}
|
||||
return convertor.ToString(response.Result.Balance)
|
||||
|
||||
101
internal/service/supplier/third_party/jd.go
vendored
101
internal/service/supplier/third_party/jd.go
vendored
@@ -1,12 +1,15 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
"net/http"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
@@ -15,12 +18,16 @@ import (
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -43,7 +50,7 @@ func (c *JDCardImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *JDCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
func (c *JDCardImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
cfg := config.Config{}
|
||||
params := make(map[string]string)
|
||||
|
||||
@@ -60,25 +67,26 @@ func (c *JDCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
if err != nil {
|
||||
return false, "获取苹果卡密地址失败!"
|
||||
}
|
||||
req := httplib.Post(url)
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, url, "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
req.Header("tokenFrom", "iframe")
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("JD请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("JD请求失败:", zap.Error(err))
|
||||
return false, ""
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return false, ""
|
||||
}
|
||||
type AutoGenerated struct {
|
||||
@@ -92,24 +100,30 @@ func (c *JDCardImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
var resData AutoGenerated
|
||||
err = json.Unmarshal([]byte(response), &resData)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response))
|
||||
return false, "内部数据处理失败"
|
||||
}
|
||||
if resData.Code != 0 {
|
||||
logs.Error("充值错误", resData.Message)
|
||||
otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message))
|
||||
return false, resData.Message
|
||||
}
|
||||
return true, "等待兑换"
|
||||
}
|
||||
|
||||
func (c *JDCardImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *JDCardImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "JDCardImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
var scanData supplier.ScanData
|
||||
if !ok {
|
||||
scanData = supplier.ScanData{
|
||||
@@ -131,11 +145,12 @@ func (c *JDCardImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, mer
|
||||
|
||||
// KMEncrypt 加密卡密
|
||||
func (c *JDCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
|
||||
block, err := aes.NewCipher([]byte(secret))
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher")
|
||||
return "", err
|
||||
}
|
||||
// 数据填充
|
||||
@@ -147,23 +162,24 @@ func (c *JDCardImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *JDCardImpl) PayNotify() {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
attach := strings.TrimSpace(c.GetString("merchantId"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【JD】回调的订单号不存在,订单号=", attach)
|
||||
otel.Logger.WithContext(ctx).Error("【JD】回调的订单号不存在,订单号=", zap.String("attach", attach))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【JD】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【JD】支付通道已经关系或者删除,不进行回调")
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【JD】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【JD】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
@@ -176,14 +192,14 @@ func (c *JDCardImpl) PayNotify() {
|
||||
orderInfo.BankTransId = params["merchantId"]
|
||||
if params["status"] == "1" {
|
||||
// TODO 订单支付成功
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
}
|
||||
} else {
|
||||
isOk := service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "")
|
||||
isOk := service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -196,7 +212,7 @@ func (c *JDCardImpl) PayNotify() {
|
||||
|
||||
func (c *JDCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -218,23 +234,23 @@ func (c *JDCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo)
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -259,7 +275,7 @@ func (c *JDCardImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo)
|
||||
|
||||
func (c *JDCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return supply_model.CardMsgErr
|
||||
@@ -281,12 +297,12 @@ func (c *JDCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInf
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -296,7 +312,7 @@ func (c *JDCardImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInf
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -335,6 +351,7 @@ func (c *JDCardImpl) PayFor(info payfor.PayforInfo) string {
|
||||
func (c *JDCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
cfg := config.Config{}
|
||||
url, err := cfg.GetMFCardQueryUrl()
|
||||
ctx := c.Ctx.Request.Context()
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
@@ -346,25 +363,25 @@ func (c *JDCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -401,7 +418,7 @@ func (c *JDCardImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
94
internal/service/supplier/third_party/kuaifu.go
vendored
94
internal/service/supplier/third_party/kuaifu.go
vendored
@@ -1,8 +1,10 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
@@ -12,13 +14,17 @@ import (
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/maputil"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/maputil"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
@@ -46,7 +52,13 @@ func (c *KuaiFuImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *KuaiFuImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *KuaiFuImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "KuaiFuImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
payWayCode := ""
|
||||
switch orderInfo.PayTypeCode {
|
||||
case "ALI_SCAN":
|
||||
@@ -88,14 +100,14 @@ func (c *KuaiFuImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, mer
|
||||
scanData.OrderPrice = convertor.ToString(params["orderPrice"])
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("KF 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("KF 请求失败:", zap.Error(err))
|
||||
scanData.Status = "01"
|
||||
scanData.Msg = gojson.Json(response).Get("statusMsg").Tostring()
|
||||
return scanData
|
||||
}
|
||||
statusCode := gojson.Json(response).Get("statusCode").Tostring()
|
||||
if statusCode != "00" {
|
||||
logs.Error("KF生成扫码地址失败")
|
||||
otel.Logger.WithContext(ctx).Error("KF生成扫码地址失败")
|
||||
scanData.Status = "01"
|
||||
scanData.Msg = "生成扫码地址失败"
|
||||
return scanData
|
||||
@@ -109,21 +121,22 @@ func (c *KuaiFuImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, mer
|
||||
|
||||
// PayNotify 支付回调
|
||||
func (c *KuaiFuImpl) PayNotify() {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
orderNo := strings.TrimSpace(c.GetString("orderNo"))
|
||||
orderInfo := order.GetOrderByBankOrderId(orderNo)
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, orderNo)
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("快付回调的订单号不存在,订单号=", orderNo)
|
||||
otel.Logger.WithContext(ctx).Error("快付回调的订单号不存在,订单号=", zap.String("orderNo", orderNo))
|
||||
c.StopRun()
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("支付通道已经关系或者删除,不进行回调")
|
||||
c.StopRun()
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.StopRun()
|
||||
}
|
||||
params := make(map[string]any)
|
||||
@@ -141,38 +154,39 @@ func (c *KuaiFuImpl) PayNotify() {
|
||||
tmpSign := utils.GetMD5Sign(params, keys, paySecret)
|
||||
sign := strings.TrimSpace(c.GetString("sign"))
|
||||
if tmpSign != sign {
|
||||
logs.Error("快付回调签名异常,回调失败")
|
||||
otel.Logger.WithContext(ctx).Error("快付回调签名异常,回调失败")
|
||||
c.StopRun()
|
||||
}
|
||||
// 实际支付金额
|
||||
factAmount, err := strconv.ParseFloat(convertor.ToString(params["orderPrice"]), 64)
|
||||
if err != nil {
|
||||
logs.Error("快付回调实际金额有误, factAmount=", params["orderPrice"])
|
||||
otel.Logger.WithContext(ctx).Error("快付回调实际金额有误,", zap.Any("factAmount=", params["orderPrice"]))
|
||||
c.StopRun()
|
||||
}
|
||||
orderInfo.FactAmount = factAmount
|
||||
orderInfo.BankTransId = convertor.ToString(params["trxNo"])
|
||||
tradeStatus := params["tradeStatus"]
|
||||
if tradeStatus == "FAILED" {
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "") {
|
||||
logs.Error("solve order fail fail")
|
||||
if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") {
|
||||
otel.Logger.WithContext(ctx).Error("solve order fail fail")
|
||||
}
|
||||
} else if tradeStatus == "CANCELED" {
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "") {
|
||||
logs.Error("solve order cancel fail")
|
||||
if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") {
|
||||
otel.Logger.WithContext(ctx).Error("solve order cancel fail")
|
||||
}
|
||||
} else if tradeStatus == "WAITING_PAYMENT" {
|
||||
logs.Notice("快付回调,该订单还处于等待支付,订单id=", orderNo)
|
||||
} else if tradeStatus == "SUCCESS" {
|
||||
// 订单支付成功,需要搞很多事情 TODO
|
||||
service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, c.GetString("trxNo"), "支付成功")
|
||||
service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, c.GetString("trxNo"), "支付成功")
|
||||
}
|
||||
c.Ctx.WriteString("success")
|
||||
}
|
||||
|
||||
func (c *KuaiFuImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
if orderInfo.Status != "wait" && orderInfo.Status != "" {
|
||||
logs.Error("订单已经被处理,不需要查询,bankOrderId:", orderInfo.BankOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("订单已经被处理,不需要查询,bankOrderId:", zap.String("BankOrderId", orderInfo.BankOrderId))
|
||||
return false
|
||||
}
|
||||
params := make(map[string]any)
|
||||
@@ -187,21 +201,20 @@ func (c *KuaiFuImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo)
|
||||
}
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("快付订单查询失败,bankOrderId: ", orderInfo.BankOrderId)
|
||||
logs.Error("err: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("快付订单查询失败,bankOrderId: ", zap.String("BankOrderId", orderInfo.BankOrderId))
|
||||
otel.Logger.WithContext(ctx).Error("err: ", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
statusCode := gojson.Json(response).Get("statusCode").Tostring()
|
||||
if statusCode != "00" {
|
||||
logs.Error("快付订单查询返回失败,bankOrderId:", orderInfo.BankOrderId)
|
||||
logs.Error("err: ", response)
|
||||
otel.Logger.WithContext(ctx).Error("快付订单查询返回失败,bankOrderId:", zap.String("BankOrderId", orderInfo.BankOrderId), zap.String("response", response))
|
||||
return false
|
||||
}
|
||||
// 获取用户的实际支付金额
|
||||
orderPrice := gojson.Json(response).Get("orderPrice").Tostring()
|
||||
factAmount, err := strconv.ParseFloat(orderPrice, 64)
|
||||
if err != nil {
|
||||
logs.Error("快速查询得到的实际金额错误, orderPrice=", orderPrice)
|
||||
otel.Logger.WithContext(ctx).Error("快速查询得到的实际金额错误, orderPrice=", zap.Any("orderPrice", orderPrice))
|
||||
}
|
||||
|
||||
// orderInfo.FactAmount = orderInfo.OrderAmount
|
||||
@@ -209,15 +222,15 @@ func (c *KuaiFuImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo)
|
||||
trxNo := gojson.Json(response).Get("trxNo").Tostring()
|
||||
if tradeStatus == "SUCCESS" {
|
||||
// 调用支付成功的接口,做加款更新操作,需要把实际支付金额传入
|
||||
if !service.SolvePaySuccess(orderInfo.BankOrderId, factAmount, trxNo, "支付成功") {
|
||||
if !service.SolvePaySuccess(ctx, orderInfo.BankOrderId, factAmount, trxNo, "支付成功") {
|
||||
return false
|
||||
}
|
||||
} else if tradeStatus == "FAILED" {
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "") {
|
||||
if !service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "") {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
logs.Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId)
|
||||
otel.Logger.WithContext(ctx).Info("订单状态处于:" + tradeStatus + ";bankOrderId:" + orderInfo.BankOrderId)
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -227,6 +240,7 @@ func (c *KuaiFuImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInf
|
||||
}
|
||||
|
||||
func (c *KuaiFuImpl) PayFor(payFor payfor.PayforInfo) string {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
params := make(map[string]any)
|
||||
params["merchantKey"] = KF_PAY_KEY
|
||||
params["realname"] = payFor.BankAccountName
|
||||
@@ -253,20 +267,20 @@ func (c *KuaiFuImpl) PayFor(payFor payfor.PayforInfo) string {
|
||||
}
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("快付代付返回错误结果: ", response)
|
||||
otel.Logger.WithContext(ctx).Error("快付代付返回错误结果: ", zap.String("response", response))
|
||||
} else {
|
||||
json := gojson.Json(response)
|
||||
resultCode := json.Get("resultCode").Tostring()
|
||||
resultMsg := json.Get("resultMsg").Tostring()
|
||||
if resultCode != "00" {
|
||||
logs.Error("快付代付返回错误信息:", resultMsg)
|
||||
otel.Logger.WithContext(ctx).Error("快付代付返回错误信息:", zap.String("resultMsg", resultMsg))
|
||||
return "fail"
|
||||
}
|
||||
settStatus := json.Get("settStatus").Tostring()
|
||||
if settStatus == "00" {
|
||||
logs.Info(fmt.Sprintf("代付uid=%s,已经成功发送给了上游处理", payFor.PayforUid))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,已经成功发送给了上游处理", payFor.PayforUid))
|
||||
} else if settStatus == "01" {
|
||||
logs.Info(fmt.Sprintf("代付uid=%s,发送失败", payFor.PayforUid))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("代付uid=%s,发送失败", payFor.PayforUid))
|
||||
}
|
||||
}
|
||||
return "success"
|
||||
@@ -277,6 +291,7 @@ func (c *KuaiFuImpl) PayForNotify() string {
|
||||
}
|
||||
|
||||
func (c *KuaiFuImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
params := make(map[string]any)
|
||||
params["merchantKey"] = KF_PAY_KEY
|
||||
params["timestamp"] = utils.GetNowTimesTamp()
|
||||
@@ -291,30 +306,30 @@ func (c *KuaiFuImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
}
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("快付代付查询失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("快付代付查询失败:", zap.Error(err))
|
||||
return config.PAYFOR_SOLVING, "查询失败"
|
||||
}
|
||||
|
||||
payFor.ResponseContent = response
|
||||
payFor.ResponseTime = utils.GetBasicDateTime()
|
||||
payFor.UpdateTime = time.Now()
|
||||
if !payfor.UpdatePayFor(payFor) {
|
||||
logs.Error("更新快付代付订单状态失败")
|
||||
if !payfor.UpdatePayFor(ctx, payFor) {
|
||||
otel.Logger.WithContext(ctx).Error("更新快付代付订单状态失败")
|
||||
}
|
||||
|
||||
resultCode := gojson.Json(response).Get("resultCode").Tostring()
|
||||
resultMsg := gojson.Json(response).Get("resultMsg").Tostring()
|
||||
|
||||
if resultCode != "00" {
|
||||
logs.Error("快付代付查询返回错误:", resultMsg)
|
||||
otel.Logger.WithContext(ctx).Error("快付代付查询返回错误:", zap.String("resultMsg", resultMsg))
|
||||
return config.PAYFOR_SOLVING, resultMsg
|
||||
}
|
||||
|
||||
logs.Info("快付代付查询返回结果:", resultMsg)
|
||||
otel.Logger.WithContext(ctx).Info("快付代付查询返回结果:", zap.String("resultMsg", resultMsg))
|
||||
|
||||
merchantOrderId := gojson.Json(response).Get("merchantOrderId").Tostring()
|
||||
if merchantOrderId != payFor.BankOrderId {
|
||||
logs.Error("快付代付返回结果,订单id不一致: ", merchantOrderId)
|
||||
otel.Logger.WithContext(ctx).Error("快付代付返回结果,订单id不一致: ", zap.String("resultMsg", merchantOrderId))
|
||||
return config.PAYFOR_SOLVING, "快付代付返回结果,订单id不一致"
|
||||
}
|
||||
|
||||
@@ -335,6 +350,7 @@ func (c *KuaiFuImpl) BalanceQuery(roadInfo road.RoadInfo) float64 {
|
||||
"timestamp": utils.GetNowTimesTamp(),
|
||||
"merchantOrderId": xid.New().String(),
|
||||
}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
keys := utils.SortMap(params)
|
||||
sign := utils.GetMD5Sign(params, keys, KF_PAY_SECRET)
|
||||
params["sign"] = sign
|
||||
@@ -345,7 +361,7 @@ func (c *KuaiFuImpl) BalanceQuery(roadInfo road.RoadInfo) float64 {
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("快付余额查询失败,err: ", err)
|
||||
otel.Logger.WithContext(ctx).Error("快付余额查询失败,err: ", zap.Error(err))
|
||||
return 0.00
|
||||
}
|
||||
logs.Debug("快付余额查询返回:", response)
|
||||
@@ -361,7 +377,7 @@ func (c *KuaiFuImpl) BalanceQuery(roadInfo road.RoadInfo) float64 {
|
||||
balance := gojson.Json(response).Get("balance").Tostring()
|
||||
availableAmount := gojson.Json(response).Get("availableAmount").Tostring()
|
||||
|
||||
logs.Info(fmt.Sprintf("快付余额=%s,可用金额=%s", balance, availableAmount))
|
||||
otel.Logger.WithContext(ctx).Info(fmt.Sprintf("快付余额=%s,可用金额=%s", balance, availableAmount))
|
||||
|
||||
f, err := strconv.ParseFloat(availableAmount, 64)
|
||||
return f
|
||||
|
||||
@@ -58,7 +58,7 @@ func (c *MFCardImpl) GetToken(jsonStr string) (bool, string) {
|
||||
req := httplib.Post(MF_sURL)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", err)
|
||||
//fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
return false, ""
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func (c *MFCardImpl) GetToken(jsonStr string) (bool, string) {
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", err)
|
||||
return false, ""
|
||||
}
|
||||
//{
|
||||
@@ -80,12 +80,12 @@ func (c *MFCardImpl) GetToken(jsonStr string) (bool, string) {
|
||||
//}
|
||||
|
||||
if gojson.Json(response).Get("ret").Tostring() == "" {
|
||||
logs.Error("MF GetToken 获取返回值失败:")
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 获取返回值失败:")
|
||||
return false, ""
|
||||
}
|
||||
|
||||
if gojson.Json(response).Get("ret").Tostring() == "1" {
|
||||
logs.Error("MF GetToken 失败:", gojson.Json(response).Get("msg").Tostring())
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 失败:", gojson.Json(response).Get("msg").Tostring())
|
||||
return false, ""
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ func (c *MFCardImpl) SendCard(jsonStr string, CardInfo CardInfo, attach string)
|
||||
req := httplib.Post(MF_sURL)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", err)
|
||||
//fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
//for k, v := range params {
|
||||
@@ -137,7 +137,7 @@ func (c *MFCardImpl) SendCard(jsonStr string, CardInfo CardInfo, attach string)
|
||||
//}
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", err)
|
||||
return false, ""
|
||||
}
|
||||
//{
|
||||
@@ -145,10 +145,10 @@ func (c *MFCardImpl) SendCard(jsonStr string, CardInfo CardInfo, attach string)
|
||||
// "msg" : "SUCCESS", //返回消息
|
||||
// "data" : "77754b9000d9ac80c2c3bd9e934cd587" //32位登录token 有效期30分钟,每次请求都会刷新过期时间
|
||||
//}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("ret").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return false, ""
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ func (c *MFCardImpl) SendCard(jsonStr string, CardInfo CardInfo, attach string)
|
||||
|
||||
dataX := gojson.Json(response).Get("error_data").Getdata()
|
||||
msg := dataX["msg"].(string)
|
||||
logs.Error("远程返回错误:", msg)
|
||||
otel.Logger.WithContext(ctx).Error("远程返回错误:", msg)
|
||||
//error_data
|
||||
return false, msg
|
||||
}
|
||||
@@ -204,14 +204,14 @@ func (c *MFCardImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, mer
|
||||
//
|
||||
//err = o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
|
||||
// if _, err := txOrm.Update(&orderInfo); err != nil || orderInfo.BankOrderId == "" {
|
||||
// logs.Error(fmt.Sprintf("solve pay success, update order info fail: %s, bankOrderId = %s", err, ""))
|
||||
// otel.Logger.WithContext(ctx).Error(fmt.Sprintf("solve pay success, update order info fail: %s, bankOrderId = %s", err, ""))
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
//})
|
||||
|
||||
if err != nil {
|
||||
logs.Error("SolvePaySuccess失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", err)
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func (c *MFCardImpl) Syt(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merc
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logs.Error("SolvePaySuccess失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", err)
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
|
||||
@@ -288,18 +288,18 @@ func (c *MFCardImpl) PayNotify() {
|
||||
attach := strings.TrimSpace(c.GetString("attach"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach)
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【MF178】回调的订单号不存在,订单号=", attach)
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】回调的订单号不存在,订单号=", attach)
|
||||
c.StopRun()
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【MF178】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】支付通道已经关系或者删除,不进行回调")
|
||||
c.StopRun()
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【MF178】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
c.StopRun()
|
||||
}
|
||||
paySecret := merchantInfo.MerchantSecret
|
||||
@@ -316,7 +316,7 @@ func (c *MFCardImpl) PayNotify() {
|
||||
tmpSign := utils.GetMD5Sign(params, keys, paySecret)
|
||||
sign := strings.TrimSpace(c.GetString("sign"))
|
||||
if tmpSign != sign {
|
||||
logs.Error("【MF178】回调签名异常,回调失败")
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】回调签名异常,回调失败")
|
||||
//c.StopRun()
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ func (c *MFCardImpl) PayNotify() {
|
||||
//paySolveController := new(service.PaySolveController)
|
||||
if tradeStatus == "8" { //失败
|
||||
if !service.SolvePayFail(orderInfo.BankOrderId, "") {
|
||||
logs.Error("solve order fail fail")
|
||||
otel.Logger.WithContext(ctx).Error("solve order fail fail")
|
||||
}
|
||||
} else if tradeStatus == "9" {
|
||||
//订单支付成功,需要搞很多事情 TODO
|
||||
|
||||
113
internal/service/supplier/third_party/mf178_v2.go
vendored
113
internal/service/supplier/third_party/mf178_v2.go
vendored
@@ -1,6 +1,7 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
@@ -12,16 +13,22 @@ import (
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/service/supplier"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -36,7 +43,7 @@ func (c *MFCardV2Impl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *MFCardV2Impl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string) (bool, string) {
|
||||
func (c *MFCardV2Impl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, attach string) (bool, string) {
|
||||
appKey := gojson.Json(jsonStr).Get("appKey").Tostring()
|
||||
appSecret := gojson.Json(jsonStr).Get("appSecret").Tostring()
|
||||
goodsSku := gojson.Json(jsonStr).Get("goodsSku").Tostring()
|
||||
@@ -64,31 +71,32 @@ func (c *MFCardV2Impl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo
|
||||
sign := utils.GetMD5SignMF(params, appSecret)
|
||||
params["sign"] = sign
|
||||
|
||||
logs.Info("params", params)
|
||||
otel.Logger.WithContext(ctx).Info("params", zap.Any("params", params))
|
||||
url, err := cfg.GetMFCardSubmitUrl()
|
||||
if err != nil {
|
||||
return false, ""
|
||||
}
|
||||
req := httplib.Post(url)
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, url, "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false, ""
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return false, ""
|
||||
}
|
||||
type AutoGenerated struct {
|
||||
@@ -116,14 +124,20 @@ func (c *MFCardV2Impl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo
|
||||
return true, response
|
||||
}
|
||||
|
||||
func (c *MFCardV2Impl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *MFCardV2Impl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "MFCardV2Impl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue), zap.Error(err))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, orderInfo.BankOrderId)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId)
|
||||
if !ok {
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试:" + str}
|
||||
}
|
||||
@@ -137,7 +151,7 @@ func (c *MFCardV2Impl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, m
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logs.Error("SolvePaySuccess失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("SolvePaySuccess失败:", zap.Error(err))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
var scanData supplier.ScanData
|
||||
@@ -155,11 +169,11 @@ func (c *MFCardV2Impl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, m
|
||||
|
||||
// KMEncrypt 加密卡密
|
||||
func (c *MFCardV2Impl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
|
||||
block, err := aes.NewCipher([]byte(secret))
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher")
|
||||
return "", err
|
||||
}
|
||||
// 数据填充
|
||||
@@ -171,31 +185,32 @@ func (c *MFCardV2Impl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *MFCardV2Impl) PayNotify() {
|
||||
logs.Info("消息回调成功!!!")
|
||||
ctx := c.Ctx.Request.Context()
|
||||
otel.Logger.WithContext(ctx).Info("消息回调成功!!!")
|
||||
params := make(map[string]any)
|
||||
attach := strings.TrimSpace(c.GetString("attach"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【MF178】回调的订单号不存在,订单号=", attach)
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】回调的订单号不存在,订单号=", zap.String("attach", attach))
|
||||
c.StopRun()
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【MF178】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】支付通道已经关系或者删除,不进行回调")
|
||||
c.StopRun()
|
||||
return
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【MF178】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.StopRun()
|
||||
return
|
||||
}
|
||||
paySecretGroup, err := sonic.GetFromString(roadInfo.Params)
|
||||
if err != nil {
|
||||
logs.Error("获取蜜蜂秘钥失败", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("获取蜜蜂秘钥失败", zap.String("merchantUid", merchantUid))
|
||||
c.StopRun()
|
||||
return
|
||||
}
|
||||
@@ -216,7 +231,7 @@ func (c *MFCardV2Impl) PayNotify() {
|
||||
sign := strings.TrimSpace(c.GetString("sign"))
|
||||
params["sign"] = sign // 签名
|
||||
if tmpSign != sign {
|
||||
logs.Error("【MF178】回调签名异常,回调失败")
|
||||
otel.Logger.WithContext(ctx).Error("【MF178】回调签名异常,回调失败")
|
||||
c.StopRun()
|
||||
return
|
||||
}
|
||||
@@ -226,18 +241,19 @@ func (c *MFCardV2Impl) PayNotify() {
|
||||
orderInfo.FactAmount = 0
|
||||
}
|
||||
if params["status"] == "8" { // 失败
|
||||
logs.Info("【MF178】回调失败,订单信息", params)
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), convertor.ToString(params["order_id"]), "", "") {
|
||||
logs.Error("solve order fail fail")
|
||||
otel.Logger.WithContext(ctx).Info("【MF178】回调失败,订单信息", zap.Any("params", params))
|
||||
if !service.SolvePayFail(ctx, convertor.ToString(params["order_id"]), "", "") {
|
||||
otel.Logger.WithContext(ctx).Error("solve order fail fail")
|
||||
}
|
||||
} else if params["status"] == "9" && factAmount == orderInfo.FactAmount {
|
||||
// TODO 订单支付成功
|
||||
service.SolvePaySuccess(convertor.ToString(params["order_id"]), factAmount, convertor.ToString(params["order_id"]), "支付成功")
|
||||
service.SolvePaySuccess(ctx, convertor.ToString(params["order_id"]), factAmount, convertor.ToString(params["order_id"]), "支付成功")
|
||||
}
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
}
|
||||
|
||||
func (c *MFCardV2Impl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
params := map[string]any{}
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
@@ -261,23 +277,23 @@ func (c *MFCardV2Impl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInf
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -302,7 +318,7 @@ func (c *MFCardV2Impl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInf
|
||||
|
||||
func (c *MFCardV2Impl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return supply_model.CardMsgErr
|
||||
@@ -324,12 +340,12 @@ func (c *MFCardV2Impl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadI
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -339,7 +355,7 @@ func (c *MFCardV2Impl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadI
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -378,6 +394,7 @@ func (c *MFCardV2Impl) PayFor(info payfor.PayforInfo) string {
|
||||
|
||||
func (c *MFCardV2Impl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
cfg := config.Config{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
url, err := cfg.GetMFCardQueryUrl()
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
@@ -390,25 +407,25 @@ func (c *MFCardV2Impl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -445,7 +462,7 @@ func (c *MFCardV2Impl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
99
internal/service/supplier/third_party/self.go
vendored
99
internal/service/supplier/third_party/self.go
vendored
@@ -1,11 +1,13 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
@@ -15,14 +17,17 @@ import (
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type SelfThirdImpl struct {
|
||||
@@ -34,7 +39,7 @@ func (c *SelfThirdImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *SelfThirdImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, orderInfo order.OrderInfo, roadInfo road.RoadInfo) (bool, string) {
|
||||
func (c *SelfThirdImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, orderInfo order.OrderInfo, roadInfo road.RoadInfo) (bool, string) {
|
||||
params := map[string]any{
|
||||
"exValue": strings.TrimSpace(c.GetString("exValue")),
|
||||
"orderNo": orderInfo.BankOrderId,
|
||||
@@ -53,20 +58,20 @@ func (c *SelfThirdImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInf
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("【自有三方】 GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("【自有三方】 GetToken 请求失败:", zap.Error(err))
|
||||
return false, ""
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return false, ""
|
||||
}
|
||||
type AutoGenerated struct {
|
||||
@@ -77,7 +82,7 @@ func (c *SelfThirdImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInf
|
||||
var resData AutoGenerated
|
||||
err = json.Unmarshal([]byte(response), &resData)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response))
|
||||
return false, "内部数据处理失败"
|
||||
}
|
||||
if resData.Code == 0 {
|
||||
@@ -86,14 +91,20 @@ func (c *SelfThirdImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInf
|
||||
return false, response
|
||||
}
|
||||
|
||||
func (c *SelfThirdImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *SelfThirdImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "SelfThirdImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, orderInfo, roadInfo)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo, roadInfo)
|
||||
var scanData supplier.ScanData
|
||||
if !ok {
|
||||
scanData = supplier.ScanData{
|
||||
@@ -115,11 +126,12 @@ func (c *SelfThirdImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo,
|
||||
|
||||
// KMEncrypt 加密卡密
|
||||
func (c *SelfThirdImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
|
||||
block, err := aes.NewCipher([]byte(secret))
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher")
|
||||
return "", err
|
||||
}
|
||||
// 数据填充
|
||||
@@ -131,6 +143,8 @@ func (c *SelfThirdImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *SelfThirdImpl) PayNotify() {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
params := map[string]any{
|
||||
"orderNo": c.GetString("orderNo"),
|
||||
"orderPrice": c.GetString("orderPrice"),
|
||||
@@ -142,36 +156,36 @@ func (c *SelfThirdImpl) PayNotify() {
|
||||
"tradeStatus": c.GetString("tradeStatus"),
|
||||
"sign": c.GetString("sign"),
|
||||
}
|
||||
orderInfo := order.GetOrderByBankOrderId(params["orderNo"].(string))
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, params["orderNo"].(string))
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【自有三方】回调的订单号不存在,订单号=", params["orderNo"].(string))
|
||||
otel.Logger.WithContext(ctx).Error("【自有三方】回调的订单号不存在,订单号=", zap.String("orderNo", params["orderNo"].(string)))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【自有三方】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【自有三方】支付通道已经关系或者删除,不进行回调")
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【自有三方】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【自有三方】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
orderInfo.BankTransId = params["trxNo"].(string)
|
||||
if params["statusCode"] == "01" {
|
||||
// TODO 订单支付成功
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, params["trxNo"].(string), "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, params["trxNo"].(string), "支付成功")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
}
|
||||
} else {
|
||||
isOk := service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "")
|
||||
isOk := service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -182,6 +196,7 @@ func (c *SelfThirdImpl) PayNotify() {
|
||||
}
|
||||
|
||||
func (c *SelfThirdImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -206,23 +221,23 @@ func (c *SelfThirdImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -246,6 +261,7 @@ func (c *SelfThirdImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
}
|
||||
|
||||
func (c *SelfThirdImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -270,12 +286,12 @@ func (c *SelfThirdImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -285,7 +301,7 @@ func (c *SelfThirdImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -327,6 +343,7 @@ func (c *SelfThirdImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
params := map[string]string{}
|
||||
params["order_id"] = payFor.BankOrderId
|
||||
@@ -335,25 +352,25 @@ func (c *SelfThirdImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -390,7 +407,7 @@ func (c *SelfThirdImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -10,14 +11,10 @@ import (
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/service/supplier"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/cryptor"
|
||||
"github.com/duke-git/lancet/v2/netutil"
|
||||
"io"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -25,6 +22,15 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/duke-git/lancet/v2/cryptor"
|
||||
"github.com/duke-git/lancet/v2/netutil"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -40,7 +46,7 @@ func (c *StarSilenceImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *StarSilenceImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, orderInfo *order.OrderInfo) (bool, string) {
|
||||
func (c *StarSilenceImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, orderInfo *order.OrderInfo) (bool, string) {
|
||||
|
||||
params := map[string]string{
|
||||
"supplierId": gojson.Json(jsonStr).Get("supplierId").Tostring(),
|
||||
@@ -60,25 +66,33 @@ func (c *StarSilenceImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardI
|
||||
for s, s2 := range params {
|
||||
formData.Set(s, s2)
|
||||
}
|
||||
logs.Info("formData", formData)
|
||||
resp, _ := netutil.NewHttpClient().SendRequest(&netutil.HttpRequest{
|
||||
otel.Logger.WithContext(ctx).Info("formData", zap.Any("formData", formData))
|
||||
client := netutil.NewHttpClient()
|
||||
client.Transport = otelhttp.NewTransport(client.Transport)
|
||||
resp, _ := client.SendRequest(&netutil.HttpRequest{
|
||||
RawURL: "https://www.xingjiyou.cn/cardapi/submitOrder",
|
||||
Method: "POST",
|
||||
QueryParams: formData,
|
||||
})
|
||||
result, _ := io.ReadAll(resp.Body)
|
||||
logs.Info("远端请求返回数据:%s", string(result))
|
||||
otel.Logger.WithContext(ctx).Sugar().Infof("远端请求返回数据:%s\n", string(result))
|
||||
return gojson.Json(string(result)).Get("code").Tostring() == "0", gojson.Json(string(result)).Get("msg").Tostring()
|
||||
}
|
||||
|
||||
func (c *StarSilenceImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *StarSilenceImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "StarSilenceImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, &orderInfo)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, &orderInfo)
|
||||
if !ok {
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试:" + str}
|
||||
}
|
||||
@@ -92,7 +106,8 @@ func (c *StarSilenceImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo
|
||||
}
|
||||
|
||||
func (c *StarSilenceImpl) PayNotify() {
|
||||
logs.Info("消息回调成功!!!")
|
||||
ctx := c.Ctx.Request.Context()
|
||||
otel.Logger.WithContext(ctx).Info("消息回调成功!!!")
|
||||
params := map[string]string{
|
||||
"supplierOrderId": strings.TrimSpace(c.GetString("supplierOrderId")),
|
||||
"deservedValue": strings.TrimSpace(c.GetString("deservedValue")),
|
||||
@@ -102,17 +117,17 @@ func (c *StarSilenceImpl) PayNotify() {
|
||||
"sign": strings.TrimSpace(c.GetString("sign")),
|
||||
}
|
||||
r, _ := json.Marshal(params)
|
||||
logs.Info("回调参数:%s", string(r))
|
||||
otel.Logger.WithContext(ctx).Sugar().Infof("回调参数:%s", string(r))
|
||||
|
||||
orderInfo := order.GetOrderByBankOrderId(params["supplierOrderId"]) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, params["supplierOrderId"]) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【星寂】回调的订单号不存在,订单号=", params["supplierOrderId"])
|
||||
otel.Logger.WithContext(ctx).Error("【星寂】回调的订单号不存在,订单号=", zap.String("supplierOrderId", params["supplierOrderId"]))
|
||||
c.Ctx.WriteString("订单不存在")
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【星寂】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【星寂】支付通道已经关系或者删除,不进行回调")
|
||||
c.Ctx.WriteString("通道不存在")
|
||||
c.StopRun()
|
||||
return
|
||||
@@ -122,15 +137,15 @@ func (c *StarSilenceImpl) PayNotify() {
|
||||
params["deservedValue"], params["code"], params["msg"], gojson.Json(roadInfo.Params).Get("signKey").Tostring())),
|
||||
)
|
||||
if tmpSign != params["sign"] {
|
||||
logs.Error("签名验证失败", tmpSign, params["sign"])
|
||||
otel.Logger.WithContext(ctx).Error("签名验证失败", zap.String(tmpSign, "tmpSign"), zap.String("sign", params["sign"]))
|
||||
c.Ctx.WriteString("签名验证失败")
|
||||
c.StopRun()
|
||||
}
|
||||
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【星寂】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【星寂】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.Ctx.WriteString("商户不存在")
|
||||
c.StopRun()
|
||||
return
|
||||
@@ -138,18 +153,18 @@ func (c *StarSilenceImpl) PayNotify() {
|
||||
// 实际支付金额
|
||||
factAmount, err := strconv.ParseFloat(convertor.ToString(params["realParvalue"]), 64)
|
||||
if err != nil {
|
||||
logs.Error("【星寂】处理失败,%s", err)
|
||||
otel.Logger.WithContext(ctx).Error("【星寂】处理失败,%s", zap.Error(err))
|
||||
c.Ctx.WriteString("订单转换失败")
|
||||
return
|
||||
}
|
||||
//判断实付金额是否与订单金额一致
|
||||
if params["code"] == "1" && factAmount == orderInfo.OrderAmount {
|
||||
service.SolvePaySuccess(convertor.ToString(params["supplierOrderId"]), factAmount, "", "支付成功")
|
||||
service.SolvePaySuccess(ctx, convertor.ToString(params["supplierOrderId"]), factAmount, "", "支付成功")
|
||||
} else if params["code"] == "1" && factAmount != orderInfo.OrderAmount {
|
||||
service.SolvePayFail(c.Ctx.Request.Context(), convertor.ToString(params["supplierOrderId"]), "", fmt.Sprintf("实付金额与订单金额不一致,实际金额%.2f,卡面金额:%.2f", factAmount, orderInfo.OrderAmount))
|
||||
service.SolvePayFail(ctx, convertor.ToString(params["supplierOrderId"]), "", fmt.Sprintf("实付金额与订单金额不一致,实际金额%.2f,卡面金额:%.2f", factAmount, orderInfo.OrderAmount))
|
||||
} else {
|
||||
if !service.SolvePayFail(c.Ctx.Request.Context(), convertor.ToString(params["supplierOrderId"]), "", params["msg"]) {
|
||||
logs.Error("【星寂】处理失败")
|
||||
if !service.SolvePayFail(ctx, convertor.ToString(params["supplierOrderId"]), "", params["msg"]) {
|
||||
otel.Logger.WithContext(ctx).Error("【星寂】处理失败")
|
||||
}
|
||||
}
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
@@ -157,7 +172,7 @@ func (c *StarSilenceImpl) PayNotify() {
|
||||
|
||||
func (c *StarSilenceImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -179,23 +194,23 @@ func (c *StarSilenceImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -220,7 +235,7 @@ func (c *StarSilenceImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
|
||||
func (c *StarSilenceImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return supply_model.CardMsgErr
|
||||
@@ -242,12 +257,12 @@ func (c *StarSilenceImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -257,7 +272,7 @@ func (c *StarSilenceImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -296,6 +311,7 @@ func (c *StarSilenceImpl) PayFor(info payfor.PayforInfo) string {
|
||||
|
||||
func (c *StarSilenceImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
cfg := config.Config{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
url, err := cfg.GetMFCardQueryUrl()
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
@@ -308,25 +324,25 @@ func (c *StarSilenceImpl) PayForQuery(payFor payfor.PayforInfo) (string, string)
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -363,7 +379,7 @@ func (c *StarSilenceImpl) PayForQuery(payFor payfor.PayforInfo) (string, string)
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,16 @@ package third_party
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
|
||||
"gateway/internal/models/order"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/duke-git/lancet/v2/cryptor"
|
||||
"github.com/duke-git/lancet/v2/random"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/duke-git/lancet/v2/cryptor"
|
||||
"github.com/duke-git/lancet/v2/random"
|
||||
)
|
||||
|
||||
func TestStarSilenceImpl_SendCard(t *testing.T) {
|
||||
@@ -73,5 +74,5 @@ func TestStarSilenceImpl_PayNotify(t *testing.T) {
|
||||
fmt.Sprintf("%s%s%s%s%s%s", "6666cuhprmeqgjec73975600", "0", "0", "2", "销卡失败-卡密无效", "e90db0fea5be42f98a376b0049c9aa8c"),
|
||||
),
|
||||
)
|
||||
logs.Info(tmpSign)
|
||||
otel.Logger.WithContext(ctx).Info(tmpSign)
|
||||
}
|
||||
|
||||
103
internal/service/supplier/third_party/t_mall_game.go
vendored
103
internal/service/supplier/third_party/t_mall_game.go
vendored
@@ -1,9 +1,12 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
"net/http"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
@@ -12,12 +15,16 @@ import (
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -40,7 +47,13 @@ func (c *TMAllGameImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, orderInfo order.OrderInfo) (bool, string) {
|
||||
func (c *TMAllGameImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.CardInfo, orderInfo order.OrderInfo) (bool, string) {
|
||||
ctx, cancel := otel.Span(ctx, "TMAllGameImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cfg := config.Config{}
|
||||
var err error
|
||||
|
||||
@@ -62,29 +75,30 @@ func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, ord
|
||||
}
|
||||
params["sign"] = utils.TmpEncrypt(params["merchantOrder"] + params["accountNumber"] + params["timestamp"])
|
||||
url, err := cfg.GetTMallGameSubmitUrl()
|
||||
logs.Info("获取TMallGame地址:", url)
|
||||
otel.Logger.WithContext(ctx).Sugar().Infof("获取TMallGame地址:%s\n", url)
|
||||
if err != nil {
|
||||
return false, "获取天猫充值地址失败!"
|
||||
}
|
||||
req := httplib.Post(url)
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, url, "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
req.Header("tokenFrom", "iframe")
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("天猫店铺请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("天猫店铺请求失败:", zap.Error(err))
|
||||
return false, ""
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return false, ""
|
||||
}
|
||||
type AutoGenerated struct {
|
||||
@@ -98,11 +112,11 @@ func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, ord
|
||||
var resData AutoGenerated
|
||||
err = json.Unmarshal([]byte(response), &resData)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response))
|
||||
return false, "内部数据处理失败"
|
||||
}
|
||||
if resData.Code != 0 {
|
||||
logs.Error("充值错误", resData.Message)
|
||||
otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message))
|
||||
return false, resData.Message
|
||||
}
|
||||
switch resData.Data.Status {
|
||||
@@ -114,13 +128,13 @@ func (c *TMAllGameImpl) SendCard(jsonStr string, cardInfo supplier.CardInfo, ord
|
||||
return true, "等待兑换"
|
||||
}
|
||||
|
||||
func (c *TMAllGameImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
logs.Info("TMallGame支付")
|
||||
func (c *TMAllGameImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
otel.Logger.WithContext(ctx).Info("TMallGame支付")
|
||||
var cdata supplier.CardInfo
|
||||
cdata = &supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
channel := ""
|
||||
@@ -129,7 +143,7 @@ func (c *TMAllGameImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo,
|
||||
} else {
|
||||
channel = "evaluation"
|
||||
}
|
||||
ok, str := c.SendCard(channel, cdata, orderInfo)
|
||||
ok, str := c.SendCard(ctx, channel, cdata, orderInfo)
|
||||
if !ok {
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试:" + str}
|
||||
}
|
||||
@@ -150,22 +164,24 @@ func (c *TMAllGameImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo,
|
||||
}
|
||||
|
||||
func (c *TMAllGameImpl) PayNotify() {
|
||||
orderInfo := order.GetOrderByBankOrderId(strings.TrimSpace(c.GetString("merchantOrder"))) // OrderId
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, strings.TrimSpace(c.GetString("merchantOrder"))) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【TMALLGAME】回调的订单号不存在,订单号=", strings.TrimSpace(c.GetString("merchantOrder")))
|
||||
otel.Logger.WithContext(ctx).Error("【TMALLGAME】回调的订单号不存在,订单号=", zap.String("merchantOrder", strings.TrimSpace(c.GetString("merchantOrder"))))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【TMALLGAME】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【TMALLGAME】支付通道已经关系或者删除,不进行回调")
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【TMALLGAME】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【TMALLGAME】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
@@ -180,22 +196,22 @@ func (c *TMAllGameImpl) PayNotify() {
|
||||
}
|
||||
tmpSign := utils.TmpEncrypt(strings.TrimSpace(c.GetString("merchantOrder")) + params["orderId"] + params["timestamp"])
|
||||
if tmpSign != params["sign"] {
|
||||
logs.Error("【TMALLGAME】回调签名错误,签名=", params["sign"], "计算签名=", tmpSign)
|
||||
otel.Logger.WithContext(ctx).Error("【TMALLGAME】回调签名错误,签名=", zap.String("签名", params["sign"]), zap.String("计算签名", tmpSign))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
orderInfo.BankTransId = params["orderId"]
|
||||
logs.Info("【TMALLGAME】回调参数:", params)
|
||||
otel.Logger.WithContext(ctx).Info("【TMALLGAME】回调参数:", zap.Any("params", params))
|
||||
if params["status"] == "finished" {
|
||||
// TODO 订单支付成功
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, params["orderId"], "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, params["orderId"], "支付成功")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
}
|
||||
} else {
|
||||
isOk := service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", "")
|
||||
isOk := service.SolvePayFail(ctx, orderInfo.BankOrderId, "", "")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -207,6 +223,7 @@ func (c *TMAllGameImpl) PayNotify() {
|
||||
|
||||
func (c *TMAllGameImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
params := map[string]any{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -229,23 +246,23 @@ func (c *TMAllGameImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -270,6 +287,7 @@ func (c *TMAllGameImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
|
||||
func (c *TMAllGameImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
params := map[string]any{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
@@ -292,12 +310,12 @@ func (c *TMAllGameImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -307,7 +325,7 @@ func (c *TMAllGameImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -350,6 +368,7 @@ func (c *TMAllGameImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
params := map[string]string{}
|
||||
params["order_id"] = payFor.BankOrderId
|
||||
@@ -358,25 +377,25 @@ func (c *TMAllGameImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -413,7 +432,7 @@ func (c *TMAllGameImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
95
internal/service/supplier/third_party/walmart.go
vendored
95
internal/service/supplier/third_party/walmart.go
vendored
@@ -1,9 +1,11 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
@@ -13,13 +15,18 @@ import (
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -118,11 +125,11 @@ type SendCardInfo struct {
|
||||
ExpectCardType int `json:"expectCardType"` // 卡密类型京东E卡传3,沃尔玛卡传23,天猫卡传33
|
||||
}
|
||||
|
||||
func (c *WalMartImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string) (bool, string) {
|
||||
func (c *WalMartImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, attach string) (bool, string) {
|
||||
cfg := config.GetConfig()
|
||||
expectAmount, err := strconv.ParseInt(cardInfo.FaceType, 10, 64)
|
||||
if err != nil {
|
||||
logs.Error("金额转换失败", err)
|
||||
otel.Logger.WithContext(ctx).Error("金额转换失败", zap.Error(err))
|
||||
expectAmount = 0
|
||||
}
|
||||
params := SendCardInfo{
|
||||
@@ -140,22 +147,23 @@ func (c *WalMartImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
"sign": c.sendEncrypt(params, "0468b97dfd8747f5ad57e06a17e03c365ae3269d70c14db39ddea25e70d55bbf"),
|
||||
"data": params,
|
||||
}
|
||||
req := httplib.Post("http://47.76.153.52/merchant/api/order")
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, "http://47.76.153.52/merchant/api/order", "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
marshal, err := json.Marshal(requestData)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("Apple GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("Apple GetToken 请求失败:", zap.Error(err))
|
||||
return false, ""
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
type AutoGenerated struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
@@ -166,24 +174,30 @@ func (c *WalMartImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo,
|
||||
var resData AutoGenerated
|
||||
err = json.Unmarshal([]byte(response), &resData)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response))
|
||||
return false, "内部数据处理失败"
|
||||
}
|
||||
if resData.Code != 200 {
|
||||
logs.Error("充值错误", resData.Message)
|
||||
otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message))
|
||||
return false, resData.Message
|
||||
}
|
||||
return true, response
|
||||
}
|
||||
|
||||
func (c *WalMartImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *WalMartImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "WalMartImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, orderInfo.BankOrderId)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId)
|
||||
var scanData supplier.ScanData
|
||||
if !ok {
|
||||
scanData = supplier.ScanData{
|
||||
@@ -216,30 +230,31 @@ type ResponseStruct struct {
|
||||
}
|
||||
|
||||
func (c *WalMartImpl) PayNotify() {
|
||||
logs.Info("【沃尔玛】快付回调开始")
|
||||
ctx := c.Ctx.Request.Context()
|
||||
otel.Logger.WithContext(ctx).Info("【沃尔玛】快付回调开始")
|
||||
response := ResponseStruct{}
|
||||
err := json.Unmarshal(c.Ctx.Input.RequestBody, &response)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, string(c.Ctx.Input.RequestBody))
|
||||
otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("RequestBody", string(c.Ctx.Input.RequestBody)))
|
||||
c.Ctx.WriteString("fail")
|
||||
return
|
||||
}
|
||||
if c.notifyEncrypt(response, "0468b97dfd8747f5ad57e06a17e03c365ae3269d70c14db39ddea25e70d55bbf") != response.Sign {
|
||||
logs.Error("【沃尔玛】快付回调失败,签名错误,参数=", string(c.Ctx.Input.RequestBody))
|
||||
otel.Logger.WithContext(ctx).Sugar().Errorf("【沃尔玛】快付回调失败,签名错误,参数=%s", string(c.Ctx.Input.RequestBody))
|
||||
c.Ctx.WriteString("fail")
|
||||
return
|
||||
}
|
||||
orderInfo := order.GetOrderByBankOrderId(response.Data.BizOrderNo) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, response.Data.BizOrderNo) // OrderId
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Sugar().Errorf("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=%s\n", merchantUid)
|
||||
c.Ctx.WriteString("fail")
|
||||
return
|
||||
}
|
||||
orderInfo.BankTransId = response.Data.BizOrderNo
|
||||
if WalMartOrderStatus(response.Data.BindState) == WalMartOrderSuccess {
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, response.Data.BizOrderNo, "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, response.Data.BizOrderNo, "支付成功")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("success")
|
||||
} else {
|
||||
@@ -253,7 +268,7 @@ func (c *WalMartImpl) PayNotify() {
|
||||
|
||||
func (c *WalMartImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -275,23 +290,23 @@ func (c *WalMartImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo
|
||||
req := httplib.Post(url1)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -316,7 +331,7 @@ func (c *WalMartImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo
|
||||
|
||||
func (c *WalMartImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return supply_model.CardMsgErr
|
||||
@@ -338,12 +353,12 @@ func (c *WalMartImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
req := httplib.Post(url1)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -353,7 +368,7 @@ func (c *WalMartImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadIn
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -395,7 +410,7 @@ func (c *WalMartImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
params := map[string]string{}
|
||||
params["order_id"] = payFor.BankOrderId
|
||||
params["app_key"] = gojson.Json("").Get("appKey").Tostring()
|
||||
@@ -403,25 +418,25 @@ func (c *WalMartImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
req := httplib.Post(url1)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -458,7 +473,7 @@ func (c *WalMartImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package third_party
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"gateway/internal/config"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
"net/http"
|
||||
|
||||
"gateway/internal/models/merchant"
|
||||
"gateway/internal/models/order"
|
||||
@@ -15,12 +18,16 @@ import (
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/service"
|
||||
"gateway/internal/utils"
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"github.com/bytedance/sonic"
|
||||
"github.com/widuu/gojson"
|
||||
@@ -43,7 +50,8 @@ func (c *WalmartSelfImpl) HasDependencyHTML() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *WalmartSelfImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
func (c *WalmartSelfImpl) SendCard(ctx context.Context, jsonStr string, cardInfo supplier.RedeemCardInfo, attach string, merchantId string) (bool, string) {
|
||||
|
||||
cfg := config.Config{}
|
||||
params := make(map[string]string)
|
||||
|
||||
@@ -60,25 +68,27 @@ func (c *WalmartSelfImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardI
|
||||
if err != nil {
|
||||
return false, "获取沃尔玛密地址失败!"
|
||||
}
|
||||
req := httplib.Post(url)
|
||||
req := httplib.NewBeegoRequestWithCtx(ctx, url, "POST")
|
||||
req.SetTransport(otelhttp.NewTransport(http.DefaultTransport))
|
||||
// req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
return false, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
req.Header("tokenFrom", "iframe")
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("沃尔玛请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("沃尔玛请求失败:", zap.Error(err))
|
||||
return false, ""
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return false, ""
|
||||
}
|
||||
type AutoGenerated struct {
|
||||
@@ -92,24 +102,30 @@ func (c *WalmartSelfImpl) SendCard(jsonStr string, cardInfo supplier.RedeemCardI
|
||||
var resData AutoGenerated
|
||||
err = json.Unmarshal([]byte(response), &resData)
|
||||
if err != nil {
|
||||
logs.Error("json解析失败", err, response)
|
||||
otel.Logger.WithContext(ctx).Error("json解析失败", zap.Error(err), zap.String("response", response))
|
||||
return false, "内部数据处理失败"
|
||||
}
|
||||
if resData.Code != 0 {
|
||||
logs.Error("充值错误", resData.Message)
|
||||
otel.Logger.WithContext(ctx).Error("充值错误", zap.String("Message", resData.Message))
|
||||
return false, resData.Message
|
||||
}
|
||||
return true, "等待兑换"
|
||||
}
|
||||
|
||||
func (c *WalmartSelfImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
func (c *WalmartSelfImpl) Scan(ctx context.Context, orderInfo order.OrderInfo, roadInfo road.RoadInfo, merchantInfo merchant.MerchantInfo) supplier.ScanData {
|
||||
ctx, cancel := otel.Span(ctx, "WalmartSelfImpl", "Scan", trace.WithAttributes(
|
||||
attribute.String("BankOrderId", orderInfo.BankOrderId),
|
||||
attribute.String("MerchantUid", orderInfo.MerchantUid),
|
||||
attribute.String("ExValue", orderInfo.ExValue),
|
||||
))
|
||||
defer cancel()
|
||||
cdata := supplier.RedeemCardInfo{}
|
||||
err := json.Unmarshal([]byte(orderInfo.ExValue), &cdata)
|
||||
if err != nil {
|
||||
logs.Error("格式化数据失败", orderInfo.ExValue)
|
||||
otel.Logger.WithContext(ctx).Error("格式化数据失败", zap.String("ExValue", orderInfo.ExValue))
|
||||
return supplier.ScanData{Status: "-1", Msg: "订单有有误,请稍后再试"}
|
||||
}
|
||||
ok, str := c.SendCard(roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
ok, str := c.SendCard(ctx, roadInfo.Params, cdata, orderInfo.BankOrderId, orderInfo.MerchantOrderId)
|
||||
var scanData supplier.ScanData
|
||||
if !ok {
|
||||
scanData = supplier.ScanData{
|
||||
@@ -131,11 +147,12 @@ func (c *WalmartSelfImpl) Scan(orderInfo order.OrderInfo, roadInfo road.RoadInfo
|
||||
|
||||
// KMEncrypt 加密卡密
|
||||
func (c *WalmartSelfImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
ctx := c.Ctx.Request.Context()
|
||||
|
||||
secret := utils.GetMD5LOWER(appSecret)[:16] // 加密秘钥
|
||||
block, err := aes.NewCipher([]byte(secret))
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher")
|
||||
return "", err
|
||||
}
|
||||
// 数据填充
|
||||
@@ -147,24 +164,25 @@ func (c *WalmartSelfImpl) kMEncrypt(kf, appSecret string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *WalmartSelfImpl) PayNotify() {
|
||||
logs.Info("【沃尔玛】回调开始")
|
||||
ctx := c.Ctx.Request.Context()
|
||||
otel.Logger.WithContext(ctx).Info("【沃尔玛】回调开始")
|
||||
attach := strings.TrimSpace(c.GetString("merchantId"))
|
||||
orderInfo := order.GetOrderByBankOrderId(attach) // OrderId
|
||||
orderInfo := order.GetOrderByBankOrderId(ctx, attach) // OrderId
|
||||
if orderInfo.BankOrderId == "" || len(orderInfo.BankOrderId) == 0 {
|
||||
logs.Error("【沃尔玛】回调的订单号不存在,订单号=", attach)
|
||||
otel.Logger.WithContext(ctx).Error("【沃尔玛】回调的订单号不存在,订单号=", zap.String("attach", attach))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
roadInfo := road.GetRoadInfoByRoadUid(orderInfo.RoadUid)
|
||||
roadInfo := road.GetRoadInfoByRoadUid(ctx, orderInfo.RoadUid)
|
||||
if roadInfo.RoadUid == "" || len(roadInfo.RoadUid) == 0 {
|
||||
logs.Error("【沃尔玛】支付通道已经关系或者删除,不进行回调")
|
||||
otel.Logger.WithContext(ctx).Error("【沃尔玛】支付通道已经关系或者删除,不进行回调")
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
merchantUid := orderInfo.MerchantUid
|
||||
merchantInfo := merchant.GetMerchantByUid(merchantUid)
|
||||
merchantInfo := merchant.GetMerchantByUid(ctx, merchantUid)
|
||||
if merchantInfo.MerchantUid == "" || len(merchantInfo.MerchantUid) == 0 {
|
||||
logs.Error("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=", merchantUid)
|
||||
otel.Logger.WithContext(ctx).Error("【沃尔玛】快付回调失败,该商户不存在或者已经删除,商户uid=", zap.String("merchantUid", merchantUid))
|
||||
c.Ctx.WriteString("FAIL")
|
||||
return
|
||||
}
|
||||
@@ -176,18 +194,18 @@ func (c *WalmartSelfImpl) PayNotify() {
|
||||
//"sign": strings.TrimSpace(c.GetString("sign")),
|
||||
"remark": strings.TrimSpace(c.GetString("remark")),
|
||||
}
|
||||
logs.Info("【沃尔玛】回调参数:", params)
|
||||
otel.Logger.WithContext(ctx).Info("【沃尔玛】回调参数:", zap.Any("params", params))
|
||||
orderInfo.BankTransId = params["merchantId"]
|
||||
if params["status"] == "1" {
|
||||
// TODO 订单支付成功
|
||||
isOk := service.SolvePaySuccess(orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
isOk := service.SolvePaySuccess(ctx, orderInfo.BankOrderId, orderInfo.FactAmount, params["merchantId"], "支付成功")
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
c.Ctx.WriteString("FAIL")
|
||||
}
|
||||
} else {
|
||||
isOk := service.SolvePayFail(c.Ctx.Request.Context(), orderInfo.BankOrderId, "", params["remark"])
|
||||
isOk := service.SolvePayFail(ctx, orderInfo.BankOrderId, "", params["remark"])
|
||||
if isOk {
|
||||
c.Ctx.WriteString("SUCCESS")
|
||||
} else {
|
||||
@@ -199,7 +217,7 @@ func (c *WalmartSelfImpl) PayNotify() {
|
||||
|
||||
func (c *WalmartSelfImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.RoadInfo) bool {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -221,22 +239,22 @@ func (c *WalmartSelfImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return false
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return false
|
||||
}
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -257,7 +275,7 @@ func (c *WalmartSelfImpl) PayQuery(orderInfo order.OrderInfo, roadInfo road.Road
|
||||
|
||||
func (c *WalmartSelfImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.RoadInfo) supply_model.MsgModel {
|
||||
params := map[string]any{}
|
||||
|
||||
ctx := c.Ctx.Request.Context()
|
||||
cardData, err := sonic.GetFromString(orderInfo.CardReturnData)
|
||||
if err != nil {
|
||||
return supply_model.CardMsgErr
|
||||
@@ -279,12 +297,12 @@ func (c *WalmartSelfImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return supply_model.DataErr
|
||||
}
|
||||
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
@@ -294,7 +312,7 @@ func (c *WalmartSelfImpl) PayQueryV2(orderInfo order.OrderInfo, roadInfo road.Ro
|
||||
return supply_model.RemoteDataErr
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
resData, err := sonic.GetFromString(response)
|
||||
if err != nil {
|
||||
@@ -332,6 +350,7 @@ func (c *WalmartSelfImpl) PayFor(info payfor.PayforInfo) string {
|
||||
|
||||
func (c *WalmartSelfImpl) PayForQuery(payFor payfor.PayforInfo) (string, string) {
|
||||
cfg := config.Config{}
|
||||
ctx := c.Ctx.Request.Context()
|
||||
url, err := cfg.GetMFCardQueryUrl()
|
||||
if err != nil {
|
||||
return config.PAYFOR_FAIL, ""
|
||||
@@ -344,25 +363,25 @@ func (c *WalmartSelfImpl) PayForQuery(payFor payfor.PayforInfo) (string, string)
|
||||
req := httplib.Post(url)
|
||||
marshal, err := json.Marshal(params)
|
||||
if err != nil {
|
||||
logs.Error("Map转化为byte数组失败,异常。", err)
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n", err)
|
||||
otel.Logger.WithContext(ctx).Error("Map转化为byte数组失败,异常。", zap.Error(err))
|
||||
// fmt.Printf("Map转化为byte数组失败,异常:%s\n",zap.Error(err))
|
||||
return config.PAYFOR_FAIL, "内部错误请稍后再试试(01)"
|
||||
}
|
||||
logs.Info("请求参数:" + string(marshal))
|
||||
otel.Logger.WithContext(ctx).Info("请求参数:" + string(marshal))
|
||||
req.Header("Content-Type", "application/json")
|
||||
req.Body(marshal)
|
||||
req.Header("Accept-Charset", "utf-8")
|
||||
|
||||
response, err := req.String()
|
||||
if err != nil {
|
||||
logs.Error("MF GetToken 请求失败:", err)
|
||||
otel.Logger.WithContext(ctx).Error("MF GetToken 请求失败:", zap.Error(err))
|
||||
return config.PAYFOR_FAIL, ""
|
||||
}
|
||||
|
||||
logs.Info("远端请求返回数据:" + response)
|
||||
otel.Logger.WithContext(ctx).Info("远端请求返回数据:" + response)
|
||||
|
||||
if gojson.Json(response).Get("code").Tostring() == "" {
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
@@ -399,7 +418,7 @@ func (c *WalmartSelfImpl) PayForQuery(payFor payfor.PayforInfo) (string, string)
|
||||
}
|
||||
}
|
||||
|
||||
logs.Error("远程调用失败")
|
||||
otel.Logger.WithContext(ctx).Error("远程调用失败")
|
||||
return config.PAYFOR_BANKING, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,12 @@ import (
|
||||
"gateway/internal/models/payfor"
|
||||
"gateway/internal/models/road"
|
||||
"gateway/internal/models/supply_model"
|
||||
"gateway/internal/otel"
|
||||
"gateway/internal/service/supplier"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
func TestAppleCardImpl_BalanceQuery(t *testing.T) {
|
||||
@@ -1801,6 +1802,6 @@ func TestWalMartImpl_SendCard1(t *testing.T) {
|
||||
Data: "123",
|
||||
CardNo: "123",
|
||||
}, "12345")
|
||||
logs.Info(isOk, response)
|
||||
otel.Logger.WithContext(ctx).Info(isOk, response)
|
||||
|
||||
}
|
||||
|
||||
@@ -2,17 +2,19 @@ package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/hex"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"gateway/internal/otel"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func AesDecrypt(src, key []byte) []byte {
|
||||
func AesDecrypt(ctx context.Context, src, key []byte) []byte {
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesDecrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesDecrypt failed to NewCipher", zap.Error(err))
|
||||
}
|
||||
blockMode := NewECBDecrypter(block)
|
||||
origData := make([]byte, len(src))
|
||||
@@ -22,19 +24,17 @@ func AesDecrypt(src, key []byte) []byte {
|
||||
}
|
||||
|
||||
/*aes编码*/
|
||||
func AesEncrypt(src []byte, key string) []byte {
|
||||
func AesEncrypt(ctx context.Context, src []byte, key string) []byte {
|
||||
decodeString, err := hex.DecodeString(key)
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesEncrypt failed to hex key")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesEncrypt failed to hex key", zap.Error(err))
|
||||
}
|
||||
block, err := aes.NewCipher(decodeString)
|
||||
if err != nil {
|
||||
logs.Error("Joker: AesEncrypt failed to NewCipher")
|
||||
logs.Error(err)
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesEncrypt failed to NewCipher")
|
||||
}
|
||||
if len(src) < 0 {
|
||||
logs.Error("Joker: AesEncrypt`s input is null ")
|
||||
otel.Logger.WithContext(ctx).Error("Joker: AesEncrypt`s input is null ")
|
||||
}
|
||||
ecb := NewECBEncrypter(block)
|
||||
src = PKCS5Padding(src, block.BlockSize())
|
||||
@@ -81,10 +81,11 @@ func NewECBEncrypter(b cipher.Block) cipher.BlockMode {
|
||||
func (x *ecbEncrypter) BlockSize() int { return x.blockSize }
|
||||
func (x *ecbEncrypter) CryptBlocks(dst, src []byte) {
|
||||
if len(src)%x.blockSize != 0 {
|
||||
logs.Error("Joker: CryptBlocks`s input not full blocks")
|
||||
return
|
||||
// otel.Logger.WithContext(ctx).Error("Joker: CryptBlocks`s input not full blocks")
|
||||
}
|
||||
if len(dst) < len(src) {
|
||||
logs.Error("Joker: CryptBlocks`s output smaller than input")
|
||||
return
|
||||
}
|
||||
for len(src) > 0 {
|
||||
x.b.Encrypt(dst, src[:x.blockSize])
|
||||
@@ -103,10 +104,11 @@ func NewECBDecrypter(b cipher.Block) cipher.BlockMode {
|
||||
func (x *ecbDecrypter) BlockSize() int { return x.blockSize }
|
||||
func (x *ecbDecrypter) CryptBlocks(dst, src []byte) {
|
||||
if len(src)%x.blockSize != 0 {
|
||||
logs.Error("Joker: CryptBlocks`s input not full blocks")
|
||||
return
|
||||
// otel.Logger.WithContext(ctx).Error("Joker: CryptBlocks`s input not full blocks")
|
||||
}
|
||||
if len(dst) < len(src) {
|
||||
logs.Error("Joker: CryptBlocks`s output smaller than input")
|
||||
return
|
||||
}
|
||||
for len(src) > 0 {
|
||||
x.b.Decrypt(dst, src[:x.blockSize])
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
|
||||
"github.com/beego/beego/v2/client/httplib"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/widuu/gojson"
|
||||
)
|
||||
|
||||
@@ -14,16 +16,16 @@ const (
|
||||
/**
|
||||
** 根据银行卡号获取银行信息
|
||||
*/
|
||||
func GetBankCodeByBankCardNo(bankCardNo string) string {
|
||||
func GetBankCodeByBankCardNo(ctx context.Context, bankCardNo string) string {
|
||||
bUrl := bankUrl + bankCardNo
|
||||
request := httplib.Get(bUrl)
|
||||
s, err := request.String()
|
||||
if err != nil {
|
||||
logs.Error("获取银行信息失败:" + err.Error())
|
||||
otel.Logger.WithContext(ctx).Error("获取银行信息失败:" + err.Error())
|
||||
return ""
|
||||
}
|
||||
|
||||
logs.Info("获取到银行信息为:" + s)
|
||||
otel.Logger.WithContext(ctx).Info("获取到银行信息为:" + s)
|
||||
code := gojson.Json(s).Get("bank").Tostring()
|
||||
return code
|
||||
}
|
||||
@@ -31,8 +33,8 @@ func GetBankCodeByBankCardNo(bankCardNo string) string {
|
||||
/**
|
||||
** 根据银行卡号获取银行名称
|
||||
*/
|
||||
func GetBankNameByCardNo(cardNo string) string {
|
||||
code := GetBankCodeByBankCardNo(cardNo)
|
||||
func GetBankNameByCardNo(ctx context.Context, cardNo string) string {
|
||||
code := GetBankCodeByBankCardNo(ctx, cardNo)
|
||||
if code == "" {
|
||||
return code
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"context"
|
||||
"gateway/internal/otel"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func GetMD5Sign(params map[string]any, keys []string, paySecret string) string {
|
||||
@@ -42,7 +45,7 @@ func Md5Verify(params map[string]any, paySecret string) bool {
|
||||
return tmpSign == sign
|
||||
}
|
||||
|
||||
func Md5MFVerify(params map[string]any, paySecret string) bool {
|
||||
func Md5MFVerify(ctx context.Context, params map[string]any, paySecret string) bool {
|
||||
//生成map一个copy
|
||||
paramsCopy := make(map[string]any)
|
||||
for k, v := range params {
|
||||
@@ -56,12 +59,12 @@ func Md5MFVerify(params map[string]any, paySecret string) bool {
|
||||
delete(paramsCopy, "deviceId")
|
||||
delete(paramsCopy, "ip")
|
||||
tmpSign := GetMD5SignMF(paramsCopy, paySecret)
|
||||
logs.Info("signStr=%s tmpStr=%s, %s", tmpSign, "tmpStr", sign, tmpSign != sign)
|
||||
otel.Logger.WithContext(ctx).Info("signStr=%s tmpStr=%s, %s", zap.String("signStr", tmpSign), zap.Any("tmpStr", sign), zap.Bool("sign!=tmpSign", tmpSign != sign))
|
||||
return tmpSign == sign
|
||||
}
|
||||
|
||||
// Md5TMPMFVerify TODO: 兼容之前验证的代码
|
||||
func Md5TMPMFVerify(params map[string]any, paySecret string) bool {
|
||||
func Md5TMPMFVerify(ctx context.Context, params map[string]any, paySecret string) bool {
|
||||
//生成map一个copy
|
||||
paramsCopy := make(map[string]any)
|
||||
for k, v := range params {
|
||||
@@ -74,7 +77,7 @@ func Md5TMPMFVerify(params map[string]any, paySecret string) bool {
|
||||
delete(paramsCopy, "sign")
|
||||
delete(paramsCopy, "deviceId")
|
||||
tmpSign := GetMD5SignMF(paramsCopy, paySecret)
|
||||
logs.Info("signStr=%s tmpStr=%s, %s", tmpSign, "tmpStr", sign, tmpSign != sign)
|
||||
otel.Logger.WithContext(ctx).Info("signStr=%s tmpStr=%s, %s", zap.String("signStr", tmpSign), zap.Any("tmpStr", sign), zap.Bool("sign!=tmpSign", tmpSign != sign))
|
||||
return tmpSign == sign
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package utils
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetMD5SignMF(t *testing.T) {
|
||||
str := GetMD5SignMF(map[string]string{
|
||||
str := GetMD5SignMF(map[string]any{
|
||||
"appKey": "kkkkcsgc5gg9t3hs7393fjtg",
|
||||
"orderNo": "GT1854079990006681600",
|
||||
"timestamp": "1730882348",
|
||||
@@ -11,7 +13,7 @@ func TestGetMD5SignMF(t *testing.T) {
|
||||
t.Log(str)
|
||||
|
||||
//factPrice=50.00&orderNo=csju0sp1194c73aa3ifg&orderPrice=50.00&orderTime=2024110404%3A43%3A38&payKey=kkkkc9kit6bimggos5kk0c90&sign=52f20334db5b511bf99baefad6c06a0c&statusCode=01&tradeStatus=success&trxNo=6666csju0sp1194c73cs7l8g
|
||||
str = GetMD5SignMF(map[string]string{
|
||||
str = GetMD5SignMF(map[string]any{
|
||||
"orderNo": "csju0sp1194c73aa3ifg",
|
||||
"orderTime": "2024110404:43:38",
|
||||
"trxNo": "6666csju0sp1194c73cs7l8g",
|
||||
|
||||
19
main.go
19
main.go
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "gateway/internal/models"
|
||||
"gateway/internal/otel"
|
||||
_ "gateway/internal/routers"
|
||||
@@ -10,28 +9,28 @@ import (
|
||||
_ "gateway/internal/service/message"
|
||||
"gateway/internal/service/notify"
|
||||
_ "gateway/internal/service/supplier/third_party"
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/beego/beego/v2/server/web"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cleanup1, cleanup2, cleanup3 := otel.InitTracer()
|
||||
defer func() {
|
||||
ctx := context.Background()
|
||||
if cleanup1 != nil {
|
||||
_ = cleanup1(ctx)
|
||||
_ = cleanup1(otel.InitCtx)
|
||||
}
|
||||
if cleanup2 != nil {
|
||||
_ = cleanup2(ctx)
|
||||
_ = cleanup2(otel.InitCtx)
|
||||
}
|
||||
if cleanup3 != nil {
|
||||
_ = cleanup3(ctx)
|
||||
_ = cleanup3(otel.InitCtx)
|
||||
}
|
||||
}()
|
||||
go notify.CreateOrderNotifyConsumer()
|
||||
go query.CreatePayForQueryConsumer()
|
||||
go service.OrderSettleInit()
|
||||
go query.CreateSupplierOrderQueryCuConsumer()
|
||||
go notify.CreateOrderNotifyConsumer(otel.InitCtx)
|
||||
go query.CreatePayForQueryConsumer(otel.InitCtx)
|
||||
go service.OrderSettleInit(otel.InitCtx)
|
||||
go query.CreateSupplierOrderQueryCuConsumer(otel.InitCtx)
|
||||
web.Run()
|
||||
}
|
||||
|
||||
BIN
views/.DS_Store
vendored
BIN
views/.DS_Store
vendored
Binary file not shown.
Reference in New Issue
Block a user