diff --git a/app/http/controllers/transfersys/transfersys.go b/app/http/controllers/transfersys/transfersys.go index 58ba04a..44c73ce 100644 --- a/app/http/controllers/transfersys/transfersys.go +++ b/app/http/controllers/transfersys/transfersys.go @@ -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) +} diff --git a/app/http/entities/transfersys/transfersys.go b/app/http/entities/transfersys/transfersys.go index 335177f..77610eb 100644 --- a/app/http/entities/transfersys/transfersys.go +++ b/app/http/entities/transfersys/transfersys.go @@ -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"` +} + diff --git a/app/http/routes/route.go b/app/http/routes/route.go index eeffde6..bbdaa2a 100644 --- a/app/http/routes/route.go +++ b/app/http/routes/route.go @@ -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") diff --git a/app/models/orders/orders.go b/app/models/orders/orders.go index ecb2f5e..62455cf 100644 --- a/app/models/orders/orders.go +++ b/app/models/orders/orders.go @@ -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 +} diff --git a/app/services/transfersys/transfersys.go b/app/services/transfersys/transfersys.go index e62cde1..3e99f4b 100644 --- a/app/services/transfersys/transfersys.go +++ b/app/services/transfersys/transfersys.go @@ -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 +}