This commit is contained in:
邹宗楠
2024-10-16 09:17:05 +08:00
parent a6e6222075
commit 32cde499da
28 changed files with 271 additions and 167 deletions

View File

@@ -10,6 +10,7 @@ import (
"git.rosy.net.cn/jx-callback/business/partner/purchase/tiktok_store"
"github.com/astaxie/beego/server/web"
"io/ioutil"
"net/http"
"time"
)
@@ -60,25 +61,30 @@ func (c *LogisticsController) LogisticsRegister() {
data, err := dao.GetWayBillsByWayBillId(dao.GetDB(), register.TrackNo)
// 此订单可能是果园订单
if web.BConfig.RunMode != "jxgy" && (len(data) == 0 || err != nil) {
resp, err := tiktok_store.HttpToGuoYuan(utils.Struct2Map(register, "", true), tiktok_store.CaiShiPushGyTagDeliveryRegister)
if err != nil {
c.Data["json"] = LogisticsRegisterResp{
Result: false,
ReturnCode: "1002",
Message: "单号不存在",
if len(data) == 0 || err != nil {
var resp *http.Response
var err error
switch web.BConfig.RunMode {
case model.ServerTypeVegetable:
resp, err = tiktok_store.HttpToGuoYuan(utils.Struct2Map(register, "", true), tiktok_store.CaiShiPushGyTagDeliveryRegister, model.ServerTypeFruits)
if err != nil {
c.Data["json"] = LogisticsQueryRestMsg("单号不存在", "1002")
c.ServeJSON()
return
}
case model.ServerTypeFruits:
resp, err = tiktok_store.HttpToGuoYuan(utils.Struct2Map(register, "", true), tiktok_store.CaiShiPushGyTagDeliveryRegister, model.ServerTypePet)
if err != nil {
c.Data["json"] = LogisticsQueryRestMsg("单号不存在", "1002")
c.ServeJSON()
return
}
c.ServeJSON()
return
}
gyData := &LogisticsRegisterResp{}
gyBody, _ := ioutil.ReadAll(resp.Body)
if err := json.Unmarshal(gyBody, gyData); err != nil {
c.Data["json"] = LogisticsRegisterResp{
Result: false,
ReturnCode: "1002",
Message: "单号不存在",
}
c.Data["json"] = LogisticsQueryRestMsg("单号不存在", "1002")
c.ServeJSON()
return
}
@@ -86,16 +92,6 @@ func (c *LogisticsController) LogisticsRegister() {
c.ServeJSON()
}
if len(data) == 0 || err != nil {
c.Data["json"] = LogisticsRegisterResp{
Result: false,
ReturnCode: "1002",
Message: "单号不存在",
}
c.ServeJSON()
return
}
c.Data["json"] = LogisticsRegisterResp{
Result: true,
ReturnCode: "200",
@@ -159,46 +155,47 @@ func (c *LogisticsController) LogisticsQuery() {
body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
param := &LogisticsQueryReq{}
if err := json.Unmarshal(body, param); err != nil {
c.Data["json"] = LogisticsQueryRest{
Result: false,
ReturnCode: "1005",
Message: "数据解析错误",
}
c.Data["json"] = LogisticsQueryRestMsg("数据解析错误", "1005")
c.ServeJSON()
return
}
if param.TrackNo == "" {
c.Data["json"] = LogisticsQueryRest{
Result: false,
ReturnCode: "1002",
Message: "运单账号不存在",
}
c.Data["json"] = LogisticsQueryRestMsg("运单账号不存在", "1002")
c.ServeJSON()
return
}
// 查询订单的运单是否存在
data, err := dao.GetWayBillsByWayBillId(dao.GetDB(), param.TrackNo)
if (err != nil || len(data) == 0) && web.BConfig.RunMode != "jxgy" {
resp, err := tiktok_store.HttpToGuoYuan(utils.Struct2Map(param, "", true), tiktok_store.CaiShiPushGyTagDeliveryDetail)
if err != nil {
c.Data["json"] = LogisticsQueryRest{
Result: false,
ReturnCode: "1002",
Message: "运单账号不存在",
if err != nil || len(data) == 0 {
var resp *http.Response
var err error
switch web.BConfig.RunMode {
case model.ServerTypeVegetable:
resp, err = tiktok_store.HttpToGuoYuan(utils.Struct2Map(param, "", true), tiktok_store.CaiShiPushGyTagDeliveryDetail, model.ServerTypeFruits)
if err != nil {
c.Data["json"] = LogisticsQueryRestMsg("运单账号不存在", "1002")
c.ServeJSON()
return
}
case model.ServerTypeFruits:
resp, err = tiktok_store.HttpToGuoYuan(utils.Struct2Map(param, "", true), tiktok_store.CaiShiPushGyTagDeliveryDetail, model.ServerTypePet)
if err != nil {
c.Data["json"] = LogisticsQueryRestMsg("运单账号不存在", "1002")
c.ServeJSON()
return
}
case "jxpet":
c.Data["json"] = LogisticsQueryRestMsg("运单账号不存在", "1002")
c.ServeJSON()
return
}
wayBillDetail := &LogisticsQueryRest{}
gyBody, _ := ioutil.ReadAll(resp.Body)
if err := json.Unmarshal(gyBody, wayBillDetail); err != nil {
c.Data["json"] = LogisticsQueryRest{
Result: false,
ReturnCode: "1002",
Message: "json unmarshal",
}
c.Data["json"] = LogisticsQueryRestMsg("json unmarshal", "1002")
c.ServeJSON()
return
}
@@ -271,4 +268,19 @@ func (c *LogisticsController) LogisticsQuery() {
c.ServeJSON()
}
func LogisticsQueryRestMsg(err string, errCode string) LogisticsQueryRest {
if err == "" {
return LogisticsQueryRest{
Result: false,
ReturnCode: errCode,
Message: err,
}
}
return LogisticsQueryRest{
Result: false,
ReturnCode: "1002",
Message: "json unmarshal",
}
}
//#endregion