- trim store deliveryRange(possible additional ;)

This commit is contained in:
gazebo
2018-11-14 12:11:43 +08:00
parent ec1a3deee6
commit f9e8e4745a
2 changed files with 18 additions and 7 deletions

View File

@@ -259,10 +259,11 @@ func GetVendorStore(ctx *jxcontext.Context, vendorStoreID string, vendorID int)
}
func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
globals.SugarLogger.Debugf("UpdateStore storeID:%d, payload:%s", storeID, utils.Format4Output(payload, false))
store := &model.Store{}
store.ID = storeID
valid := dao.NormalMakeMapByStructObject(payload, store, userName)
globals.SugarLogger.Debug(utils.Format4Output(valid, false))
if valid["name"] != nil {
valid["name"] = jxutils.FormalizeName(valid["name"].(string))
}
@@ -270,6 +271,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
valid["lng"] = jxutils.StandardCoordinate2Int(utils.Interface2FloatWithDefault(payload["lng"], 0.0))
valid["lat"] = jxutils.StandardCoordinate2Int(utils.Interface2FloatWithDefault(payload["lat"], 0.0))
}
if valid["deliveryRange"] != nil {
valid["deliveryRange"] = strings.Trim(valid["deliveryRange"].(string), ";")
}
if len(valid) > 0 {
db := dao.GetDB()
dao.Begin(db)
@@ -291,11 +295,14 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
}
func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (id int, err error) {
globals.SugarLogger.Debugf("CreateStore storeExt:%s", utils.Format4Output(storeExt, false))
store := &storeExt.Store
existingID := store.ID
store.Lng = jxutils.StandardCoordinate2Int(storeExt.FloatLng)
store.Lat = jxutils.StandardCoordinate2Int(storeExt.FloatLat)
store.Name = jxutils.FormalizeName(store.Name)
store.DeliveryRange = strings.Trim(store.DeliveryRange, ";")
dao.WrapAddIDCULDEntity(store, userName)
store.ID = existingID
if err = dao.CreateEntity(nil, store); err == nil {

View File

@@ -147,6 +147,8 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
}
func (p *PurchaseHandler) UpdateStore(db *dao.DaoDB, storeID int, userName string) (err error) {
globals.SugarLogger.Debugf("ebai UpdateStore storeID:%d, userName:%s", storeID, userName)
var stores []*tEbaiStoreInfo
sql := `
SELECT t1.*, t2.status ebai_store_status, t2.vendor_store_id,
@@ -279,17 +281,19 @@ func EbaiDeliveryRegion2Jx(deliveryRegion interface{}) string {
}
func JxDeliveryRegion2Ebai(store *model.Store) interface{} {
rangeStr := store.DeliveryRange
rangeStr := strings.Trim(store.DeliveryRange, ";")
if store.DeliveryRangeType == model.DeliveryRangeTypeRadius {
rangeStr = jxutils.GetPolygonFromCircleStr(jxutils.IntCoordinate2Standard(store.Lng), jxutils.IntCoordinate2Standard(store.Lat), utils.Str2Float64(store.DeliveryRange), 8)
}
pointPairs := strings.Split(rangeStr, ";")
region := make([]map[string]interface{}, len(pointPairs))
for k, v := range pointPairs {
region := make([]map[string]interface{}, 0)
for _, v := range pointPairs {
pointPair := strings.Split(v, ",")
region[k] = map[string]interface{}{
"longitude": utils.Str2Float64(pointPair[0]),
"latitude": utils.Str2Float64(pointPair[1]),
if len(pointPair) == 2 {
region = append(region, map[string]interface{}{
"longitude": utils.Str2Float64(pointPair[0]),
"latitude": utils.Str2Float64(pointPair[1]),
})
}
}
deliveryRegion := []interface{}{