- add bank list.
This commit is contained in:
@@ -69,35 +69,38 @@ func UpdatePlace(placeCode int, payload map[string]interface{}, userName string)
|
||||
|
||||
// todo 门店绑定信息可以考虑以数组形式返回,而不是现在这样
|
||||
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, err error) {
|
||||
sql := `
|
||||
sqlFrom := `
|
||||
FROM store t1
|
||||
LEFT JOIN place city ON t1.city_code = city.code AND city.level = 2
|
||||
LEFT JOIN place district ON t1.district_code = district.code AND district.level = 3
|
||||
LEFT JOIN store_map jdm ON t1.id = jdm.store_id AND jdm.vendor_id = 0
|
||||
LEFT JOIN store_map elmm ON t1.id = elmm.store_id AND elmm.vendor_id = 2
|
||||
LEFT JOIN store_map ebaim ON t1.id = ebaim.store_id AND ebaim.vendor_id = 3
|
||||
WHERE`
|
||||
`
|
||||
sqlWhere := `
|
||||
WHERE
|
||||
`
|
||||
sqlParams := make([]interface{}, 0)
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " (t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ? OR city.name LIKE ?"
|
||||
sqlWhere += " (t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ? OR city.name LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
sql += " OR t1.id = ? OR t1.city_code = ? OR t1.district_code = ? OR t1.lng = ? OR t1.lat = ?"
|
||||
sqlWhere += " OR t1.id = ? OR t1.city_code = ? OR t1.district_code = ? OR t1.lng = ? OR t1.lat = ?"
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64)
|
||||
}
|
||||
sql += ")"
|
||||
sqlWhere += ")"
|
||||
} else {
|
||||
sql += " 1 = 1"
|
||||
sqlWhere += " 1 = 1"
|
||||
}
|
||||
|
||||
if params["id"] != nil {
|
||||
sql += " AND t1.id = ?"
|
||||
sqlWhere += " AND t1.id = ?"
|
||||
sqlParams = append(sqlParams, params["id"].(int))
|
||||
}
|
||||
if params["name"] != nil {
|
||||
sql += " AND t1.name LIKE ?"
|
||||
sqlWhere += " AND t1.name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+params["name"].(string)+"%")
|
||||
}
|
||||
if params["placeID"] != nil {
|
||||
@@ -106,35 +109,46 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
level = params["placeLevel"].(int)
|
||||
}
|
||||
if level == 2 {
|
||||
sql += " AND t1.city_code = ?"
|
||||
sqlWhere += " AND t1.city_code = ?"
|
||||
} else {
|
||||
sql += " AND t1.district_code = ?"
|
||||
sqlWhere += " AND t1.district_code = ?"
|
||||
}
|
||||
sqlParams = append(sqlParams, params["placeID"].(int))
|
||||
}
|
||||
if params["address"] != nil {
|
||||
sql += " AND t1.address LIKE ?"
|
||||
sqlWhere += " AND t1.address LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+params["address"].(string)+"%")
|
||||
}
|
||||
if params["tel"] != nil {
|
||||
sql += " AND (t1.tel1 LIKE ? OR t1.tel2 LIKE ?)"
|
||||
sqlWhere += " AND (t1.tel1 LIKE ? OR t1.tel2 LIKE ?)"
|
||||
sqlParams = append(sqlParams, "%"+params["tel"].(string)+"%")
|
||||
sqlParams = append(sqlParams, "%"+params["tel"].(string)+"%")
|
||||
}
|
||||
// if params["cardCond"] != nil {
|
||||
// cardCond := params["cardCond"].(int)
|
||||
// if cardCond == -1 || cardCond == 1 {
|
||||
// sqlFrom += "\nLEFT JOIN bill_info ON t1.store_id = bill_info.jx_store_id\n"
|
||||
// if cardCond == -1 {
|
||||
// sqlWhere += " AND bill_info.id IS NULL"
|
||||
// } else {
|
||||
// sqlWhere += " AND bill_info.id IS NOT NULL"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if params["fromStatus"] != nil {
|
||||
fromStatus := params["fromStatus"].(int)
|
||||
toStatus := fromStatus
|
||||
if params["toStatus"] != nil {
|
||||
toStatus = params["toStatus"].(int)
|
||||
}
|
||||
sql += " AND t1.status >= ? AND t1.status <= ?"
|
||||
sqlWhere += " AND t1.status >= ? AND t1.status <= ?"
|
||||
sqlParams = append(sqlParams, fromStatus, toStatus)
|
||||
}
|
||||
if vendorStoreCond := strings.ToUpper(utils.Interface2String(params["vendorStoreCond"])); vendorStoreCond == "AND" || vendorStoreCond == "OR" {
|
||||
if vendorStoreCond == "AND" {
|
||||
sql += " AND ( 1 = 1"
|
||||
sqlWhere += " AND ( 1 = 1"
|
||||
} else {
|
||||
sql += " AND ( 1 = 0"
|
||||
sqlWhere += " AND ( 1 = 0"
|
||||
}
|
||||
condMap := map[string]int{
|
||||
"jdm": utils.Interface2DirectIntWithDefault(params["jdCond"], 0),
|
||||
@@ -143,18 +157,19 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
}
|
||||
for tableName, cond := range condMap {
|
||||
if cond != 0 {
|
||||
sql += " " + vendorStoreCond + " " + tableName
|
||||
sqlWhere += " " + vendorStoreCond + " " + tableName
|
||||
}
|
||||
if cond == -1 {
|
||||
sql += ".vendor_store_id IS NULL"
|
||||
sqlWhere += ".vendor_store_id IS NULL"
|
||||
} else if cond == 1 {
|
||||
sql += ".vendor_store_id IS NOT NULL"
|
||||
sqlWhere += ".vendor_store_id IS NOT NULL"
|
||||
}
|
||||
}
|
||||
sql += ")"
|
||||
sqlWhere += ")"
|
||||
}
|
||||
sqlData := "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 + `
|
||||
ORDER BY id
|
||||
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 + `
|
||||
ORDER BY t1.id
|
||||
LIMIT ? OFFSET ?`
|
||||
if pageSize == 0 {
|
||||
pageSize = model.DefPageSize
|
||||
@@ -165,7 +180,7 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
retVal = &StoresInfo{}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetRows(db, &retVal.Stores, sqlData, sqlParams...); err == nil {
|
||||
if err = dao.GetRows(db, &retVal.Stores, sql, sqlParams...); err == nil {
|
||||
countInfo := &struct{ Ct int }{}
|
||||
if err = dao.GetRow(db, countInfo, "SELECT FOUND_ROWS() ct"); err == nil {
|
||||
retVal.TotalCount = countInfo.Ct
|
||||
|
||||
Reference in New Issue
Block a user