新增查询绑定结果接口(自建发货页轮询角色信息)
- GET /api/client/v1/orders/{order_no}/delivery/bind-result?bind_uuid=xxx
- 返回 bound/game_account/role_name/game_channel;未绑定返回 bound=false(不报错,供轮询)
- 对接文档自建发货页模式新增该接口,注明轮询建议间隔
This commit is contained in:
@@ -227,6 +227,22 @@ func (h *OpenV1Handler) BindDeliveryOrder(c *gin.Context) {
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
// GetDeliveryBindResult GET /api/client/v1/orders/:order_no/delivery/bind-result
|
||||
// 查询绑定结果与角色信息(自建发货页轮询绑定状态用)。
|
||||
func (h *OpenV1Handler) GetDeliveryBindResult(c *gin.Context) {
|
||||
openlog.SetAction(c, openlog.ActionQuery)
|
||||
orderNo := c.Param("order_no")
|
||||
bindUUID := c.Query("bind_uuid")
|
||||
openlog.Info(c, "delivery_bind_result start order_no=%s bind_uuid=%s", orderNo, bindUUID)
|
||||
result, err := h.deliverySvc.GetBindResult(middleware.GetMerchantID(c), orderNo, bindUUID)
|
||||
if err != nil {
|
||||
openlog.Warn(c, "delivery_bind_result fail order_no=%s err=%v", orderNo, err)
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
type openDeliverySubmitReq struct {
|
||||
GameAccount string `json:"game_account" binding:"required"`
|
||||
BindUUID string `json:"bind_uuid" binding:"required"`
|
||||
|
||||
@@ -87,6 +87,7 @@ func Setup(h *Handlers) *gin.Engine {
|
||||
clientOpen.GET("/orders/:order_no/delivery-link", middleware.RequireMerchantFeature(h.OpenDB, model.MerchantFeatureOrders), middleware.RequireAPIScope("orders:read", "shipping:read"), h.Open.GetDeliveryLink)
|
||||
clientOpen.GET("/orders/:order_no/delivery", middleware.RequireMerchantFeature(h.OpenDB, model.MerchantFeatureOrders), middleware.RequireAPIScope("orders:read", "shipping:read"), h.Open.GetDeliveryOrder)
|
||||
clientOpen.POST("/orders/:order_no/delivery/bind", middleware.RequireMerchantFeature(h.OpenDB, model.MerchantFeatureOrders), middleware.RequireAPIScope("orders:write"), h.Open.BindDeliveryOrder)
|
||||
clientOpen.GET("/orders/:order_no/delivery/bind-result", middleware.RequireMerchantFeature(h.OpenDB, model.MerchantFeatureOrders), middleware.RequireAPIScope("orders:read", "shipping:read"), h.Open.GetDeliveryBindResult)
|
||||
clientOpen.POST("/orders/:order_no/delivery/submit", middleware.RequireMerchantFeature(h.OpenDB, model.MerchantFeatureOrders), middleware.RequireAPIScope("orders:write"), h.Open.SubmitDeliveryOrder)
|
||||
clientOpen.GET("/wallet", middleware.RequireMerchantFeature(h.OpenDB, model.MerchantFeatureWallet), middleware.RequireAPIScope("wallet:read"), h.Open.GetWallet)
|
||||
}
|
||||
|
||||
@@ -128,9 +128,14 @@ type DeliveryProduct struct {
|
||||
}
|
||||
|
||||
type DeliveryBindResult struct {
|
||||
BindUUID string `json:"bind_uuid"`
|
||||
BindURL string `json:"bind_url"`
|
||||
QRURL string `json:"qr_url"`
|
||||
BindUUID string `json:"bind_uuid"`
|
||||
BindURL string `json:"bind_url"`
|
||||
QRURL string `json:"qr_url"`
|
||||
Bound bool `json:"bound"`
|
||||
GameAccount string `json:"game_account,omitempty"`
|
||||
RoleName string `json:"role_name,omitempty"`
|
||||
GameChannel string `json:"game_channel,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type DeliveryLinkResult struct {
|
||||
@@ -194,6 +199,37 @@ func (s *DeliveryService) BindForMerchant(merchantID uint, orderNo, gameAccount
|
||||
return s.bindWithOrder(orderNo, gameAccount, nil, merchantID)
|
||||
}
|
||||
|
||||
// GetBindResult 查询绑定结果(自建发货页轮询用)。
|
||||
// 绑定未完成时返回 bound=false(不报错),由前端提示继续扫码。
|
||||
func (s *DeliveryService) GetBindResult(merchantID uint, orderNo, bindUUID string) (*DeliveryBindResult, error) {
|
||||
bindUUID = strings.TrimSpace(bindUUID)
|
||||
if bindUUID == "" {
|
||||
return nil, errors.New("bind_uuid 不能为空")
|
||||
}
|
||||
openOrder, order, goodID, err := s.loadMerchantOrder(merchantID, orderNo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, _, _, err := s.buildDeliveryState(openOrder, order, goodID, false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
account, err := s.accountBound(bindUUID, goodID)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "尚未绑定") || strings.Contains(err.Error(), "未绑定") {
|
||||
return &DeliveryBindResult{BindUUID: bindUUID, Bound: false, Message: "尚未绑定,请先完成扫码绑定"}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &DeliveryBindResult{
|
||||
BindUUID: bindUUID,
|
||||
Bound: true,
|
||||
GameAccount: stringFromMap(account, "game_account"),
|
||||
RoleName: stringFromMap(account, "game_account_role_name"),
|
||||
GameChannel: gameChannelText(account),
|
||||
Message: "绑定成功",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *DeliveryService) bindWithOrder(orderNo, gameAccount string, auth *DeliveryLinkAuth, merchantID uint) (*DeliveryBindResult, error) {
|
||||
gameAccount = strings.TrimSpace(gameAccount)
|
||||
if gameAccount == "" {
|
||||
|
||||
Reference in New Issue
Block a user