添加抖音订单转果园

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.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)
}, 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)

View File

@@ -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)

View File

@@ -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) {

View File

@@ -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}