This commit is contained in:
duyu 2024-08-15 09:13:51 +08:00
parent d51411f7ae
commit ce5253c889
5 changed files with 84 additions and 0 deletions

View File

@ -102,3 +102,31 @@ func FinishOrder(c *gin.Context) {
common.Success(c, response)
}
func SetOrderMobile(c *gin.Context) {
request := new(transEnt.SetOrderMobileReq)
err := common.GenRequest(c, request)
if err != nil {
common.Error(c, 400, err.Error())
return
}
orders := &orderMod.Orders{
Id: request.Id,
ProductId: request.ProductId,
MerchantId: request.MerchantId,
DeviceNo: request.DeviceNo,
}
affected, err := transServ.SetOrderMobile(orders)
if err != nil || affected == 0 {
common.Error(c, 400, "设置订单失败:"+err.Error())
return
}
response := &transEnt.SetOrderMobileResp{
Id: orders.Id,
}
common.Success(c, response)
}

View File

@ -34,3 +34,16 @@ type FinishOrderReq struct {
type FinishOrderResp struct {
Id int64 `json:"id"`
}
type SetOrderMobileReq struct {
Id int64 `json:"id" validate:"required"`
OrderNo string `json:"order_no" validate:"required"`
ProductId int64 `json:"product_id" validate:"required"`
MerchantId int64 `json:"merchant_id" validate:"required"`
DeviceNo string `json:"device_no"`
}
type SetOrderMobileResp struct {
Id int64 `json:"id"`
}

View File

@ -123,6 +123,7 @@ func RegisterRoute(router *gin.Engine) {
{
transfersys.GET("/recharge/get_order", transCon.GetOrder)
transfersys.POST("/recharge/finish", transCon.FinishOrder)
transfersys.POST("/recharge/set_order_mobile", transCon.SetOrderMobile)
}
temp := router.Group("temp")

View File

@ -370,3 +370,20 @@ func (m *ordersModel) GetTimeoutOrder(
err = m.GetDb().Where(sql, args...).OrderBy("created_at").Limit(limit).Find(&orders)
return
}
func (m *ordersModel) SetOrderMobile(orders *Orders) (affected int64, err error) {
session := m.GetDb().NewSession()
defer session.Close()
// add Begin() before any action
if err = session.Begin(); err != nil {
orders = nil
return
}
affected, err = session.ID(orders.Id).Update(orders)
if err != nil || affected == 0 {
orders = nil
return
}
err = session.Commit()
return
}

View File

@ -51,3 +51,28 @@ func AddCallback(order_id string) (err error) {
err = rdbdq.WriteOne("1_"+order_id, time.Now().Add(1*time.Second).Unix())
return
}
func SetOrderMobile(orders *models.Orders) (affected int64, err error) {
//验证商户是否存在
_, has, err := mermod.GetInstance().GetById(orders.MerchantId)
if err != nil {
return
}
if !has {
err = errors.New("商户不存在")
return
}
//验证产品是否存在
_, has, err = promod.GetInstance().GetById(orders.ProductId)
if err != nil {
return
}
if !has {
err = errors.New("产品不存在")
return
}
affected, err = models.GetInstance().SetOrderMobile(orders)
return
}