|
|
|
|
@@ -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
|
|
|
|
|
}
|
|
|
|
|
|