add cancel
This commit is contained in:
parent
347c44ce01
commit
06ca99cf73
|
@ -1,6 +1,7 @@
|
||||||
package orders
|
package orders
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"com.snow.auto_monitor/app/constants/errorcode"
|
"com.snow.auto_monitor/app/constants/errorcode"
|
||||||
|
@ -8,6 +9,7 @@ import (
|
||||||
orderEnt "com.snow.auto_monitor/app/http/entities/orders"
|
orderEnt "com.snow.auto_monitor/app/http/entities/orders"
|
||||||
orderMod "com.snow.auto_monitor/app/models/orders"
|
orderMod "com.snow.auto_monitor/app/models/orders"
|
||||||
orderServ "com.snow.auto_monitor/app/services/orders"
|
orderServ "com.snow.auto_monitor/app/services/orders"
|
||||||
|
transServ "com.snow.auto_monitor/app/services/transfersys"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -197,6 +199,33 @@ func Update(c *gin.Context) {
|
||||||
common.Success(c, response)
|
common.Success(c, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Cancel(c *gin.Context) {
|
||||||
|
request := new(orderEnt.CancelReq)
|
||||||
|
err := common.GenRequest(c, request)
|
||||||
|
if err != nil {
|
||||||
|
common.Error(c, errorcode.ParamError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
affected, err := orderServ.Cancel(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) {
|
func Delete(c *gin.Context) {
|
||||||
request := new(orderEnt.DeleteReq)
|
request := new(orderEnt.DeleteReq)
|
||||||
err := common.GenRequest(c, request)
|
err := common.GenRequest(c, request)
|
||||||
|
|
|
@ -18,6 +18,11 @@ func GetOrder(c *gin.Context) {
|
||||||
common.Error(c, 400, err.Error())
|
common.Error(c, 400, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
err = orderMod.GetInstance().OrderOutQueue(item.Id)
|
||||||
|
if err != nil {
|
||||||
|
common.Error(c, 400, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var response *transEnt.GetOrderResp = nil
|
var response *transEnt.GetOrderResp = nil
|
||||||
|
|
||||||
|
@ -80,7 +85,7 @@ func FinishOrder(c *gin.Context) {
|
||||||
|
|
||||||
affected, err := transServ.FinishOrder(orders)
|
affected, err := transServ.FinishOrder(orders)
|
||||||
if err != nil || affected == 0 {
|
if err != nil || affected == 0 {
|
||||||
common.Error(c, 400, "无法修改已完成订单")
|
common.Error(c, 400, "完成订单失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,6 +90,14 @@ type UpdateResp struct {
|
||||||
Id int64 `json:"id" `
|
Id int64 `json:"id" `
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CancelReq struct {
|
||||||
|
Id int64 `json:"id" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CancelResp struct {
|
||||||
|
Id int64 `json:"id" `
|
||||||
|
}
|
||||||
|
|
||||||
type DeleteReq struct {
|
type DeleteReq struct {
|
||||||
Id int64 `json:"id" validate:"required"`
|
Id int64 `json:"id" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ func RegisterRoute(router *gin.Engine) {
|
||||||
{
|
{
|
||||||
orders.POST("/get_by_id", ordersCon.GetById)
|
orders.POST("/get_by_id", ordersCon.GetById)
|
||||||
orders.POST("/search", ordersCon.Search)
|
orders.POST("/search", ordersCon.Search)
|
||||||
|
orders.POST("/cancel", ordersCon.Cancel)
|
||||||
// orders.POST("/create", ordersCon.Create)
|
// orders.POST("/create", ordersCon.Create)
|
||||||
// orders.POST("/update", ordersCon.Update)
|
// orders.POST("/update", ordersCon.Update)
|
||||||
// orders.POST("/delete", ordersCon.Delete)
|
// orders.POST("/delete", ordersCon.Delete)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package orders
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -242,7 +243,7 @@ func (m *ordersModel) GetIdleOrder() (orders *Orders, has bool, err error) {
|
||||||
orders = nil
|
orders = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
orders.TransferStatus = 2 // 1.成功 2.充值中 3. 等待充值 4.充值失败 5.异常需要人工处理
|
orders.TransferStatus = 7 // 1.成功 2.充值中 3. 等待充值 4.充值失败 5.异常需要人工处理 6.取消订单 7.订单入队
|
||||||
affected, err := session.ID(orders.Id).Where("transfer_status = 3").Update(orders)
|
affected, err := session.ID(orders.Id).Where("transfer_status = 3").Update(orders)
|
||||||
if err != nil || affected == 0 {
|
if err != nil || affected == 0 {
|
||||||
orders = nil
|
orders = nil
|
||||||
|
@ -252,6 +253,70 @@ func (m *ordersModel) GetIdleOrder() (orders *Orders, has bool, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *ordersModel) OrderOutQueue(orderId 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
|
||||||
|
}
|
||||||
|
|
||||||
|
if orders.TransferStatus != 7 {
|
||||||
|
err = errors.New("订单已取消或者未在队列中")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
orders.TransferStatus = 2 // 1.成功 2.充值中 3. 等待充值 4.充值失败 5.异常需要人工处理 6.取消订单 7.订单入队
|
||||||
|
affected, err := session.ID(orders.Id).Where("transfer_status = 7").Update(orders)
|
||||||
|
if err != nil || affected == 0 {
|
||||||
|
orders = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = session.Commit()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ordersModel) CancelOrder(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.ID(orders.Id).Where("transfer_status not in (1,2,4,5,6)").Update(orders)
|
||||||
|
if err != nil || affected == 0 {
|
||||||
|
err = errors.New("订单正在充值或者已经完成")
|
||||||
|
orders = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = session.Commit()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (m *ordersModel) SetDealingOrder(orders *Orders) (affected int64, err error) {
|
func (m *ordersModel) SetDealingOrder(orders *Orders) (affected int64, err error) {
|
||||||
|
|
||||||
session := m.GetDb().NewSession()
|
session := m.GetDb().NewSession()
|
||||||
|
|
|
@ -70,6 +70,11 @@ func Update(orders *models.Orders) (affected int64, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Cancel(id int64) (affected int64, err error) {
|
||||||
|
affected, err = models.GetInstance().CancelOrder(id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func Delete(id int64) (affected int64, err error) {
|
func Delete(id int64) (affected int64, err error) {
|
||||||
affected, err = models.GetInstance().Delete(id)
|
affected, err = models.GetInstance().Delete(id)
|
||||||
return
|
return
|
||||||
|
|
|
@ -35,6 +35,8 @@ func ReadGroup() (order *models.Orders, err error) {
|
||||||
}
|
}
|
||||||
jsonstr := res[key].(string)
|
jsonstr := res[key].(string)
|
||||||
json.Unmarshal([]byte(jsonstr), &order)
|
json.Unmarshal([]byte(jsonstr), &order)
|
||||||
|
|
||||||
|
|
||||||
return order, nil
|
return order, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ create table orders (
|
||||||
notify_url varchar(255),
|
notify_url varchar(255),
|
||||||
extend_parameter varchar(1024),
|
extend_parameter varchar(1024),
|
||||||
|
|
||||||
status tinyint,-- 1.成功 2.充值中 3.充值失败 4.异常需要人工处理
|
status tinyint,-- 1.成功 2.充值中 3.充值失败 4.异常需要人工处理 5.取消订单
|
||||||
transfer_status tinyint,-- 1.成功 2.充值中 3. 等待充值 4.充值失败 5.异常需要人工处理
|
transfer_status tinyint,-- 1.成功 2.充值中(出队) 3. 等待充值(等待入队) 4.充值失败 5.异常需要人工处理 6.取消订单 7.订单入队
|
||||||
fail_reason varchar(255),
|
fail_reason varchar(255),
|
||||||
created_at timestamp default current_timestamp
|
created_at timestamp default current_timestamp
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue