+ OpenRemoteStoreByJxStatus
This commit is contained in:
57
business/jxstore/cms/sync_store.go
Normal file
57
business/jxstore/cms/sync_store.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package cms
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 如果京西门为打开,打开状态为非营业的平台门店
|
||||||
|
func OpenRemoteStoreByJxStatus(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isForce, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||||
|
db := dao.GetDB()
|
||||||
|
status := model.StoreStatusAll
|
||||||
|
if !isForce {
|
||||||
|
status = model.StoreStatusClosed
|
||||||
|
}
|
||||||
|
storeMapList, err := dao.GetStoresMapList(db, vendorIDs, storeIDs, status, model.StoreIsSyncYes, "")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
vendorIDMap := make(map[int]int)
|
||||||
|
if len(vendorIDs) == 0 {
|
||||||
|
for k := range partner.PurchasePlatformHandlers {
|
||||||
|
vendorIDMap[k] = 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for _, v := range vendorIDs {
|
||||||
|
vendorIDMap[v] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
task := tasksch.NewParallelTask("OpenRemoteStoreByJxStatus", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
storeMap := batchItemList[0].(*model.StoreMap)
|
||||||
|
if handler, _ := partner.GetPurchasePlatformFromVendorID(storeMap.VendorID).(partner.IStoreHandler); handler != nil {
|
||||||
|
storeDetail, err := dao.GetStoreDetail(db, storeMap.StoreID, storeMap.VendorID)
|
||||||
|
if err == nil && storeDetail.Status == model.StoreStatusOpened {
|
||||||
|
if err = handler.UpdateStoreStatus(ctx, storeMap.StoreID, storeMap.VendorStoreID, model.StoreStatusOpened); err == nil {
|
||||||
|
retVal = []int{0}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retVal, err
|
||||||
|
}, storeMapList)
|
||||||
|
tasksch.HandleTask(task, nil, true).Run()
|
||||||
|
|
||||||
|
if isAsync {
|
||||||
|
hint = task.GetID()
|
||||||
|
} else {
|
||||||
|
resultList, err2 := task.GetResult(0)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
hint = utils.Int2Str(len(resultList))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hint, err
|
||||||
|
}
|
||||||
9
business/partner/partner_store.go
Normal file
9
business/partner/partner_store.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package partner
|
||||||
|
|
||||||
|
import "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
|
|
||||||
|
type IStoreHandler interface {
|
||||||
|
UpdateStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, status int) (err error)
|
||||||
|
// opTime格式为整数1130代表11:30
|
||||||
|
// ChangeStoreOptime(ctx *jxcontext.Context, opTimeList []int) (err error)
|
||||||
|
}
|
||||||
@@ -181,27 +181,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
|||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus)
|
mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus)
|
||||||
if !isStoreStatusSame(store2.Status, mergeStatus) {
|
if err = p.updateStoreStatus(userName, storeID, store.VendorStoreID, mergeStatus, store2.Status); err != nil {
|
||||||
if mergeStatus == model.StoreStatusOpened {
|
|
||||||
err = api.EbaiAPI.ShopOpen("", utils.Str2Int64(store.VendorStoreID))
|
|
||||||
} else if mergeStatus == model.StoreStatusHaveRest || mergeStatus == model.StoreStatusClosed {
|
|
||||||
err = api.EbaiAPI.ShopClose("", utils.Str2Int64(store.VendorStoreID))
|
|
||||||
} else if mergeStatus == model.StoreStatusDisabled {
|
|
||||||
err = api.EbaiAPI.ShopOffline("", utils.Str2Int64(store.VendorStoreID))
|
|
||||||
}
|
|
||||||
if intErr, ok := err.(*utils.ErrorWithCode); ok && intErr.IntCode() == 201100 {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
// todo
|
|
||||||
if intErr, ok := err.(*utils.ErrorWithCode); ok {
|
|
||||||
if intErr.IntCode() == 201101 {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
params := genStoreMapFromStore(store)
|
params := genStoreMapFromStore(store)
|
||||||
@@ -441,3 +421,29 @@ func (c *PurchaseHandler) GetShopHealthInfo(vendorShopID string) (shopHealthInfo
|
|||||||
}
|
}
|
||||||
return shopHealthInfo, err
|
return shopHealthInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, status int) (err error) {
|
||||||
|
store, err := c.ReadStore(vendorStoreID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.updateStoreStatus(ctx.GetUserName(), storeID, vendorStoreID, status, store.Status)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *PurchaseHandler) updateStoreStatus(userName string, storeID int, vendorStoreID string, status, currentStatus int) (err error) {
|
||||||
|
if !isStoreStatusSame(currentStatus, status) {
|
||||||
|
if globals.EnableEbaiStoreWrite {
|
||||||
|
if status == model.StoreStatusOpened {
|
||||||
|
err = api.EbaiAPI.ShopOpen("", utils.Str2Int64(vendorStoreID))
|
||||||
|
} else if status == model.StoreStatusHaveRest || status == model.StoreStatusClosed {
|
||||||
|
err = api.EbaiAPI.ShopClose("", utils.Str2Int64(vendorStoreID))
|
||||||
|
} else if status == model.StoreStatusDisabled {
|
||||||
|
err = api.EbaiAPI.ShopOffline("", utils.Str2Int64(vendorStoreID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if intErr, ok := err.(*utils.ErrorWithCode); ok && intErr.IntCode() == 201100 {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -318,3 +318,13 @@ func (c *PurchaseHandler) OnStoreMsg(msg *jdapi.CallbackOrderMsg) (response *jda
|
|||||||
// }
|
// }
|
||||||
return jdapi.Err2CallbackResponse(err, "")
|
return jdapi.Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, status int) (err error) {
|
||||||
|
_, closeStatus := JxStoreStatus2JdStatus(status)
|
||||||
|
if globals.EnableJdStoreWrite {
|
||||||
|
err = api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, ctx.GetUserName(), map[string]interface{}{
|
||||||
|
"closeStatus": closeStatus,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -107,7 +107,6 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
|||||||
if storeDetail.OpenTime2 > 0 {
|
if storeDetail.OpenTime2 > 0 {
|
||||||
openTime = append(openTime, [2]int16{storeDetail.OpenTime2, storeDetail.CloseTime2})
|
openTime = append(openTime, [2]int16{storeDetail.OpenTime2, storeDetail.CloseTime2})
|
||||||
}
|
}
|
||||||
openLevel, isOnline := bizStatusJX2Mtwm(jxutils.MergeStoreStatus(storeDetail.Status, storeDetail.VendorStatus))
|
|
||||||
// remoteStoreInfo, err := api.MtwmAPI.PoiGet(storeDetail.VendorStoreID)
|
// remoteStoreInfo, err := api.MtwmAPI.PoiGet(storeDetail.VendorStoreID)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// return err
|
// return err
|
||||||
@@ -130,29 +129,9 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
|||||||
// if globals.EnableMtwmStoreWrite {
|
// if globals.EnableMtwmStoreWrite {
|
||||||
// err = api.MtwmAPI.PoiSave(storeDetail.VendorStoreID, params)
|
// err = api.MtwmAPI.PoiSave(storeDetail.VendorStoreID, params)
|
||||||
// }
|
// }
|
||||||
if globals.EnableMtwmStoreWrite {
|
if err = p.UpdateStoreStatus(jxcontext.AdminCtx, storeID, storeDetail.VendorStoreID, jxutils.MergeStoreStatus(storeDetail.Status, storeDetail.VendorStatus)); err == nil {
|
||||||
if isOnline != mtwmapi.PoiStatusOnline {
|
if globals.EnableMtwmStoreWrite {
|
||||||
err = api.MtwmAPI.PoiOffline(storeDetail.VendorStoreID)
|
err = api.MtwmAPI.PoiShipTimeUpdate(storeDetail.VendorStoreID, openTimeJX2Mtwm(openTime))
|
||||||
} else {
|
|
||||||
if err = api.MtwmAPI.PoiOnline(storeDetail.VendorStoreID); err == nil {
|
|
||||||
// 这个函数成功返回也并不表示上线成功。。。
|
|
||||||
remoteStoreInfo, err2 := api.MtwmAPI.PoiGet(storeDetail.VendorStoreID)
|
|
||||||
if err = err2; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if remoteStoreInfo.IsOnline == mtwmapi.PoiStatusOnline {
|
|
||||||
if openLevel == mtwmapi.PoiOpenLevelHaveRest {
|
|
||||||
err = api.MtwmAPI.PoiClose(storeDetail.VendorStoreID)
|
|
||||||
} else {
|
|
||||||
err = api.MtwmAPI.PoiOpen(storeDetail.VendorStoreID)
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
err = api.MtwmAPI.PoiShipTimeUpdate(storeDetail.VendorStoreID, openTimeJX2Mtwm(openTime))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
err = errors.New("门店还未上线,不能修改营业状态")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@@ -190,3 +169,29 @@ func (p *PurchaseHandler) GetStoreStatus(ctx *jxcontext.Context, vendorStoreID s
|
|||||||
}
|
}
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *PurchaseHandler) UpdateStoreStatus(ctx *jxcontext.Context, storeID int, vendorStoreID string, status int) (err error) {
|
||||||
|
openLevel, isOnline := bizStatusJX2Mtwm(status)
|
||||||
|
if globals.EnableMtwmStoreWrite {
|
||||||
|
if isOnline != mtwmapi.PoiStatusOnline {
|
||||||
|
err = api.MtwmAPI.PoiOffline(vendorStoreID)
|
||||||
|
} else {
|
||||||
|
if err = api.MtwmAPI.PoiOnline(vendorStoreID); err == nil { // 这个函数成功返回也并不表示上线成功。。。
|
||||||
|
remoteStoreInfo, err2 := api.MtwmAPI.PoiGet(vendorStoreID)
|
||||||
|
if err = err2; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if remoteStoreInfo.IsOnline == mtwmapi.PoiStatusOnline {
|
||||||
|
if openLevel == mtwmapi.PoiOpenLevelHaveRest {
|
||||||
|
err = api.MtwmAPI.PoiClose(vendorStoreID)
|
||||||
|
} else {
|
||||||
|
err = api.MtwmAPI.PoiOpen(vendorStoreID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = errors.New("门店还未上线,不能修改营业状态")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
|
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxstore/tempop"
|
"git.rosy.net.cn/jx-callback/business/jxstore/tempop"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -242,26 +240,27 @@ func (c *TempOpController) RefreshMtpsWaybillFee() {
|
|||||||
// @router /TestIt [get]
|
// @router /TestIt [get]
|
||||||
func (c *TempOpController) TestIt() {
|
func (c *TempOpController) TestIt() {
|
||||||
c.callTestIt(func(params *tTempopTestItParams) (retVal interface{}, errCode string, err error) {
|
c.callTestIt(func(params *tTempopTestItParams) (retVal interface{}, errCode string, err error) {
|
||||||
shopList, err := api.EbaiAPI.ShopList(ebaiapi.SysStatusAll)
|
retVal, err = cms.OpenRemoteStoreByJxStatus(params.Ctx, nil, nil, false, true, true)
|
||||||
task := tasksch.NewParallelTask("tttt", nil, params.Ctx,
|
// shopList, err := api.EbaiAPI.ShopList(ebaiapi.SysStatusAll)
|
||||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
// task := tasksch.NewParallelTask("tttt", nil, params.Ctx,
|
||||||
shop := batchItemList[0].(*ebaiapi.ShopInfo)
|
// func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
skuInfo, err := api.EbaiAPI.SkuList(shop.ShopID, &ebaiapi.SkuListParams{})
|
// shop := batchItemList[0].(*ebaiapi.ShopInfo)
|
||||||
if err == nil && skuInfo.Total > 500 {
|
// skuInfo, err := api.EbaiAPI.SkuList(shop.ShopID, &ebaiapi.SkuListParams{})
|
||||||
errSkuCount := 0
|
// if err == nil && skuInfo.Total > 500 {
|
||||||
for _, sku := range skuInfo.List {
|
// errSkuCount := 0
|
||||||
if sku.CustomCatIDs == "" {
|
// for _, sku := range skuInfo.List {
|
||||||
errSkuCount++
|
// if sku.CustomCatIDs == "" {
|
||||||
}
|
// errSkuCount++
|
||||||
}
|
// }
|
||||||
if errSkuCount > len(skuInfo.List)/3 {
|
// }
|
||||||
retVal = []string{shop.ShopID}
|
// if errSkuCount > len(skuInfo.List)/3 {
|
||||||
}
|
// retVal = []string{shop.ShopID}
|
||||||
}
|
// }
|
||||||
return retVal, err
|
// }
|
||||||
}, shopList)
|
// return retVal, err
|
||||||
task.Run()
|
// }, shopList)
|
||||||
retVal, err = task.GetResult(0)
|
// task.Run()
|
||||||
|
// retVal, err = task.GetResult(0)
|
||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user