From d4734e25a107167c7ba706532a1751f5cefed03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 14 Feb 2023 14:08:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=96=E9=9F=B3=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E8=BD=AC=E6=9E=9C=E5=9B=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/store.go | 1 + business/jxstore/misc/misc.go | 12 +++-- .../partner/purchase/tiktok_store/callback.go | 52 +++++++++++-------- business/partner/purchase/tiktok_store/dy.go | 18 ++----- controllers/tiktok_store.go | 23 +++++++- 5 files changed, 63 insertions(+), 43 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index cf7db4c10..89dbca91f 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -4454,6 +4454,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") } } } diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 1ef8763d0..7c85a0fcb 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -245,11 +245,6 @@ func Init() { orderman.FixedOrderManager.AmendMissingOrders(jxcontext.AdminCtx, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI, model.VendorIDDD}, 0, curDate, curDate, true, true) }, 5*time.Second, 10*time.Minute) - //刷新抖音门店token - ScheduleTimerFuncByInterval(func() { - cms.RefreshTiktokShopToken(jxcontext.AdminCtx) - }, 60*time.Second, 30*time.Minute) - // 抖音更新门店商品 if beego.BConfig.RunMode != "jxgy" { ScheduleTimerFunc("RefreshSyncSkuList", func() { @@ -257,6 +252,13 @@ func Init() { }, []string{"11:30:00"}) } + //刷新抖音门店token + if beego.BConfig.RunMode != "jxgy" { + ScheduleTimerFuncByInterval(func() { + cms.RefreshTiktokShopToken(jxcontext.AdminCtx) + }, 60*time.Second, 30*time.Minute) + } + // 定时任务刷新当前订单的物流信息 ScheduleTimerFunc("RefreshMaterialLogistics", func() { bidding.LoadingLogistics(nil) diff --git a/business/partner/purchase/tiktok_store/callback.go b/business/partner/purchase/tiktok_store/callback.go index 9bf6d126a..b89b7fbf3 100644 --- a/business/partner/purchase/tiktok_store/callback.go +++ b/business/partner/purchase/tiktok_store/callback.go @@ -6,38 +6,42 @@ import ( "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) { - globals.SugarLogger.Debugf("GetCallbackOrderId tiktok msg %s", utils.Format4Output(msg, false)) if CurPurchaseHandler != nil { orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg) - globals.SugarLogger.Debugf("shopId %d", shopId) - //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, "order") - // 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 - //} - //} + orderDetail, err := GetTiktokApi(utils.Int64ToStr(shopId), 0, "").GetTiktokOrderDetail(orderId) + if err != nil { + return tiktokShop.Err2CallbackResponse(err, "") + } + vendorStoreID := orderDetail.ShopId + if vendorStoreID != 0 { + storeDetail, err := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), utils.Int64ToStr(vendorStoreID), model.VendorIDDD, "") + 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, "order") + 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)) @@ -46,6 +50,7 @@ func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackRes } func HttpToGuoYuan(param map[string]interface{}, requestType string) (*http.Response, error) { + globals.SugarLogger.Debugf("=========param %s", utils.Format4Output(param, false)) paramData, err := json.Marshal(param) if err != nil { return nil, err @@ -58,7 +63,8 @@ func HttpToGuoYuan(param map[string]interface{}, requestType string) (*http.Resp case "order": // 订单相关 url = "http://callback-jxgy.jxc4.com/tiktok/callbackTiktokOrderMsg" case "token": // 授权相关 - case "wayBill": // 授权相关 + url = "http://callback-jxgy.jxc4.com/tiktokShop/jxcsToGyTiktokToken" + case "wayBill": // 运单消息 } httpReq, err := http.NewRequest(http.MethodPost, url, body) diff --git a/business/partner/purchase/tiktok_store/dy.go b/business/partner/purchase/tiktok_store/dy.go index 4e5544300..355e52627 100644 --- a/business/partner/purchase/tiktok_store/dy.go +++ b/business/partner/purchase/tiktok_store/dy.go @@ -221,19 +221,11 @@ func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) { } func getAPI(appOrgCode string, storeID int, vendorStoreID string) (apiObj *tiktok_api.API) { - apiObj = partner.CurAPIManager.GetAPI(model.VendorIDDD, appOrgCode).(*tiktok_api.API) - //if appOrgCode == globals.TiktokShopCode { - // var storeDetail *dao.StoreDetail - // if storeID != 0 { - // storeDetail, _ = dao.GetStoreDetail(dao.GetDB(), storeID, model.VendorIDDD, appOrgCode) - // } else if vendorStoreID != "" { - // storeDetail, _ = dao.GetStoreDetailByVendorStoreID(dao.GetDB(), vendorStoreID, model.VendorIDDD, appOrgCode) - // } - // if storeDetail != nil { - // apiObj.SetToken(storeDetail.MtwmToken) - // } - //} - return apiObj + return partner.CurAPIManager.GetAPI(model.VendorIDDD, appOrgCode).(*tiktok_api.API) +} + +func GetTiktokApi(appOrgCode string, storeID int, vendorStoreID string) *tiktok_api.API { + return getAPI(appOrgCode, storeID, vendorStoreID) } func getAPIWithoutToken(appOrgCode string) (apiObj *tiktok_api.API) { diff --git a/controllers/tiktok_store.go b/controllers/tiktok_store.go index df46382c2..3ad78c873 100644 --- a/controllers/tiktok_store.go +++ b/controllers/tiktok_store.go @@ -150,9 +150,28 @@ func (c *TiktokShopController) TokenMsg() { return } - // 授权码发生变化,通知到果园 - { + c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess} + c.ServeJSON() +} +func (c *TiktokShopController) JxcsToGyTiktokToken() { + data, err := ioutil.ReadAll(c.Ctx.Request.Body) + if err != nil { + c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} + c.ServeJSON() + return + } + param := &model.VendorOrgCode{} + if err := json.Unmarshal(data, param); err != nil { + c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} + c.ServeJSON() + return + } + + if err := common.AddVendorOrgCode(nil, param); err != nil { + c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackFailCode, Msg: tiktok_api.CallbackFail} + c.ServeJSON() + return } c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess}