From 20a71bdb2cb03c4a0207fb8f83e1f092f6c61bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 24 Nov 2022 18:16:18 +0800 Subject: [PATCH] 1 --- .../partner/purchase/tiktok_store/callback.go | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/business/partner/purchase/tiktok_store/callback.go b/business/partner/purchase/tiktok_store/callback.go index e6f48308c..e2fce2970 100644 --- a/business/partner/purchase/tiktok_store/callback.go +++ b/business/partner/purchase/tiktok_store/callback.go @@ -1,19 +1,64 @@ package tiktok_store import ( + "encoding/json" tiktokShop "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api" + "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/jxutils" "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/globals/api" + "io/ioutil" + "net/http" + "strings" + "time" ) // OnOrderMsg 抖音 func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) { if CurPurchaseHandler != nil { - orderId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg) + orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg) + if shopId != 0 { + storeDetail, err := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), utils.Int64ToStr(shopId), model.VendorIDDD, "") + globals.SugarLogger.Debugf("==storeDetail=: %s", utils.Format4Output(storeDetail, false)) + globals.SugarLogger.Debugf("==err=: %s", utils.Format4Output(err, false)) + if err != nil || storeDetail == nil || storeDetail.Store.ID == 0 { + // 当前订单所属门店不属于菜市时,将消息推送到果园 + gyMsg := map[string]interface{}{"tag": msgId, "msg_id": utils.Int64ToStr(time.Now().Unix()) + msgId, "data": msg} + // 通知到果园 + gyResult, err := HttpToGuoYuan(gyMsg) + if err != nil { + return tiktokShop.Err2CallbackResponse(err, "") + } + result, _ := ioutil.ReadAll(gyResult.Body) + var guoYuan *tiktokShop.CallbackResponse + if err := json.Unmarshal(result, guoYuan); err != nil { + return tiktokShop.Err2CallbackResponse(err, "") + } + return guoYuan + } + } jxutils.CallMsgHandler(func() { response = CurPurchaseHandler.onOrderMsg(msgId, orderId, msg) }, jxutils.ComposeUniversalOrderID(orderId, model.VendorIDDD)) } return response } + +func HttpToGuoYuan(param map[string]interface{}) (*http.Response, error) { + paramData, err := json.Marshal(param) + if err != nil { + return nil, err + } + + body := strings.NewReader(string(paramData)) + httpReq, err := http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/tiktok/callbackTiktokOrderMsg", body) + if err != nil { + return nil, err + } + httpReq.Header.Set("Content-Type", "application/json") + + httpRes, err := http.DefaultClient.Do(httpReq) + return httpRes, err +}