PaymentCenter/app/services/request_log.go

49 lines
1.4 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)
requestLog, checkCode := RequestLogCreate(&orderrequestlogmodel.OrderRequestLog{
OutTradeNo: tempMap["out_trade_no"].(string),
IpAddress: ip,
MerchantRequest: string(requestDataByte),
URL: url,
MerchantResponse: "{}",
Status: common.STATUS_ENABLE,
})
return requestLog.Id, checkCode
}