优化闲麦接口返回值处理

This commit is contained in:
chenlin 2023-11-22 14:43:00 +08:00
parent 66f268a2c1
commit d1975f15f8
3 changed files with 106 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import (
"encoding/xml" "encoding/xml"
"fmt" "fmt"
"mh-server/lib/status" "mh-server/lib/status"
"strconv"
"github.com/codinl/go-logger" "github.com/codinl/go-logger"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -128,3 +129,23 @@ func Toast(c *gin.Context, data interface{}) {
c.Data(status.OK, "application/json; charset=utf-8", body) c.Data(status.OK, "application/json; charset=utf-8", body)
c.Abort() c.Abort()
} }
// 比较 Code 是否为 200
func CompareCode(code interface{}) bool {
switch v := code.(type) {
case int:
return v == status.OK
case string:
// 尝试将字符串转换为整数
if intValue, err := strconv.Atoi(v); err == nil {
return intValue == status.OK
}
// 如果转换失败,比较字符串值
return v == strconv.Itoa(status.OK)
case float64:
return int(v) == status.OK
default:
// 其他类型视为不相等
return false
}
}

View File

@ -430,6 +430,11 @@ func RecycleCardBrandList(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -449,6 +454,11 @@ func RecycleCardGoodsList(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -475,6 +485,11 @@ func RecycleCardProblemSkuList(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -514,6 +529,11 @@ func RecycleCardSubmitOrderEvaluation(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -553,6 +573,11 @@ func RecycleCardSubmitOrderDelivery(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -592,6 +617,11 @@ func RecycleCardCancelOrderDelivery(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -631,6 +661,11 @@ func RecycleCardQueryMemberOrderList(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -670,6 +705,11 @@ func RecycleCardQueryMemberOrderdetail(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -709,6 +749,11 @@ func RecycleCardQueryMemberOrderDelivery(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data) RespOK(c, resp.Data)
return return
} }
@ -748,6 +793,11 @@ func RecycleCardSubmitConfirmPrice(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, nil) RespOK(c, nil)
return return
} }
@ -787,6 +837,11 @@ func RecycleCardCancelOrderEvaluation(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, nil) RespOK(c, nil)
return return
} }
@ -826,6 +881,11 @@ func RecycleCardSubmitOrderToCart(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, nil) RespOK(c, nil)
return return
} }
@ -865,6 +925,11 @@ func RecycleCardRemoveCartOrder(c *gin.Context) {
return return
} }
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, nil) RespOK(c, nil)
return return
} }
@ -882,7 +947,7 @@ func RecycleCardSubmitCartDelivery(c *gin.Context) {
RespJson(c, status.Unauthorized, nil) RespJson(c, status.Unauthorized, nil)
return return
} }
//uc = &auth.UserClaims{Uid: 63192613} //uc := &auth.UserClaims{Uid: 64359323}
user := model.GetUserByUid(uc.Uid) user := model.GetUserByUid(uc.Uid)
if user.Tel == "" { if user.Tel == "" {
logger.Error("GetUserByUid err:") logger.Error("GetUserByUid err:")
@ -904,7 +969,12 @@ func RecycleCardSubmitCartDelivery(c *gin.Context) {
return return
} }
RespOK(c, nil) if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data)
return return
} }
@ -943,6 +1013,11 @@ func RecycleCardUpdateOrderQcReport(c *gin.Context) {
return return
} }
RespOK(c, nil) if !CompareCode(resp.Code) { //接口报错,需要将错误转发
RespError(c, resp.Message)
return
}
RespOK(c, resp.Data)
return return
} }

View File

@ -6,7 +6,7 @@ type ProblemSkuListReq struct {
type ProblemSkuListResp struct { type ProblemSkuListResp struct {
Flag bool `json:"flag"` Flag bool `json:"flag"`
Code int `json:"code"` Code interface{} `json:"code"`
Message string `json:"message"` Message string `json:"message"`
Data1 interface{} `json:"data1"` Data1 interface{} `json:"data1"`
Data struct { Data struct {
@ -75,7 +75,7 @@ type SubmitOrderEvaluationReq struct {
type SubmitOrderEvaluationResp struct { type SubmitOrderEvaluationResp struct {
Flag bool `json:"flag"` Flag bool `json:"flag"`
Code int `json:"code"` Code interface{} `json:"code"`
Message string `json:"message"` Message string `json:"message"`
Data1 interface{} `json:"data1"` Data1 interface{} `json:"data1"`
Data struct { Data struct {
@ -126,7 +126,7 @@ type QueryMemberOrderListReq struct {
} }
type QueryMemberOrderListResp struct { type QueryMemberOrderListResp struct {
Flag bool `json:"flag"` Flag bool `json:"flag"`
Code int `json:"code"` Code interface{} `json:"code"`
Message string `json:"message"` Message string `json:"message"`
Data1 interface{} `json:"data1"` Data1 interface{} `json:"data1"`
Data struct { Data struct {
@ -393,9 +393,11 @@ type RecycleCardSubmitCartDeliveryReq struct {
} }
type RecycleCardSubmitCartDeliveryResp struct { type RecycleCardSubmitCartDeliveryResp struct {
Code interface{} `json:"code"`
Flag bool `json:"flag"` Flag bool `json:"flag"`
Code interface{} `json:"code"`
Message string `json:"message"` Message string `json:"message"`
Data1 interface{} `json:"data1"`
Data string `json:"data"`
} }
type RecycleCardUpdateOrderQcReportReq struct { type RecycleCardUpdateOrderQcReportReq struct {
@ -412,7 +414,7 @@ type RecycleCardUpdateOrderQcReportReq struct {
type RecycleCardUpdateOrderQcReportResp struct { type RecycleCardUpdateOrderQcReportResp struct {
Flag bool `json:"flag"` Flag bool `json:"flag"`
Code int `json:"code"` Code interface{} `json:"code"`
Message string `json:"message"` Message string `json:"message"`
Data1 interface{} `json:"data1"` Data1 interface{} `json:"data1"`
Data struct { Data struct {