mirror of
https://github.com/kongyuebin1/dongfeng-pay.git
synced 2024-11-23 02:39:26 +08:00
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
/***************************************************
|
||
** @Desc : 处理网关模块的一些需要操作数据库的功能
|
||
** @Time : 2019/12/7 16:40
|
||
** @Author : yuebin
|
||
** @File : gateway_solve
|
||
** @Last Modified by : yuebin
|
||
** @Last Modified time: 2019/12/7 16:40
|
||
** @Software: GoLand
|
||
****************************************************/
|
||
package controller
|
||
|
||
import (
|
||
"boss/models"
|
||
"github.com/beego/beego/v2/adapter/orm"
|
||
"github.com/beego/beego/v2/core/logs"
|
||
)
|
||
|
||
/*
|
||
* 插入支付订单记录和订单利润记录,保证一致性
|
||
*/
|
||
func InsertOrderAndOrderProfit(orderInfo models.OrderInfo, orderProfitInfo models.OrderProfitInfo) bool {
|
||
o := orm.NewOrm()
|
||
_ = o.Begin()
|
||
|
||
defer func(interface{}) {
|
||
if err := recover(); err != nil {
|
||
_ = o.Rollback()
|
||
}
|
||
}(o)
|
||
|
||
if _, err := o.Insert(&orderInfo); err != nil {
|
||
logs.Error("insert orderInfo fail: ", err)
|
||
_ = o.Rollback()
|
||
return false
|
||
}
|
||
if _, err := o.Insert(&orderProfitInfo); err != nil {
|
||
logs.Error("insert orderProfit fail: ", err)
|
||
_ = o.Rollback()
|
||
return false
|
||
}
|
||
|
||
if err := o.Commit(); err != nil {
|
||
logs.Error("insert order and orderProfit fail:", err)
|
||
} else {
|
||
logs.Info("插入order和orderProfit记录成功")
|
||
}
|
||
return true
|
||
}
|