- fix placeCond and vendorStoreCond bug.

This commit is contained in:
gazebo
2018-09-13 11:29:28 +08:00
parent 016727586d
commit f782e8dcc0
2 changed files with 22 additions and 14 deletions

View File

@@ -9,15 +9,16 @@ import (
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
) )
type SkuNameExt struct { type SkuNameExt struct {
model.SkuName model.SkuName
Skus []*model.Sku `orm:"-" json:"skus"` Skus []*model.Sku `orm:"-" json:"skus"`
SkusStr string `orm:"size(2000)" json:"-"` SkusStr string `json:"-"`
Places []*model.SkuNamePlaceBind `orm:"-" json:"places"` Places []*model.SkuNamePlaceBind `orm:"-" json:"places"`
PlacesStr string `orm:"size(2000)" json:"-"` PlacesStr string `json:"-"`
} }
type SkuNamesInfo struct { type SkuNamesInfo struct {
@@ -189,23 +190,26 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
sqlParams = append(sqlParams, params["unit"].(string)) sqlParams = append(sqlParams, params["unit"].(string))
} }
if placeCond := strings.ToUpper(utils.Interface2String(params["placeCond"])); placeCond == "AND" || placeCond == "OR" { if placeCond := strings.ToUpper(utils.Interface2String(params["placeCond"])); placeCond == "AND" || placeCond == "OR" {
sqlPlaceCond := ""
if placeCond == "AND" { if placeCond == "AND" {
sql += " AND ( 1 = 1" sqlPlaceCond += " AND ( 1 = 1"
} else { } else {
sql += " AND ( 1 = 0" sqlPlaceCond += " AND ( 1 = 0"
} }
if params["placeCode"] != nil { if params["placeCode"] != nil {
sql += " " + placeCond + " t3.place_code = ?" sqlPlaceCond += " " + placeCond + " t3.place_code = ?"
sqlParams = append(sqlParams, params["placeCode"].(int)) sqlParams = append(sqlParams, params["placeCode"].(int))
} }
if params["isGlobal"] != nil { if params["isGlobal"] != nil {
if params["isGlobal"].(bool) { if params["isGlobal"].(bool) {
sql += " " + placeCond + " t1.is_global = 1" sqlPlaceCond += " " + placeCond + " t1.is_global = 1"
} else { } 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 { if params["skuID"] != nil {
sql += " AND t2.id = ?" sql += " AND t2.id = ?"
@@ -267,6 +271,7 @@ func GetSkuNames(keyword string, params map[string]interface{}, offset, pageSize
} }
sqlParams = append(sqlParams, pageSize, offset) sqlParams = append(sqlParams, pageSize, offset)
skuNamesInfo = &SkuNamesInfo{} skuNamesInfo = &SkuNamesInfo{}
globals.SugarLogger.Debug(sqlData)
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil { if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
countInfo := &struct{ Ct int }{} countInfo := &struct{ Ct int }{}
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil { if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {

View File

@@ -145,10 +145,11 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
sqlParams = append(sqlParams, fromStatus, toStatus) sqlParams = append(sqlParams, fromStatus, toStatus)
} }
if vendorStoreCond := strings.ToUpper(utils.Interface2String(params["vendorStoreCond"])); vendorStoreCond == "AND" || vendorStoreCond == "OR" { if vendorStoreCond := strings.ToUpper(utils.Interface2String(params["vendorStoreCond"])); vendorStoreCond == "AND" || vendorStoreCond == "OR" {
sqlVendorStoreCond := ""
if vendorStoreCond == "AND" { if vendorStoreCond == "AND" {
sqlWhere += " AND ( 1 = 1" sqlVendorStoreCond += " AND ( 1 = 1"
} else { } else {
sqlWhere += " AND ( 1 = 0" sqlVendorStoreCond += " AND ( 1 = 0"
} }
condMap := map[string]int{ condMap := map[string]int{
"jdm": utils.Interface2DirectIntWithDefault(params["jdCond"], 0), "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 { for tableName, cond := range condMap {
if cond != 0 { if cond != 0 {
sqlWhere += " " + vendorStoreCond + " " + tableName sqlVendorStoreCond += " " + vendorStoreCond + " " + tableName
} }
if cond == -1 { if cond == -1 {
sqlWhere += ".vendor_store_id IS NULL" sqlVendorStoreCond += ".vendor_store_id IS NULL"
} else if cond == 1 { } 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" + 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 + ` sqlFrom + sqlWhere + `