This commit is contained in:
gazebo
2018-09-20 17:02:25 +08:00
parent 1fa6540f19
commit d8eb17f6be
9 changed files with 176 additions and 104 deletions

View File

@@ -25,6 +25,7 @@ type tEbaiStoreInfo struct {
VendorStoreID string `orm:"column(vendor_store_id)"`
RealLastOperator string
EbaiStoreStatus int
SyncStatus int
}
func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error) {
@@ -90,11 +91,12 @@ func (p *PurchaseHandler) UpdateStore(storeID int, userName string) (err error)
var store 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
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 = ?`
if err = dao.GetRow(db, &store, sql, model.VendorIDJD, storeID); err == nil {
WHERE t1.id = ?;
`
if err = dao.GetRow(db, &store, sql, model.VendorIDEBAI, storeID); err == nil {
params := map[string]interface{}{
"baidu_shop_id": store.VendorStoreID,
"name": jxutils.ComposeStoreName(store.Name, partner.StoreNameSeparator, VendorStorePrefix),
@@ -107,10 +109,26 @@ func (p *PurchaseHandler) UpdateStore(storeID int, userName string) (err error)
"delivery_region": JxDeliveryRegion2Ebai(&store.Store),
"business_time": JxBusinessTime2Ebai(&store.Store),
}
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
globals.SugarLogger.Debug(utils.Format4Output(params, false))
if globals.EnableStoreWrite {
if err = api.EbaiAPI.ShopUpdate(params); err == nil {
// todo 设置 shop_id
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 == nil {
if shopID > 0 {
err = api.EbaiAPI.ShopIDBatchUpdate([]string{store.VendorStoreID}, []string{utils.Int2Str(shopID)})
} else if shopID == 0 {
// todo remove out shop id
}
}
}
}
}
@@ -171,8 +189,10 @@ func JxDeliveryRegion2Ebai(store *model.Store) interface{} {
func JxBusinessTime2Ebai(store *model.Store) interface{} {
bTime := make([]map[string]interface{}, 1)
bTime[0]["start"] = jxutils.JxOperationTime2StrTime(store.OpenTime1)
bTime[0]["end"] = jxutils.JxOperationTime2StrTime(store.CloseTime1)
bTime[0] = map[string]interface{}{
"start": jxutils.JxOperationTime2StrTime(store.OpenTime1),
"end": jxutils.JxOperationTime2StrTime(store.CloseTime1),
}
if store.OpenTime2 != 0 {
bTime = append(bTime, map[string]interface{}{
"start": jxutils.JxOperationTime2StrTime(store.OpenTime2),