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

@@ -0,0 +1,23 @@
package ebai
import (
_ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/beegodb"
"github.com/astaxie/beego"
)
const (
testShopBaiduID = 2233043816
testShopID = "test_708706_63032"
)
func init() {
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
globals.Init()
beegodb.Init()
api.Init()
}

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),

View File

@@ -0,0 +1,22 @@
package ebai
import (
"testing"
"git.rosy.net.cn/baseapi/utils"
)
func TestReadStore(t *testing.T) {
result, err := new(PurchaseHandler).ReadStore(utils.Int2Str(testShopBaiduID))
if err != nil {
t.Fatal(err.Error())
}
t.Log(utils.Format4Output(result, false))
}
func TestUpdateStore(t *testing.T) {
err := new(PurchaseHandler).UpdateStore(100002, "autotest")
if err != nil {
t.Fatal(err.Error())
}
}

View File

@@ -22,7 +22,7 @@ func (p *PurchaseHandler) SyncStoreSku(storeID int, skuIDs []int, isForce bool,
FROM store_sku_bind
WHERE store_id = ?
`
if skuIDs != nil {
if skuIDs != nil && len(skuIDs) > 0 {
sql += " AND sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
sqlParams = append(sqlParams, skuIDs)
}
@@ -84,7 +84,7 @@ func (p *PurchaseHandler) SyncStoreSku(storeID int, skuIDs []int, isForce bool,
SET jd_sync_status = 0
WHERE store_id = ?
`
if skuIDs != nil {
if skuIDs != nil && len(skuIDs) > 0 {
sql += " AND sku_id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
}
_, err = dao.ExecuteSQL(db, sql, sqlParams)