This commit is contained in:
duyu 2024-08-21 19:50:25 +08:00
parent 3929672566
commit 959a0d00b6
4 changed files with 68 additions and 0 deletions

View File

@ -230,6 +230,33 @@ func Cancel(c *gin.Context) {
common.Success(c, response)
}
func DangerousCancel(c *gin.Context) {
request := new(orderEnt.CancelReq)
err := common.GenRequest(c, request)
if err != nil {
common.Error(c, errorcode.ParamError)
return
}
affected, err := orderServ.DangerousCancel(request.Id)
if err != nil || affected == 0 {
common.Error(c, 400, err.Error())
return
}
err = transServ.AddCallback(strconv.Itoa(int(request.Id)))
if err != nil {
common.Error(c, 400, "添加回调失败")
return
}
response := &orderEnt.CancelResp{
Id: request.Id,
}
common.Success(c, response)
}
func Delete(c *gin.Context) {
request := new(orderEnt.DeleteReq)
err := common.GenRequest(c, request)

View File

@ -76,6 +76,7 @@ func RegisterRoute(router *gin.Engine) {
orders.POST("/get_by_id", ordersCon.GetById)
orders.POST("/search", ordersCon.Search)
orders.POST("/cancel", ordersCon.Cancel)
orders.POST("/dangerous_cancel", ordersCon.DangerousCancel)
// orders.POST("/create", ordersCon.Create)
// orders.POST("/update", ordersCon.Update)
// orders.POST("/delete", ordersCon.Delete)

View File

@ -332,6 +332,41 @@ func (m *ordersModel) CancelOrder(orderId int64) (affected int64, err error) {
return
}
func (m *ordersModel) DangerousCancel(orderId int64) (affected int64, err error) {
orders := &Orders{}
session := m.GetDb().NewSession()
defer session.Close()
// add Begin() before any action
if err = session.Begin(); err != nil {
orders = nil
return
}
orders = &Orders{}
has, err := session.ID(orderId).Get(orders)
if err != nil || !has {
orders = nil
return
}
orders.Status = 5
orders.TransferStatus = 6 // 1.成功 2.充值中 3. 等待充值 4.充值失败 5.异常需要人工处理 6.取消订单 7.订单入队
orders.FailReason = "订单取消"
affected, err = session.ForUpdate().ID(orders.Id).Where("transfer_status not in (1,4,6)").Update(orders)
if err != nil || affected == 0 {
err = errors.New("订单正在充值或者已经完成")
orders = nil
return
}
err = session.Commit()
if err != nil {
session.Rollback()
return
}
return
}
func (m *ordersModel) SetDealingOrder(orders *Orders) (affected int64, err error) {
session := m.GetDb().NewSession()

View File

@ -77,6 +77,11 @@ func Cancel(id int64) (affected int64, err error) {
return
}
func DangerousCancel(id int64) (affected int64, err error) {
affected, err = models.GetInstance().DangerousCancel(id)
return
}
func Delete(id int64) (affected int64, err error) {
affected, err = models.GetInstance().Delete(id)
return