- check store_map

This commit is contained in:
gazebo
2018-10-24 14:54:20 +08:00
parent 7b6c9fd73a
commit 508a949006
4 changed files with 100 additions and 88 deletions

View File

@@ -49,13 +49,13 @@ func (p *PurchaseHandler) CreateStore(db *dao.DaoDB, storeID int, userName strin
IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status,
province.ebai_code province_id, city.ebai_code city_id, district.ebai_code district_id
FROM store t1
LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ?
LEFT JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND t2.deleted_at = ?
JOIN place district ON t1.district_code = district.code
JOIN place city ON t1.city_code = city.code
JOIN place province ON city.parent_code = province.code
WHERE t1.id = ? AND t2.id IS NULL;
`
if err = dao.GetRow(db, &store, sql, model.VendorIDEBAI, storeID); err == nil {
if err = dao.GetRow(db, &store, sql, model.VendorIDEBAI, utils.DefaultTimeValue, storeID); err == nil {
params := genStoreMapFromStore(&store)
params["shop_id"] = store.ID
params["business_form_id"] = "179"
@@ -135,44 +135,50 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
}
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
var store tEbaiStoreInfo
var stores []*tEbaiStoreInfo
sql := `
SELECT t1.*, t2.status ebai_store_status, t2.vendor_store_id,
IF(t1.updated_at > t2.updated_at, t1.last_operator, t2.last_operator) real_last_operator, t2.sync_status
FROM store t1
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ?
WHERE t1.id = ?;
JOIN store_map t2 ON t1.id = t2.store_id AND t2.vendor_id = ? AND (t2.deleted_at = ? OR t2.sync_status <> 0)
WHERE t1.id = ?
ORDER BY t2.updated_at
`
if err = dao.GetRow(db, &store, sql, model.VendorIDEBAI, storeID); err == nil {
params := genStoreMapFromStore(&store)
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
if globals.EnableStoreWrite {
if err = api.EbaiAPI.ShopUpdate(params); err == nil {
shopID := 0
if store.SyncStatus&model.SyncFlagDeletedMask == 0 {
shopID = store.ID
}
store2, err2 := p.ReadStore(store.VendorStoreID)
if err = err2; err == nil {
if store2.ID == store.ID {
shopID = -1
if err = dao.GetRow(db, &stores, sql, model.VendorIDEBAI, utils.DefaultTimeValue, storeID); err == nil {
for _, store := range stores {
params := genStoreMapFromStore(store)
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
if globals.EnableStoreWrite {
if err = api.EbaiAPI.ShopUpdate(params); err == nil {
shopID := 0
if store.SyncStatus&model.SyncFlagDeletedMask == 0 {
shopID = store.ID
}
}
if err == nil {
if shopID > 0 {
err = api.EbaiAPI.ShopIDBatchUpdate([]string{store.VendorStoreID}, []string{utils.Int2Str(shopID)})
} else if shopID == 0 {
// todo remove out shop id
store2, err2 := p.ReadStore(store.VendorStoreID)
if err = err2; err == nil {
if store2.ID == store.ID {
shopID = -1
}
}
}
if err == nil {
mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus)
if mergeStatus == model.StoreStatusOpened {
err = api.EbaiAPI.ShopOnline("", utils.Str2Int64(store.VendorStoreID))
} else if mergeStatus == model.StoreStatusClosed {
err = api.EbaiAPI.ShopOffline("", utils.Str2Int64(store.VendorStoreID))
} else if mergeStatus == model.StoreStatusClosed {
err = api.EbaiAPI.ShopClose("", utils.Str2Int64(store.VendorStoreID))
if err == nil {
if shopID > 0 {
err = api.EbaiAPI.ShopIDBatchUpdate([]string{store.VendorStoreID}, []string{utils.Int2Str(shopID)})
} else if shopID == 0 {
// todo remove out shop id
}
}
if err == nil {
mergeStatus := jxutils.MergeStoreStatus(store.Status, store.EbaiStoreStatus)
if mergeStatus == model.StoreStatusOpened {
err = api.EbaiAPI.ShopOnline("", utils.Str2Int64(store.VendorStoreID))
} else if mergeStatus == model.StoreStatusClosed {
err = api.EbaiAPI.ShopOffline("", utils.Str2Int64(store.VendorStoreID))
} else if mergeStatus == model.StoreStatusClosed {
err = api.EbaiAPI.ShopClose("", utils.Str2Int64(store.VendorStoreID))
}
if err != nil {
return err
}
}
}
}