diff --git a/app/http/controllers/orders/orders.go b/app/http/controllers/orders/orders.go index dcc7b69..a2e03e0 100644 --- a/app/http/controllers/orders/orders.go +++ b/app/http/controllers/orders/orders.go @@ -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) diff --git a/app/http/routes/route.go b/app/http/routes/route.go index 214b296..7d94bc6 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -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) diff --git a/app/models/orders/orders.go b/app/models/orders/orders.go index d45c7b2..70f1d9d 100644 --- a/app/models/orders/orders.go +++ b/app/models/orders/orders.go @@ -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() diff --git a/app/services/orders/orders.go b/app/services/orders/orders.go index 72629ad..5d783bf 100644 --- a/app/services/orders/orders.go +++ b/app/services/orders/orders.go @@ -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