From eab817817fda59c04d0dd18c9f9d231dca0e9d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Wed, 15 Feb 2023 14:09:51 +0800 Subject: [PATCH] 1 --- business/jxstore/cms/store.go | 3 +- business/model/store.go | 11 ++-- business/partner/purchase/ebai/order.go | 46 ++++++++++----- .../partner/purchase/tiktok_store/callback.go | 22 +++++-- controllers/tiktok_delivery.go | 58 ++++++++++++++++--- controllers/tiktok_store.go | 1 + 6 files changed, 105 insertions(+), 36 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 4572b9723..a90fff742 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -523,6 +523,7 @@ func setStoreMapInfo(ctx *jxcontext.Context, db *dao.DaoDB, storesInfo *StoresIn v.IDCardFront = "" v.IDCardBack = "" v.IDCardHand = "" + v.IDCardHandBack = "" v.Licence = "" v.Licence2Image = "" } @@ -4455,7 +4456,7 @@ func RefreshTiktokShopToken(ctx *jxcontext.Context) (err error) { v.UpdatedAt = time.Now() v.StoreBrandName = "定时任务更新" dao.UpdateEntity(db, v, "Token", "UpdatedAt", "StoreBrandName") - tiktok_store.HttpToGuoYuan(utils.Struct2MapByJson(v), "token") + tiktok_store.HttpToGuoYuan(utils.Struct2MapByJson(v), tiktok_store.CaiShiPushGyTagToken) } } } diff --git a/business/model/store.go b/business/model/store.go index 763dcdb04..1c0ed42b3 100644 --- a/business/model/store.go +++ b/business/model/store.go @@ -340,11 +340,12 @@ type Store struct { PrinterSound string `json:"printerSound"` //打印机语音,京西打印机 PrinterTemplate string `json:"printerTemplate"` //打印模板。京西打印机 - IDCardFront string `orm:"size(255);column(id_card_front)" json:"idCardFront"` - IDCardBack string `orm:"size(255);column(id_card_back)" json:"idCardBack"` - IDCardHand string `orm:"size(255);column(id_card_hand)" json:"idCardHand"` - Licence string `orm:"size(255)" json:"licence"` // 营业执照图片 - LicenceCode string `orm:"size(32)" json:"licenceCode"` + IDCardFront string `orm:"size(255);column(id_card_front)" json:"idCardFront"` // 身份证正面 + IDCardBack string `orm:"size(255);column(id_card_back)" json:"idCardBack"` // 身份证背面 + IDCardHand string `orm:"size(255);column(id_card_hand)" json:"idCardHand"` // 手持身份证正面 + IDCardHandBack string `orm:"size(255);column(id_card_hand_back)" json:"idCardHandBack"` // 手持身份证背面 + Licence string `orm:"size(255)" json:"licence"` // 营业执照图片 + LicenceCode string `orm:"size(32)" json:"licenceCode"` LicenceType int8 `json:"licenceType"` // 营业执照类型,0:个人,1:公司 LicenceCorpName string `orm:"size(64)" json:"licenceCorpName"` // 营业执照公司名称 diff --git a/business/partner/purchase/ebai/order.go b/business/partner/purchase/ebai/order.go index f4d92ddb1..5eea2f695 100644 --- a/business/partner/purchase/ebai/order.go +++ b/business/partner/purchase/ebai/order.go @@ -1,6 +1,7 @@ package ebai import ( + "errors" "fmt" "math" "strings" @@ -387,23 +388,36 @@ func (p *PurchaseHandler) ConfirmReceiveGoods(ctx *jxcontext.Context, order *mod // 将订单从购物平台配送转为自送 func (p *PurchaseHandler) Swtich2SelfDeliver(order *model.GoodsOrder, userName string) (err error) { if globals.EnableEbaiStoreWrite { - if order.DeliveryType == model.OrderDeliveryTypePlatform { - if err = api.EbaiAPI.OrderSwitchselfdelivery(order.VendorOrderID); err != nil { - if strings.Contains(err.Error(), "301251") { - api.EbaiAPI.OrderCancelDelivery(order.VendorOrderID) // 取消呼叫众包骑手 - } - if utils.IsErrMatch(err, "301251", nil) { - if deliveryStatus, err2 := api.EbaiAPI.OrderDeliveryGet(order.VendorOrderID); err2 == nil { - deliveryStatus := utils.Int64ToStr(utils.MustInterface2Int64(deliveryStatus["status"])) - if deliveryStatus == ebaiapi.WaybillStatusSelfDelivery { - err = nil - } else if deliveryStatus == ebaiapi.WaybillStatusDeliveryCancled { - p.trySyncCancelStatus(order.VendorOrderID) - } - } - } - } + deliveryStatusObj, _ := api.EbaiAPI.OrderDeliveryGet(order.VendorOrderID) + deliveryStatus := utils.Int64ToStr(utils.MustInterface2Int64(deliveryStatusObj["status"])) + switch deliveryStatus { + case ebaiapi.WaybillStatusSelfDelivery: + err = nil + case ebaiapi.WaybillStatusDeliveryCancled: + p.trySyncCancelStatus(order.VendorOrderID) + case ebaiapi.WaybillStatusNew, ebaiapi.WaybillStatusRequestDelivery, ebaiapi.WaybillStatusWait4Courier: + err = api.EbaiAPI.OrderCancelDelivery(order.VendorOrderID) // 取消呼叫众包骑手 + case ebaiapi.WaybillStatusCourierAccepted: + err = errors.New("骑手已接单,无法转自送") } + + //if order.DeliveryType == model.OrderDeliveryTypePlatform { + // if err = api.EbaiAPI.OrderSwitchselfdelivery(order.VendorOrderID); err != nil { + // if strings.Contains(err.Error(), "301251") { + // api.EbaiAPI.OrderCancelDelivery(order.VendorOrderID) // 取消呼叫众包骑手 + // } + // if utils.IsErrMatch(err, "301251", nil) { + // if deliveryStatus, err2 := api.EbaiAPI.OrderDeliveryGet(order.VendorOrderID); err2 == nil { + // deliveryStatus := utils.Int64ToStr(utils.MustInterface2Int64(deliveryStatus["status"])) + // if deliveryStatus == ebaiapi.WaybillStatusSelfDelivery { + // err = nil + // } else if deliveryStatus == ebaiapi.WaybillStatusDeliveryCancled { + // p.trySyncCancelStatus(order.VendorOrderID) + // } + // } + // } + // } + //} } if err == nil { // 饿百不会发送配送中,模拟发送 diff --git a/business/partner/purchase/tiktok_store/callback.go b/business/partner/purchase/tiktok_store/callback.go index 4afa7f607..205742f57 100644 --- a/business/partner/purchase/tiktok_store/callback.go +++ b/business/partner/purchase/tiktok_store/callback.go @@ -15,6 +15,15 @@ import ( "time" ) +// 同一账号下,菜市消息推送到果园 +const ( + CaiShiPushGyTagOrder = "order" // 订单 + CaiShiPushGyTagToken = "token" // 授权 + CaiShiPushGyTagDeliveryRegister = "delivery" // 配送注册查询 + CaiShiPushGyTagDeliveryDetail = "deliveryDetail" // 配送详情 + CaiShiPushGyTagWayBill = "waybill" // 配送 +) + // OnOrderMsg 抖音 func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) { globals.SugarLogger.Debugf("guoyuan %s,%s", msgId, utils.Format4Output(msg, false)) @@ -33,7 +42,7 @@ func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackRes // 当前订单所属门店不属于菜市时,将消息推送到果园 gyMsg := map[string]interface{}{"tag": msgId, "msg_id": utils.Int64ToStr(time.Now().Unix()) + msgId, "data": msg} // 通知到果园 - gyResult, err := HttpToGuoYuan(gyMsg, "order") + gyResult, err := HttpToGuoYuan(gyMsg, CaiShiPushGyTagOrder) if err != nil { return tiktokShop.Err2CallbackResponse(err, "") } @@ -50,7 +59,6 @@ func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackRes }, jxutils.ComposeUniversalOrderID(orderId, model.VendorIDDD)) } else { globals.SugarLogger.Debugf("============2") - } return response } @@ -74,11 +82,15 @@ func HttpToGuoYuan(param map[string]interface{}, requestType string) (*http.Resp url := "" switch requestType { - case "order": // 订单相关 + case CaiShiPushGyTagOrder: // 订单相关 url = "http://callback-jxgy.jxc4.com/tiktok/callbackTiktokOrderMsg" - case "token": // 授权相关 + case CaiShiPushGyTagToken: // 授权相关 url = "http://callback-jxgy.jxc4.com/tiktokShop/jxcsToGyTiktokToken" - case "wayBill": // 运单消息 + case CaiShiPushGyTagDeliveryRegister: // 配送查询注册 + url = "http://callback-jxgy.jxc4.com/logistics/logisticsRegister" + case CaiShiPushGyTagDeliveryDetail: // 配送查询详情 + url = "http://callback-jxgy.jxc4.com/logistics/logisticsQuery" + case CaiShiPushGyTagWayBill: // 运单消息 } httpReq, err := http.NewRequest(http.MethodPost, url, body) diff --git a/controllers/tiktok_delivery.go b/controllers/tiktok_delivery.go index 0bd9daf92..377f98bb5 100644 --- a/controllers/tiktok_delivery.go +++ b/controllers/tiktok_delivery.go @@ -7,7 +7,7 @@ import ( "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" - "git.rosy.net.cn/jx-callback/globals" + "git.rosy.net.cn/jx-callback/business/partner/purchase/tiktok_store" "github.com/astaxie/beego/server/web" "io/ioutil" "time" @@ -58,8 +58,32 @@ func (c *LogisticsController) LogisticsRegister() { } // 查询订单的运单是否存在 data, err := dao.GetWayBillsByWayBillId(dao.GetDB(), register.TrackNo) - if err != nil { - globals.SugarLogger.Debugf("根据单号查询运单数据错误:%s", err) + + // 此订单可能是果园订单 + 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: "单号不存在", + } + 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.ServeJSON() + return + } + c.Data["json"] = gyData + c.ServeJSON() } if len(data) == 0 || err != nil { @@ -156,14 +180,30 @@ func (c *LogisticsController) LogisticsQuery() { // 查询订单的运单是否存在 data, err := dao.GetWayBillsByWayBillId(dao.GetDB(), param.TrackNo) - if err != nil || len(data) == 0 { - c.Data["json"] = LogisticsQueryRest{ - Result: false, - ReturnCode: "1002", - Message: "运单账号不存在", + 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: "运单账号不存在", + } + 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.ServeJSON() + return + } + c.Data["json"] = wayBillDetail c.ServeJSON() - return } returnParam := &LogisticsQueryRest{ diff --git a/controllers/tiktok_store.go b/controllers/tiktok_store.go index 3ad78c873..f08a3aab4 100644 --- a/controllers/tiktok_store.go +++ b/controllers/tiktok_store.go @@ -154,6 +154,7 @@ func (c *TiktokShopController) TokenMsg() { c.ServeJSON() } +// JxcsToGyTiktokToken 果园京西速食接受token更新 func (c *TiktokShopController) JxcsToGyTiktokToken() { data, err := ioutil.ReadAll(c.Ctx.Request.Body) if err != nil {