Browse Source

新增手机号校验

rdluck 4 years ago
parent
commit
66454f7e46
3 changed files with 41 additions and 0 deletions
  1. 5 0
      controllers/user.go
  2. 35 0
      services/elasticsearch.go
  3. 1 0
      services/task.go

+ 5 - 0
controllers/user.go

@@ -51,6 +51,11 @@ func (this *UserController) Login() {
 	}
 	newUserId := 0
 	if req.LoginType == 1 {
+		if req.Mobile=="" {
+			br.Msg = "参数错误"
+			br.ErrMsg = "参数错误,手机号为空 为空"
+			return
+		}
 		//BindMobile(openId, mobile string, userId, loginType int) (err error) {
 		req.Mobile = strings.Trim(req.Mobile, " ")
 		newUserId, err = models.PcBindMobile(unionId, req.Mobile, userId, req.LoginType)

+ 35 - 0
services/elasticsearch.go

@@ -432,3 +432,38 @@ func init21123() {
 	fmt.Println(searchByMatch)
 	fmt.Println("end")
 }
+
+func SearchByKeyWordQuery(keyWord string) (result []*models.SearchItem, err error) {
+	errorlog := log.New(os.Stdout, "APP", log.LstdFlags)
+	file := "./rdlucklog/eslog.log"
+	logFile, _ := os.OpenFile(file, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766)
+
+	client, err := elastic.NewClient(
+		elastic.SetURL(ES_URL),
+		elastic.SetBasicAuth(ES_USERNAME, ES_PASSWORD),
+		elastic.SetTraceLog(log.New(logFile, "ES-TRACE: ", 0)),
+		elastic.SetSniff(false), elastic.SetErrorLog(errorlog))
+
+	var esIndex = "cygx_article"
+
+	keyWordStr := "医疗"
+	queryString := elastic.NewQueryStringQuery(`Title:(` + keyWordStr + `) BodyText:(` + keyWordStr + `)`).Analyzer("ik_smart")
+	highlight := elastic.NewHighlight()
+	highlight = highlight.Fields(elastic.NewHighlighterField("Title"), elastic.NewHighlighterField("BodyText"))
+	highlight = highlight.PreTags("<font color='red'>").PostTags("</font>")
+	request := client.Search(esIndex).Highlight(highlight).Query(queryString)
+
+	searchByMatch, err := request.Do(context.Background())
+	if err != nil {
+		fmt.Println("request.Do err:",err.Error())
+		return result, err
+	}
+	if searchByMatch.Hits != nil {
+		for _, v := range searchByMatch.Hits.Hits {
+			articleJson, _ := v.Source.MarshalJSON()
+			utils.FileLog.Info("%s", string(articleJson))
+			fmt.Println(string(articleJson))
+		}
+	}
+	return
+}

+ 1 - 0
services/task.go

@@ -13,5 +13,6 @@ func Task() {
 	//GetIndustryMap()
 	//解析报告
 	//GetArticleExpert()
+	//SearchByKeyWordQuery("")
 	fmt.Println("end")
 }