+ GetStoresSkus添加平台同步参数条件
+ GetStoreAbnoramlSkuCount + GetVendorStoreSkusInfo
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||||
@@ -201,7 +202,8 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
|||||||
sqlParams = append(sqlParams, skuIDs)
|
sqlParams = append(sqlParams, skuIDs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if isFocus && params["fromStatus"] != nil {
|
if isFocus {
|
||||||
|
if params["fromStatus"] != nil {
|
||||||
fromStatus := params["fromStatus"].(int)
|
fromStatus := params["fromStatus"].(int)
|
||||||
toStatus := fromStatus
|
toStatus := fromStatus
|
||||||
if params["toStatus"] != nil {
|
if params["toStatus"] != nil {
|
||||||
@@ -210,6 +212,23 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
|||||||
sql += " AND t4.status >= ? AND t4.status <= ?"
|
sql += " AND t4.status >= ? AND t4.status <= ?"
|
||||||
sqlParams = append(sqlParams, fromStatus, toStatus)
|
sqlParams = append(sqlParams, fromStatus, toStatus)
|
||||||
}
|
}
|
||||||
|
if params["jdSyncStatus"] != nil || params["ebaiSyncStatus"] != nil || params["mtwmSyncStatus"] != nil {
|
||||||
|
sql += "AND ( 1 = 0"
|
||||||
|
if params["jdSyncStatus"] != nil {
|
||||||
|
sql += " OR t4.jd_sync_status & ? <> 0"
|
||||||
|
sqlParams = append(sqlParams, params["jdSyncStatus"])
|
||||||
|
}
|
||||||
|
if params["ebaiSyncStatus"] != nil {
|
||||||
|
sql += " OR t4.ebai_sync_status & ? <> 0"
|
||||||
|
sqlParams = append(sqlParams, params["ebaiSyncStatus"])
|
||||||
|
}
|
||||||
|
if params["mtwmSyncStatus"] != nil {
|
||||||
|
sql += " OR t4.mtwm_sync_status & ? <> 0"
|
||||||
|
sqlParams = append(sqlParams, params["mtwmSyncStatus"])
|
||||||
|
}
|
||||||
|
sql += ")"
|
||||||
|
}
|
||||||
|
}
|
||||||
sql += `
|
sql += `
|
||||||
GROUP BY
|
GROUP BY
|
||||||
t1.id,
|
t1.id,
|
||||||
@@ -396,6 +415,30 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs []int, isFocus bool, keyword
|
|||||||
return skuNamesInfo, err
|
return skuNamesInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetStoreAbnoramlSkuCount(ctx *jxcontext.Context, storeID int) (count int, err error) {
|
||||||
|
db := dao.GetDB()
|
||||||
|
sql := `
|
||||||
|
SELECT COUNT(*) ct
|
||||||
|
FROM store_sku_bind t1
|
||||||
|
JOIN sku t2 ON t2.id = t1.sku_id AND t2.deleted_at = ?
|
||||||
|
JOIN sku_name t3 ON t3.id = t2.name_id AND t3.deleted_at = ?
|
||||||
|
WHERE t1.deleted_at = ? AND t1.store_id = ? AND
|
||||||
|
(t1.jd_sync_status <> 0 OR t1.ebai_sync_status <> 0 OR t1.mtwm_sync_status <> 0) AND
|
||||||
|
((t2.status = ? AND t3.status = ?) OR t1.status = ?)
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
storeID,
|
||||||
|
model.SkuStatusNormal,
|
||||||
|
model.SkuStatusNormal,
|
||||||
|
model.SkuStatusNormal,
|
||||||
|
}
|
||||||
|
err = dao.GetRow(db, &count, sql, sqlParams...)
|
||||||
|
return count, err
|
||||||
|
}
|
||||||
|
|
||||||
func GetStoresSkusSaleInfo(ctx *jxcontext.Context, storeIDs []int, skuIDs []int, fromTime, toTime time.Time, fromCount, toCount int) (saleInfoList []*SkuSaleInfo, err error) {
|
func GetStoresSkusSaleInfo(ctx *jxcontext.Context, storeIDs []int, skuIDs []int, fromTime, toTime time.Time, fromCount, toCount int) (saleInfoList []*SkuSaleInfo, err error) {
|
||||||
globals.SugarLogger.Debugf("GetStoresSkusSaleInfo storeIDs:%v, fromTime:%v, toTime:%v, fromCount:%d, toCount:%d", storeIDs, fromTime, toTime, fromCount, toCount)
|
globals.SugarLogger.Debugf("GetStoresSkusSaleInfo storeIDs:%v, fromTime:%v, toTime:%v, fromCount:%d, toCount:%d", storeIDs, fromTime, toTime, fromCount, toCount)
|
||||||
|
|
||||||
@@ -1459,3 +1502,36 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
|
|||||||
}
|
}
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetVendorStoreSkusInfo(ctx *jxcontext.Context, storeID int, vendorIDs, skuIDs []int, isContinueWhenError bool) (skuVendorMap map[int][]*partner.BareStoreSkuInfo, err error) {
|
||||||
|
globals.SugarLogger.Debugf("GetVendorStoreSkusInfo, storeID:%d, vendorIDs:%v, skuID:%v", storeID, vendorIDs, skuIDs)
|
||||||
|
db := dao.GetDB()
|
||||||
|
var locker sync.RWMutex
|
||||||
|
skuVendorMap = make(map[int][]*partner.BareStoreSkuInfo)
|
||||||
|
_, err = CurVendorSync.LoopStoresMap(ctx, db, fmt.Sprintf("GetVendorStoreSkusInfo:%d", storeID), false, false, vendorIDs, []int{storeID},
|
||||||
|
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||||
|
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||||
|
if handler := CurVendorSync.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
|
||||||
|
storeSkuList, err2 := dao.GetStoreSkus2(db, loopMapInfo.VendorID, storeID, skuIDs, false)
|
||||||
|
if err = err2; err == nil && len(storeSkuList) > 0 {
|
||||||
|
bareStoreSkuInfoList := make([]*partner.BareStoreSkuInfo, len(skuIDs))
|
||||||
|
for k, v := range storeSkuList {
|
||||||
|
bareStoreSkuInfoList[k] = &partner.BareStoreSkuInfo{
|
||||||
|
SkuID: v.SkuID,
|
||||||
|
VendorSkuID: v.VendorSkuID,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err = handler.GetStoreSkusInfo(ctx, t, loopMapInfo.StoreMapList[0].StoreID, loopMapInfo.StoreMapList[0].VendorStoreID, bareStoreSkuInfoList); err == nil {
|
||||||
|
locker.Lock()
|
||||||
|
defer locker.Unlock()
|
||||||
|
skuVendorMap[loopMapInfo.VendorID] = bareStoreSkuInfoList
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
skuVendorMap = nil
|
||||||
|
}
|
||||||
|
return skuVendorMap, stripSyncError(err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -586,6 +586,13 @@ func makeSyncError(err error) (newErr error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stripSyncError(err error) (newErr error) {
|
||||||
|
if syncErr, ok := err.(*SyncError); ok && syncErr != nil {
|
||||||
|
return syncErr.Original
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (e *SyncError) Error() string {
|
func (e *SyncError) Error() string {
|
||||||
return fmt.Sprintf("本地数据修改成功,但同步失败,请根据错误提示处理!,同步错误信息:%s", e.Original.Error())
|
return fmt.Sprintf("本地数据修改成功,但同步失败,请根据错误提示处理!,同步错误信息:%s", e.Original.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ func GetStoreCategories(db *DaoDB, vendorID, storeID int, level int) (cats []*Sk
|
|||||||
|
|
||||||
// 以store_sku_bind为基础来做同步,正常情况下使用
|
// 以store_sku_bind为基础来做同步,正常情况下使用
|
||||||
// 单多门店模式厂商通用
|
// 单多门店模式厂商通用
|
||||||
func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*StoreSkuSyncInfo, err error) {
|
func GetStoreSkus2(db *DaoDB, vendorID, storeID int, skuIDs []int, isDirty bool) (skus []*StoreSkuSyncInfo, err error) {
|
||||||
isSingleStorePF := model.MultiStoresVendorMap[vendorID] != 1
|
isSingleStorePF := model.MultiStoresVendorMap[vendorID] != 1
|
||||||
tableName := "t1"
|
tableName := "t1"
|
||||||
if !isSingleStorePF {
|
if !isSingleStorePF {
|
||||||
@@ -200,9 +200,15 @@ func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*Store
|
|||||||
LEFT JOIN store_sku_category_map t5sku ON t2.category_id = t5sku.category_id AND t5sku.store_id = t1.store_id AND t5sku.deleted_at = ?`
|
LEFT JOIN store_sku_category_map t5sku ON t2.category_id = t5sku.category_id AND t5sku.store_id = t1.store_id AND t5sku.deleted_at = ?`
|
||||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, utils.DefaultTimeValue)
|
sqlParams = append(sqlParams, utils.DefaultTimeValue, utils.DefaultTimeValue)
|
||||||
}
|
}
|
||||||
sql += " WHERE t1.store_id = ? AND (t1.%s_sync_status <> 0 OR (%s.%s_id <> 0 AND t3.id IS NULL))"
|
sql += " WHERE t1.store_id = ?"
|
||||||
fmtParams = append(fmtParams, fieldPrefix, tableName, fieldPrefix)
|
|
||||||
sqlParams = append(sqlParams, storeID)
|
sqlParams = append(sqlParams, storeID)
|
||||||
|
if isDirty {
|
||||||
|
sql += " AND (t1.%s_sync_status <> 0 OR (%s.%s_id <> 0 AND t3.id IS NULL))"
|
||||||
|
fmtParams = append(fmtParams, fieldPrefix, tableName, fieldPrefix)
|
||||||
|
} else {
|
||||||
|
sql += " AND t1.deleted_at = ?"
|
||||||
|
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||||
|
}
|
||||||
if len(skuIDs) > 0 {
|
if len(skuIDs) > 0 {
|
||||||
sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
sql += " AND t1.sku_id IN (" + GenQuestionMarks(len(skuIDs)) + ")"
|
||||||
sqlParams = append(sqlParams, skuIDs)
|
sqlParams = append(sqlParams, skuIDs)
|
||||||
@@ -220,6 +226,10 @@ func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*Store
|
|||||||
return skus, err
|
return skus, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetStoreSkus(db *DaoDB, vendorID, storeID int, skuIDs []int) (skus []*StoreSkuSyncInfo, err error) {
|
||||||
|
return GetStoreSkus2(db, vendorID, storeID, skuIDs, true)
|
||||||
|
}
|
||||||
|
|
||||||
// 以sku为基础来做全同步,
|
// 以sku为基础来做全同步,
|
||||||
// 多门店模式厂商适用
|
// 多门店模式厂商适用
|
||||||
func GetFullStoreSkus(db *DaoDB, vendorID, storeID int) (skus []*StoreSkuSyncInfo, err error) {
|
func GetFullStoreSkus(db *DaoDB, vendorID, storeID int) (skus []*StoreSkuSyncInfo, err error) {
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ type IPurchasePlatformHandler interface {
|
|||||||
GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error)
|
GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error)
|
||||||
|
|
||||||
GetStoresSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeIDs []int) (storeSkuList []*model.StoreSkuBind, err error)
|
GetStoresSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeIDs []int) (storeSkuList []*model.StoreSkuBind, err error)
|
||||||
|
GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*BareStoreSkuInfo) (outStoreSkuList []*BareStoreSkuInfo, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// db *dao.DaoDB,
|
// db *dao.DaoDB,
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package partner
|
package partner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
)
|
)
|
||||||
@@ -19,7 +20,7 @@ type BareStoreSkuInfo struct {
|
|||||||
NameID int `json:"nameID,omitempty"`
|
NameID int `json:"nameID,omitempty"`
|
||||||
VendorNameID string `json:"vendorNameID,omitempty"`
|
VendorNameID string `json:"vendorNameID,omitempty"`
|
||||||
|
|
||||||
Price int `json:"prrice,omitempty"`
|
Price int64 `json:"price,omitempty"`
|
||||||
Status int `json:"status,omitempty"`
|
Status int `json:"status,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +34,22 @@ func (l BareStoreSkuInfoList) GetVendorSkuIDList() (vendorSkuIDList []string) {
|
|||||||
return vendorSkuIDList
|
return vendorSkuIDList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l BareStoreSkuInfoList) GetVendorSkuIDIntList() (vendorSkuIDIntList []int64) {
|
||||||
|
vendorSkuIDIntList = make([]int64, len(l))
|
||||||
|
for k, v := range l {
|
||||||
|
vendorSkuIDIntList[k] = utils.Str2Int64(v.VendorSkuID)
|
||||||
|
}
|
||||||
|
return vendorSkuIDIntList
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l BareStoreSkuInfoList) GetSkuIDList() (skuIDList []int) {
|
||||||
|
skuIDList = make([]int, len(l))
|
||||||
|
for k, v := range l {
|
||||||
|
skuIDList[k] = v.SkuID
|
||||||
|
}
|
||||||
|
return skuIDList
|
||||||
|
}
|
||||||
|
|
||||||
type BareCategoryInfo struct {
|
type BareCategoryInfo struct {
|
||||||
VendorCatID string `json:"vendorCatID"`
|
VendorCatID string `json:"vendorCatID"`
|
||||||
|
|
||||||
|
|||||||
@@ -335,9 +335,11 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks
|
|||||||
return rootTask.ID, err
|
return rootTask.ID, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int, parentTask tasksch.ITask) (skus []map[string]interface{}, err error) {
|
func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int, parentTask tasksch.ITask) (skus []*ebaiapi.SkuInfo, err error) {
|
||||||
globals.SugarLogger.Debugf("ebai GetAllRemoteSkus storeID:%d, userName:%s", storeID, ctx.GetUserName())
|
globals.SugarLogger.Debugf("ebai GetAllRemoteSkus storeID:%d, userName:%s", storeID, ctx.GetUserName())
|
||||||
page1, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), utils.Params2Map("pagesize", MaxPageSize))
|
page1, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||||
|
PageSize: MaxPageSize,
|
||||||
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
skus = append(skus, page1.List...)
|
skus = append(skus, page1.List...)
|
||||||
if page1.Pages > 1 {
|
if page1.Pages > 1 {
|
||||||
@@ -347,9 +349,9 @@ func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int,
|
|||||||
}
|
}
|
||||||
task := tasksch.NewParallelTask("GetAllRemoteSkus", nil, ctx,
|
task := tasksch.NewParallelTask("GetAllRemoteSkus", nil, ctx,
|
||||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
callParams := map[string]interface{}{
|
callParams := &ebaiapi.SkuListParams{
|
||||||
"pagesize": MaxPageSize,
|
PageSize: MaxPageSize,
|
||||||
"page": batchItemList[0],
|
Page: batchItemList[0].(int),
|
||||||
}
|
}
|
||||||
pageSku, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), callParams)
|
pageSku, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), callParams)
|
||||||
if err2 == nil {
|
if err2 == nil {
|
||||||
@@ -362,7 +364,7 @@ func (p *PurchaseHandler) GetAllRemoteSkus(ctx *jxcontext.Context, storeID int,
|
|||||||
result, err2 := task.GetResult(0)
|
result, err2 := task.GetResult(0)
|
||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
for _, v := range result {
|
for _, v := range result {
|
||||||
skus = append(skus, v.(map[string]interface{}))
|
skus = append(skus, v.(*ebaiapi.SkuInfo))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -378,7 +380,7 @@ func (p *PurchaseHandler) DeleteRemoteSkus(ctx *jxcontext.Context, parentTask ta
|
|||||||
if err = err2; err == nil {
|
if err = err2; err == nil {
|
||||||
vendorSkuIDs = make([]string, len(result))
|
vendorSkuIDs = make([]string, len(result))
|
||||||
for k, v := range result {
|
for k, v := range result {
|
||||||
vendorSkuIDs[k] = utils.Interface2String(v[ebaiapi.KeySkuID])
|
vendorSkuIDs[k] = utils.Int64ToStr(v.SkuID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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/jxutils/jxcontext"
|
"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"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
@@ -190,3 +191,55 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[s
|
|||||||
}
|
}
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||||
|
vendorSkuIDIntList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
|
||||||
|
var vendorSkuList []*ebaiapi.SkuInfo
|
||||||
|
if len(inStoreSkuList) > 1 {
|
||||||
|
task := tasksch.NewParallelTask("获取饿百平台门店商品信息", nil, ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
vendorSkuID := batchItemList[0].(int64)
|
||||||
|
skuInfo, err := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||||
|
SkuID: vendorSkuID,
|
||||||
|
})
|
||||||
|
if err == nil {
|
||||||
|
vendorSkuList = skuInfo.List
|
||||||
|
return skuInfo.List, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}, vendorSkuIDIntList)
|
||||||
|
tasksch.HandleTask(task, parentTask, false).Run()
|
||||||
|
_, err = task.GetResult(0)
|
||||||
|
} else {
|
||||||
|
skuInfo, err2 := api.EbaiAPI.SkuList(utils.Int2Str(storeID), &ebaiapi.SkuListParams{
|
||||||
|
SkuID: utils.Str2Int64(inStoreSkuList[0].VendorSkuID),
|
||||||
|
})
|
||||||
|
if err = err2; err == nil {
|
||||||
|
vendorSkuList = skuInfo.List
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
|
||||||
|
for _, v := range inStoreSkuList {
|
||||||
|
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
|
||||||
|
}
|
||||||
|
for _, skuInfo := range vendorSkuList {
|
||||||
|
storeSku := storeSkuMap[skuInfo.SkuID]
|
||||||
|
storeSku.Price = skuInfo.SalePrice
|
||||||
|
storeSku.Status = ebaiSkuStatus2Jx(skuInfo.Status)
|
||||||
|
}
|
||||||
|
outStoreSkuList = inStoreSkuList
|
||||||
|
}
|
||||||
|
return outStoreSkuList, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func ebaiSkuStatus2Jx(ebaiSkuStatus int) (jxSkuStatus int) {
|
||||||
|
if ebaiSkuStatus == ebaiapi.SkuStatusOnline {
|
||||||
|
jxSkuStatus = model.SkuStatusNormal
|
||||||
|
} else if ebaiSkuStatus == ebaiapi.SkuStatusOffline {
|
||||||
|
jxSkuStatus = model.SkuStatusDontSale
|
||||||
|
} else if ebaiSkuStatus == ebaiapi.SkuStatusOnline {
|
||||||
|
jxSkuStatus = model.SkuStatusDeleted
|
||||||
|
}
|
||||||
|
return jxSkuStatus
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"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/jxutils/tasksch"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
func (p *PurchaseHandler) SyncStoreCategory(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync bool) (hint string, err error) {
|
||||||
@@ -29,3 +30,7 @@ func (p *PurchaseHandler) DeleteRemoteStoreSkus(ctx *jxcontext.Context, parentTa
|
|||||||
func (p *PurchaseHandler) GetStoresSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeIDs []int) (storeSkuList []*model.StoreSkuBind, err error) {
|
func (p *PurchaseHandler) GetStoresSku(ctx *jxcontext.Context, parentTask tasksch.ITask, storeIDs []int) (storeSkuList []*model.StoreSkuBind, err error) {
|
||||||
return storeSkuList, err
|
return storeSkuList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||||
|
return outStoreSkuList, err
|
||||||
|
}
|
||||||
|
|||||||
61
business/partner/purchase/jd/store_sku2.go
Normal file
61
business/partner/purchase/jd/store_sku2.go
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||||||
|
"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/partner"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||||
|
batchSkuInfoList := make([]*jdapi.BaseStockCenterRequest, len(inStoreSkuList))
|
||||||
|
batchSkuList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDIntList()
|
||||||
|
for k, v := range inStoreSkuList {
|
||||||
|
batchSkuInfoList[k] = &jdapi.BaseStockCenterRequest{
|
||||||
|
StationNo: vendorStoreID,
|
||||||
|
SkuId: utils.Str2Int64(v.VendorSkuID),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var stockInfo []*jdapi.QueryStockResponse
|
||||||
|
var priceInfo []*jdapi.StorePriceInfo
|
||||||
|
task := tasksch.NewParallelTask("获取京东到家平台门店商品信息", tasksch.NewParallelConfig().SetParallelCount(2), ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
subTaskID := batchItemList[0].(int)
|
||||||
|
if subTaskID == 0 {
|
||||||
|
stockInfo, err = api.JdAPI.QueryOpenUseable(batchSkuInfoList)
|
||||||
|
} else {
|
||||||
|
priceInfo, err = api.JdAPI.GetStationInfoList(vendorStoreID, batchSkuList)
|
||||||
|
globals.SugarLogger.Debug(utils.Format4Output(priceInfo, false))
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}, []int{0, 1})
|
||||||
|
tasksch.HandleTask(task, parentTask, false).Run()
|
||||||
|
_, err = task.GetResult(0)
|
||||||
|
if err == nil {
|
||||||
|
storeSkuMap := make(map[int64]*partner.BareStoreSkuInfo)
|
||||||
|
for _, v := range inStoreSkuList {
|
||||||
|
storeSkuMap[utils.Str2Int64(v.VendorSkuID)] = v
|
||||||
|
}
|
||||||
|
for _, v := range stockInfo {
|
||||||
|
storeSkuMap[v.SkuID].Status = jdStoreSkuStatus2Jx(v.Vendibility)
|
||||||
|
}
|
||||||
|
for _, v := range priceInfo {
|
||||||
|
storeSkuMap[v.SkuID].Price = v.Price
|
||||||
|
}
|
||||||
|
outStoreSkuList = inStoreSkuList
|
||||||
|
}
|
||||||
|
return outStoreSkuList, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func jdStoreSkuStatus2Jx(jdStoreSkuStatus int) (jxSkuStatus int) {
|
||||||
|
if jdStoreSkuStatus == 0 {
|
||||||
|
jxSkuStatus = model.SkuStatusNormal
|
||||||
|
} else {
|
||||||
|
jxSkuStatus = model.SkuStatusDontSale
|
||||||
|
}
|
||||||
|
return jxSkuStatus
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ 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/jxutils/jxcontext"
|
"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"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
@@ -191,7 +192,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
|||||||
Skus: []*mtwmapi.BareStoreSkuInfo{
|
Skus: []*mtwmapi.BareStoreSkuInfo{
|
||||||
&mtwmapi.BareStoreSkuInfo{
|
&mtwmapi.BareStoreSkuInfo{
|
||||||
SkuID: storeSku.VendorSkuID,
|
SkuID: storeSku.VendorSkuID,
|
||||||
Price: utils.Int2Str(storeSku.Price),
|
Price: utils.Int64ToStr(storeSku.Price),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -202,3 +203,50 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||||
|
vendorSkuIDList := partner.BareStoreSkuInfoList(inStoreSkuList).GetVendorSkuIDList()
|
||||||
|
var vendorFoodList []*mtwmapi.AppFood
|
||||||
|
if len(inStoreSkuList) > 1 {
|
||||||
|
task := tasksch.NewParallelTask("获取饿百平台门店商品信息", nil, ctx,
|
||||||
|
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||||
|
vendorSkuID := batchItemList[0].(string)
|
||||||
|
skuInfo, err := api.MtwmAPI.RetailGet(vendorStoreID, vendorSkuID)
|
||||||
|
if err == nil {
|
||||||
|
vendorFoodList = []*mtwmapi.AppFood{skuInfo}
|
||||||
|
return vendorFoodList, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}, vendorSkuIDList)
|
||||||
|
tasksch.HandleTask(task, parentTask, false).Run()
|
||||||
|
_, err = task.GetResult(0)
|
||||||
|
} else {
|
||||||
|
skuInfo, err2 := api.MtwmAPI.RetailGet(vendorStoreID, inStoreSkuList[0].VendorSkuID)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
vendorFoodList = []*mtwmapi.AppFood{skuInfo}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
storeSkuMap := make(map[string]*partner.BareStoreSkuInfo)
|
||||||
|
for _, v := range inStoreSkuList {
|
||||||
|
storeSkuMap[v.VendorSkuID] = v
|
||||||
|
}
|
||||||
|
for _, foodInfo := range vendorFoodList {
|
||||||
|
vendorSku := foodInfo.SkuList[0]
|
||||||
|
storeSku := storeSkuMap[vendorSku.SkuID]
|
||||||
|
storeSku.Price = jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(vendorSku.Price, 0))
|
||||||
|
storeSku.Status = mtwmSkuStatus2Jx(foodInfo.IsSoldOut)
|
||||||
|
}
|
||||||
|
outStoreSkuList = inStoreSkuList
|
||||||
|
}
|
||||||
|
return outStoreSkuList, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func mtwmSkuStatus2Jx(mtwmSkuStatus int) (jxSkuStatus int) {
|
||||||
|
if mtwmSkuStatus == 0 {
|
||||||
|
jxSkuStatus = model.SkuStatusNormal
|
||||||
|
} else {
|
||||||
|
jxSkuStatus = model.SkuStatusDontSale
|
||||||
|
}
|
||||||
|
return jxSkuStatus
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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/jxutils/jxcontext"
|
"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"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner"
|
"git.rosy.net.cn/jx-callback/business/partner"
|
||||||
@@ -185,3 +186,7 @@ func (p *PurchaseHandler) UpdateStoreSkusPrice(ctx *jxcontext.Context, storeID i
|
|||||||
err = fmt.Errorf("内部错误,微商城不支持UpdateStoreSkusPrice!")
|
err = fmt.Errorf("内部错误,微商城不支持UpdateStoreSkusPrice!")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) GetStoreSkusInfo(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, vendorStoreID string, inStoreSkuList []*partner.BareStoreSkuInfo) (outStoreSkuList []*partner.BareStoreSkuInfo, err error) {
|
||||||
|
return outStoreSkuList, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ type StoreSkuController struct {
|
|||||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||||
// @Param isBySku query bool false "是否按SKU分拆"
|
// @Param isBySku query bool false "是否按SKU分拆"
|
||||||
|
// @Param jdSyncStatus query int false "京东同步标识"
|
||||||
|
// @Param ebaiSyncStatus query int false "饿百同步标识"
|
||||||
|
// @Param mtwmSyncStatus query int false "美团外卖同步标识"
|
||||||
// @Success 200 {object} controllers.CallResult
|
// @Success 200 {object} controllers.CallResult
|
||||||
// @Failure 200 {object} controllers.CallResult
|
// @Failure 200 {object} controllers.CallResult
|
||||||
// @router /GetStoreSkus [get]
|
// @router /GetStoreSkus [get]
|
||||||
@@ -86,6 +89,41 @@ func (c *StoreSkuController) GetStoresSkus() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 得到异常门店商品数量
|
||||||
|
// @Description 得到异常门店商品数量
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param storeID query int true "门店ID"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /GetStoreAbnoramlSkuCount [get]
|
||||||
|
func (c *StoreSkuController) GetStoreAbnoramlSkuCount() {
|
||||||
|
c.callGetStoreAbnoramlSkuCount(func(params *tStoreSkuGetStoreAbnoramlSkuCountParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
retVal, err = cms.GetStoreAbnoramlSkuCount(params.Ctx, params.StoreID)
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Title 得到门店商品全信息
|
||||||
|
// @Description 得到异常门店商品数量
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param storeID query int true "门店ID"
|
||||||
|
// @Param vendorIDs query string false "厂商ID列表"
|
||||||
|
// @Param skuIDs query string true "Sku ID列表对象"
|
||||||
|
// @Param isContinueWhenError query bool false "单个同步失败是否继续,缺省false"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /GetVendorStoreSkusInfo [get]
|
||||||
|
func (c *StoreSkuController) GetVendorStoreSkusInfo() {
|
||||||
|
c.callGetVendorStoreSkusInfo(func(params *tStoreSkuGetVendorStoreSkusInfoParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
var vendorIDs, skuIDs []int
|
||||||
|
err = jxutils.Strings2Objs(params.VendorIDs, &vendorIDs, params.SkuIDs, &skuIDs)
|
||||||
|
if err == nil {
|
||||||
|
retVal, err = cms.GetVendorStoreSkusInfo(params.Ctx, params.StoreID, vendorIDs, skuIDs, params.IsContinueWhenError)
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// @Title 修改商家商品绑定
|
// @Title 修改商家商品绑定
|
||||||
// @Description 修改商家商品绑定,请换用UpdateStoresSkus
|
// @Description 修改商家商品绑定,请换用UpdateStoresSkus
|
||||||
// @Param token header string true "认证token"
|
// @Param token header string true "认证token"
|
||||||
|
|||||||
@@ -1195,6 +1195,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetStoreAbnoramlSkuCount",
|
||||||
|
Router: `/GetStoreAbnoramlSkuCount`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetStoreOpRequests",
|
Method: "GetStoreOpRequests",
|
||||||
@@ -1231,6 +1240,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetVendorStoreSkusInfo",
|
||||||
|
Router: `/GetVendorStoreSkusInfo`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "HandleStoreOpRequest",
|
Method: "HandleStoreOpRequest",
|
||||||
|
|||||||
Reference in New Issue
Block a user