178 lines
6.3 KiB
Go
178 lines
6.3 KiB
Go
package jd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
)
|
|
|
|
func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error) {
|
|
result, err := api.JdAPI.GetStoreInfoByStationNo(vendorStoreID)
|
|
if err == nil {
|
|
retVal := &model.Store{
|
|
Name: utils.Interface2String(result["stationName"]),
|
|
Address: utils.Interface2String(result["stationAddress"]),
|
|
OpenTime1: JdOperationTime2JxOperationTime(result["serviceTimeStart1"]),
|
|
CloseTime1: JdOperationTime2JxOperationTime(result["serviceTimeEnd1"]),
|
|
OpenTime2: JdOperationTime2JxOperationTime(result["serviceTimeStart2"]),
|
|
CloseTime2: JdOperationTime2JxOperationTime(result["serviceTimeEnd2"]),
|
|
Status: JdStoreStatus2JxStatus(result["yn"], result["closeStatus"]),
|
|
Tel1: utils.Interface2String(result["phone"]),
|
|
}
|
|
retVal.DeliveryType = JdDeliveryType2Jx(int(utils.MustInterface2Int64(result["carrierNo"])))
|
|
|
|
tel2 := utils.Interface2String(result["mobile"])
|
|
if tel2 != "" && tel2 != retVal.Tel1 {
|
|
retVal.Tel2 = tel2
|
|
}
|
|
cityCode := int(utils.MustInterface2Int64(result["city"]))
|
|
if cityCode != 0 {
|
|
db := dao.GetDB()
|
|
if city, err2 := dao.GetPlaceByJdCode(db, cityCode); err2 == nil {
|
|
retVal.CityCode = city.Code
|
|
districtName := utils.Interface2String(result["countyName"]) // 京东的市区号码与通用数据完全无法关联,只有通过名字来关联
|
|
if district, err2 := dao.GetPlaceByName(db, districtName, 3, city.Code); err2 == nil {
|
|
retVal.DistrictCode = district.Code
|
|
}
|
|
}
|
|
}
|
|
retVal.Lng = jxutils.StandardCoordinate2Int(utils.MustInterface2Float64(result["lng"]))
|
|
retVal.Lat = jxutils.StandardCoordinate2Int(utils.MustInterface2Float64(result["lat"]))
|
|
|
|
retVal.ID = int(utils.Str2Int64WithDefault(utils.Interface2String(result["outSystemId"]), 0))
|
|
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
|
|
}
|
|
|
|
func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store, userName string) error {
|
|
params := map[string]interface{}{
|
|
"outSystemId": utils.Int2Str(int(store.ID)),
|
|
"stationName": store.Name,
|
|
"stationAddress": store.Address,
|
|
"serviceTimeStart1": JxOperationTime2JdOperationTime(store.OpenTime1),
|
|
"serviceTimeEnd1": JxOperationTime2JdOperationTime(store.CloseTime1),
|
|
"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))
|
|
return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
|
}
|
|
|
|
// 没用
|
|
// func (p *PurchaseHandler) DeleteStore(vendorStoreID, userName string) error {
|
|
// params := map[string]interface{}{
|
|
// "yn": 1,
|
|
// }
|
|
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
|
// }
|
|
|
|
// func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
|
// _, err := api.JdAPI.UpdateStoreConfig4Open(vendorStoreID, isEnabled)
|
|
// return err
|
|
// }
|
|
|
|
// func (p *PurchaseHandler) OpenStore(vendorStoreID string, userName string) error {
|
|
// params := map[string]interface{}{
|
|
// "closeStatus": 0,
|
|
// "storeNotice": "",
|
|
// }
|
|
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
|
// }
|
|
|
|
// func (p *PurchaseHandler) CloseStore(vendorStoreID, closeNotice, userName string) error {
|
|
// params := map[string]interface{}{
|
|
// "closeStatus": 1,
|
|
// "storeNotice": closeNotice,
|
|
// }
|
|
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
|
// }
|
|
|
|
///////////////////////
|
|
func (p *PurchaseHandler) GetAllStoreIDsFromRemote() ([]string, error) {
|
|
result, err := api.JdAPI.GetStationsByVenderId()
|
|
return result, err
|
|
}
|
|
|
|
func (p *PurchaseHandler) GetAllStoresFromRemote() ([]*model.Store, error) {
|
|
ids, err := p.GetAllStoreIDsFromRemote()
|
|
if err == nil {
|
|
retVal := make([]*model.Store, len(ids))
|
|
for index, id := range ids {
|
|
store, err2 := p.ReadStore(id)
|
|
if err2 == nil {
|
|
retVal[index] = store
|
|
} else {
|
|
return nil, err2
|
|
}
|
|
}
|
|
return retVal, nil
|
|
}
|
|
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, ";")
|
|
}
|
|
|
|
func JdDeliveryType2Jx(deliveryType int) int8 {
|
|
if deliveryType == 2938 {
|
|
return scheduler.StoreDeliveryTypeByStore
|
|
} else if deliveryType == 9966 {
|
|
return scheduler.StoreDeliveryTypeCrowdSourcing
|
|
}
|
|
return scheduler.StoreDeliveryTypeByPlatform
|
|
}
|