支付准备
This commit is contained in:
parent
7dc1f9ef08
commit
79723bd945
|
@ -49,6 +49,12 @@ const (
|
|||
|
||||
//渠道
|
||||
PayChannelNotFound = 1300
|
||||
|
||||
//订单
|
||||
OrdersNotFound = 1300
|
||||
|
||||
//网页支付
|
||||
RequestLogErrors = 1400
|
||||
)
|
||||
|
||||
var MsgEN = map[int]string{
|
||||
|
@ -89,6 +95,8 @@ var MsgZH = map[int]string{
|
|||
AppSM4EncryptFail: "sm4加密失败",
|
||||
|
||||
PayChannelNotFound: "支付方式不存在",
|
||||
|
||||
RequestLogErrors: "请求日志错误",
|
||||
}
|
||||
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package data
|
|||
import (
|
||||
"PaymentCenter/app/http/entities"
|
||||
"PaymentCenter/app/models/ordersmodel"
|
||||
"database/sql"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
@ -59,3 +60,11 @@ func (m *OrderRepo) OrdersLeftPayChannelList(conn builder.Cond, pageFilter entit
|
|||
repo = repo.Join("left", "pay_channel", "pay_channel.id = orders.pay_id")
|
||||
return repo.Find(orderList)
|
||||
}
|
||||
|
||||
func (m *OrderRepo) OrderFindOne(order *ordersmodel.Orders, conn builder.Cond, columns ...string) (*ordersmodel.Orders, error) {
|
||||
has, err := m.repo.Where(conn).Get(order)
|
||||
if !has {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return order, err
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package data
|
|||
import (
|
||||
"PaymentCenter/app/http/entities"
|
||||
"PaymentCenter/app/models/paychannelmodel"
|
||||
"database/sql"
|
||||
"xorm.io/builder"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
@ -41,3 +42,11 @@ func (m *PayChannelRepo) PayChannelUpdate(payChannel *paychannelmodel.PayChannel
|
|||
func (m *PayChannelRepo) PayChannelGet(payChannel *paychannelmodel.PayChannel, conn builder.Cond) (bool, error) {
|
||||
return m.repo.Where(conn).Get(payChannel)
|
||||
}
|
||||
|
||||
func (m *PayChannelRepo) PayChannelFindOne(payChannel *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (*paychannelmodel.PayChannel, error) {
|
||||
has, err := m.repo.Where(conn).Get(payChannel)
|
||||
if !has {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return payChannel, err
|
||||
}
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"PaymentCenter/app/constants/common"
|
||||
"PaymentCenter/app/constants/errorcode"
|
||||
"PaymentCenter/app/data"
|
||||
"PaymentCenter/app/http/entities/backend"
|
||||
"PaymentCenter/app/models/orderrequestlogmodel"
|
||||
"PaymentCenter/app/models/ordersmodel"
|
||||
"PaymentCenter/app/models/orderthirdpaylogmodel"
|
||||
"PaymentCenter/app/models/paychannelmodel"
|
||||
"database/sql"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
|
@ -72,3 +75,26 @@ func OrderLogsList(req backend.OrderLogsListRequest) (requestLog []orderrequestl
|
|||
|
||||
return orderLogList, thirdLogList, code
|
||||
}
|
||||
|
||||
func OrderFindOne(order *ordersmodel.Orders, conn builder.Cond, col ...string) (merchantInfo *ordersmodel.Orders, code int) {
|
||||
repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb())
|
||||
// 拼接查询条件
|
||||
orderInfo, err := repo.OrderFindOne(order, conn, col...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errorcode.OrdersNotFound
|
||||
}
|
||||
return nil, errorcode.SystemError
|
||||
}
|
||||
return orderInfo, errorcode.Success
|
||||
}
|
||||
|
||||
func HadSameValueOrder(order *ordersmodel.Orders) (exist bool, code int) {
|
||||
conn := builder.NewCond()
|
||||
conn = conn.And(builder.Neq{"Status": common.ORDER_STATUS_CLOSE})
|
||||
_, code = OrderFindOne(order, conn)
|
||||
if code != errorcode.OrdersNotFound {
|
||||
return false, errorcode.Success
|
||||
}
|
||||
return true, code
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"PaymentCenter/app/http/entities/backend"
|
||||
"PaymentCenter/app/models/merchantmodel"
|
||||
"PaymentCenter/app/models/paychannelmodel"
|
||||
"database/sql"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
|
@ -92,3 +93,27 @@ func PayChannelGet(payChannel *paychannelmodel.PayChannel) (code int) {
|
|||
code = errorcode.Success
|
||||
return
|
||||
}
|
||||
|
||||
func PayChannelFindOne(channel *paychannelmodel.PayChannel, conn builder.Cond, col ...string) (merchantInfo *paychannelmodel.PayChannel, code int) {
|
||||
repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
|
||||
// 拼接查询条件
|
||||
channelInfo, err := repo.PayChannelFindOne(channel, conn, col...)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, errorcode.MerchantNotFound
|
||||
}
|
||||
return nil, errorcode.SystemError
|
||||
}
|
||||
return channelInfo, errorcode.Success
|
||||
}
|
||||
|
||||
func GetAndCheckPayChannel(channel *paychannelmodel.PayChannel, conn builder.Cond, col ...string) (code int) {
|
||||
merchantInfo, code := PayChannelFindOne(channel, conn, col...)
|
||||
if code != errorcode.Success {
|
||||
return code
|
||||
}
|
||||
if merchantInfo.DeleteTime.Location() != nil {
|
||||
return errorcode.PayChannelNotFound
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package services
|
||||
|
||||
import (
|
||||
"PaymentCenter/app/data"
|
||||
"PaymentCenter/app/models/orderrequestlogmodel"
|
||||
)
|
||||
|
||||
func RequestLogCreate(log *orderrequestlogmodel.OrderRequestLog) (code int) {
|
||||
db := orderrequestlogmodel.GetInstance().GetDb()
|
||||
repo := data.NewOrderRequestLogRepo(db)
|
||||
_, err := repo.OrderRequestLogInsertOne(log)
|
||||
code = handErr(err)
|
||||
return
|
||||
}
|
|
@ -5,6 +5,10 @@ import (
|
|||
"PaymentCenter/app/data"
|
||||
"PaymentCenter/app/http/entities/front"
|
||||
"PaymentCenter/app/models/merchantmodel"
|
||||
"PaymentCenter/app/models/orderrequestlogmodel"
|
||||
"PaymentCenter/app/models/ordersmodel"
|
||||
"PaymentCenter/app/models/paychannelmodel"
|
||||
"github.com/bytedance/sonic"
|
||||
)
|
||||
|
||||
type WebPay struct {
|
||||
|
@ -29,13 +33,30 @@ func NewWebPay(resp *front.PayWebReqs, appCheck *AppCheck) *WebPay {
|
|||
}
|
||||
|
||||
func (w *WebPay) AddPayLog() {
|
||||
w.PayCode = GetAndCheckMerchant(&merchantmodel.Merchant{Id: w.AppCheck.App.MerchantId}, nil)
|
||||
requestJson, err := sonic.Marshal(w.WebPayReqs)
|
||||
if err != nil {
|
||||
w.PayCode = errorcode.RequestLogErrors
|
||||
return
|
||||
}
|
||||
code := RequestLogCreate(&orderrequestlogmodel.OrderRequestLog{
|
||||
IpAddress: w.AppCheck.Ip,
|
||||
MerchantRequest: string(requestJson),
|
||||
})
|
||||
w.PayCode = code
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WebPay) CheckMerchant() {
|
||||
w.PayCode = GetAndCheckMerchant(&merchantmodel.Merchant{Id: w.AppCheck.App.MerchantId}, nil)
|
||||
w.PayCode = GetAndCheckPayChannel(&paychannelmodel.PayChannel{Id: w.WebPayReqs.PayChannelId}, nil)
|
||||
}
|
||||
|
||||
func (w *WebPay) CheckPayChannel() {
|
||||
w.PayCode = GetAndCheckMerchant(&merchantmodel.Merchant{Id: w.AppCheck.App.MerchantId}, nil)
|
||||
}
|
||||
|
||||
func (w *WebPay) CheckOrder() {
|
||||
exist, code := HadSameValueOrder(&ordersmodel.Orders{OutTreadNo: w.WebPayReqs.OutTradeNo})
|
||||
if exist {
|
||||
w.PayCode = code
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue