- jd basic api(category, sku, store management) finished.

This commit is contained in:
gazebo
2018-08-30 15:22:26 +08:00
parent 7774fd0995
commit 29d358af5e
12 changed files with 485 additions and 86 deletions

View File

@@ -1,6 +1,11 @@
package jd
import (
"fmt"
"strings"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/globals/api"
@@ -18,8 +23,18 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
CloseTime2: JdOperationTime2JxOperationTime(result["serviceTimeEnd2"]),
Status: JdStoreStatus2JxStatus(result["yn"], result["closeStatus"]),
}
retVal.ID = int(utils.Str2Int64WithDefault(utils.Interface2String(result["outSystemId"]), 0))
return retVal, nil
result, err2 := api.JdAPI.GetDeliveryRangeByStationNo(vendorStoreID)
if err = err2; err == nil {
retVal.DeliveryRangeType = int8(utils.MustInterface2Int64(result["deliveryRangeType"]))
if retVal.DeliveryRangeType == model.DeliveryRangeTypePolygon {
retVal.DeliveryRange = JdRange2JxRange(utils.Interface2String(result["deliveryRange"]))
} else {
retVal.DeliveryRange = utils.Int64ToStr(utils.MustInterface2Int64(result["deliveryRangeRadius"]))
}
return retVal, nil
}
}
return nil, err
}
@@ -31,8 +46,19 @@ func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store,
"stationAddress": store.Address,
"serviceTimeStart1": JxOperationTime2JdOperationTime(store.OpenTime1),
"serviceTimeEnd1": JxOperationTime2JdOperationTime(store.CloseTime1),
"serviceTimeStart2": JxOperationTime2JdOperationTime(store.OpenTime2),
"serviceTimeEnd2": JxOperationTime2JdOperationTime(store.CloseTime2),
"deliveryRangeType": store.DeliveryRangeType,
"coordinateType": 3, // 一直用高德
}
if store.DeliveryRangeType == model.DeliveryRangeTypePolygon {
params["coordinatePoints"] = JxRange2JdRange(store.DeliveryRange)
} else {
params["deliveryRangeRadius"] = utils.Str2Int64(store.DeliveryRange)
}
openTime2 := JxOperationTime2JdOperationTime(store.OpenTime2)
if openTime2 != 0 {
params["serviceTimeStart2"] = openTime2
params["serviceTimeEnd2"] = JxOperationTime2JdOperationTime(store.CloseTime2)
}
_, params["closeStatus"] = JxStoreStatus2JdStatus(store.Status)
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
@@ -44,8 +70,7 @@ func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store,
// params := map[string]interface{}{
// "yn": 1,
// }
// _, err := api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
// return err
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
// }
func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
@@ -91,3 +116,31 @@ func (p *PurchaseHandler) GetAllStoresFromRemote() ([]*model.Store, error) {
}
return nil, err
}
func JdRange2JxRange(jdRanges string) (jxRanges string) {
coords := strings.Split(jdRanges, ";")
intCoords := []string{}
for _, coord := range coords {
items := strings.Split(coord, ",")
if len(items) == 2 {
lng := jxutils.StandardCoordinate2Int(utils.Str2Float64(items[0]))
lat := jxutils.StandardCoordinate2Int(utils.Str2Float64(items[1]))
intCoords = append(intCoords, fmt.Sprintf("%d,%d", lng, lat))
}
}
return strings.Join(intCoords, ";")
}
func JxRange2JdRange(jxRanges string) (jdRanges string) {
coords := strings.Split(jxRanges, ";")
intCoords := []string{}
for _, coord := range coords {
items := strings.Split(coord, ",")
if len(items) == 2 {
lng := jxutils.IntCoordinate2Standard(int(utils.Str2Int64(items[0])))
lat := jxutils.IntCoordinate2Standard(int(utils.Str2Int64(items[1])))
intCoords = append(intCoords, fmt.Sprintf("%f,%f", lng, lat))
}
}
return strings.Join(intCoords, ";")
}