方法移动到check文件

This commit is contained in:
qidongsheng
2020-06-19 14:18:56 +08:00
39 changed files with 1446 additions and 408 deletions

View File

@@ -412,7 +412,7 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
db := dao.GetDB()
switch configType {
case model.ConfigTypePricePack:
storeMapList, err2 := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key)
storeMapList, err2 := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key, "")
if err = err2; err == nil {
var storeInfo []string
for _, v := range storeMapList {
@@ -423,7 +423,7 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
}
}
case model.ConfigTypeFreightPack:
storeMapList, err2 := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
storeMapList, err2 := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "")
if err = err2; err == nil {
var storeInfo []string
for _, v := range storeMapList {
@@ -503,7 +503,7 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
}
switch configType {
case model.ConfigTypePricePack:
storeMapList, err := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key)
storeMapList, err := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, key, "")
if err != nil {
dao.Rollback(db)
return "", err
@@ -522,7 +522,7 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
}
case model.ConfigTypeFreightPack:
dao.Commit(db)
storeMapList, err := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
storeMapList, err := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "")
if err != nil {
return "", err
}

View File

@@ -595,7 +595,8 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
t1.ex_prefix,
t1.ex_prefix_begin,
t1.ex_prefix_end,
t1.yb_name_suffix
t1.yb_name_suffix,
t1.jds_stock_switch
`
if isQueryMidPrice {
sql += `,
@@ -635,6 +636,7 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
t1.ex_prefix_begin,
t1.ex_prefix_end,
t1.yb_name_suffix,
t1.jds_stock_switch,
`
if isQueryMidPrice {
sqlData += " t4.mid_unit_price,"
@@ -992,6 +994,12 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
dao.Rollback(db)
return 0, err
}
if valid["jdsStockSwitch"] != nil {
if _, err = SetStoreSkuSyncStatus2(db, []int{model.JdShopMainStoreID}, []int{model.VendorIDJDShop}, skuIDs, model.SyncFlagSaleMask); err != nil {
dao.Rollback(db)
return 0, err
}
}
}
dao.Commit(db)
@@ -1124,7 +1132,7 @@ func AddSku(ctx *jxcontext.Context, nameID int, sku *model.Sku, userName string)
storeSkus, err := dao.GetStoreSkusByNameIDs(db, []int{model.JdShopMainStoreID}, nameID)
if len(storeSkus) > 0 {
storeIDs := make(map[int]int)
storeMaps, err2 := dao.GetStoresMapList(db, []int{model.VendorIDJDShop}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
storeMaps, err2 := dao.GetStoresMapList(db, []int{model.VendorIDJDShop}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
err = err2
for _, v := range storeMaps {
storeSkus2, err2 := dao.GetStoreSkusByNameIDs(db, []int{v.StoreID}, nameID)

View File

@@ -78,55 +78,6 @@ type StoreExt struct {
OrderCount int `json:"orderCount"`
}
type Store4User struct {
model.ModelIDCULD
OriginalName string `orm:"-" json:"originalName"`
Name string `orm:"size(255)" json:"name"`
OpenTime1 int16 `json:"openTime1"` // 930就表示9点半用两个的原因是为了支持中午休息1与2的时间段不能交叉为0表示没有
CloseTime1 int16 `json:"closeTime1"` // 格式同上
OpenTime2 int16 `json:"openTime2"` // 格式同上
CloseTime2 int16 `json:"closeTime2"` // 格式同上
Status int `json:"status"`
CityCode int `orm:"default(0);null" json:"cityCode"` // todo ?
DistrictCode int `orm:"default(0);null" json:"districtCode"` // todo ?
Address string `orm:"size(255)" json:"address"`
Tel1 string `orm:"size(32);index" json:"tel1"`
Tel2 string `orm:"size(32);index" json:"tel2"`
Lng int `json:"-"` // 乘了10的6次方
Lat int `json:"-"` // 乘了10的6次方
DeliveryRangeType int8 `json:"-"` // 参见相关常量定义
DeliveryRange string `orm:"type(text)" json:"-"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon则为逗号分隔坐标分号分隔的坐标点坐标与Lng和Lat一样都是整数比如 121361504,31189308;121420555,31150238。否则为半径单位为米
FloatLng float64 `json:"lng"`
FloatLat float64 `json:"lat"`
CityName string `json:"cityName"`
DistrictName string `json:"districtName"`
Distance int `json:"distance"`
WalkDistance int `json:"walkDistance"`
}
type Store4UserList []*Store4User
func (x Store4UserList) Len() int {
return len(x)
}
func (x Store4UserList) Less(i, j int) bool {
if x[i].Status != x[j].Status {
return x[i].Status > x[j].Status
}
if x[i].WalkDistance != x[j].WalkDistance {
return x[i].WalkDistance < x[j].WalkDistance
}
return x[i].Distance < x[j].Distance
}
func (x Store4UserList) Swap(i, j int) {
x[i], x[j] = x[j], x[i]
}
type StoresInfo struct {
TotalCount int `json:"totalCount"`
MapCenterLng float64 `json:"mapCenterLng"`
@@ -426,7 +377,7 @@ func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]inte
}
func setStoreMapInfo(ctx *jxcontext.Context, db *dao.DaoDB, storesInfo *StoresInfo, storeIDs []int, briefLevel int) (err error) {
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
if err != nil {
return err
}
@@ -1194,7 +1145,7 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
}
}
}
storeMapList, err := dao.GetStoresMapList2(db, []int{vendorID}, []int{storeID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", true)
storeMapList, err := dao.GetStoresMapList2(db, []int{vendorID}, []int{storeID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", true)
if len(storeMapList) > 0 {
_, err = CurVendorSync.SyncStore(ctx, db, storeMap.VendorID, storeID, false, userName)
} else {
@@ -1806,7 +1757,7 @@ type EbaiStoreHealthy struct {
func ExportShopsHealthInfo(ctx *jxcontext.Context, vendorIDs, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
vendorID := model.VendorIDEBAI
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "")
if err != nil {
return "", err
}
@@ -1924,7 +1875,7 @@ func GetCorporationInfo(ctx *jxcontext.Context, licenceCode string) (corporation
func GetStoresVendorSnapshot(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorIDs, storeIDs []int) (vendorStoreSnapshotList []*model.VendorStoreSnapshot, err error) {
db := dao.GetDB()
storeMapList, err := dao.GetStoresMapList(db, vendorIDs, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
storeMapList, err := dao.GetStoresMapList(db, vendorIDs, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "")
if err != nil {
return nil, err
}
@@ -1971,7 +1922,7 @@ func getCurrentSnapshotAt(now time.Time) (snapshotAt time.Time) {
}
func updateVendorStoreStatusBySnapshot(db *dao.DaoDB, curSnapshotList []*model.VendorStoreSnapshot) (err error) {
storeMapList, err := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
storeMapList, err := dao.GetStoresMapList(db, nil, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
if err != nil {
return err
}
@@ -2482,98 +2433,6 @@ func SyncStoresQualify(ctx *jxcontext.Context, storeIDs []int, isAsync, isContin
return hint, err
}
func GetStoreListByLocation(ctx *jxcontext.Context, lng, lat float64, needWalkDistance bool) (storeList []*Store4User, err error) {
const (
maxRadius = 20000
maxStoreCount4User = 5
)
lng2, _ := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 90)
_, lat2 := jxutils.ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 0)
lng1 := lng - (lng2 - lng)
lat1 := lat - (lat2 - lat)
// globals.SugarLogger.Debugf("%f,%f,%f,%f\n", lng1, lng2, lat1, lat2)
sql := `
SELECT t1.*,
city.name city_name
FROM store t1
JOIN place city ON city.code = t1.city_code
JOIN store_map sm ON sm.store_id = t1.id AND sm.vendor_id = ? AND sm.deleted_at = ? AND sm.status <> ?
WHERE t1.deleted_at = ? AND t1.status <> ? AND t1.lng > ? AND t1.lng < ? AND t1.lat > ? AND t1.lat < ?
AND sm.is_order <> ?
AND t1.id <> ?
ORDER BY t1.id
`
sqlParams := []interface{}{
model.VendorIDJX, utils.DefaultTimeValue, model.StoreStatusDisabled,
utils.DefaultTimeValue, model.StoreStatusDisabled, jxutils.StandardCoordinate2Int(lng1), jxutils.StandardCoordinate2Int(lng2), jxutils.StandardCoordinate2Int(lat1), jxutils.StandardCoordinate2Int(lat2),
model.YES,
model.MatterStoreID,
}
var storeList1 []*Store4User
if err = dao.GetRows(dao.GetDB(), &storeList1, sql, sqlParams...); err == nil {
var storeList2 []*Store4User
for _, v := range storeList1 {
distance := jxutils.Point2StoreDistance(lng, lat, v.Lng, v.Lat, v.DeliveryRangeType, v.DeliveryRange)
if distance > 0 || (lng == jxutils.IntCoordinate2Standard(v.Lng) && lat == jxutils.IntCoordinate2Standard(v.Lat)) {
v.Distance = distance
storeList2 = append(storeList2, v)
}
}
// 为了审核用
if len(storeList2) == 0 {
sql2 := `
SELECT t1.*,
city.name city_name
FROM store t1
JOIN place city ON city.code = t1.city_code
WHERE t1.deleted_at = ? AND t1.status <> ? AND t1.id = ?
`
sqlParams2 := []interface{}{
// model.VendorIDJX, utils.DefaultTimeValue, model.StoreStatusDisabled,
utils.DefaultTimeValue,
model.StoreStatusDisabled,
// jxutils.StandardCoordinate2Int(0),
// jxutils.StandardCoordinate2Int(10000),
// jxutils.StandardCoordinate2Int(0),
// jxutils.StandardCoordinate2Int(10000),
// model.YES,
102919, //商城模板店
}
dao.GetRows(dao.GetDB(), &storeList2, sql2, sqlParams2...)
// if len(storeList2) > 1 {
// storeList2 = storeList2[:1]
// }
}
// 如果要求以步行距离来算
if needWalkDistance {
var coordList []*autonavi.Coordinate
for _, v := range storeList2 {
coordList = append(coordList, &autonavi.Coordinate{
Lng: v.FloatLng,
Lat: v.FloatLat,
})
}
if distanceList, err2 := api.AutonaviAPI.BatchWalkingDistance(lng, lat, coordList); err2 == nil {
for k, v := range storeList2 {
v.WalkDistance = int(distanceList[k])
}
} else {
return nil, err2
}
}
sort.Sort(Store4UserList(storeList2))
storeList = storeList2
if len(storeList) > maxStoreCount4User {
storeList = storeList[:maxStoreCount4User]
}
}
return storeList, err
}
func JdStoreInfoCoordinateRecover(ctx *jxcontext.Context, vendorOrgCode string, files []*multipart.FileHeader) (err error) {
if len(files) == 0 {
return errors.New("没有文件上传!")
@@ -2583,7 +2442,7 @@ func JdStoreInfoCoordinateRecover(ctx *jxcontext.Context, vendorOrgCode string,
defer file1.Close()
db := dao.GetDB()
storeList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
storeList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "")
if err == nil {
var validStoreList []*dao.StoreDetail
for _, v := range storeList {
@@ -2849,7 +2708,7 @@ func CreateStorePriceScore(ctx *jxcontext.Context) (err error) {
func RefreshJdLevel(ctx *jxcontext.Context) (err error) {
db := dao.GetDB()
storeMapList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, nil, model.StoreStatusOpened, -1, "")
storeMapList, err := dao.GetStoresMapList(db, []int{model.VendorIDJD}, nil, nil, model.StoreStatusOpened, -1, "", "")
if len(storeMapList) > 0 {
dao.Begin(db)
defer func() {
@@ -3036,7 +2895,7 @@ func checkYbParams(db *dao.DaoDB, storeMap *model.StoreMap, storeID int) (err er
}
}
}
storeMaps, err := dao.GetStoresMapList2(db, []int{model.VendorIDYB}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", false)
storeMaps, err := dao.GetStoresMapList2(db, []int{model.VendorIDYB}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", false)
if len(storeMaps) > 0 {
for _, v := range storeMaps {
if v.YbAppID == appID {
@@ -3121,7 +2980,7 @@ func DisabledStoreWithoutVendor(ctx *jxcontext.Context, isContinueWhenError, isA
task := tasksch.NewParallelTask("DisabledStoreWithoutVendor", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
store := batchItemList[0].(*model.Store)
storeMaps, err := dao.GetStoresMapList(db, []int{model.VendorIDYB, model.VendorIDJD, model.VendorIDJX, model.VendorIDEBAI, model.VendorIDMTWM}, []int{store.ID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
storeMaps, err := dao.GetStoresMapList(db, []int{model.VendorIDYB, model.VendorIDJD, model.VendorIDJX, model.VendorIDEBAI, model.VendorIDMTWM}, []int{store.ID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
if len(storeMaps) == 0 {
store.Status = model.StoreStatusDisabled
dao.UpdateEntity(db, store, "Status")

View File

@@ -96,6 +96,7 @@ type tStoreSkuBindAndSpec struct {
ExdSkuID string `orm:"column(exd_sku_id)"`
StoreName string
ChangePriceType int8 `json:"changePriceType"` // 修改价格类型,即是否需要审核
NameID int `orm:"column(name_id)" json:"nameID"`
}
type SkuSaleInfo struct {
@@ -128,6 +129,7 @@ type tGetStoresSkusInfo struct {
dao.StoreSkuExt
RealMidUnitPrice int `json:"realMidUnitPrice"` //真实的该商品的全国中位价
YbSkuName string
AuditUnitPrice int
}
type SheetParam struct {
@@ -312,11 +314,13 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
JOIN store_sku_bind t4 ON t4.store_id = t3.id AND t4.sku_id = t2.id AND t4.deleted_at = ?
LEFT JOIN sku_name_place_bind t5 ON t1.id = t5.name_id AND t3.city_code = t5.place_code
LEFT JOIN price_refer_snapshot t6 ON t6.city_code = ? AND t6.sku_id = t2.id AND t6.snapshot_at = ?
LEFT JOIN store_sku_audit t7 ON t7.store_id = t3.id AND t7.name_id = t1.id AND t7.status = ? AND t7.deleted_at = ?
WHERE t1.deleted_at = ? AND (t1.is_global = 1 OR t5.id IS NOT NULL OR 1 = ?)/* AND t1.status = ?*/
`
sqlParams = append(sqlParams, []interface{}{
utils.DefaultTimeValue,
0, utils.Time2Date(time.Now().AddDate(0, 0, -1)),
model.StoreAuditStatusOnline, utils.DefaultTimeValue,
utils.DefaultTimeValue,
utils.Bool2Int(isFocus),
})
@@ -544,7 +548,8 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, i
t4.jd_price, t4.ebai_price, t4.mtwm_price, t4.jx_price, t4.yb_price, t4.jds_price,
t4.jd_lock_time, t4.ebai_lock_time, t4.mtwm_lock_time, t4.jx_lock_time, t4.yb_lock_time, t4.jds_lock_time,
t4.status_sale_begin, t4.status_sale_end,
t6.mid_unit_price real_mid_unit_price
t6.mid_unit_price real_mid_unit_price,
t7.unit_price audit_unit_price
` + sql
if isHighPrice || priceType != 0 {
sql += " , t4.unit_price DESC LIMIT 99"
@@ -573,6 +578,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, i
PayPercentage: v.PayPercentage,
RealMidUnitPrice: v.RealMidUnitPrice,
YbSkuName: v.YbSkuName,
AuditUnitPrice: v.AuditUnitPrice,
}
if !isBySku {
storeNameMap[index] = storeName
@@ -702,7 +708,7 @@ func updateSaleInfo4StoreSkuName(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
}
func getValidStoreVendorMap(db *dao.DaoDB, storeIDs []int) (realVendorMap map[int]int, err error) {
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "")
if err != nil {
return nil, err
}
@@ -832,29 +838,43 @@ func UpdateStoreSku(ctx *jxcontext.Context, causeFlag, storeID int, skuBindInfo
}
func UpdateStoreSkus(ctx *jxcontext.Context, causeFlag, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
return UpdateStoresSkus(ctx, causeFlag, []int{storeID}, skuBindInfos, false, isAsync, isContinueWhenError)
return UpdateStoresSkus(ctx, causeFlag, []int{storeID}, skuBindInfos, false, false, isAsync, isContinueWhenError)
}
func UpdateStoresSkus(ctx *jxcontext.Context, causeFlag int, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isAsync, isContinueWhenError bool) (hint string, err error) {
func UpdateStoresSkus(ctx *jxcontext.Context, causeFlag int, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isRefreshHigh, isAsync, isContinueWhenError bool) (hint string, err error) {
globals.SugarLogger.Debugf("UpdateStoresSkus:%s, storeIDs:%v, skuBindInfos:%s", ctx.GetTrackInfo(), storeIDs, utils.Format4Output(skuBindInfos, true))
var num int64
db := dao.GetDB()
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale)
if err != nil {
return "", err
}
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
num = int64(len(skuIDs))
if num > 0 {
hint, err = CurVendorSync.SyncStoresSkus(ctx, nil, causeFlag, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
}
if num == 0 || !isAsync || hint == "" {
hint = utils.Int64ToStr(num)
flag, err := doStoreSkuAudit(ctx, storeIDs, skuBindInfos)
if !flag {
var num int64
db := dao.GetDB()
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale, isRefreshHigh)
if err != nil {
return "", err
}
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
num = int64(len(skuIDs))
if num > 0 {
hint, err = CurVendorSync.SyncStoresSkus(ctx, nil, causeFlag, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
}
if num == 0 || !isAsync || hint == "" {
hint = utils.Int64ToStr(num)
}
}
return hint, err
}
func UpdateStoresSkusWithoutSync(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isRefreshHigh bool) (err error) {
db := dao.GetDB()
if len(storeIDs) == 0 {
stores, _ := dao.GetStoreList(db, nil, nil, nil, nil, "")
for _, v := range stores {
storeIDs = append(storeIDs, v.ID)
}
}
updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, false, isRefreshHigh)
return err
}
func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError, isFos bool) (hint string, err error) {
// if len(skuBindInfos) > maxStoreNameBind {
// return "", fmt.Errorf("门店商品信息大于%d", maxStoreNameBind)
@@ -880,7 +900,7 @@ func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, sk
// }
// }()
for _, storeID := range storeIDs {
skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID], false)
skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID], false, false)
if err = err2; err != nil {
// dao.Rollback(db)
return "", err
@@ -960,7 +980,7 @@ func uniqueStoreNameBind(skuBindInfos []*StoreSkuBindInfo) (outSkuBindInfos []*S
return outSkuBindInfos
}
func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale bool) (needSyncSkus []int, err error) {
func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isRefreshHigh bool) (needSyncSkus []int, err error) {
// if len(storeIDs)*len(skuBindInfos) > maxStoreNameBind2 {
// return nil, fmt.Errorf("门店商品信息大于%d", maxStoreNameBind2)
// }
@@ -976,9 +996,6 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
// if err = checkStoresSkusSaleCity(ctx, db, storeIDs, skuBindInfos); err != nil {
// return nil, err
// }
// if storeIDs, skuBindInfos, err = filterStorePriceChange(ctx, storeIDs, skuBindInfos); err != nil {
// return nil, err
// }
// globals.SugarLogger.Debugf("updateStoresSkusWithoutSync2, storeIDs:%v, skuBindInfos:%s", storeIDs, utils.Format4Output(skuBindInfos, false))
isUserCanDirectChangePrice := true
if user := ctx.GetFullUser(); user != nil {
@@ -1018,7 +1035,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
sql += " IF(t5.unit_price > 0, t5.unit_price, t3.price) sku_name_price,"
}
sql += `
t3.unit sku_name_unit, t3.name, t3.status sku_name_status,
t3.unit sku_name_unit, t3.name, t3.status sku_name_status, t3.id name_id,
ts.change_price_type, ts.name store_name
FROM sku t1
JOIN store ts ON ts.id = ? AND ts.deleted_at = ?
@@ -1139,6 +1156,15 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
dao.Rollback(db)
return nil, err
}
//删除待审核商品信息
storeAudits, err := dao.GetStoreSkuAuditLight(db, []int{storeID}, []int{v.NameID}, model.StoreAuditStatusOnline)
if len(storeAudits) > 0 {
storeAudits[0].DeletedAt = time.Now()
if _, err = dao.UpdateEntity(db, storeAudits[0], "DeletedAt"); err != nil {
dao.Rollback(db)
return nil, err
}
}
} else {
// 用了SELECT FOR UPDATE后只更新修改字段是没有必要的暂时保留
updateFieldMap := make(map[string]interface{})
@@ -1168,11 +1194,21 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
setStoreSkuBindStatus(skuBind, model.SyncFlagPriceMask)
updateFieldMap["Price"] = 1
}
skuBind.UnitPrice = unitPrice
skuBind.Price = price
skuBind.JxPrice = jxPrice
updateFieldMap["UnitPrice"] = 1
updateFieldMap["JxPrice"] = 1
if isRefreshHigh {
if beforeMsg.UnitPrice > skuBindInfo.UnitPrice {
skuBind.UnitPrice = unitPrice
skuBind.Price = price
skuBind.JxPrice = jxPrice
updateFieldMap["UnitPrice"] = 1
updateFieldMap["JxPrice"] = 1
}
} else {
skuBind.UnitPrice = unitPrice
skuBind.Price = price
skuBind.JxPrice = jxPrice
updateFieldMap["UnitPrice"] = 1
updateFieldMap["JxPrice"] = 1
}
}
}
if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 {
@@ -1851,7 +1887,7 @@ func AcceptStoreOpRequests(ctx *jxcontext.Context, reqIDs []int) (err error) {
}
}
if err2 == nil {
_, err2 := UpdateStoresSkus(ctx, 0, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false)
_, err2 := UpdateStoresSkus(ctx, 0, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false, false)
isLocalSucess := true
if err2 != nil {
subErrors[reqID] = err2
@@ -2067,7 +2103,7 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
return "", fmt.Errorf("此功能当前只支持京东到家平台")
}
db := dao.GetDB()
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
if err != nil {
return "", err
}
@@ -2570,7 +2606,7 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int, isCountry
}
}
}
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false)
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false, false)
}
if err == nil {
CreateStorePriceScore(ctx)
@@ -2712,7 +2748,7 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
skuBindInfoList = append(skuBindInfoList, v.(*StoreSkuBindInfo))
}
if isErr {
UpdateStoresSkus(ctx, 0, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError)
UpdateStoresSkus(ctx, 0, storeIDs, skuBindInfoList, false, false, isAsync, isContinueWhenError)
}
case 3:
//写Excel
@@ -3372,7 +3408,7 @@ func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync
if isSync {
UpdateStoreSkus(ctx, 0, v.StoreID, skuBindInfoList, true, true)
} else {
updateStoresSkusWithoutSync(ctx, db, []int{v.StoreID}, skuBindInfoList, false)
updateStoresSkusWithoutSync(ctx, db, []int{v.StoreID}, skuBindInfoList, false, false)
}
}
return err
@@ -3479,7 +3515,7 @@ func SendSeckillSkusCountMsg(ctx *jxcontext.Context, vendorIDs []int, isAsync, i
ddMsgresult []interface{}
)
db := dao.GetDB()
storeList, err := dao.GetStoresMapList(db, vendorIDs, nil, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, model.StoreStatusOpened, model.StoreIsSyncAll, "")
storeList, err := dao.GetStoresMapList(db, vendorIDs, nil, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, model.StoreStatusOpened, model.StoreIsSyncAll, "", "")
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
switch step {
case 0:
@@ -4076,7 +4112,7 @@ func RefreshMatterStock(ctx *jxcontext.Context, skuID int) (err error) {
}
}
//物料店666666
updateStoresSkusWithoutSync(ctx, db, []int{666666}, skuBindInfos, false)
updateStoresSkusWithoutSync(ctx, db, []int{666666}, skuBindInfos, false, false)
return err
}
@@ -4424,7 +4460,7 @@ func focusC4Matters(ctx *jxcontext.Context, db *dao.DaoDB, v *model.Sku) (err er
}
skuBindInfos = append(skuBindInfos, skuBindInfo)
}
updateStoresSkusWithoutSync(ctx, db, []int{model.MatterStoreID}, skuBindInfos, false)
updateStoresSkusWithoutSync(ctx, db, []int{model.MatterStoreID}, skuBindInfos, false, false)
}
return err
}
@@ -4443,24 +4479,190 @@ func RefreshJdsSkusStatus(ctx *jxcontext.Context) (err error) {
return err
}
func GetStoreSkuAudit(ctx *jxcontext.Context, storeIDs, nameIDs, skuIDs []int, status int, name, remark string, applyTimeStart, applyTimeEnd, auditTimeStart, auditTimeEnd time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
pagedInfo, err = dao.GetStoreSkuAudit(dao.GetDB(), storeIDs, nameIDs, skuIDs, status, name, remark, applyTimeStart, applyTimeEnd, auditTimeStart, auditTimeEnd, pageSize, offset)
func GetStoreSkuAudit(ctx *jxcontext.Context, storeIDs, nameIDs, skuIDs, statuss, types []int, name, remark, keyword, cityName, marketManPhone, applyTimeStart, applyTimeEnd, auditTimeStart, auditTimeEnd string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
var (
applyTimeStartp, applyTimeEndp, auditTimeStartp, auditTimeEndp time.Time
)
if applyTimeStart != "" {
applyTimeStartp = utils.Str2Time(applyTimeStart)
}
if applyTimeEnd != "" {
applyTimeEndp = utils.Str2Time(applyTimeEnd)
}
if auditTimeStart != "" {
auditTimeStartp = utils.Str2Time(auditTimeStart)
}
if auditTimeEnd != "" {
auditTimeEndp = utils.Str2Time(auditTimeEnd)
}
pagedInfo, err = dao.GetStoreSkuAudit(dao.GetDB(), storeIDs, nameIDs, skuIDs, statuss, types, name, remark, keyword, marketManPhone, cityName, applyTimeStartp, applyTimeEndp, auditTimeStartp, auditTimeEndp, pageSize, offset)
return pagedInfo, err
}
func SetJxPrice(jxSkuInfoDataMulti *dao.StoreSkuNamesInfo,storeId int) (err error){
func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo) (isAudit bool, err error) {
globals.SugarLogger.Debugf("doStoreSkuAudit storeIDs: %v", storeIDs)
time.Sleep(time.Second / 5)
db := dao.GetDB()
storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeId, model.VendorIDJX)
if err != nil {
dao.Rollback(db)
return err
}
/*重新计算京西价格*/
for _,values := range jxSkuInfoDataMulti.SkuNames{
for _,value := range values.Skus{
value.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), value.JxPrice)
for _, storeID := range storeIDs {
for _, skuBindInfo := range skuBindInfos {
globals.SugarLogger.Debugf("doStoreSkuAudit storeID: %v , nameID: %v", storeID, skuBindInfo.NameID)
storeAudits, err := dao.GetStoreSkuAuditLight(db, []int{storeID}, []int{skuBindInfo.NameID}, model.StoreAuditStatusOnline)
//取消关注,可售排除
if skuBindInfo.IsFocus == -1 || skuBindInfo.IsSale != 0 || skuBindInfo.UnitPrice == 0 {
globals.SugarLogger.Debugf("doStoreSkuAudit return1 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
return false, err
}
//运营排除
// if (ctx.GetFullUser().Type & model.UserTypeOperator) != 0 {
// if len(storeAudits) > 0 {
// storeAudits[0].DeletedAt = time.Now()
// dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
// }
// globals.SugarLogger.Debugf("doStoreSkuAudit return2 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
// return false, err
// }
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini {
if len(storeAudits) > 0 {
storeAudits[0].DeletedAt = time.Now()
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
if globals.IsProductEnv() {
skuAndNames, err := dao.GetSkus(db, nil, []int{skuBindInfo.NameID}, nil, nil, nil)
if len(skuAndNames) > 0 && err == nil {
weixinmsg.NotifyStoreOpRequestStatus(true, storeID, skuBindInfo.NameID, jxutils.ComposeSpuName(skuAndNames[0].Prefix, skuAndNames[0].Name, 0), storeAudits[0].OriginUnitPrice, skuBindInfo.UnitPrice, "")
}
}
}
globals.SugarLogger.Debugf("doStoreSkuAudit return3 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
return false, err
}
storeSkuAudit := &model.StoreSkuAudit{
StoreID: storeID,
NameID: skuBindInfo.NameID,
Status: model.StoreAuditStatusOnline,
UnitPrice: skuBindInfo.UnitPrice,
}
//如果是关注改价
if skuBindInfo.IsFocus == 1 {
if len(storeAudits) > 0 {
storeAudits[0].DeletedAt = time.Now()
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
}
storeSkuAudit.Type = model.StoreSkuAuditTypeFocus
} else {
storeSkus, err := dao.GetStoreSkusByNameIDs(db, []int{storeID}, skuBindInfo.NameID)
if len(storeSkus) > 0 {
//如果改的价比原价低排除
if skuBindInfo.UnitPrice <= int(storeSkus[0].UnitPrice) {
if len(storeAudits) > 0 {
storeAudits[0].DeletedAt = time.Now()
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
}
globals.SugarLogger.Debugf("doStoreSkuAudit return4 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
return false, err
} else {
if len(storeAudits) > 0 {
storeAudits[0].DeletedAt = time.Now()
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
}
globals.SugarLogger.Debugf("doStoreSkuAudit cover storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
}
} else {
return false, fmt.Errorf("未查询到该门店商品价storeID: %v, nameID: %V", storeID, skuBindInfo.NameID)
}
storeSkuAudit.Type = model.StoreSkuAuditTypePrice
storeSkuAudit.OriginUnitPrice = int(storeSkus[0].UnitPrice)
}
dao.WrapAddIDCULDEntity(storeSkuAudit, ctx.GetUserName())
err = dao.CreateEntity(db, storeSkuAudit)
}
}
/*重新计算京西价格*/
return nil
}
return true, err
}
func StoreSkuPriceAudit(ctx *jxcontext.Context, storeSkuAudits []*model.StoreSkuAudit, status int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
if status == model.StoreAuditStatusOnline {
return "", fmt.Errorf("审核标志不正确!")
}
task := tasksch.NewParallelTask("StoreSkuPriceAudit", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeAudit := batchItemList[0].(*model.StoreSkuAudit)
storeAudits, err := dao.GetStoreSkuAuditLight(db, []int{storeAudit.StoreID}, []int{storeAudit.NameID}, model.StoreAuditStatusOnline)
if len(storeAudits) == 0 || err != nil {
return retVal, fmt.Errorf("未查询到该门店该商品的待审核信息storeID: %v, nameID: %v", storeAudit.StoreID, storeAudit.NameID)
}
if len(storeAudits) > 1 {
return retVal, fmt.Errorf("查询到该门店该商品的待审核信息大于1条storeID: %v, nameID: %v", storeAudit.StoreID, storeAudit.NameID)
}
flag := false
//审核通过
if status == model.StoreAuditStatusCreated {
flag = true
storeAudits[0].UserID = ctx.GetUserID()
storeAudits[0].Status = model.StoreAuditStatusCreated
storeAudits[0].Remark = storeAudit.Remark
storeAudits[0].AuditPrice = storeAudit.AuditPrice
_, err = dao.UpdateEntity(db, storeAudits[0], "UserID", "Status", "Remark", "AuditPrice")
var skuBindInfos = []*StoreSkuBindInfo{
&StoreSkuBindInfo{
NameID: storeAudit.NameID,
UnitPrice: storeAudits[0].UnitPrice,
},
}
//证明填了额外的审核价格
if storeAudit.AuditPrice != 0 {
skuBindInfos[0].UnitPrice = storeAudit.AuditPrice
}
//如果是关注改价
if storeAudits[0].Type == model.StoreSkuAuditTypeFocus {
skuBindInfos[0].IsFocus = 1
}
var num int64
db := dao.GetDB()
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, []int{storeAudit.StoreID}, skuBindInfos, false, false)
if err != nil {
return "", err
}
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
num = int64(len(skuIDs))
if num > 0 {
hint, err = CurVendorSync.SyncStoresSkus(ctx, nil, 0, db, nil, []int{storeAudit.StoreID}, skuIDs, false, isAsync, isContinueWhenError)
}
if num == 0 || !isAsync || hint == "" {
hint = utils.Int64ToStr(num)
}
// _, err = UpdateStoresSkus(ctx, 0, []int{storeID}, skuBindInfos, false, isAsync, isContinueWhenError)
} else if status == model.StoreAuditStatusRejected {
storeAudits[0].UserID = ctx.GetUserID()
storeAudits[0].Status = model.StoreAuditStatusRejected
storeAudits[0].Remark = storeAudit.Remark
_, err = dao.UpdateEntity(db, storeAudits[0], "UserID", "Status", "Remark")
} else {
return retVal, fmt.Errorf("审核标志不正确!")
}
if err == nil {
if globals.IsProductEnv() {
skuAndNames, err := dao.GetSkus(db, nil, []int{storeAudit.NameID}, nil, nil, nil)
if len(skuAndNames) > 0 && err == nil {
price := 0
if storeAudit.AuditPrice != 0 {
price = storeAudit.AuditPrice
} else {
price = storeAudits[0].UnitPrice
}
weixinmsg.NotifyStoreOpRequestStatus(flag, storeAudit.StoreID, storeAudit.NameID, jxutils.ComposeSpuName(skuAndNames[0].Prefix, skuAndNames[0].Name, 0), storeAudits[0].OriginUnitPrice, price, storeAudit.Remark)
}
}
}
return retVal, err
}, storeSkuAudits)
tasksch.HandleTask(task, nil, true).Run()
if isAsync {
hint = task.GetID()
} else {
_, err = task.GetResult(0)
hint = "1"
}
return hint, err
}

View File

@@ -1017,7 +1017,7 @@ func WriteToExcel(task *tasksch.SeqTask, data map[int][]DiffData, depotData map[
}
}
func SetAAJxPrice(jxSkuInfoDataMulti *dao.StoreSkuNamesInfo, storeId int) (err error) {
func SetJxPrice(jxSkuInfoDataMulti *dao.StoreSkuNamesInfo, storeId int) (err error) {
db := dao.GetDB()
storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeId, model.VendorIDJX)
if err != nil {

View File

@@ -645,7 +645,7 @@ func (v *VendorSync) AmendAndPruneStoreStuff(ctx *jxcontext.Context, vendorIDs [
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, parentTask tasksch.ITask, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, mustDirty bool, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
var storeMapList []*model.StoreMap
if storeMapList, err = dao.GetStoresMapList2(db, vendorIDs, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", mustDirty); err != nil {
if storeMapList, err = dao.GetStoresMapList2(db, vendorIDs, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "", mustDirty); err != nil {
return nil, "", err
}
if len(storeMapList) == 0 {
@@ -1028,7 +1028,7 @@ func syncStoreSkusFromYb(ctx *jxcontext.Context, storeID, vendorID int, vendorSt
for _, v := range resultDel {
skuBindInfosDel = append(skuBindInfosDel, v.(*StoreSkuBindInfo))
}
_, err = updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosDel, false)
_, err = updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosDel, false, false)
}
case 2:
if len(updateList) > 0 {
@@ -1071,7 +1071,7 @@ func syncStoreSkusFromYb(ctx *jxcontext.Context, storeID, vendorID int, vendorSt
for _, v := range resultUpt {
skuBindInfosUpt = append(skuBindInfosUpt, v.(*StoreSkuBindInfo))
}
_, err = updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosUpt, false)
_, err = updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosUpt, false, false)
}
case 3:
_, err = CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, []int{0, 1, 3}, nil, false, nil, nil, 0, true, true)
@@ -1101,7 +1101,7 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeMap := batchItemList[0].(*model.StoreMap)
if storeMap.Status > model.StoreStatusDisabled && storeMap.StoreID != model.JdShopMainStoreID && storeMap.SyncRule != 0 {
_, err = syncJdsStoresSkus(ctx, db, task, storeMap, isAsync, isContinueWhenError)
err = syncJdsStoresSkus(ctx, db, task, storeMap, isAsync, isContinueWhenError)
}
return nil, err
}, loopMapInfo.StoreMapList)
@@ -1113,16 +1113,14 @@ func (v *VendorSync) SyncJdsStoresSkus(ctx *jxcontext.Context, storeIDs []int, i
return hint, err
}
func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (hint string, err error) {
func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, storeMap *model.StoreMap, isAsync, isContinueWhenError bool) (err error) {
var (
mainSkusMap = make(map[int]*model.StoreSkuBind)
skusMap = make(map[int]*model.StoreSkuBind)
updateList []*model.StoreSkuBind
addList []*model.StoreSkuBind
skuBindInfos1 []*StoreSkuBindInfo
skuBindInfos2 []*StoreSkuBindInfo
resultInterface1 []interface{}
resultInterface2 []interface{}
mainSkusMap = make(map[int]*model.StoreSkuBind)
skusMap = make(map[int]*model.StoreSkuBind)
updateList []*model.StoreSkuBind
addList []*model.StoreSkuBind
skuBindInfos1 []*StoreSkuBindInfo
skuBindInfos2 []*StoreSkuBindInfo
)
storeSkusMain, err := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID}, nil)
for _, v := range storeSkusMain {
@@ -1142,53 +1140,20 @@ func syncJdsStoresSkus(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch
}
}
}
// fmt.Println("updateList", utils.Format4Output(updateList, false))
// fmt.Println("addList", utils.Format4Output(addList, false))
task := tasksch.NewParallelTask("正在同步京东商城的库存商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(ptTask *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
step := batchItemList[0].(int)
switch step {
case 0:
if len(updateList) > 0 {
task := tasksch.NewParallelTask("同步门店库存", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeBind := batchItemList[0].(*model.StoreSkuBind)
retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, false)}
return retVal, err
}, updateList)
tasksch.HandleTask(task, ptTask, false).Run()
resultInterface1, err = task.GetResult(0)
for _, v := range resultInterface1 {
skuBindInfos1 = append(skuBindInfos1, v.(*StoreSkuBindInfo))
}
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos1, isAsync, isContinueWhenError, false)
}
case 1:
if len(addList) > 0 {
task := tasksch.NewParallelTask("同步门店商品", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
storeBind := batchItemList[0].(*model.StoreSkuBind)
retVal = []*StoreSkuBindInfo{buildStoreSkuBindInfo(db, storeMap.StoreID, storeBind, true)}
return retVal, err
}, addList)
tasksch.HandleTask(task, ptTask, false).Run()
resultInterface2, err = task.GetResult(0)
for _, v := range resultInterface2 {
skuBindInfos2 = append(skuBindInfos2, v.(*StoreSkuBindInfo))
}
hint, err = UpdateStoresSkusByBind(ctx, ptTask, skuBindInfos2, isAsync, isContinueWhenError, false)
}
}
return retVal, err
}, []int{0, 1})
tasksch.HandleTask(task, nil, true).Run()
if isAsync {
hint = task.GetID()
} else {
_, err = task.GetResult(0)
hint = "1"
if len(updateList) > 0 {
for _, v := range updateList {
skuBindInfos1 = append(skuBindInfos1, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
}
_, err = UpdateStoresSkusByBind(ctx, parentTask, skuBindInfos1, isAsync, isContinueWhenError, false)
}
return hint, err
if len(addList) > 0 {
for _, v := range addList {
skuBindInfos2 = append(skuBindInfos2, buildStoreSkuBindInfo(db, storeMap.StoreID, v, false))
}
_, err = UpdateStoresSkusByBind(ctx, parentTask, skuBindInfos2, isAsync, isContinueWhenError, false)
}
return err
}
func buildStoreSkuBindInfo(db *dao.DaoDB, storeID int, storeBind *model.StoreSkuBind, isFocus bool) (skuBindInfo *StoreSkuBindInfo) {

View File

@@ -16,7 +16,7 @@ func OpenRemoteStoreByJxStatus(ctx *jxcontext.Context, vendorIDs, storeIDs []int
if !isForce {
status = model.StoreStatusClosed
}
storeMapList, err := dao.GetStoresMapList(db, vendorIDs, storeIDs, nil, status, model.StoreIsSyncYes, "")
storeMapList, err := dao.GetStoresMapList(db, vendorIDs, storeIDs, nil, status, model.StoreIsSyncYes, "", "")
if err != nil {
return "", err
}

View File

@@ -231,12 +231,13 @@ func storeSkuSyncInfo2Bare(inSku *dao.StoreSkuSyncInfo) (outSku *partner.StoreSk
NameID: inSku.NameID,
VendorNameID: inSku.VendorNameID,
Status: inSku.MergedStatus,
VendorPrice: inSku.VendorPrice,
Seq: inSku.Seq,
JxPrice: inSku.Price,
JxUnitPrice: inSku.UnitPrice,
VendorSkuID2: utils.Int64ToStr(inSku.JdsWareID),
Status: inSku.MergedStatus,
VendorPrice: inSku.VendorPrice,
Seq: inSku.Seq,
JxPrice: inSku.Price,
JxUnitPrice: inSku.UnitPrice,
VendorSkuID2: utils.Int64ToStr(inSku.JdsWareID),
JdsStockSwitch: inSku.JdsStockSwitch,
}
if !isStoreSkuSyncNeedDelete(inSku) {
outSku.Stock = model.MaxStoreSkuStockQty