优化闲麦接口返回值处理
This commit is contained in:
parent
66f268a2c1
commit
d1975f15f8
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/xml"
|
||||
"fmt"
|
||||
"mh-server/lib/status"
|
||||
"strconv"
|
||||
|
||||
"github.com/codinl/go-logger"
|
||||
"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.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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -430,6 +430,11 @@ func RecycleCardBrandList(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -449,6 +454,11 @@ func RecycleCardGoodsList(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -475,6 +485,11 @@ func RecycleCardProblemSkuList(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -514,6 +529,11 @@ func RecycleCardSubmitOrderEvaluation(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -553,6 +573,11 @@ func RecycleCardSubmitOrderDelivery(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -592,6 +617,11 @@ func RecycleCardCancelOrderDelivery(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -631,6 +661,11 @@ func RecycleCardQueryMemberOrderList(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -670,6 +705,11 @@ func RecycleCardQueryMemberOrderdetail(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -709,6 +749,11 @@ func RecycleCardQueryMemberOrderDelivery(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
@ -748,6 +793,11 @@ func RecycleCardSubmitConfirmPrice(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, nil)
|
||||
return
|
||||
}
|
||||
|
@ -787,6 +837,11 @@ func RecycleCardCancelOrderEvaluation(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, nil)
|
||||
return
|
||||
}
|
||||
|
@ -826,6 +881,11 @@ func RecycleCardSubmitOrderToCart(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, nil)
|
||||
return
|
||||
}
|
||||
|
@ -865,6 +925,11 @@ func RecycleCardRemoveCartOrder(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, nil)
|
||||
return
|
||||
}
|
||||
|
@ -882,7 +947,7 @@ func RecycleCardSubmitCartDelivery(c *gin.Context) {
|
|||
RespJson(c, status.Unauthorized, nil)
|
||||
return
|
||||
}
|
||||
//uc = &auth.UserClaims{Uid: 63192613}
|
||||
//uc := &auth.UserClaims{Uid: 64359323}
|
||||
user := model.GetUserByUid(uc.Uid)
|
||||
if user.Tel == "" {
|
||||
logger.Error("GetUserByUid err:")
|
||||
|
@ -904,7 +969,12 @@ func RecycleCardSubmitCartDelivery(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
RespOK(c, nil)
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -943,6 +1013,11 @@ func RecycleCardUpdateOrderQcReport(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
RespOK(c, nil)
|
||||
if !CompareCode(resp.Code) { //接口报错,需要将错误转发
|
||||
RespError(c, resp.Message)
|
||||
return
|
||||
}
|
||||
|
||||
RespOK(c, resp.Data)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ type ProblemSkuListReq struct {
|
|||
|
||||
type ProblemSkuListResp struct {
|
||||
Flag bool `json:"flag"`
|
||||
Code int `json:"code"`
|
||||
Code interface{} `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 interface{} `json:"data1"`
|
||||
Data struct {
|
||||
|
@ -75,7 +75,7 @@ type SubmitOrderEvaluationReq struct {
|
|||
|
||||
type SubmitOrderEvaluationResp struct {
|
||||
Flag bool `json:"flag"`
|
||||
Code int `json:"code"`
|
||||
Code interface{} `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 interface{} `json:"data1"`
|
||||
Data struct {
|
||||
|
@ -126,7 +126,7 @@ type QueryMemberOrderListReq struct {
|
|||
}
|
||||
type QueryMemberOrderListResp struct {
|
||||
Flag bool `json:"flag"`
|
||||
Code int `json:"code"`
|
||||
Code interface{} `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 interface{} `json:"data1"`
|
||||
Data struct {
|
||||
|
@ -393,9 +393,11 @@ type RecycleCardSubmitCartDeliveryReq struct {
|
|||
}
|
||||
|
||||
type RecycleCardSubmitCartDeliveryResp struct {
|
||||
Code interface{} `json:"code"`
|
||||
Flag bool `json:"flag"`
|
||||
Code interface{} `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 interface{} `json:"data1"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type RecycleCardUpdateOrderQcReportReq struct {
|
||||
|
@ -412,7 +414,7 @@ type RecycleCardUpdateOrderQcReportReq struct {
|
|||
|
||||
type RecycleCardUpdateOrderQcReportResp struct {
|
||||
Flag bool `json:"flag"`
|
||||
Code int `json:"code"`
|
||||
Code interface{} `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data1 interface{} `json:"data1"`
|
||||
Data struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user