Преглед на файлове

绑定手机号加区号

xingzai преди 3 години
родител
ревизия
a15f5a6c26
променени са 7 файла, в които са добавени 116 реда и са изтрити 11 реда
  1. 7 6
      controllers/user.go
  2. 9 0
      models/article.go
  3. 5 4
      models/user.go
  4. 1 0
      models/wx_user.go
  5. 49 0
      services/elastic.go
  6. 43 0
      services/task.go
  7. 2 1
      services/user.go

+ 7 - 6
controllers/user.go

@@ -260,7 +260,7 @@ func (this *UserController) Login() {
 		br.ErrMsg = "无效的登录方式,Err:" + err.Error()
 		return
 	}
-	user, err = services.BindWxUser(openId, req.Mobile, req.Email)
+	user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
 	userId := user.UserId
 	var token string
 	tokenItem, err := models.GetTokenByOpenId(openId)
@@ -336,7 +336,7 @@ func (this *UserController) Detail() {
 	}
 	uid := user.UserId
 
-	fmt.Println("uid:",uid)
+	fmt.Println("uid:", uid)
 
 	var hasPermission int
 	detail := new(models.UserDetail)
@@ -808,9 +808,9 @@ func (this *UserController) ApplyTryOut() {
 	uid := user.UserId
 
 	//缓存校验
-	cacheKey := fmt.Sprint("xygx:apply_record:add:",uid)
+	cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
 	ttlTime := utils.Rc.GetRedisTTL(cacheKey)
-	if ttlTime > 0{
+	if ttlTime > 0 {
 		br.Msg = "申请失败,申请过于频繁"
 		br.ErrMsg = "申请失败,申请过于频繁"
 		return
@@ -946,9 +946,10 @@ func (this *UserController) ApplyTryOut() {
 	br.Data = sellerMobile
 }
 
-func sentMsgToSeller(){
+func sentMsgToSeller() {
 
 }
+
 //func init() {
 //	fmt.Println("start")
 //	realName:="沈涛"
@@ -959,4 +960,4 @@ func sentMsgToSeller(){
 //	services.SendPermissionApplyTemplateMsg(realName, companyName, mobile, openId, applyMethod)
 //	return
 //	fmt.Println("end")
-//}
+//}

+ 9 - 0
models/article.go

@@ -77,6 +77,8 @@ type ArticleDetail struct {
 	ArticleIdMd5         string `description:"纪要id"`
 	IsClass              int    `description:"是否归类,1是,0否"`
 	CategoryId           int    `description:"分类ID"`
+	IsSummary            int    `description:"是否是纪要库,1是,0否"`
+	IsReport             int    `description:"是否属于报告,1是,0否"`
 	FileLink             string `description:"下载预览链接"`
 	SellerAndMobile      string `description:"销售和手机号"`
 	SellerList           []*SellerRep
@@ -179,6 +181,13 @@ func GetArticleAll() (item []*ArticleDetail, err error) {
 	return
 }
 
+func GetArticleAll2() (item []*ArticleDetail, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article  `
+	_, err = o.Raw(sql).QueryRows(&item)
+	return
+}
+
 func ModifyArticleContent(articleId int, content, expertNumStr, expertContentStr, interviewDateStr string) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE cygx_article SET body=?,expert_background=?,expert_number=?,interview_date=? WHERE article_id=? `

+ 5 - 4
models/user.go

@@ -34,10 +34,11 @@ type UserPermission struct {
 }
 
 type LoginReq struct {
-	LoginType int    `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
-	Mobile    string `description:"手机号"`
-	Email     string `description:"邮箱"`
-	VCode     string `description:"验证码"`
+	LoginType   int    `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
+	Mobile      string `description:"手机号"`
+	Email       string `description:"邮箱"`
+	VCode       string `description:"验证码"`
+	CountryCode string `description:"区号"`
 }
 
 func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {

+ 1 - 0
models/wx_user.go

@@ -45,6 +45,7 @@ type WxUser struct {
 	SessionKey       string    `description:"微信小程序会话密钥"`
 	IsRegister       int       `description:"是否注册:1:已注册,0:未注册"`
 	Source           int       `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
+	CountryCode      string    `description:"区号"`
 }
 
 //添加用户信息

+ 49 - 0
services/elastic.go

@@ -105,6 +105,55 @@ func EsAddOrEditData(indexName, docId string, item *ElasticTestArticleDetail) (e
 	return
 }
 
+//新增和修改数据
+func EsAddOrEditDataV4(indexName, docId string, item *ElasticTestArticleDetailV4) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("EsAddOrEditData Err:", err.Error())
+		}
+	}()
+	client, err := NewClient()
+	if err != nil {
+		return
+	}
+	searchById, err := client.Get().Index(indexName).Id(docId).Do(context.Background())
+	if err != nil && !strings.Contains(err.Error(), "404") {
+		fmt.Println("Get Err" + err.Error())
+		return
+	}
+	if searchById != nil && searchById.Found {
+		resp, err := client.Update().Index(indexName).Id(docId).Doc(map[string]interface{}{
+			"BodyText":    item.BodyText,
+			"Title":       item.Title,
+			"PublishDate": item.PublishDate,
+			"IsSummary":   item.IsSummary,
+			"IsReport":    item.IsReport,
+		}).Do(context.Background())
+		if err != nil {
+			return err
+		}
+		fmt.Println(resp.Status, resp.Result)
+		if resp.Status == 0 {
+			fmt.Println("修改成功")
+		} else {
+			fmt.Println("EditData", resp.Status, resp.Result)
+		}
+	} else {
+		resp, err := client.Index().Index(indexName).Id(docId).BodyJson(item).Do(context.Background())
+		if err != nil {
+			fmt.Println("新增失败:", err.Error())
+			return err
+		}
+		if resp.Status == 0 && resp.Result == "created" {
+			fmt.Println("新增成功")
+			err = nil
+		} else {
+			fmt.Println("AddData", resp.Status, resp.Result)
+		}
+	}
+	return
+}
+
 //删除数据
 func EsDeleteData(indexName, docId string) (err error) {
 	client, err := NewClient()

+ 43 - 0
services/task.go

@@ -269,6 +269,40 @@ func AddAllArticle() {
 	}
 }
 
+func AddAllArticleV4() {
+	allList, err := models.GetArticleAll2()
+	if err != nil {
+		fmt.Println("GetArticleAll Err:", err.Error())
+		return
+	}
+
+	indexName := "cygx_article_v4"
+
+	for _, v := range allList {
+		content := html.UnescapeString(v.Body)
+		doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
+		if err != nil {
+			fmt.Println("create doc err:", err.Error())
+			return
+		}
+		bodyText := doc.Text()
+
+		item := new(ElasticTestArticleDetailV4)
+		item.ArticleId = v.ArticleId
+		item.Title = v.Title
+		item.PublishDate = v.PublishDate
+		item.BodyText = bodyText
+		if v.IsReport == 1 {
+			item.IsReport = true
+		}
+		if v.IsSummary == 1 {
+			item.IsSummary = true
+		}
+		EsAddOrEditDataV4(indexName, strconv.Itoa(v.ArticleId), item)
+		fmt.Println(v.ArticleId)
+	}
+}
+
 // "term_vector": "with_positions_offsets"
 
 type ElasticArticleDetail struct {
@@ -295,3 +329,12 @@ type ElasticTestArticleDetail struct {
 	BodyText    string `description:"内容"`
 	PublishDate string `description:"发布时间"`
 }
+
+type ElasticTestArticleDetailV4 struct {
+	ArticleId   int    `description:"报告id"`
+	Title       string `description:"标题"`
+	BodyText    string `description:"内容"`
+	PublishDate string `description:"发布时间"`
+	IsSummary   bool   `description:"是否属于纪要库"`
+	IsReport    bool   `description:"是否属于报告"`
+}

+ 2 - 1
services/user.go

@@ -165,7 +165,7 @@ func formatWxUser(wxUser *models.WxUserItem, platform int) {
 }
 
 //用户绑定
-func BindWxUser(openid, mobile, email string) (wxUser *models.WxUserItem, err error) {
+func BindWxUser(openid, mobile, email, countryCode string) (wxUser *models.WxUserItem, err error) {
 	if mobile == "" && email == "" {
 		err = errors.New("手机号或邮箱必填一个")
 		return
@@ -212,6 +212,7 @@ func BindWxUser(openid, mobile, email string) (wxUser *models.WxUserItem, err er
 			Email:            email,
 			IsRegister:       1,
 			Source:           3,
+			CountryCode:      countryCode,
 		}
 		tmpUserId, addUserErr := models.AddWxUser(user)
 		if err != nil {