From f782e8dcc05e01eb2384f472007033e2e4065e89 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 13 Sep 2018 11:29:28 +0800 Subject: [PATCH] - fix placeCond and vendorStoreCond bug. --- business/jxstore/cms/sku.go | 21 +++++++++++++-------- business/jxstore/cms/store.go | 15 +++++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index cc3aa1f2b..2341d90ff 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -9,15 +9,16 @@ import ( "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" + "git.rosy.net.cn/jx-callback/globals" ) type SkuNameExt struct { model.SkuName Skus []*model.Sku `orm:"-" json:"skus"` - SkusStr string `orm:"size(2000)" json:"-"` + SkusStr string `json:"-"` Places []*model.SkuNamePlaceBind `orm:"-" json:"places"` - PlacesStr string `orm:"size(2000)" json:"-"` + PlacesStr string `json:"-"` } type SkuNamesInfo struct { @@ -189,23 +190,26 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize sqlParams = append(sqlParams, params["unit"].(string)) } if placeCond := strings.ToUpper(utils.Interface2String(params["placeCond"])); placeCond == "AND" || placeCond == "OR" { + sqlPlaceCond := "" if placeCond == "AND" { - sql += " AND ( 1 = 1" + sqlPlaceCond += " AND ( 1 = 1" } else { - sql += " AND ( 1 = 0" + sqlPlaceCond += " AND ( 1 = 0" } if params["placeCode"] != nil { - sql += " " + placeCond + " t3.place_code = ?" + sqlPlaceCond += " " + placeCond + " t3.place_code = ?" sqlParams = append(sqlParams, params["placeCode"].(int)) } if params["isGlobal"] != nil { if params["isGlobal"].(bool) { - sql += " " + placeCond + " t1.is_global = 1" + sqlPlaceCond += " " + placeCond + " t1.is_global = 1" } else { - sql += " " + placeCond + " t1.is_global = 0" + sqlPlaceCond += " " + placeCond + " t1.is_global = 0" } } - sql += ")" + if sqlPlaceCond != " AND ( 1 = 0" { + sql += sqlPlaceCond + ")" + } } if params["skuID"] != nil { sql += " AND t2.id = ?" @@ -267,6 +271,7 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize } sqlParams = append(sqlParams, pageSize, offset) skuNamesInfo = &SkuNamesInfo{} + globals.SugarLogger.Debug(sqlData) if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil { countInfo := &struct{ Ct int }{} if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil { diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 85b66ea0e..1070124a1 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -145,10 +145,11 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i sqlParams = append(sqlParams, fromStatus, toStatus) } if vendorStoreCond := strings.ToUpper(utils.Interface2String(params["vendorStoreCond"])); vendorStoreCond == "AND" || vendorStoreCond == "OR" { + sqlVendorStoreCond := "" if vendorStoreCond == "AND" { - sqlWhere += " AND ( 1 = 1" + sqlVendorStoreCond += " AND ( 1 = 1" } else { - sqlWhere += " AND ( 1 = 0" + sqlVendorStoreCond += " AND ( 1 = 0" } condMap := map[string]int{ "jdm": utils.Interface2DirectIntWithDefault(params["jdCond"], 0), @@ -157,15 +158,17 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i } for tableName, cond := range condMap { if cond != 0 { - sqlWhere += " " + vendorStoreCond + " " + tableName + sqlVendorStoreCond += " " + vendorStoreCond + " " + tableName } if cond == -1 { - sqlWhere += ".vendor_store_id IS NULL" + sqlVendorStoreCond += ".vendor_store_id IS NULL" } else if cond == 1 { - sqlWhere += ".vendor_store_id IS NOT NULL" + sqlVendorStoreCond += ".vendor_store_id IS NOT NULL" } } - sqlWhere += ")" + if sqlVendorStoreCond != " AND ( 1 = 0" { + sqlWhere += sqlVendorStoreCond + ")" + } } sql := "SELECT SQL_CALC_FOUND_ROWS t1.*, city.name city_name, district.name district_name, jdm.vendor_store_id jd_id, elmm.vendor_store_id elm_id, ebaim.vendor_store_id ebai_id\n" + sqlFrom + sqlWhere + `