From a5d22c3655ce5d8a0634f213f9556d51a4dc7ce1 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 7 Nov 2018 18:12:32 +0800 Subject: [PATCH] - handle special chars in store name. --- business/jxstore/cms/store.go | 9 ++++-- business/jxstore/promotion/jd_promotion.go | 36 ++++++++++++---------- business/jxutils/jxutils_cms.go | 4 +++ business/model/model.go | 1 + 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index b817d415e..d6902a612 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -257,6 +257,10 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa 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)) + } if payload["lng"] != nil { valid["lng"] = jxutils.StandardCoordinate2Int(utils.Interface2FloatWithDefault(payload["lng"], 0.0)) valid["lat"] = jxutils.StandardCoordinate2Int(utils.Interface2FloatWithDefault(payload["lat"], 0.0)) @@ -284,8 +288,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (id int, err error) { store := &storeExt.Store existingID := store.ID - storeExt.Lng = jxutils.StandardCoordinate2Int(storeExt.FloatLng) - storeExt.Lat = jxutils.StandardCoordinate2Int(storeExt.FloatLat) + store.Lng = jxutils.StandardCoordinate2Int(storeExt.FloatLng) + store.Lat = jxutils.StandardCoordinate2Int(storeExt.FloatLat) + store.Name = jxutils.FormalizeName(store.Name) dao.WrapAddIDCULDEntity(store, userName) store.ID = existingID if err = dao.CreateEntity(nil, store); err == nil { diff --git a/business/jxstore/promotion/jd_promotion.go b/business/jxstore/promotion/jd_promotion.go index 08fe9bb79..dd344bd24 100644 --- a/business/jxstore/promotion/jd_promotion.go +++ b/business/jxstore/promotion/jd_promotion.go @@ -487,7 +487,7 @@ func GetJdPromotions(ctx *jxcontext.Context, keyword string, params map[string]i t1.begin_at, t1.end_at, t1.advertising, - CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"storeID":', t2.store_id, ', "name":"', t22.name, '"}')), "]") store_str, + CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"storeID":', t2.store_id, ', "name":"', REPLACE(REPLACE(t22.name, '\t', ''), '"', ''), '"}')), "]") store_str, CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"skuID":', t3.sku_id, ', "priceType":', t3.price_type, ', "price":', t3.price, ', "limitSkuCount":', t3.limit_sku_count, ', "isLock":', t3.is_lock, '}')), "]") sku_price_str FROM promotion t1 JOIN promotion_store t2 ON t1.id = t2.promotion_id @@ -843,24 +843,26 @@ func OnStoreStockMsg(msg *jdapi.CallbackStoreStockMsg) (retVal *jdapi.CallbackRe sku := &model.Sku{} sku.JdID = msg.SkuId if err = dao.GetEntity(db, sku, model.FieldJdID); err == nil { - if msg.Vendibility == 1 { - vendibility := &jdapi.StockVendibility{ - OutSkuId: utils.Int2Str(sku.ID), - DoSale: true, + go func() { + if msg.Vendibility == 1 { + vendibility := &jdapi.StockVendibility{ + OutSkuId: utils.Int2Str(sku.ID), + DoSale: true, + } + _, err = api.JdAPI.BatchUpdateVendibility("", msg.StationNo, []*jdapi.StockVendibility{ + vendibility, + }, userName) } - _, err = api.JdAPI.BatchUpdateVendibility("", msg.StationNo, []*jdapi.StockVendibility{ - vendibility, - }, userName) - } - if !msg.Have { - stock := &jdapi.SkuStock{ - OutSkuId: utils.Int2Str(sku.ID), - StockQty: model.MaxStoreSkuStockQty, + if !msg.Have { + stock := &jdapi.SkuStock{ + OutSkuId: utils.Int2Str(sku.ID), + StockQty: model.MaxStoreSkuStockQty, + } + _, err = api.JdAPI.BatchUpdateCurrentQtys("", msg.StationNo, []*jdapi.SkuStock{ + stock, + }, userName) } - _, err = api.JdAPI.BatchUpdateCurrentQtys("", msg.StationNo, []*jdapi.SkuStock{ - stock, - }, userName) - } + }() } } return jdapi.Err2CallbackResponse(err, "") diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 1f2fb00c5..028239321 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -166,3 +166,7 @@ func FormalizePageSize(pageSize int) int { } return pageSize } + +func FormalizeName(name string) string { + return utils.TrimBlankChar(strings.Replace(strings.Replace(name, "\t", "", -1), "\"", "", -1)) +} diff --git a/business/model/model.go b/business/model/model.go index f3a121566..f0c069907 100644 --- a/business/model/model.go +++ b/business/model/model.go @@ -35,6 +35,7 @@ const ( FieldEnabled = "Enabled" FieldSpecQuality = "SpecQuality" FieldSpecUnit = "SpecUnit" + FieldName = "Name" ) type ModelIDCUL struct {