- ebai
This commit is contained in:
@@ -2,6 +2,7 @@ package cms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
||||
@@ -32,7 +33,7 @@ func Init() {
|
||||
} else if _, ok := v.(partner.ISingleStoreHandler); ok {
|
||||
SingleStoreVendorIDs = append(SingleStoreVendorIDs, k)
|
||||
} else {
|
||||
panic("delivery platform type is wrong!")
|
||||
panic(fmt.Sprintf("platform:%d type is wrong!", k))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,16 +13,23 @@ func (p *PurchaseHandler) UpdatePlaces() (err error) {
|
||||
if err == nil {
|
||||
task := tasksch.RunTask("UpdatePlaces", false, nil, 0, 1, "", func(batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
province := batchItemList[0].(*ebaiapi.CityInfo)
|
||||
cities, err := api.EbaiAPI.CommonShopCities(province.ID)
|
||||
retSlice := make([]*ebaiapi.CityInfo, len(cities))
|
||||
copy(retSlice, cities)
|
||||
for _, city := range cities {
|
||||
if city.IsOpen != 0 {
|
||||
districts, err2 := api.EbaiAPI.CommonShopCities(city.ID)
|
||||
if err = err2; err == nil {
|
||||
retSlice = append(retSlice, districts...)
|
||||
} else {
|
||||
break
|
||||
retSlice := make([]*ebaiapi.CityInfo, 0)
|
||||
if province.IsOpen != 0 {
|
||||
retSlice = append(retSlice, province)
|
||||
cities, err := api.EbaiAPI.CommonShopCities(province.ID)
|
||||
for _, city := range cities {
|
||||
if city.IsOpen != 0 {
|
||||
retSlice = append(retSlice, city)
|
||||
districts, err2 := api.EbaiAPI.CommonShopCities(city.ID)
|
||||
if err = err2; err == nil {
|
||||
for _, district := range districts {
|
||||
if district.IsOpen != 0 {
|
||||
retSlice = append(retSlice, district)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ type tEbaiStoreInfo struct {
|
||||
RealLastOperator string
|
||||
EbaiStoreStatus int
|
||||
SyncStatus int
|
||||
|
||||
ProvinceID int `orm:"column(province_id)"`
|
||||
CityID int `orm:"column(city_id)"`
|
||||
DistrictID int `orm:"column(district_id)"`
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) GetFieldIDName() string {
|
||||
@@ -36,7 +40,36 @@ func (p *PurchaseHandler) GetFieldSyncStatusName() string {
|
||||
return model.FieldEbaiSyncStatus
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) CreateStore(storeID int) (vendorStoreID string, err error) {
|
||||
func (p *PurchaseHandler) CreateStore(db *dao.DaoDB, storeID int, userName string) (vendorStoreID 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, 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 = ?
|
||||
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 {
|
||||
params := genStoreMapFromStore(&store)
|
||||
params["shop_id"] = store.ID
|
||||
params["business_form_id"] = "179"
|
||||
params["service_phone"] = store.Tel1
|
||||
params["invoice_support"] = 2
|
||||
params["package_box_price"] = 0
|
||||
params["encrypt"] = ""
|
||||
|
||||
params["category1"] = ""
|
||||
params["category2"] = ""
|
||||
params["category3"] = ""
|
||||
intVendorStoreID, err2 := api.EbaiAPI.ShopCreate(params)
|
||||
if err = err2; err == nil {
|
||||
return utils.Int64ToStr(intVendorStoreID), err
|
||||
}
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -44,6 +77,7 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
|
||||
baiduShopID := utils.Str2Int64(vendorStoreID)
|
||||
result, err := api.EbaiAPI.ShopGet("", baiduShopID)
|
||||
if err == nil {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(result, false))
|
||||
retVal := &model.Store{
|
||||
Address: utils.Interface2String(result["address"]),
|
||||
Tel1: utils.Interface2String(result["phone"]),
|
||||
@@ -108,20 +142,7 @@ func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName strin
|
||||
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),
|
||||
"phone": store.Tel1,
|
||||
"longitude": jxutils.IntCoordinate2Standard(store.Lng),
|
||||
"latitude": jxutils.IntCoordinate2Standard(store.Lat),
|
||||
"address": store.Address,
|
||||
"coord_type": ebaiapi.CoordTypeAutonavi, // 一直用高德
|
||||
"delivery_region": JxDeliveryRegion2Ebai(&store.Store),
|
||||
"business_time": JxBusinessTime2Ebai(&store.Store),
|
||||
}
|
||||
if store.Tel2 != "" {
|
||||
params["ivr_phone"] = store.Tel2
|
||||
}
|
||||
params := genStoreMapFromStore(&store)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
|
||||
if globals.EnableStoreWrite {
|
||||
if err = api.EbaiAPI.ShopUpdate(params); err == nil {
|
||||
@@ -178,7 +199,7 @@ func EbaiDeliveryRegion2Jx(deliveryRegion interface{}) string {
|
||||
coords := make([]string, len(region))
|
||||
for k, v := range region {
|
||||
mapV := v.(map[string]interface{})
|
||||
coords[k] = fmt.Sprintf("%d,%d", jxutils.StandardCoordinate2Int(utils.MustInterface2Float64(mapV["longitude"])), jxutils.StandardCoordinate2Int(utils.MustInterface2Float64(mapV["latitude"])))
|
||||
coords[k] = fmt.Sprintf("%.6f,%.6f", utils.MustInterface2Float64(mapV["longitude"]), utils.MustInterface2Float64(mapV["latitude"]))
|
||||
}
|
||||
return strings.Join(coords, ";")
|
||||
}
|
||||
@@ -226,3 +247,32 @@ func JxBusinessTime2Ebai(store *model.Store) interface{} {
|
||||
}
|
||||
return bTime
|
||||
}
|
||||
|
||||
func genStoreMapFromStore(store *tEbaiStoreInfo) map[string]interface{} {
|
||||
params := map[string]interface{}{
|
||||
"name": jxutils.ComposeStoreName(store.Name, partner.StoreNameSeparator, VendorStorePrefix),
|
||||
"phone": store.Tel1,
|
||||
"longitude": jxutils.IntCoordinate2Standard(store.Lng),
|
||||
"latitude": jxutils.IntCoordinate2Standard(store.Lat),
|
||||
"address": store.Address,
|
||||
"coord_type": ebaiapi.CoordTypeAutonavi, // 一直用高德
|
||||
"delivery_region": JxDeliveryRegion2Ebai(&store.Store),
|
||||
"business_time": JxBusinessTime2Ebai(&store.Store),
|
||||
}
|
||||
if store.VendorStoreID != "" {
|
||||
params["baidu_shop_id"] = store.VendorStoreID
|
||||
}
|
||||
if store.Tel2 != "" {
|
||||
params["ivr_phone"] = store.Tel2
|
||||
}
|
||||
if store.ProvinceID != 0 {
|
||||
params["province"] = store.ProvinceID
|
||||
}
|
||||
if store.CityID != 0 {
|
||||
params["city"] = store.CityID
|
||||
}
|
||||
if store.DistrictID != 0 {
|
||||
params["county"] = store.DistrictID
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (p *PurchaseHandler) syncOneStoreSkus(db *dao.DaoDB, storeID int, skuIDs []
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) SyncStoreCategories(db *dao.DaoDB, storeID int, catIDs []int) (err error) {
|
||||
func (p *PurchaseHandler) SyncStoreCategories(db *dao.DaoDB, storeIDs []int, catIDs []int) (err error) {
|
||||
// sql := `
|
||||
// SELECT *
|
||||
// FROM store_sku_bind t1
|
||||
|
||||
@@ -22,3 +22,11 @@ func TestUpdateStore(t *testing.T) {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateStore(t *testing.T) {
|
||||
db := dao.GetDB()
|
||||
_, err := new(PurchaseHandler).CreateStore(db, 1, "autotest")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,20 @@ func TestUpdateStore(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateStore2(t *testing.T) {
|
||||
handler := new(PurchaseHandler)
|
||||
|
||||
// result := &model.Store{}
|
||||
// result.ID = 100164
|
||||
// err := dao.GetEntity(nil, result)
|
||||
db := dao.GetDB()
|
||||
// restore
|
||||
err := handler.UpdateStore(db, 1, "autotest")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// func TestCoordRangeConversion(t *testing.T) {
|
||||
// jxRange := "108841759,34332892;108842271,34330820;108846013,34331422;108846110,34333189;108847722,34331853;108856703,34331729;108866149,34327507;108873423,34320980;108877737,34312856;108877727,34299624;108870105,34287988;108855137,34290911;108867884,34286298;108858260,34281316;108854162,34283490;108853803,34280145;108846110,34279291;108830587,34282539;108818806,34291500;108814493,34299624;108813596,34308465;108818797,34320980;108830582,34329941;108841759,34332892"
|
||||
// jdRange := "108.841759,34.332892;108.842271,34.330820;108.846013,34.331422;108.846110,34.333189;108.847722,34.331853;108.856703,34.331729;108.866149,34.327507;108.873423,34.320980;108.877737,34.312856;108.877727,34.299624;108.870105,34.287988;108.855137,34.290911;108.867884,34.286298;108.858260,34.281316;108.854162,34.283490;108.853803,34.280145;108.846110,34.279291;108.830587,34.282539;108.818806,34.291500;108.814493,34.299624;108.813596,34.308465;108.818797,34.320980;108.830582,34.329941;108.841759,34.332892"
|
||||
|
||||
Reference in New Issue
Block a user