|
@@ -4,6 +4,7 @@ import (
|
|
|
"fmt"
|
|
|
mg "mongodb"
|
|
|
qutil "qfw/util"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -24,7 +25,7 @@ func (this *PhoneUtil) Log(userId, operation, value string) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-//获取微信关联字段
|
|
|
+// 获取微信关联字段
|
|
|
func (this *PhoneUtil) getWxRelationMap(userId string) *map[string]interface{} {
|
|
|
rData, _ := this.UserMgoDB.FindById("user", userId, `{"s_unionid":1,"s_name":1,"s_nickname":1,"s_headimageurl":1}`)
|
|
|
if rData == nil || len(*rData) == 0 {
|
|
@@ -34,7 +35,7 @@ func (this *PhoneUtil) getWxRelationMap(userId string) *map[string]interface{} {
|
|
|
return rData
|
|
|
}
|
|
|
|
|
|
-//获取手机号
|
|
|
+// 获取手机号
|
|
|
func (this *PhoneUtil) getUserPhone(userId string) (phone string) {
|
|
|
rData, _ := this.UserMgoDB.FindById("user", userId, `{"s_phone":1}`)
|
|
|
if rData != nil && len(*rData) > 0 {
|
|
@@ -43,7 +44,7 @@ func (this *PhoneUtil) getUserPhone(userId string) (phone string) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//绑定微信
|
|
|
+// 绑定微信
|
|
|
func (this *PhoneUtil) bindWeixin(phoneUserId string, wxRelationMap *map[string]interface{}, opera string) error {
|
|
|
if !this.UserMgoDB.UpdateById("user", phoneUserId, map[string]interface{}{
|
|
|
"$set": wxRelationMap,
|
|
@@ -55,7 +56,7 @@ func (this *PhoneUtil) bindWeixin(phoneUserId string, wxRelationMap *map[string]
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//解绑微信
|
|
|
+// 解绑微信
|
|
|
func (this *PhoneUtil) unBindWeixin(phoneUserId, opera string) error {
|
|
|
//查询解绑微信unionid
|
|
|
logMap := this.getWxRelationMap(phoneUserId)
|
|
@@ -73,7 +74,7 @@ func (this *PhoneUtil) unBindWeixin(phoneUserId, opera string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//绑定手机号
|
|
|
+// 绑定手机号
|
|
|
func (this *PhoneUtil) bindPhone(weixinUserId, phone, opera string) error {
|
|
|
if !this.UserMgoDB.UpdateById("user", weixinUserId, map[string]interface{}{
|
|
|
"$set": map[string]interface{}{
|
|
@@ -88,7 +89,7 @@ func (this *PhoneUtil) bindPhone(weixinUserId, phone, opera string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//解除手机号关联
|
|
|
+// 解除手机号关联
|
|
|
func (this *PhoneUtil) unBindPhone(weixinUserId, opera string) error {
|
|
|
logPhone := this.getUserPhone(weixinUserId)
|
|
|
if !this.UserMgoDB.UpdateById("user", weixinUserId, map[string]interface{}{
|
|
@@ -103,7 +104,7 @@ func (this *PhoneUtil) unBindPhone(weixinUserId, opera string) error {
|
|
|
|
|
|
//=============================================
|
|
|
|
|
|
-//建立双向关联关系
|
|
|
+// 建立双向关联关系
|
|
|
func (this *PhoneUtil) buildRelation(wxUserId, phoneUserId, phone string, wxRelationMap *map[string]interface{}, opera string) error {
|
|
|
//建立双向关联关系
|
|
|
if wxRelationMap == nil {
|
|
@@ -124,7 +125,7 @@ func (this *PhoneUtil) buildRelation(wxUserId, phoneUserId, phone string, wxRela
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//解除双向绑定
|
|
|
+// 解除双向绑定
|
|
|
func (this *PhoneUtil) RelieveRelation(weixinId, phoneId, opera string) error {
|
|
|
if err := this.unBindPhone(weixinId, opera); err != nil {
|
|
|
return err
|
|
@@ -135,7 +136,7 @@ func (this *PhoneUtil) RelieveRelation(weixinId, phoneId, opera string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-//查询是否存在双向关联关系
|
|
|
+// 查询是否存在双向关联关系
|
|
|
func (this *PhoneUtil) QueryRelation(phone string) (wId, pId string, err error) {
|
|
|
relationUser, _ := this.UserMgoDB.Find("user", map[string]interface{}{
|
|
|
"i_appid": 2,
|
|
@@ -170,9 +171,13 @@ func (this *PhoneUtil) QueryRelation(phone string) (wId, pId string, err error)
|
|
|
/*
|
|
|
微信账号绑定手机号判断是否存在
|
|
|
param unionId:当前微信的s_unionid
|
|
|
- phone:要绑定的手机号
|
|
|
+
|
|
|
+ phone:要绑定的手机号
|
|
|
+
|
|
|
return exists:是否存在
|
|
|
- relationPhoneId:需要建立关联关系的手机号用户id
|
|
|
+
|
|
|
+ relationPhoneId:需要建立关联关系的手机号用户id
|
|
|
+
|
|
|
rule 1.不存在手机号,2.存在手机号用户,但此手机号未绑定微信 3.存在手机号用户,或绑定微信和当前账户绑定微信一致
|
|
|
*/
|
|
|
func (this *PhoneUtil) BindPhoneIsOccupy(unionId, phone string) (exists bool, relationPhoneId string) {
|
|
@@ -204,9 +209,10 @@ func (this *PhoneUtil) BindPhoneIsOccupy(unionId, phone string) (exists bool, re
|
|
|
/*
|
|
|
绑定手机号
|
|
|
param wxUserId:绑定手机号的微信
|
|
|
- relationPhoneId:存在关联的手机号账户
|
|
|
- phone:绑定的手机号
|
|
|
- wxRelationMap:相关联的微信信息
|
|
|
+
|
|
|
+ relationPhoneId:存在关联的手机号账户
|
|
|
+ phone:绑定的手机号
|
|
|
+ wxRelationMap:相关联的微信信息
|
|
|
*/
|
|
|
func (this *PhoneUtil) BindPhone(wxUserId, relationPhoneId, phone string, wxRelationMap *map[string]interface{}) error {
|
|
|
if relationPhoneId == "" {
|
|
@@ -221,9 +227,13 @@ func (this *PhoneUtil) BindPhone(wxUserId, relationPhoneId, phone string, wxRela
|
|
|
/*
|
|
|
更改手机号
|
|
|
param phone要更改的手机号
|
|
|
- needMerge:当前账户是否需要合并
|
|
|
+
|
|
|
+ needMerge:当前账户是否需要合并
|
|
|
+
|
|
|
return exists:是否存在
|
|
|
- relationPhoneId:需要建立关联关系的手机号用户id
|
|
|
+
|
|
|
+ relationPhoneId:需要建立关联关系的手机号用户id
|
|
|
+
|
|
|
rule:在合并状态的微信账户,可以更换存在但未绑定微信的手机号;其他情况只能更换新手机号
|
|
|
*/
|
|
|
func (this *PhoneUtil) ChangePhoneIsOccupy(phone string, isWxAndNeedMerge bool) (exists bool, relationPhoneId string) {
|
|
@@ -270,9 +280,13 @@ func (this *PhoneUtil) ChangePhoneIsOccupy(phone string, isWxAndNeedMerge bool)
|
|
|
/*
|
|
|
手机号账号绑定微信判断微信是否存在
|
|
|
param phone:当前手机号
|
|
|
- unionId:要绑定的微信s_unionid
|
|
|
+
|
|
|
+ unionId:要绑定的微信s_unionid
|
|
|
+
|
|
|
return exists:是否存在
|
|
|
- relationWeixinId:需要建立关联关系的微信用户id
|
|
|
+
|
|
|
+ relationWeixinId:需要建立关联关系的微信用户id
|
|
|
+
|
|
|
rule 存在对应的微信 1.未绑定手机号 2.绑定手机号为当前账户手机号
|
|
|
*/
|
|
|
func (this *PhoneUtil) BindWeixinIsOccupy(phone, unionId string) (exists bool, relationWeixinId string) {
|
|
@@ -304,9 +318,10 @@ func (this *PhoneUtil) BindWeixinIsOccupy(phone, unionId string) (exists bool, r
|
|
|
/*
|
|
|
手机号账号绑定微信
|
|
|
param phoneUserId:绑定微信的手机账户
|
|
|
- relationWeixinId:存在相关联的微信信息
|
|
|
- phone:当前手机账号手机号
|
|
|
- wxRelationMap:相关联的微信信息
|
|
|
+
|
|
|
+ relationWeixinId:存在相关联的微信信息
|
|
|
+ phone:当前手机账号手机号
|
|
|
+ wxRelationMap:相关联的微信信息
|
|
|
*/
|
|
|
func (this *PhoneUtil) BindWeixin(phoneUserId, relationWeixinId, phone string, wxRelationMap *map[string]interface{}, opear ...string) error {
|
|
|
logFlag := "BindWeixin"
|
|
@@ -323,7 +338,8 @@ func (this *PhoneUtil) BindWeixin(phoneUserId, relationWeixinId, phone string, w
|
|
|
/*
|
|
|
手机号解绑微信
|
|
|
param phoneUserId:绑定微信的手机账户
|
|
|
- relationWeixinId:存在相关联的微信信息
|
|
|
+
|
|
|
+ relationWeixinId:存在相关联的微信信息
|
|
|
*/
|
|
|
func (this *PhoneUtil) UnBindWeixin(phoneUserId, relationWeixinId string, opear ...string) error {
|
|
|
logFlag := "UnBindWeixin"
|
|
@@ -336,3 +352,70 @@ func (this *PhoneUtil) UnBindWeixin(phoneUserId, relationWeixinId string, opear
|
|
|
return this.RelieveRelation(relationWeixinId, phoneUserId, logFlag)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// GetMatchKey key 关键词 逗号分隔 或的关系进行关联 types 匹配类型 data数据
|
|
|
+// title 标题,detail 正文,filetext 附件,purchasing 标的物,projectname.pname 项目命,mbuyer 采购单位,mwinner 中标单位,magency 代理机构
|
|
|
+func GetMatchKey(key, types string, data map[string]interface{}) string {
|
|
|
+ keyWord := []string{}
|
|
|
+ if strings.Contains(types, "title") {
|
|
|
+ title := qutil.ObjToString(data["title"])
|
|
|
+ keyWord = KeyWordToDatas(title, key, keyWord)
|
|
|
+ }
|
|
|
+ if strings.Contains(types, "detail") {
|
|
|
+ detail := qutil.ObjToString(data["detail"])
|
|
|
+ keyWord = KeyWordToDatas(detail, key, keyWord)
|
|
|
+ }
|
|
|
+ if strings.Contains(types, "purchasing") {
|
|
|
+ purchasing := qutil.ObjToString(data["purchasing"])
|
|
|
+ keyWord = KeyWordToDatas(purchasing, key, keyWord)
|
|
|
+ }
|
|
|
+ if strings.Contains(types, "filetext") {
|
|
|
+ filetext := qutil.ObjToString(data["filetext"])
|
|
|
+ keyWord = KeyWordToDatas(filetext, key, keyWord)
|
|
|
+ }
|
|
|
+ if strings.Contains(types, "projectname.pname") {
|
|
|
+ projectname := qutil.ObjToString(data["projectname"])
|
|
|
+ keyWord = KeyWordToDatas(projectname, key, keyWord)
|
|
|
+ }
|
|
|
+ if strings.Contains(types, "mbuyer") {
|
|
|
+ buyer := qutil.ObjToString(data["buyer"])
|
|
|
+ keyWord = KeyWordToDatas(buyer, key, keyWord)
|
|
|
+ }
|
|
|
+ if strings.Contains(types, "mwinner") {
|
|
|
+ winner := qutil.ObjToString(data["s_winner"])
|
|
|
+ keyWord = KeyWordToDatas(winner, key, keyWord)
|
|
|
+ }
|
|
|
+ if strings.Contains(types, "magency") {
|
|
|
+ winner := qutil.ObjToString(data["agency"])
|
|
|
+ keyWord = KeyWordToDatas(winner, key, keyWord)
|
|
|
+ }
|
|
|
+ keyMap := map[string]bool{}
|
|
|
+ keyArr := []string{}
|
|
|
+ for _, key := range keyWord {
|
|
|
+ keyMap[key] = true
|
|
|
+ }
|
|
|
+ for k, _ := range keyMap {
|
|
|
+ keyArr = append(keyArr, k)
|
|
|
+ }
|
|
|
+ return strings.Join(keyArr, ",")
|
|
|
+}
|
|
|
+
|
|
|
+func KeyWordToDatas(item, key string, keyWord []string) []string {
|
|
|
+ for _, mk := range strings.Split(key, ",") {
|
|
|
+ if strings.Contains(mk, "&&") {
|
|
|
+ arr := strings.Split(mk, "&&")
|
|
|
+ for _, s := range arr {
|
|
|
+ if s != "" {
|
|
|
+ if strings.Contains(strings.ToUpper(item), strings.ToUpper(s)) {
|
|
|
+ keyWord = append(keyWord, mk)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if strings.Contains(strings.ToUpper(item), strings.ToUpper(mk)) {
|
|
|
+ keyWord = append(keyWord, mk)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return keyWord
|
|
|
+}
|