55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package services
|
|
|
|
import (
|
|
"PaymentCenter/app/constants/common"
|
|
"PaymentCenter/app/data"
|
|
"PaymentCenter/app/models/orderrequestlogmodel"
|
|
"encoding/json"
|
|
"xorm.io/builder"
|
|
)
|
|
|
|
func RequestLogCreate(log *orderrequestlogmodel.OrderRequestLog) (*orderrequestlogmodel.OrderRequestLog, int) {
|
|
db := orderrequestlogmodel.GetInstance().GetDb()
|
|
repo := data.NewOrderRequestLogRepo(db)
|
|
id, err := repo.OrderRequestLogInsertOne(log)
|
|
code := handErr(err)
|
|
if err != nil {
|
|
log.Id = id
|
|
}
|
|
return log, code
|
|
}
|
|
|
|
func RequestLogUpdate(log *orderrequestlogmodel.OrderRequestLog) (logOut *orderrequestlogmodel.OrderRequestLog, code int) {
|
|
db := orderrequestlogmodel.GetInstance().GetDb()
|
|
repo := data.NewOrderRequestLogRepo(db)
|
|
conn := builder.NewCond()
|
|
conn = conn.And(builder.Eq{"Id": log.Id})
|
|
id, err := repo.OrderRequestLogUpdate(log, conn)
|
|
code = handErr(err)
|
|
if err != nil {
|
|
log.Id = id
|
|
}
|
|
return log, code
|
|
}
|
|
|
|
func AddRequestLog(requestDataByte []byte, ip string, url string) (int64, int) {
|
|
tempMap := make(map[string]interface{})
|
|
_ = json.Unmarshal(requestDataByte, &tempMap)
|
|
var outTradeNo string
|
|
if tempMap["out_trade_no"] != nil {
|
|
if v, ok := tempMap["out_trade_no"].(string); ok {
|
|
outTradeNo = v
|
|
}
|
|
}
|
|
|
|
requestLog, checkCode := RequestLogCreate(&orderrequestlogmodel.OrderRequestLog{
|
|
OutTradeNo: outTradeNo,
|
|
IpAddress: ip,
|
|
MerchantRequest: string(requestDataByte),
|
|
URL: url,
|
|
MerchantResponse: "{}",
|
|
Status: common.STATUS_ENABLE,
|
|
})
|
|
return requestLog.Id, checkCode
|
|
}
|