110 lines
2.7 KiB
Go
110 lines
2.7 KiB
Go
package payfor
|
||
|
||
import (
|
||
"context"
|
||
"gateway/internal/otelTrace"
|
||
|
||
"time"
|
||
|
||
"github.com/beego/beego/v2/client/orm"
|
||
"go.uber.org/zap"
|
||
)
|
||
|
||
type PayforInfo struct {
|
||
Id int
|
||
PayforUid string
|
||
MerchantUid string
|
||
MerchantName string
|
||
MerchantOrderId string
|
||
BankOrderId string
|
||
BankTransId string
|
||
RoadUid string
|
||
RoadName string
|
||
RollPoolCode string
|
||
RollPoolName string
|
||
PayforFee float64
|
||
PayforAmount float64
|
||
PayforTotalAmount float64
|
||
BankCode string
|
||
BankName string
|
||
BankAccountName string
|
||
BankAccountNo string
|
||
BankAccountType string
|
||
Country string
|
||
City string
|
||
Ares string
|
||
BankAccountAddress string
|
||
PhoneNo string
|
||
GiveType string
|
||
Type string
|
||
NotifyUrl string
|
||
Status string
|
||
IsSend string
|
||
RequestTime time.Time
|
||
ResponseTime string
|
||
ResponseContent string
|
||
Remark string
|
||
CreateTime time.Time
|
||
UpdateTime time.Time
|
||
}
|
||
|
||
const PAYFORINFO = "payfor_info"
|
||
|
||
func InsertPayFor(ctx context.Context, payFor PayforInfo) bool {
|
||
o := orm.NewOrm()
|
||
_, err := o.Insert(&payFor)
|
||
if err != nil {
|
||
otelTrace.Logger.WithContext(ctx).Error("insert payfor fail: ", zap.Error(err))
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
func IsExistPayForByBankOrderId(bankOrderId string) bool {
|
||
o := orm.NewOrm()
|
||
exist := o.QueryTable(PAYFORINFO).Filter("bank_order_id", bankOrderId).Exist()
|
||
|
||
return exist
|
||
}
|
||
|
||
func IsExistPayForByMerchantOrderId(merchantOrderId string) bool {
|
||
o := orm.NewOrm()
|
||
exist := o.QueryTable(PAYFORINFO).Filter("merchant_order_id", merchantOrderId).Exist()
|
||
|
||
return exist
|
||
}
|
||
|
||
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 {
|
||
otelTrace.Logger.WithContext(ctx).Error("get pay for by bank_order_id fail: ", zap.Error(err))
|
||
}
|
||
|
||
return payFor
|
||
}
|
||
|
||
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 {
|
||
otelTrace.Logger.WithContext(ctx).Error("fail: ", zap.Error(err))
|
||
}
|
||
|
||
return payFor
|
||
}
|
||
|
||
func UpdatePayFor(ctx context.Context, payFor PayforInfo) bool {
|
||
o := orm.NewOrm()
|
||
_, err := o.Update(&payFor)
|
||
if err != nil {
|
||
otelTrace.Logger.WithContext(ctx).Error("update pay for fail:", zap.Error(err))
|
||
return false
|
||
}
|
||
|
||
return true
|
||
}
|