From 1bdb67864d962dbb98f5fb4fbe8687803acc7487 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 30 Oct 2018 16:40:55 +0800 Subject: [PATCH] - keyword doesn't search store address but want search owner's mobile. --- business/jxstore/cms/store.go | 12 ++++++++++-- business/jxutils/jxutils.go | 4 ++++ business/model/legacymodel/weixins.go | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 702a08dcf..d266e3143 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -123,10 +123,18 @@ func GetStores(ctx *jxcontext.Context, keyword string, params map[string]interfa } if keyword != "" { keywordLike := "%" + keyword + "%" - sqlWhere += " AND (t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ? OR city.name LIKE ? OR m1.vendor_store_id LIKE ? OR m2.vendor_store_id LIKE ?" - sqlWhereParams = append(sqlWhereParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike) + sqlWhere += " AND (t1.name LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ? OR city.name LIKE ? OR m1.vendor_store_id LIKE ? OR m2.vendor_store_id LIKE ?" + sqlWhereParams = append(sqlWhereParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike) if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil { + if jxutils.IsLegalMobileNumber(keywordInt64) { + sql += ` + LEFT JOIN weixins wx1 ON t1.id = wx1.jxstoreid AND wx1.tel = ? + LEFT JOIN weixins wx2 ON wx2.parentid = wx1.id AND wx2.tel = ? + ` + sqlParams = append(sqlParams, keywordInt64, keywordInt64) + sqlWhere += " OR wx1.id IS NOT NULL OR wx2.id IS NOT NULL" + } sqlWhere += " OR t1.id = ? OR t1.city_code = ? OR t1.district_code = ? OR t1.lng = ? OR t1.lat = ?" sqlWhereParams = append(sqlWhereParams, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64) } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index b0cb69c01..be5437244 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -343,3 +343,7 @@ func MakeValidationMapFromSlice(validValues []string, flag int) map[string]int { func ComposeQiniuResURL(key string) string { return "http://image.jxc4.com/" + key } + +func IsLegalMobileNumber(num int64) bool { + return num >= 13000000000 && num <= 19999999999 +} diff --git a/business/model/legacymodel/weixins.go b/business/model/legacymodel/weixins.go index e48f7cb31..39d716d69 100644 --- a/business/model/legacymodel/weixins.go +++ b/business/model/legacymodel/weixins.go @@ -2,7 +2,7 @@ package legacymodel type WeiXins struct { ID int `orm:"column(id)" json:"id"` - JxStoreID int `orm:"column(jxstoreid)" json:"storeID"` + JxStoreID int `orm:"column(jxstoreid);index" json:"storeID"` OpenID string `orm:"column(openid);size(70);unique;null" json:"openID"` Tel string `orm:"size(15);unique" json:"tel"` ParentID int `orm:"column(parentid);default(-1)" json:"parentID"`