添加抖音订单转果园

This commit is contained in:
邹宗楠
2023-02-14 14:08:27 +08:00
parent 91e67ba158
commit d4734e25a1
5 changed files with 63 additions and 43 deletions

View File

@@ -4454,6 +4454,7 @@ func RefreshTiktokShopToken(ctx *jxcontext.Context) (err error) {
v.UpdatedAt = time.Now() v.UpdatedAt = time.Now()
v.StoreBrandName = "定时任务更新" v.StoreBrandName = "定时任务更新"
dao.UpdateEntity(db, v, "Token", "UpdatedAt", "StoreBrandName") dao.UpdateEntity(db, v, "Token", "UpdatedAt", "StoreBrandName")
tiktok_store.HttpToGuoYuan(utils.Struct2MapByJson(v), "token")
} }
} }
} }

View File

@@ -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) 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) }, 5*time.Second, 10*time.Minute)
//刷新抖音门店token
ScheduleTimerFuncByInterval(func() {
cms.RefreshTiktokShopToken(jxcontext.AdminCtx)
}, 60*time.Second, 30*time.Minute)
// 抖音更新门店商品 // 抖音更新门店商品
if beego.BConfig.RunMode != "jxgy" { if beego.BConfig.RunMode != "jxgy" {
ScheduleTimerFunc("RefreshSyncSkuList", func() { ScheduleTimerFunc("RefreshSyncSkuList", func() {
@@ -257,6 +252,13 @@ func Init() {
}, []string{"11:30:00"}) }, []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() { ScheduleTimerFunc("RefreshMaterialLogistics", func() {
bidding.LoadingLogistics(nil) bidding.LoadingLogistics(nil)

View File

@@ -6,38 +6,42 @@ import (
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model" "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"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
"io/ioutil"
"net/http" "net/http"
"strings" "strings"
"time"
) )
// OnOrderMsg 抖音 // OnOrderMsg 抖音
func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) { func OnOrderMsg(msgId string, msg interface{}) (response *tiktokShop.CallbackResponse) {
globals.SugarLogger.Debugf("GetCallbackOrderId tiktok msg %s", utils.Format4Output(msg, false))
if CurPurchaseHandler != nil { if CurPurchaseHandler != nil {
orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg) orderId, shopId, _ := api.TiktokStore.GetCallbackOrderId(msgId, msg)
globals.SugarLogger.Debugf("shopId %d", shopId) orderDetail, err := GetTiktokApi(utils.Int64ToStr(shopId), 0, "").GetTiktokOrderDetail(orderId)
//if shopId != 0 { if err != nil {
//storeDetail, err := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), utils.Int64ToStr(shopId), model.VendorIDDD, "") return tiktokShop.Err2CallbackResponse(err, "")
//globals.SugarLogger.Debugf("==storeDetail=: %s", utils.Format4Output(storeDetail, false)) }
//globals.SugarLogger.Debugf("==err=: %s", utils.Format4Output(err, false)) vendorStoreID := orderDetail.ShopId
//if err != nil || storeDetail == nil || storeDetail.Store.ID == 0 { if vendorStoreID != 0 {
// // 当前订单所属门店不属于菜市时,将消息推送到果园 storeDetail, err := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), utils.Int64ToStr(vendorStoreID), model.VendorIDDD, "")
// gyMsg := map[string]interface{}{"tag": msgId, "msg_id": utils.Int64ToStr(time.Now().Unix()) + msgId, "data": msg} if err != nil || storeDetail == nil || storeDetail.Store.ID == 0 {
// // 通知到果园 // 当前订单所属门店不属于菜市时,将消息推送到果园
// gyResult, err := HttpToGuoYuan(gyMsg, "order") gyMsg := map[string]interface{}{"tag": msgId, "msg_id": utils.Int64ToStr(time.Now().Unix()) + msgId, "data": msg}
// if err != nil { // 通知到果园
// return tiktokShop.Err2CallbackResponse(err, "") gyResult, err := HttpToGuoYuan(gyMsg, "order")
// } if err != nil {
// result, _ := ioutil.ReadAll(gyResult.Body) return tiktokShop.Err2CallbackResponse(err, "")
// var guoYuan *tiktokShop.CallbackResponse }
// if err := json.Unmarshal(result, guoYuan); err != nil { result, _ := ioutil.ReadAll(gyResult.Body)
// return tiktokShop.Err2CallbackResponse(err, "") var guoYuan *tiktokShop.CallbackResponse
// } if err := json.Unmarshal(result, guoYuan); err != nil {
// return guoYuan return tiktokShop.Err2CallbackResponse(err, "")
//} }
//} return guoYuan
}
}
jxutils.CallMsgHandler(func() { jxutils.CallMsgHandler(func() {
response = CurPurchaseHandler.onOrderMsg(msgId, orderId, msg) response = CurPurchaseHandler.onOrderMsg(msgId, orderId, msg)
}, jxutils.ComposeUniversalOrderID(orderId, model.VendorIDDD)) }, 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) { 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) paramData, err := json.Marshal(param)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -58,7 +63,8 @@ func HttpToGuoYuan(param map[string]interface{}, requestType string) (*http.Resp
case "order": // 订单相关 case "order": // 订单相关
url = "http://callback-jxgy.jxc4.com/tiktok/callbackTiktokOrderMsg" url = "http://callback-jxgy.jxc4.com/tiktok/callbackTiktokOrderMsg"
case "token": // 授权相关 case "token": // 授权相关
case "wayBill": // 授权相关 url = "http://callback-jxgy.jxc4.com/tiktokShop/jxcsToGyTiktokToken"
case "wayBill": // 运单消息
} }
httpReq, err := http.NewRequest(http.MethodPost, url, body) httpReq, err := http.NewRequest(http.MethodPost, url, body)

View File

@@ -221,19 +221,11 @@ func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) {
} }
func getAPI(appOrgCode string, storeID int, vendorStoreID string) (apiObj *tiktok_api.API) { func getAPI(appOrgCode string, storeID int, vendorStoreID string) (apiObj *tiktok_api.API) {
apiObj = partner.CurAPIManager.GetAPI(model.VendorIDDD, appOrgCode).(*tiktok_api.API) return partner.CurAPIManager.GetAPI(model.VendorIDDD, appOrgCode).(*tiktok_api.API)
//if appOrgCode == globals.TiktokShopCode { }
// var storeDetail *dao.StoreDetail
// if storeID != 0 { func GetTiktokApi(appOrgCode string, storeID int, vendorStoreID string) *tiktok_api.API {
// storeDetail, _ = dao.GetStoreDetail(dao.GetDB(), storeID, model.VendorIDDD, appOrgCode) return getAPI(appOrgCode, storeID, vendorStoreID)
// } else if vendorStoreID != "" {
// storeDetail, _ = dao.GetStoreDetailByVendorStoreID(dao.GetDB(), vendorStoreID, model.VendorIDDD, appOrgCode)
// }
// if storeDetail != nil {
// apiObj.SetToken(storeDetail.MtwmToken)
// }
//}
return apiObj
} }
func getAPIWithoutToken(appOrgCode string) (apiObj *tiktok_api.API) { func getAPIWithoutToken(appOrgCode string) (apiObj *tiktok_api.API) {

View File

@@ -150,9 +150,28 @@ func (c *TiktokShopController) TokenMsg() {
return 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} c.Data["json"] = tiktok_api.CallbackResponse{Code: tiktok_api.CallbackSuccessCode, Msg: tiktok_api.CallbackSuccess}