|
@@ -1,1098 +1,1098 @@
|
|
|
package entity
|
|
|
|
|
|
import (
|
|
|
- qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
- "fmt"
|
|
|
- "jy/src/jfw/modules/publicapply/src/config"
|
|
|
- "jy/src/jfw/modules/publicapply/src/db"
|
|
|
- "jy/src/jfw/modules/publicapply/src/util"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
+ qutil "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/go-xweb/httpsession"
|
|
|
+ "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
|
|
|
+ "fmt"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/config"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/db"
|
|
|
+ "jy/src/jfw/modules/publicapply/src/util"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
|
|
|
- "go.mongodb.org/mongo-driver/bson"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
)
|
|
|
|
|
|
type KeyWordsSet struct {
|
|
|
- ClassifyIndex string //分类索引
|
|
|
- ClassifyName string //分类名称
|
|
|
- KeyWordIndex string //关键词索引
|
|
|
- KeyWordName string //关键词名称
|
|
|
- ActionType string //操作类型 SK:保存/修改关键词; DK:删除关键词; SC:保存/修改分类 DC:删除分类
|
|
|
- AppendKeyWord []string //附加词
|
|
|
- NotKeyWord []string //排除词
|
|
|
- MatchWay int // 单个关键词匹配方事 0:精准匹配 1:模糊匹配
|
|
|
- KeyWordsCount string //是否是首次添加关键词
|
|
|
- Type string // 大会员/超级订阅
|
|
|
- UserId string //用户id
|
|
|
- DeleteKey string //删除的关键词 json字符串{"0":"1,2","2":"0,3"} key:分类名称索引 value:分类名称下的关键词索引
|
|
|
- Power int
|
|
|
- EntId int
|
|
|
- EntUserId int
|
|
|
- Session *httpsession.Session
|
|
|
+ ClassifyIndex string //分类索引
|
|
|
+ ClassifyName string //分类名称
|
|
|
+ KeyWordIndex string //关键词索引
|
|
|
+ KeyWordName string //关键词名称
|
|
|
+ ActionType string //操作类型 SK:保存/修改关键词; DK:删除关键词; SC:保存/修改分类 DC:删除分类
|
|
|
+ AppendKeyWord []string //附加词
|
|
|
+ NotKeyWord []string //排除词
|
|
|
+ MatchWay int // 单个关键词匹配方事 0:精准匹配 1:模糊匹配
|
|
|
+ KeyWordsCount string //是否是首次添加关键词
|
|
|
+ Type string // 大会员/超级订阅
|
|
|
+ UserId string //用户id
|
|
|
+ DeleteKey string //删除的关键词 json字符串{"0":"1,2","2":"0,3"} key:分类名称索引 value:分类名称下的关键词索引
|
|
|
+ Power int
|
|
|
+ EntId int
|
|
|
+ EntUserId int
|
|
|
+ Session *httpsession.Session
|
|
|
}
|
|
|
|
|
|
func (this *KeyWordsSet) UpdateKeyWords() map[string]interface{} {
|
|
|
- power := jy.GetBigVipUserBaseMsg("10000", this.Session, config.Config.Etcd.Hosts, config.Config.Etcd.Key)
|
|
|
- if this.Type == "m" && power.Status < 0 {
|
|
|
- return map[string]interface{}{"flag": false, "msg": "暂无权限"}
|
|
|
- }
|
|
|
- types := "o_jy"
|
|
|
- if this.Type == "m" {
|
|
|
- types = "o_member_jy"
|
|
|
- } else if this.Type == "v" {
|
|
|
- types = "o_vipjy"
|
|
|
- }
|
|
|
- //付费用户
|
|
|
- if this.Type != "f" && (power.Status > 0 || power.VipStatus > 0) {
|
|
|
- switch this.ActionType {
|
|
|
- case "SK": //保存/修改关键词
|
|
|
- return AddKeyWords(types, this.UserId, this.ClassifyIndex, this.ClassifyName, this.KeyWordIndex, this.KeyWordName, this.KeyWordsCount, this.NotKeyWord, this.AppendKeyWord, this.MatchWay, this.Session)
|
|
|
- case "DK": //删除关键词
|
|
|
- return DeleteKeyWords(types, this.DeleteKey, this.UserId, this.Session)
|
|
|
- case "SC": //保存/修改分类
|
|
|
- return AddClass(types, this.ClassifyIndex, this.ClassifyName, this.UserId, this.Session)
|
|
|
- case "DC": //删除分类
|
|
|
- return DeleteClass(types, this.ClassifyIndex, this.UserId, this.Session)
|
|
|
- case "directSubKWS": //搜索列表直接订阅关键词
|
|
|
- return directSubKWS(types, this.KeyWordName, this.UserId, this.Session)
|
|
|
- }
|
|
|
- } else {
|
|
|
- this.ClassifyIndex = "0"
|
|
|
- this.ClassifyName = "未分类"
|
|
|
- switch this.ActionType {
|
|
|
- case "SK": //保存/修改关键词
|
|
|
- return AddKeyWordsFree(types, this.UserId, this.ClassifyIndex, this.ClassifyName, this.KeyWordIndex, this.KeyWordName, this.KeyWordsCount, this.NotKeyWord, this.AppendKeyWord, this.MatchWay, this.Session)
|
|
|
- case "DK": //删除关键词
|
|
|
- return DeleteKeyWordsFree(types, this.DeleteKey, this.Session)
|
|
|
- case "directSubKWS": //搜索列表直接订阅关键词
|
|
|
- return directSubKWSFree(types, this.KeyWordName, this.Session)
|
|
|
- }
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": true, "msg": ""}
|
|
|
+ power := jy.GetBigVipUserBaseMsg("10000", this.Session, config.Config.Etcd.Hosts, config.Config.Etcd.Key)
|
|
|
+ if this.Type == "m" && power.Status < 0 {
|
|
|
+ return map[string]interface{}{"flag": false, "msg": "暂无权限"}
|
|
|
+ }
|
|
|
+ types := "o_jy"
|
|
|
+ if this.Type == "m" {
|
|
|
+ types = "o_member_jy"
|
|
|
+ } else if this.Type == "v" {
|
|
|
+ types = "o_vipjy"
|
|
|
+ }
|
|
|
+ //付费用户
|
|
|
+ if this.Type != "f" && (power.Status > 0 || power.VipStatus > 0) {
|
|
|
+ switch this.ActionType {
|
|
|
+ case "SK": //保存/修改关键词
|
|
|
+ return AddKeyWords(types, this.UserId, this.ClassifyIndex, this.ClassifyName, this.KeyWordIndex, this.KeyWordName, this.KeyWordsCount, this.NotKeyWord, this.AppendKeyWord, this.MatchWay, this.Session)
|
|
|
+ case "DK": //删除关键词
|
|
|
+ return DeleteKeyWords(types, this.DeleteKey, this.UserId, this.Session)
|
|
|
+ case "SC": //保存/修改分类
|
|
|
+ return AddClass(types, this.ClassifyIndex, this.ClassifyName, this.UserId, this.Session)
|
|
|
+ case "DC": //删除分类
|
|
|
+ return DeleteClass(types, this.ClassifyIndex, this.UserId, this.Session)
|
|
|
+ case "directSubKWS": //搜索列表直接订阅关键词
|
|
|
+ return directSubKWS(types, this.KeyWordName, this.UserId, this.Session)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.ClassifyIndex = "0"
|
|
|
+ this.ClassifyName = "未分类"
|
|
|
+ switch this.ActionType {
|
|
|
+ case "SK": //保存/修改关键词
|
|
|
+ return AddKeyWordsFree(types, this.UserId, this.ClassifyIndex, this.ClassifyName, this.KeyWordIndex, this.KeyWordName, this.KeyWordsCount, this.NotKeyWord, this.AppendKeyWord, this.MatchWay, this.Session)
|
|
|
+ case "DK": //删除关键词
|
|
|
+ return DeleteKeyWordsFree(types, this.DeleteKey, this.Session)
|
|
|
+ case "directSubKWS": //搜索列表直接订阅关键词
|
|
|
+ return directSubKWSFree(types, this.KeyWordName, this.Session)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": true, "msg": ""}
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func directSubKWSFree(types string, keys string, session *httpsession.Session) map[string]interface{} {
|
|
|
- userId := qutil.ObjToString(session.Get("userId"))
|
|
|
- //data, ok := db.Mgo.FindById("user", userId, fmt.Sprintf(`{"%s":1}`, types))
|
|
|
- data := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
- var repleat = false
|
|
|
- var kwsCount = 0
|
|
|
- if len([]rune(keys)) > 20 {
|
|
|
- keys = qutil.SubString(keys, 0, 20)
|
|
|
- }
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.Int64All(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.Int64All(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- flag := "n"
|
|
|
- if data != nil && len(*data) > 0 && keys != "" {
|
|
|
- updateObj, _ := (*data)[types].(map[string]interface{})
|
|
|
- if updateObj["a_key"] != nil && len(qutil.ObjArrToMapArr(updateObj["a_key"].([]interface{}))) > 0 {
|
|
|
- a_key := updateObj["a_key"].([]interface{})
|
|
|
- for _, n := range a_key {
|
|
|
- ntmp := qutil.ObjToMap(n.(interface{}))
|
|
|
- nkey := qutil.ObjArrToStringArr((*ntmp)["key"].([]interface{}))
|
|
|
- if strings.Join(nkey, " ") == keys {
|
|
|
- repleat = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- //无关键词 直接添加
|
|
|
- if positionType == 0 {
|
|
|
- if ok := db.Mgo.UpdateById("user", userId, bson.M{"$set": bson.M{
|
|
|
- fmt.Sprintf("%s.a_key", types): bson.A{
|
|
|
- bson.M{
|
|
|
- "key": bson.A{keys},
|
|
|
- "appendkey": bson.A{},
|
|
|
- "notkey": bson.A{},
|
|
|
- "updatetime": time.Now().Unix(),
|
|
|
- },
|
|
|
- },
|
|
|
- types + ".l_modifydate": time.Now().Unix(),
|
|
|
- // types + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
- },
|
|
|
- }); ok {
|
|
|
- flag = "y"
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ok := db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{
|
|
|
- fmt.Sprintf("%s.a_key", types): bson.A{
|
|
|
- bson.M{
|
|
|
- "key": bson.A{keys},
|
|
|
- "appendkey": bson.A{},
|
|
|
- "notkey": bson.A{},
|
|
|
- "updatetime": time.Now().Unix(),
|
|
|
- },
|
|
|
- },
|
|
|
- types + ".l_modifydate": time.Now().Unix(),
|
|
|
- // types + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
- },
|
|
|
- }, true, false); ok {
|
|
|
- flag = "y"
|
|
|
- }
|
|
|
- }
|
|
|
+ userId := qutil.ObjToString(session.Get("userId"))
|
|
|
+ //data, ok := db.Mgo.FindById("user", userId, fmt.Sprintf(`{"%s":1}`, types))
|
|
|
|
|
|
- return map[string]interface{}{"flag": flag}
|
|
|
- }
|
|
|
- if repleat {
|
|
|
- flag = "o"
|
|
|
- } else if kwsCount >= 10 {
|
|
|
- flag = "m"
|
|
|
- } else {
|
|
|
- var _key = make(map[string]interface{})
|
|
|
- var a_key = make([]map[string]interface{}, 1)
|
|
|
- classify_name := "未分类"
|
|
|
- _key["key"] = strings.Split(strings.ReplaceAll(keys, " ", ""), " ")
|
|
|
- _key["appendkey"] = []string{}
|
|
|
- _key["notkey"] = []string{}
|
|
|
- _key["updatetime"] = time.Now().Unix()
|
|
|
- a_key[0] = _key
|
|
|
- if len(a_key) > 0 {
|
|
|
- ok := false
|
|
|
- if positionType == 0 {
|
|
|
- ok = db.Mgo.UpdateById("user", userId, bson.M{
|
|
|
- "$push": bson.M{
|
|
|
- types + ".a_key": bson.M{
|
|
|
- "$each": a_key,
|
|
|
- },
|
|
|
- },
|
|
|
- "$set": bson.M{
|
|
|
- types + ".l_modifydate": time.Now().Unix(),
|
|
|
- types + ".s_item": classify_name,
|
|
|
- // updateItems + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
- },
|
|
|
- })
|
|
|
- } else {
|
|
|
- ok = db.Mgo.Update("entniche_rule", query, bson.M{
|
|
|
- "$push": bson.M{
|
|
|
- types + ".a_key": bson.M{
|
|
|
- "$each": a_key,
|
|
|
- },
|
|
|
- },
|
|
|
- "$set": bson.M{
|
|
|
- types + ".l_modifydate": time.Now().Unix(),
|
|
|
- types + ".s_item": classify_name,
|
|
|
- // updateItems + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
- },
|
|
|
- }, true, false)
|
|
|
- }
|
|
|
- if ok {
|
|
|
- flag = "y"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if flag == "y" {
|
|
|
- //清楚缓存
|
|
|
- jy.ClearBigVipUserPower(userId)
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag}
|
|
|
+ var repleat = false
|
|
|
+ var kwsCount = 0
|
|
|
+ if len([]rune(keys)) > 20 {
|
|
|
+ keys = qutil.SubString(keys, 0, 20)
|
|
|
+ }
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.Int64All(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.Int64All(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ flag := "n"
|
|
|
+ updateObj := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
+ if updateObj != nil && len(*updateObj) > 0 && keys != "" {
|
|
|
+ if (*updateObj)["a_key"] != nil && len(qutil.ObjArrToMapArr((*updateObj)["a_key"].([]interface{}))) > 0 {
|
|
|
+ a_key := (*updateObj)["a_key"].([]interface{})
|
|
|
+ for _, n := range a_key {
|
|
|
+ ntmp := qutil.ObjToMap(n.(interface{}))
|
|
|
+ nkey := qutil.ObjArrToStringArr((*ntmp)["key"].([]interface{}))
|
|
|
+ if strings.Join(nkey, " ") == keys {
|
|
|
+ repleat = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //无关键词 直接添加
|
|
|
+ if positionType == 0 {
|
|
|
+ if ok := db.Mgo.UpdateById("user", userId, bson.M{"$set": bson.M{
|
|
|
+ fmt.Sprintf("%s.a_key", types): bson.A{
|
|
|
+ bson.M{
|
|
|
+ "key": bson.A{keys},
|
|
|
+ "appendkey": bson.A{},
|
|
|
+ "notkey": bson.A{},
|
|
|
+ "updatetime": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ types + ".l_modifydate": time.Now().Unix(),
|
|
|
+ // types + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
+ },
|
|
|
+ }); ok {
|
|
|
+ flag = "y"
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ok := db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{
|
|
|
+ fmt.Sprintf("%s.a_key", types): bson.A{
|
|
|
+ bson.M{
|
|
|
+ "key": bson.A{keys},
|
|
|
+ "appendkey": bson.A{},
|
|
|
+ "notkey": bson.A{},
|
|
|
+ "updatetime": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ types + ".l_modifydate": time.Now().Unix(),
|
|
|
+ // types + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
+ },
|
|
|
+ }, true, false); ok {
|
|
|
+ flag = "y"
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return map[string]interface{}{"flag": flag}
|
|
|
+ }
|
|
|
+ if repleat {
|
|
|
+ flag = "o"
|
|
|
+ } else if kwsCount >= 10 {
|
|
|
+ flag = "m"
|
|
|
+ } else {
|
|
|
+ var _key = make(map[string]interface{})
|
|
|
+ var a_key = make([]map[string]interface{}, 1)
|
|
|
+ classify_name := "未分类"
|
|
|
+ _key["key"] = strings.Split(strings.ReplaceAll(keys, " ", ""), " ")
|
|
|
+ _key["appendkey"] = []string{}
|
|
|
+ _key["notkey"] = []string{}
|
|
|
+ _key["updatetime"] = time.Now().Unix()
|
|
|
+ a_key[0] = _key
|
|
|
+ if len(a_key) > 0 {
|
|
|
+ ok := false
|
|
|
+ if positionType == 0 {
|
|
|
+ ok = db.Mgo.UpdateById("user", userId, bson.M{
|
|
|
+ "$push": bson.M{
|
|
|
+ types + ".a_key": bson.M{
|
|
|
+ "$each": a_key,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "$set": bson.M{
|
|
|
+ types + ".l_modifydate": time.Now().Unix(),
|
|
|
+ types + ".s_item": classify_name,
|
|
|
+ // updateItems + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
+ },
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ ok = db.Mgo.Update("entniche_rule", query, bson.M{
|
|
|
+ "$push": bson.M{
|
|
|
+ types + ".a_key": bson.M{
|
|
|
+ "$each": a_key,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "$set": bson.M{
|
|
|
+ types + ".l_modifydate": time.Now().Unix(),
|
|
|
+ types + ".s_item": classify_name,
|
|
|
+ // updateItems + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
+ },
|
|
|
+ }, true, false)
|
|
|
+ }
|
|
|
+ if ok {
|
|
|
+ flag = "y"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if flag == "y" {
|
|
|
+ //清楚缓存
|
|
|
+ jy.ClearBigVipUserPower(userId)
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag}
|
|
|
}
|
|
|
|
|
|
//免费用户删除关键词
|
|
|
func DeleteKeyWordsFree(types, deletekey string, session *httpsession.Session) map[string]interface{} {
|
|
|
- //免费用户只有一个分类
|
|
|
- var index = "0"
|
|
|
- userId := qutil.ObjToString(session.Get("userId"))
|
|
|
- dMap, err := util.JsonToMap(deletekey)
|
|
|
- newMap, saveData := []interface{}{}, map[string]interface{}{}
|
|
|
- if err == nil && len(dMap) > 0 {
|
|
|
- data := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
- if data != nil && len(*data) > 0 {
|
|
|
- ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
- a_key, _ := ojy["a_key"].([]interface{})
|
|
|
- if dMap[index] != nil {
|
|
|
- keyarrs := qutil.ObjArrToMapArr(a_key)
|
|
|
- for kk, vk := range keyarrs {
|
|
|
- if util.IsContain(strings.Split(dMap[index].(string), ","), strconv.Itoa(kk)) {
|
|
|
- continue
|
|
|
- }
|
|
|
- newMap = append(newMap, vk)
|
|
|
- }
|
|
|
- saveData[types+".a_key"] = newMap
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- flag := true
|
|
|
- if len(saveData) > 0 {
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType == 0 {
|
|
|
- flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- })
|
|
|
- } else {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.Int64All(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.Int64All(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- flag = db.Mgo.Update("entniche_rule", query, map[string]interface{}{"$set": saveData}, true, false)
|
|
|
+ //免费用户只有一个分类
|
|
|
+ var index = "0"
|
|
|
+ userId := qutil.ObjToString(session.Get("userId"))
|
|
|
+ dMap, err := util.JsonToMap(deletekey)
|
|
|
+ newMap, saveData := []interface{}{}, map[string]interface{}{}
|
|
|
+ if err == nil && len(dMap) > 0 {
|
|
|
+ data := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
+ a_key, _ := ojy["a_key"].([]interface{})
|
|
|
+ if dMap[index] != nil {
|
|
|
+ keyarrs := qutil.ObjArrToMapArr(a_key)
|
|
|
+ for kk, vk := range keyarrs {
|
|
|
+ if util.IsContain(strings.Split(dMap[index].(string), ","), strconv.Itoa(kk)) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ newMap = append(newMap, vk)
|
|
|
+ }
|
|
|
+ saveData[types+".a_key"] = newMap
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ flag := true
|
|
|
+ if len(saveData) > 0 {
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType == 0 {
|
|
|
+ flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.Int64All(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.Int64All(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ flag = db.Mgo.Update("entniche_rule", query, map[string]interface{}{"$set": saveData}, true, false)
|
|
|
|
|
|
- }
|
|
|
- SetLog(userId, types, 0, session)
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ }
|
|
|
+ SetLog(userId, types, 0, session)
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
}
|
|
|
|
|
|
//免费用户修改 保存关键词
|
|
|
func AddKeyWordsFree(types, userId, classIndex, className, keywordsIndex, keywordName, keywordCount string, notKeyword, appendKeyword []string, matchWay int, session *httpsession.Session) map[string]interface{} {
|
|
|
- flag := true
|
|
|
- //data, ok := db.Mgo.FindById("user", userId, `{"`+types+`":1}`)
|
|
|
- data := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
- saveData := map[string]interface{}{}
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.Int64All(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.Int64All(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- if data != nil && len(*data) > 0 {
|
|
|
- a_items := make([]interface{}, 0)
|
|
|
- ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
- a_key, errs := (*data)["a_key"].([]interface{})
|
|
|
- if !errs {
|
|
|
+ flag := true
|
|
|
+ //data, ok := db.Mgo.FindById("user", userId, `{"`+types+`":1}`)
|
|
|
+ data := jy.GetSubScribeInfo(session, db.Mgo, "f", "10000")
|
|
|
+ saveData := map[string]interface{}{}
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.Int64All(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.Int64All(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ if data != nil && len(*data) > 0 {
|
|
|
+ a_items := make([]interface{}, 0)
|
|
|
+ ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
+ a_key, errs := (*data)["a_key"].([]interface{})
|
|
|
+ if !errs {
|
|
|
|
|
|
- if positionType == 0 {
|
|
|
- db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- types + ".a_key": []map[string]interface{}{},
|
|
|
- // types + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
- },
|
|
|
- })
|
|
|
- } else {
|
|
|
+ if positionType == 0 {
|
|
|
+ db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ types + ".a_key": []map[string]interface{}{},
|
|
|
+ // types + ".i_newfree": 1, //老免费用户=>新订阅设置页面 20211122
|
|
|
+ },
|
|
|
+ })
|
|
|
+ } else {
|
|
|
|
|
|
- db.Mgo.Update("entniche_rule", query, map[string]interface{}{"$set": map[string]interface{}{
|
|
|
- "o_entniche.a_key": []map[string]interface{}{},
|
|
|
- }}, true, false)
|
|
|
- }
|
|
|
+ db.Mgo.Update("entniche_rule", query, map[string]interface{}{"$set": map[string]interface{}{
|
|
|
+ "o_entniche.a_key": []map[string]interface{}{},
|
|
|
+ }}, true, false)
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- if ki, _ := strconv.Atoi(keywordsIndex); ki > len(a_key) {
|
|
|
- keywordsIndex = strconv.Itoa(len(a_key))
|
|
|
- } else if ki == 0 {
|
|
|
- keywordsIndex = strconv.Itoa(ki)
|
|
|
- }
|
|
|
- a_items = append(a_items, ojy)
|
|
|
- //排除词处理 词过长或者为空的情况
|
|
|
- if len(notKeyword) > 0 {
|
|
|
- for i, notval := range notKeyword {
|
|
|
- if len([]rune(notval)) > 20 {
|
|
|
- notval = qutil.SubString(notval, 0, 20)
|
|
|
- }
|
|
|
- if notval == "" {
|
|
|
- notKeyword = append(notKeyword[:i], notKeyword[i+1:]...)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- var _kws []string //关键词
|
|
|
- for _, kn := range strings.Split(keywordName, " ") {
|
|
|
- if kn != "" {
|
|
|
- _kws = append(_kws, kn)
|
|
|
- }
|
|
|
- }
|
|
|
- var _key = make(map[string]interface{})
|
|
|
- newKws := []string{_kws[0]} //第一个关键词在key中 后边的存入appendkey
|
|
|
- _key["key"] = newKws
|
|
|
- _key["appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
- _key["notkey"] = notKeyword
|
|
|
- _key["matchway"] = matchWay //matchway 0:精准匹配 1:模糊匹配
|
|
|
- if KeyWordsRepeat(_key, a_items) {
|
|
|
- return map[string]interface{}{"flag": false, "msg": "关键词已存在"}
|
|
|
- } else {
|
|
|
- //修改关键词
|
|
|
- saveData[types+".s_item"] = className
|
|
|
- // saveData[types+".i_newfree"] = 1 //老免费用户=>新订阅设置页面 20211122
|
|
|
- saveData[types+".a_key."+keywordsIndex+".key"] = newKws
|
|
|
- saveData[types+".a_key."+keywordsIndex+".appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
- saveData[types+".a_key."+keywordsIndex+".notkey"] = notKeyword
|
|
|
- saveData[types+".a_key."+keywordsIndex+".matchway"] = matchWay
|
|
|
- saveData[types+".a_key."+keywordsIndex+".updatetime"] = time.Now().Unix()
|
|
|
- }
|
|
|
- }
|
|
|
- if len(saveData) > 0 {
|
|
|
- ok := false
|
|
|
- if positionType == 0 {
|
|
|
- ok = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- })
|
|
|
- } else {
|
|
|
- ok = db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- }, true, false)
|
|
|
- }
|
|
|
- if ok {
|
|
|
- flag = true
|
|
|
- //清楚缓存
|
|
|
- jy.ClearBigVipUserPower(userId)
|
|
|
- }
|
|
|
- SetLog(userId, types, 0, session)
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ }
|
|
|
+ if ki, _ := strconv.Atoi(keywordsIndex); ki > len(a_key) {
|
|
|
+ keywordsIndex = strconv.Itoa(len(a_key))
|
|
|
+ } else if ki == 0 {
|
|
|
+ keywordsIndex = strconv.Itoa(ki)
|
|
|
+ }
|
|
|
+ a_items = append(a_items, ojy)
|
|
|
+ //排除词处理 词过长或者为空的情况
|
|
|
+ if len(notKeyword) > 0 {
|
|
|
+ for i, notval := range notKeyword {
|
|
|
+ if len([]rune(notval)) > 20 {
|
|
|
+ notval = qutil.SubString(notval, 0, 20)
|
|
|
+ }
|
|
|
+ if notval == "" {
|
|
|
+ notKeyword = append(notKeyword[:i], notKeyword[i+1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var _kws []string //关键词
|
|
|
+ for _, kn := range strings.Split(keywordName, " ") {
|
|
|
+ if kn != "" {
|
|
|
+ _kws = append(_kws, kn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var _key = make(map[string]interface{})
|
|
|
+ newKws := []string{_kws[0]} //第一个关键词在key中 后边的存入appendkey
|
|
|
+ _key["key"] = newKws
|
|
|
+ _key["appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
+ _key["notkey"] = notKeyword
|
|
|
+ _key["matchway"] = matchWay //matchway 0:精准匹配 1:模糊匹配
|
|
|
+ if KeyWordsRepeat(_key, a_items) {
|
|
|
+ return map[string]interface{}{"flag": false, "msg": "关键词已存在"}
|
|
|
+ } else {
|
|
|
+ //修改关键词
|
|
|
+ saveData[types+".s_item"] = className
|
|
|
+ // saveData[types+".i_newfree"] = 1 //老免费用户=>新订阅设置页面 20211122
|
|
|
+ saveData[types+".a_key."+keywordsIndex+".key"] = newKws
|
|
|
+ saveData[types+".a_key."+keywordsIndex+".appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
+ saveData[types+".a_key."+keywordsIndex+".notkey"] = notKeyword
|
|
|
+ saveData[types+".a_key."+keywordsIndex+".matchway"] = matchWay
|
|
|
+ saveData[types+".a_key."+keywordsIndex+".updatetime"] = time.Now().Unix()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(saveData) > 0 {
|
|
|
+ ok := false
|
|
|
+ if positionType == 0 {
|
|
|
+ ok = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ ok = db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ }, true, false)
|
|
|
+ }
|
|
|
+ if ok {
|
|
|
+ flag = true
|
|
|
+ //清楚缓存
|
|
|
+ jy.ClearBigVipUserPower(userId)
|
|
|
+ }
|
|
|
+ SetLog(userId, types, 0, session)
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
}
|
|
|
|
|
|
//保存/修改关键词
|
|
|
func AddKeyWords(types, userId, classIndex, className, keywordsIndex, keywordName, keywordCount string, notKeyword, appendKeyword []string, matchWay int, session *httpsession.Session) map[string]interface{} {
|
|
|
- flag := true
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType == 0 {
|
|
|
- //个人版
|
|
|
- data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
- saveData := map[string]interface{}{}
|
|
|
- if ok && data != nil && len(*data) > 0 {
|
|
|
- ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
- a_items, errs := ojy["a_items"].([]interface{})
|
|
|
- if !errs {
|
|
|
- db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- types + ".a_items": []map[string]interface{}{},
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
- //附加词处理
|
|
|
- if len(appendKeyword) > 0 {
|
|
|
- for i, addval := range appendKeyword {
|
|
|
- if len([]rune(addval)) > 20 {
|
|
|
- addval = qutil.SubString(addval, 0, 20)
|
|
|
- }
|
|
|
- if addval == "" {
|
|
|
- appendKeyword = append(appendKeyword[:i], appendKeyword[i+1:]...)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //排除词处理 词过长或者为空的情况
|
|
|
- if len(notKeyword) > 0 {
|
|
|
- for i, notval := range notKeyword {
|
|
|
- if len([]rune(notval)) > 20 {
|
|
|
- notval = qutil.SubString(notval, 0, 20)
|
|
|
- }
|
|
|
- if notval == "" {
|
|
|
- notKeyword = append(notKeyword[:i], notKeyword[i+1:]...)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- var _kws []string //关键词
|
|
|
- for _, kn := range strings.Split(keywordName, " ") {
|
|
|
- if kn != "" {
|
|
|
- _kws = append(_kws, kn)
|
|
|
- }
|
|
|
- }
|
|
|
- var _key = make(map[string]interface{})
|
|
|
- newKws := []string{_kws[0]} //第一个关键词在key中 后边的存入appendkey
|
|
|
- _key["key"] = newKws
|
|
|
- _key["appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
- _key["notkey"] = notKeyword
|
|
|
- _key["matchway"] = matchWay //matchway 0:精准匹配 1:模糊匹配
|
|
|
- if KeyWordsRepeat(_key, a_items) {
|
|
|
- return map[string]interface{}{"flag": false, "msg": "关键词已存在"}
|
|
|
- } else {
|
|
|
- //修改关键词
|
|
|
- saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".key"] = newKws
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".notkey"] = notKeyword
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".matchway"] = matchWay
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".updatetime"] = time.Now().Unix()
|
|
|
- }
|
|
|
- }
|
|
|
+ flag := true
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType == 0 {
|
|
|
+ //个人版
|
|
|
+ data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
+ saveData := map[string]interface{}{}
|
|
|
+ if ok && data != nil && len(*data) > 0 {
|
|
|
+ ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
+ a_items, errs := ojy["a_items"].([]interface{})
|
|
|
+ if !errs {
|
|
|
+ db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ types + ".a_items": []map[string]interface{}{},
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //附加词处理
|
|
|
+ if len(appendKeyword) > 0 {
|
|
|
+ for i, addval := range appendKeyword {
|
|
|
+ if len([]rune(addval)) > 20 {
|
|
|
+ addval = qutil.SubString(addval, 0, 20)
|
|
|
+ }
|
|
|
+ if addval == "" {
|
|
|
+ appendKeyword = append(appendKeyword[:i], appendKeyword[i+1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //排除词处理 词过长或者为空的情况
|
|
|
+ if len(notKeyword) > 0 {
|
|
|
+ for i, notval := range notKeyword {
|
|
|
+ if len([]rune(notval)) > 20 {
|
|
|
+ notval = qutil.SubString(notval, 0, 20)
|
|
|
+ }
|
|
|
+ if notval == "" {
|
|
|
+ notKeyword = append(notKeyword[:i], notKeyword[i+1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var _kws []string //关键词
|
|
|
+ for _, kn := range strings.Split(keywordName, " ") {
|
|
|
+ if kn != "" {
|
|
|
+ _kws = append(_kws, kn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var _key = make(map[string]interface{})
|
|
|
+ newKws := []string{_kws[0]} //第一个关键词在key中 后边的存入appendkey
|
|
|
+ _key["key"] = newKws
|
|
|
+ _key["appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
+ _key["notkey"] = notKeyword
|
|
|
+ _key["matchway"] = matchWay //matchway 0:精准匹配 1:模糊匹配
|
|
|
+ if KeyWordsRepeat(_key, a_items) {
|
|
|
+ return map[string]interface{}{"flag": false, "msg": "关键词已存在"}
|
|
|
+ } else {
|
|
|
+ //修改关键词
|
|
|
+ saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".key"] = newKws
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".notkey"] = notKeyword
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".matchway"] = matchWay
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".updatetime"] = time.Now().Unix()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if len(saveData) > 0 {
|
|
|
- flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- })
|
|
|
- SetLog(userId, types, positionType, session)
|
|
|
- }
|
|
|
- } else {
|
|
|
- //企业个人版
|
|
|
- //先查看有没有关键词
|
|
|
- types := "o_entniche"
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- data, ok := db.Mgo.Find("entniche_rule", query, `{"`+types+`.a_items":1}`, nil, false, -1, -1)
|
|
|
- saveData := map[string]interface{}{}
|
|
|
- if !ok || data == nil || len(*data) == 0 {
|
|
|
- db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "o_entniche.a_items": []map[string]interface{}{},
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- }}, true, false)
|
|
|
- }
|
|
|
- //entniche_rule有数据
|
|
|
- ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
- a_items, errs := ojy["a_items"].([]interface{})
|
|
|
- if !errs {
|
|
|
- db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "o_entniche.a_items": []map[string]interface{}{},
|
|
|
- }}, true, false)
|
|
|
- }
|
|
|
- //附加词处理
|
|
|
- if len(appendKeyword) > 0 {
|
|
|
- for i, addval := range appendKeyword {
|
|
|
- if len([]rune(addval)) > 20 {
|
|
|
- addval = qutil.SubString(addval, 0, 20)
|
|
|
- }
|
|
|
- if addval == "" {
|
|
|
- appendKeyword = append(appendKeyword[:i], appendKeyword[i+1:]...)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //排除词处理 词过长或者为空的情况
|
|
|
- if len(notKeyword) > 0 {
|
|
|
- for i, notval := range notKeyword {
|
|
|
- if len([]rune(notval)) > 20 {
|
|
|
- notval = qutil.SubString(notval, 0, 20)
|
|
|
- }
|
|
|
- if notval == "" {
|
|
|
- notKeyword = append(notKeyword[:i], notKeyword[i+1:]...)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- var _kws []string //关键词
|
|
|
- for _, kn := range strings.Split(keywordName, " ") {
|
|
|
- if kn != "" {
|
|
|
- _kws = append(_kws, kn)
|
|
|
- }
|
|
|
- }
|
|
|
- var _key = make(map[string]interface{})
|
|
|
- newKws := []string{_kws[0]} //第一个关键词在key中 后边的存入appendkey
|
|
|
- _key["key"] = newKws
|
|
|
- _key["appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
- _key["notkey"] = notKeyword
|
|
|
- _key["updatetime"] = time.Now().Unix()
|
|
|
- _key["matchway"] = matchWay //matchway 0:精准匹配 1:模糊匹配
|
|
|
- if KeyWordsRepeat(_key, a_items) {
|
|
|
- return map[string]interface{}{"flag": false, "msg": "关键词已存在"}
|
|
|
- } else {
|
|
|
- //修改关键词
|
|
|
- saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".key"] = newKws
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".notkey"] = notKeyword
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".matchway"] = matchWay
|
|
|
- saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".updatetime"] = time.Now().Unix()
|
|
|
- }
|
|
|
+ if len(saveData) > 0 {
|
|
|
+ flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ })
|
|
|
+ SetLog(userId, types, positionType, session)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //企业个人版
|
|
|
+ //先查看有没有关键词
|
|
|
+ types := "o_entniche"
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ data, ok := db.Mgo.Find("entniche_rule", query, `{"`+types+`.a_items":1}`, nil, false, -1, -1)
|
|
|
+ saveData := map[string]interface{}{}
|
|
|
+ if !ok || data == nil || len(*data) == 0 {
|
|
|
+ db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "o_entniche.a_items": []map[string]interface{}{},
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ }}, true, false)
|
|
|
+ }
|
|
|
+ //entniche_rule有数据
|
|
|
+ ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
+ a_items, errs := ojy["a_items"].([]interface{})
|
|
|
+ if !errs {
|
|
|
+ db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "o_entniche.a_items": []map[string]interface{}{},
|
|
|
+ }}, true, false)
|
|
|
+ }
|
|
|
+ //附加词处理
|
|
|
+ if len(appendKeyword) > 0 {
|
|
|
+ for i, addval := range appendKeyword {
|
|
|
+ if len([]rune(addval)) > 20 {
|
|
|
+ addval = qutil.SubString(addval, 0, 20)
|
|
|
+ }
|
|
|
+ if addval == "" {
|
|
|
+ appendKeyword = append(appendKeyword[:i], appendKeyword[i+1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //排除词处理 词过长或者为空的情况
|
|
|
+ if len(notKeyword) > 0 {
|
|
|
+ for i, notval := range notKeyword {
|
|
|
+ if len([]rune(notval)) > 20 {
|
|
|
+ notval = qutil.SubString(notval, 0, 20)
|
|
|
+ }
|
|
|
+ if notval == "" {
|
|
|
+ notKeyword = append(notKeyword[:i], notKeyword[i+1:]...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var _kws []string //关键词
|
|
|
+ for _, kn := range strings.Split(keywordName, " ") {
|
|
|
+ if kn != "" {
|
|
|
+ _kws = append(_kws, kn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var _key = make(map[string]interface{})
|
|
|
+ newKws := []string{_kws[0]} //第一个关键词在key中 后边的存入appendkey
|
|
|
+ _key["key"] = newKws
|
|
|
+ _key["appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
+ _key["notkey"] = notKeyword
|
|
|
+ _key["updatetime"] = time.Now().Unix()
|
|
|
+ _key["matchway"] = matchWay //matchway 0:精准匹配 1:模糊匹配
|
|
|
+ if KeyWordsRepeat(_key, a_items) {
|
|
|
+ return map[string]interface{}{"flag": false, "msg": "关键词已存在"}
|
|
|
+ } else {
|
|
|
+ //修改关键词
|
|
|
+ saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".key"] = newKws
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".appendkey"] = append(appendKeyword, _kws[1:]...)
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".notkey"] = notKeyword
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".matchway"] = matchWay
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key."+keywordsIndex+".updatetime"] = time.Now().Unix()
|
|
|
+ }
|
|
|
|
|
|
- saveData["l_updatetime"] = time.Now().Unix()
|
|
|
- flag = db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- }, true, false)
|
|
|
- SetLog(userId, types, positionType, session)
|
|
|
- }
|
|
|
+ saveData["l_updatetime"] = time.Now().Unix()
|
|
|
+ flag = db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ }, true, false)
|
|
|
+ SetLog(userId, types, positionType, session)
|
|
|
+ }
|
|
|
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
}
|
|
|
|
|
|
//删除关键词可以批量
|
|
|
func DeleteKeyWords(types, deletekey, userId string, session *httpsession.Session) map[string]interface{} {
|
|
|
- flag := true
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType == 0 {
|
|
|
- dMap, err := util.JsonToMap(deletekey)
|
|
|
- newMap, saveData := []interface{}{}, map[string]interface{}{}
|
|
|
- if err == nil && len(dMap) > 0 {
|
|
|
- data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
- if data != nil && ok && len(*data) > 0 {
|
|
|
- ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
- a_items, _ := ojy["a_items"].([]interface{})
|
|
|
- for k, v := range a_items {
|
|
|
- newItems := map[string]interface{}{}
|
|
|
- if dMap[strconv.Itoa(k)] != nil {
|
|
|
- if items, ok := v.(map[string]interface{}); ok && len(items) > 0 {
|
|
|
- for kk, vv := range items {
|
|
|
- new_vv := vv
|
|
|
- new_m := []map[string]interface{}{}
|
|
|
- if kk == "a_key" {
|
|
|
- keyarrs := qutil.ObjArrToMapArr(vv.([]interface{}))
|
|
|
- for kk, vk := range keyarrs {
|
|
|
- if util.IsContain(strings.Split(dMap[strconv.Itoa(k)].(string), ","), strconv.Itoa(kk)) {
|
|
|
- continue
|
|
|
- }
|
|
|
- new_m = append(new_m, vk)
|
|
|
- }
|
|
|
- new_vv = new_m
|
|
|
- }
|
|
|
- newItems[kk] = new_vv
|
|
|
- }
|
|
|
- }
|
|
|
- newMap = append(newMap, newItems)
|
|
|
- } else {
|
|
|
- newMap = append(newMap, v)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- saveData[types+".a_items"] = newMap
|
|
|
- }
|
|
|
- if len(saveData) > 0 {
|
|
|
- flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- })
|
|
|
- SetLog(userId, types, 0, session)
|
|
|
- }
|
|
|
- } else {
|
|
|
- types := "o_entniche"
|
|
|
- dMap, err := util.JsonToMap(deletekey)
|
|
|
- newMap := []interface{}{}
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- if err == nil && len(dMap) > 0 {
|
|
|
- data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
- if data == nil || !ok || len(*data) == 0 {
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
- }
|
|
|
- ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
- a_items, _ := ojy["a_items"].([]interface{})
|
|
|
- for k, v := range a_items {
|
|
|
- newItems := map[string]interface{}{}
|
|
|
- if dMap[strconv.Itoa(k)] != nil {
|
|
|
- if items, ok := v.(map[string]interface{}); ok && len(items) > 0 {
|
|
|
- for kk, vv := range items {
|
|
|
- new_vv := vv
|
|
|
- new_m := []map[string]interface{}{}
|
|
|
- if kk == "a_key" {
|
|
|
- keyarrs := qutil.ObjArrToMapArr(vv.([]interface{}))
|
|
|
- for kk, vk := range keyarrs {
|
|
|
- if util.IsContain(strings.Split(dMap[strconv.Itoa(k)].(string), ","), strconv.Itoa(kk)) {
|
|
|
- continue
|
|
|
- }
|
|
|
- new_m = append(new_m, vk)
|
|
|
- }
|
|
|
- new_vv = new_m
|
|
|
- }
|
|
|
- newItems[kk] = new_vv
|
|
|
- }
|
|
|
- }
|
|
|
- newMap = append(newMap, newItems)
|
|
|
- } else {
|
|
|
- newMap = append(newMap, v)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ flag := true
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType == 0 {
|
|
|
+ dMap, err := util.JsonToMap(deletekey)
|
|
|
+ newMap, saveData := []interface{}{}, map[string]interface{}{}
|
|
|
+ if err == nil && len(dMap) > 0 {
|
|
|
+ data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
+ if data != nil && ok && len(*data) > 0 {
|
|
|
+ ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
+ a_items, _ := ojy["a_items"].([]interface{})
|
|
|
+ for k, v := range a_items {
|
|
|
+ newItems := map[string]interface{}{}
|
|
|
+ if dMap[strconv.Itoa(k)] != nil {
|
|
|
+ if items, ok := v.(map[string]interface{}); ok && len(items) > 0 {
|
|
|
+ for kk, vv := range items {
|
|
|
+ new_vv := vv
|
|
|
+ new_m := []map[string]interface{}{}
|
|
|
+ if kk == "a_key" {
|
|
|
+ keyarrs := qutil.ObjArrToMapArr(vv.([]interface{}))
|
|
|
+ for kk, vk := range keyarrs {
|
|
|
+ if util.IsContain(strings.Split(dMap[strconv.Itoa(k)].(string), ","), strconv.Itoa(kk)) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ new_m = append(new_m, vk)
|
|
|
+ }
|
|
|
+ new_vv = new_m
|
|
|
+ }
|
|
|
+ newItems[kk] = new_vv
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newMap = append(newMap, newItems)
|
|
|
+ } else {
|
|
|
+ newMap = append(newMap, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveData[types+".a_items"] = newMap
|
|
|
+ }
|
|
|
+ if len(saveData) > 0 {
|
|
|
+ flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ })
|
|
|
+ SetLog(userId, types, 0, session)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ types := "o_entniche"
|
|
|
+ dMap, err := util.JsonToMap(deletekey)
|
|
|
+ newMap := []interface{}{}
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ if err == nil && len(dMap) > 0 {
|
|
|
+ data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
+ if data == nil || !ok || len(*data) == 0 {
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ }
|
|
|
+ ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
+ a_items, _ := ojy["a_items"].([]interface{})
|
|
|
+ for k, v := range a_items {
|
|
|
+ newItems := map[string]interface{}{}
|
|
|
+ if dMap[strconv.Itoa(k)] != nil {
|
|
|
+ if items, ok := v.(map[string]interface{}); ok && len(items) > 0 {
|
|
|
+ for kk, vv := range items {
|
|
|
+ new_vv := vv
|
|
|
+ new_m := []map[string]interface{}{}
|
|
|
+ if kk == "a_key" {
|
|
|
+ keyarrs := qutil.ObjArrToMapArr(vv.([]interface{}))
|
|
|
+ for kk, vk := range keyarrs {
|
|
|
+ if util.IsContain(strings.Split(dMap[strconv.Itoa(k)].(string), ","), strconv.Itoa(kk)) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ new_m = append(new_m, vk)
|
|
|
+ }
|
|
|
+ new_vv = new_m
|
|
|
+ }
|
|
|
+ newItems[kk] = new_vv
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newMap = append(newMap, newItems)
|
|
|
+ } else {
|
|
|
+ newMap = append(newMap, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if len(newMap) > 0 {
|
|
|
- flag = db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- "o_entniche.a_items": newMap,
|
|
|
- }}, true, false)
|
|
|
- SetLog(userId, types, positionType, session)
|
|
|
- }
|
|
|
+ if len(newMap) > 0 {
|
|
|
+ flag = db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ "o_entniche.a_items": newMap,
|
|
|
+ }}, true, false)
|
|
|
+ SetLog(userId, types, positionType, session)
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
}
|
|
|
|
|
|
//删除分类【可以批量删除】
|
|
|
func DeleteClass(types, classIndex, userId string, session *httpsession.Session) map[string]interface{} {
|
|
|
- flag := true
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType != 1 {
|
|
|
- items, saveData := []interface{}{}, map[string]interface{}{}
|
|
|
- m := map[string]bool{}
|
|
|
- for _, v := range strings.Split(classIndex, ",") {
|
|
|
- m[v] = true
|
|
|
- }
|
|
|
- data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
- if data != nil && ok && len(*data) > 0 {
|
|
|
- ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
- a_items, _ := ojy["a_items"].([]interface{})
|
|
|
- for k, v := range a_items {
|
|
|
- if !m[strconv.Itoa(k)] {
|
|
|
- items = append(items, v)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- saveData[types+".a_items"] = items
|
|
|
+ flag := true
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType != 1 {
|
|
|
+ items, saveData := []interface{}{}, map[string]interface{}{}
|
|
|
+ m := map[string]bool{}
|
|
|
+ for _, v := range strings.Split(classIndex, ",") {
|
|
|
+ m[v] = true
|
|
|
+ }
|
|
|
+ data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
+ if data != nil && ok && len(*data) > 0 {
|
|
|
+ ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
+ a_items, _ := ojy["a_items"].([]interface{})
|
|
|
+ for k, v := range a_items {
|
|
|
+ if !m[strconv.Itoa(k)] {
|
|
|
+ items = append(items, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveData[types+".a_items"] = items
|
|
|
|
|
|
- if len(saveData) > 0 {
|
|
|
- flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- })
|
|
|
- SetLog(userId, types, 0, session)
|
|
|
- }
|
|
|
- } else {
|
|
|
- types := "o_entniche"
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- items := []interface{}{}
|
|
|
- m := map[string]bool{}
|
|
|
- for _, v := range strings.Split(classIndex, ",") {
|
|
|
- m[v] = true
|
|
|
- }
|
|
|
- data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
- if data == nil || !ok || len(*data) == 0 {
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
- }
|
|
|
- ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
- a_items, _ := ojy["a_items"].([]interface{})
|
|
|
- for k, v := range a_items {
|
|
|
- if !m[strconv.Itoa(k)] {
|
|
|
- items = append(items, v)
|
|
|
- }
|
|
|
- }
|
|
|
+ if len(saveData) > 0 {
|
|
|
+ flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ })
|
|
|
+ SetLog(userId, types, 0, session)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ types := "o_entniche"
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ items := []interface{}{}
|
|
|
+ m := map[string]bool{}
|
|
|
+ for _, v := range strings.Split(classIndex, ",") {
|
|
|
+ m[v] = true
|
|
|
+ }
|
|
|
+ data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
+ if data == nil || !ok || len(*data) == 0 {
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ }
|
|
|
+ ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
+ a_items, _ := ojy["a_items"].([]interface{})
|
|
|
+ for k, v := range a_items {
|
|
|
+ if !m[strconv.Itoa(k)] {
|
|
|
+ items = append(items, v)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if len(items) > 0 {
|
|
|
- flag = db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- "o_entniche.a_items": items,
|
|
|
- }}, true, false)
|
|
|
- SetLog(userId, types, positionType, session)
|
|
|
- }
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ if len(items) > 0 {
|
|
|
+ flag = db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ "o_entniche.a_items": items,
|
|
|
+ }}, true, false)
|
|
|
+ SetLog(userId, types, positionType, session)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
}
|
|
|
|
|
|
//创建分类名
|
|
|
func AddClass(types, classIndex, className, userId string, session *httpsession.Session) map[string]interface{} {
|
|
|
- flag := true
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType == 0 {
|
|
|
- saveData := map[string]interface{}{}
|
|
|
- data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
- if data != nil && ok && len(*data) > 0 {
|
|
|
- ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
- a_items, errs := ojy["a_items"].([]interface{})
|
|
|
- //没有该字段创建
|
|
|
- if !errs {
|
|
|
- db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "" + types + ".a_items": []map[string]interface{}{},
|
|
|
- },
|
|
|
- })
|
|
|
- }
|
|
|
- sitemsArr := []string{} //分类名称数组
|
|
|
- for _, av := range a_items {
|
|
|
- _av := qutil.ObjToMap(av)
|
|
|
- sitemsArr = append(sitemsArr, qutil.ObjToString((*_av)["s_item"]))
|
|
|
- }
|
|
|
- if util.IsRepeat(append(sitemsArr, className)) {
|
|
|
- return map[string]interface{}{"flag": false, "msg": "分类名称重复"}
|
|
|
- }
|
|
|
- c_lens := strconv.Itoa(len(a_items))
|
|
|
- if ci, _ := strconv.Atoi(classIndex); ci < len(a_items)+1 {
|
|
|
- if classIndex == "" || c_lens == classIndex { //新增
|
|
|
- classIndex = strconv.Itoa(len(a_items)) //索引
|
|
|
- saveData[types+".a_items."+classIndex+".a_key"] = []map[string]interface{}{}
|
|
|
- }
|
|
|
- saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
- saveData[types+".a_items."+classIndex+".updatetime"] = time.Now().Unix()
|
|
|
- }
|
|
|
- }
|
|
|
+ flag := true
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType == 0 {
|
|
|
+ saveData := map[string]interface{}{}
|
|
|
+ data, ok := db.Mgo.FindById("user", userId, `{"`+types+`.a_items":1}`)
|
|
|
+ if data != nil && ok && len(*data) > 0 {
|
|
|
+ ojy, _ := (*data)[types].(map[string]interface{})
|
|
|
+ a_items, errs := ojy["a_items"].([]interface{})
|
|
|
+ //没有该字段创建
|
|
|
+ if !errs {
|
|
|
+ db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "" + types + ".a_items": []map[string]interface{}{},
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ sitemsArr := []string{} //分类名称数组
|
|
|
+ for _, av := range a_items {
|
|
|
+ _av := qutil.ObjToMap(av)
|
|
|
+ sitemsArr = append(sitemsArr, qutil.ObjToString((*_av)["s_item"]))
|
|
|
+ }
|
|
|
+ if util.IsRepeat(append(sitemsArr, className)) {
|
|
|
+ return map[string]interface{}{"flag": false, "msg": "分类名称重复"}
|
|
|
+ }
|
|
|
+ c_lens := strconv.Itoa(len(a_items))
|
|
|
+ if ci, _ := strconv.Atoi(classIndex); ci < len(a_items)+1 {
|
|
|
+ if classIndex == "" || c_lens == classIndex { //新增
|
|
|
+ classIndex = strconv.Itoa(len(a_items)) //索引
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key"] = []map[string]interface{}{}
|
|
|
+ }
|
|
|
+ saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
+ saveData[types+".a_items."+classIndex+".updatetime"] = time.Now().Unix()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if len(saveData) > 0 {
|
|
|
- flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- })
|
|
|
- SetLog(userId, types, 0, session)
|
|
|
- }
|
|
|
- } else {
|
|
|
- types := "o_entniche"
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- saveData := map[string]interface{}{}
|
|
|
- data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
- a_items := []interface{}{}
|
|
|
- if data == nil || !ok || len(*data) == 0 {
|
|
|
- db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": map[string]interface{}{
|
|
|
- "o_entniche.a_items": []map[string]interface{}{},
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- }}, true, false)
|
|
|
+ if len(saveData) > 0 {
|
|
|
+ flag = db.Mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ })
|
|
|
+ SetLog(userId, types, 0, session)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ types := "o_entniche"
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ saveData := map[string]interface{}{}
|
|
|
+ data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
+ a_items := []interface{}{}
|
|
|
+ if data == nil || !ok || len(*data) == 0 {
|
|
|
+ db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
+ "$set": map[string]interface{}{
|
|
|
+ "o_entniche.a_items": []map[string]interface{}{},
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ }}, true, false)
|
|
|
|
|
|
- } else {
|
|
|
- ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
- a_items, _ = ojy["a_items"].([]interface{})
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ ojy, _ := (*data)[0][types].(map[string]interface{})
|
|
|
+ a_items, _ = ojy["a_items"].([]interface{})
|
|
|
+ }
|
|
|
|
|
|
- sitemsArr := []string{} //分类名称数组
|
|
|
- for _, av := range a_items {
|
|
|
- _av := qutil.ObjToMap(av)
|
|
|
- sitemsArr = append(sitemsArr, qutil.ObjToString((*_av)["s_item"]))
|
|
|
- }
|
|
|
- if util.IsRepeat(append(sitemsArr, className)) {
|
|
|
- return map[string]interface{}{"flag": false, "msg": "分类名称重复"}
|
|
|
- }
|
|
|
- c_lens := strconv.Itoa(len(a_items))
|
|
|
- if ci, _ := strconv.Atoi(classIndex); ci < len(a_items)+1 {
|
|
|
- if classIndex == "" || c_lens == classIndex { //新增
|
|
|
- classIndex = strconv.Itoa(len(a_items)) //索引
|
|
|
- saveData[types+".a_items."+classIndex+".a_key"] = []map[string]interface{}{}
|
|
|
- }
|
|
|
- saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
- saveData[types+".a_items."+classIndex+".updatetime"] = time.Now().Unix()
|
|
|
+ sitemsArr := []string{} //分类名称数组
|
|
|
+ for _, av := range a_items {
|
|
|
+ _av := qutil.ObjToMap(av)
|
|
|
+ sitemsArr = append(sitemsArr, qutil.ObjToString((*_av)["s_item"]))
|
|
|
+ }
|
|
|
+ if util.IsRepeat(append(sitemsArr, className)) {
|
|
|
+ return map[string]interface{}{"flag": false, "msg": "分类名称重复"}
|
|
|
+ }
|
|
|
+ c_lens := strconv.Itoa(len(a_items))
|
|
|
+ if ci, _ := strconv.Atoi(classIndex); ci < len(a_items)+1 {
|
|
|
+ if classIndex == "" || c_lens == classIndex { //新增
|
|
|
+ classIndex = strconv.Itoa(len(a_items)) //索引
|
|
|
+ saveData[types+".a_items."+classIndex+".a_key"] = []map[string]interface{}{}
|
|
|
+ }
|
|
|
+ saveData[types+".a_items."+classIndex+".s_item"] = className
|
|
|
+ saveData[types+".a_items."+classIndex+".updatetime"] = time.Now().Unix()
|
|
|
|
|
|
- }
|
|
|
- saveData["l_updatetime"] = time.Now().Unix()
|
|
|
- if len(saveData) > 0 {
|
|
|
- flag = db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": saveData,
|
|
|
- }, true, false)
|
|
|
- SetLog(userId, types, positionType, session)
|
|
|
- }
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ }
|
|
|
+ saveData["l_updatetime"] = time.Now().Unix()
|
|
|
+ if len(saveData) > 0 {
|
|
|
+ flag = db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
+ "$set": saveData,
|
|
|
+ }, true, false)
|
|
|
+ SetLog(userId, types, positionType, session)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
|
|
|
}
|
|
|
|
|
|
//关键词判重
|
|
|
func KeyWordsRepeat(obj map[string]interface{}, aitems []interface{}) bool {
|
|
|
- // 录入的关键词
|
|
|
- key, _ := obj["key"].([]string)
|
|
|
- notkey, _ := obj["notkey"].([]string)
|
|
|
- matchway, _ := obj["matchway"].(int) //matchway 0:精准匹配 1:模糊匹配
|
|
|
- appendkey, _ := obj["appendkey"].([]string)
|
|
|
- if util.IsRepeat(key) || util.IsRepeat(appendkey) {
|
|
|
- return true
|
|
|
- }
|
|
|
- // 录入的关键词
|
|
|
- for _, v := range aitems {
|
|
|
- if items, ok := v.(map[string]interface{}); ok && len(items) > 0 {
|
|
|
- for kk, vv := range items {
|
|
|
- if kk == "a_key" {
|
|
|
- for _, n := range qutil.ObjArrToMapArr(vv.([]interface{})) {
|
|
|
- db_not := []string{}
|
|
|
- db_key := []string{}
|
|
|
- db_append := []string{}
|
|
|
- if n["key"] != nil {
|
|
|
- db_key = qutil.ObjArrToStringArr(n["key"].([]interface{}))
|
|
|
- }
|
|
|
- if n["notkey"] != nil {
|
|
|
- db_not = qutil.ObjArrToStringArr(n["notkey"].([]interface{}))
|
|
|
- }
|
|
|
- if n["appendkey"] != nil {
|
|
|
- db_append = qutil.ObjArrToStringArr(n["appendkey"].([]interface{}))
|
|
|
- }
|
|
|
- if util.StringArrEqual(key, db_key) && util.StringArrEqual(notkey, db_not) && qutil.IntAllDef(n["matchway"], 0) == matchway && util.StringArrEqual(appendkey, db_append) {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
+ // 录入的关键词
|
|
|
+ key, _ := obj["key"].([]string)
|
|
|
+ notkey, _ := obj["notkey"].([]string)
|
|
|
+ matchway, _ := obj["matchway"].(int) //matchway 0:精准匹配 1:模糊匹配
|
|
|
+ appendkey, _ := obj["appendkey"].([]string)
|
|
|
+ if util.IsRepeat(key) || util.IsRepeat(appendkey) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ // 录入的关键词
|
|
|
+ for _, v := range aitems {
|
|
|
+ if items, ok := v.(map[string]interface{}); ok && len(items) > 0 {
|
|
|
+ for kk, vv := range items {
|
|
|
+ if kk == "a_key" {
|
|
|
+ for _, n := range qutil.ObjArrToMapArr(vv.([]interface{})) {
|
|
|
+ db_not := []string{}
|
|
|
+ db_key := []string{}
|
|
|
+ db_append := []string{}
|
|
|
+ if n["key"] != nil {
|
|
|
+ db_key = qutil.ObjArrToStringArr(n["key"].([]interface{}))
|
|
|
+ }
|
|
|
+ if n["notkey"] != nil {
|
|
|
+ db_not = qutil.ObjArrToStringArr(n["notkey"].([]interface{}))
|
|
|
+ }
|
|
|
+ if n["appendkey"] != nil {
|
|
|
+ db_append = qutil.ObjArrToStringArr(n["appendkey"].([]interface{}))
|
|
|
+ }
|
|
|
+ if util.StringArrEqual(key, db_key) && util.StringArrEqual(notkey, db_not) && qutil.IntAllDef(n["matchway"], 0) == matchway && util.StringArrEqual(appendkey, db_append) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
type UpdateOther struct {
|
|
|
- PageType string //projectMatch项目匹配 saveSeniorset关键词匹配方式 infoType信息类型
|
|
|
- Pmindex int //1项目匹配开启 0项目匹配关闭
|
|
|
- InfoTypeArr string //信息类型
|
|
|
- Matchtype int //1标题匹配 2项目匹配
|
|
|
- UserId string
|
|
|
- Type string
|
|
|
- OtherBuyerclass int //其它采购单位
|
|
|
- EntId int
|
|
|
- EntUserId int
|
|
|
- Session *httpsession.Session
|
|
|
+ PageType string //projectMatch项目匹配 saveSeniorset关键词匹配方式 infoType信息类型
|
|
|
+ Pmindex int //1项目匹配开启 0项目匹配关闭
|
|
|
+ InfoTypeArr string //信息类型
|
|
|
+ Matchtype int //1标题匹配 2项目匹配
|
|
|
+ UserId string
|
|
|
+ Type string
|
|
|
+ OtherBuyerclass int //其它采购单位
|
|
|
+ EntId int
|
|
|
+ EntUserId int
|
|
|
+ Session *httpsession.Session
|
|
|
}
|
|
|
|
|
|
func (this *UpdateOther) UpdateOther() map[string]interface{} {
|
|
|
- power := jy.GetBigVipUserBaseMsg("10000", this.Session, config.Config.Etcd.Hosts, config.Config.Etcd.Key)
|
|
|
- positionType := qutil.Int64All(this.Session.Get("positionType"))
|
|
|
- if this.Type == "m" && power.Status < 0 {
|
|
|
- return map[string]interface{}{"flag": false, "msg": "暂无权限"}
|
|
|
- }
|
|
|
- types := "o_jy"
|
|
|
- if this.Type == "m" {
|
|
|
- types = "o_member_jy"
|
|
|
- } else if this.Type == "v" {
|
|
|
- types = "o_vipjy"
|
|
|
- }
|
|
|
- if positionType == 1 {
|
|
|
- types = "o_entniche"
|
|
|
- }
|
|
|
- setMap := func() map[string]interface{} {
|
|
|
- switch this.PageType {
|
|
|
- case "projectMatch": //项目匹配
|
|
|
- return UpdateProjectMatch(types, this.Pmindex)
|
|
|
- case "saveSeniorset": //关键词匹配方式
|
|
|
- return UpdateSaveSeniorset(types, this.Matchtype)
|
|
|
- case "infoType": //信息类型
|
|
|
- return UpdateInfoType(types, this.InfoTypeArr)
|
|
|
- case "other_buyerclass":
|
|
|
- return UpdateOtherBuyerClass(types, this.OtherBuyerclass)
|
|
|
- case "keytip": //关键词升级弹窗提示(一个用户只提示一次)
|
|
|
- return UpdateKeyTip(types)
|
|
|
- }
|
|
|
- return nil
|
|
|
- }()
|
|
|
- flag := true
|
|
|
- if types == "o_jy" {
|
|
|
- // setMap["o_jy.i_newfree"] = 1 //老免费用户=>新订阅设置页面 20211122
|
|
|
- }
|
|
|
- if setMap != nil {
|
|
|
- if positionType == 1 {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": this.EntUserId,
|
|
|
- "i_entid": this.EntId,
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- if db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
- "$set": setMap,
|
|
|
- }, true, false) {
|
|
|
- flag = true
|
|
|
- //清楚缓存
|
|
|
- jy.ClearBigVipUserPower(this.UserId)
|
|
|
- }
|
|
|
- SetLog(this.UserId, types, positionType, this.Session)
|
|
|
- } else {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": this.EntUserId,
|
|
|
- "i_entid": this.EntId,
|
|
|
- }
|
|
|
- setMap["l_updatetime"] = time.Now().Unix()
|
|
|
- flag = db.Mgo.Update("entniche_rule", query, bson.M{"$set": setMap}, true, false)
|
|
|
- if flag {
|
|
|
- flag = true
|
|
|
- //清楚缓存
|
|
|
- jy.ClearBigVipUserPower(this.UserId)
|
|
|
- }
|
|
|
- SetLog(this.UserId, types, positionType, this.Session)
|
|
|
+ power := jy.GetBigVipUserBaseMsg("10000", this.Session, config.Config.Etcd.Hosts, config.Config.Etcd.Key)
|
|
|
+ positionType := qutil.Int64All(this.Session.Get("positionType"))
|
|
|
+ if this.Type == "m" && power.Status < 0 {
|
|
|
+ return map[string]interface{}{"flag": false, "msg": "暂无权限"}
|
|
|
+ }
|
|
|
+ types := "o_jy"
|
|
|
+ if this.Type == "m" {
|
|
|
+ types = "o_member_jy"
|
|
|
+ } else if this.Type == "v" {
|
|
|
+ types = "o_vipjy"
|
|
|
+ }
|
|
|
+ if positionType == 1 {
|
|
|
+ types = "o_entniche"
|
|
|
+ }
|
|
|
+ setMap := func() map[string]interface{} {
|
|
|
+ switch this.PageType {
|
|
|
+ case "projectMatch": //项目匹配
|
|
|
+ return UpdateProjectMatch(types, this.Pmindex)
|
|
|
+ case "saveSeniorset": //关键词匹配方式
|
|
|
+ return UpdateSaveSeniorset(types, this.Matchtype)
|
|
|
+ case "infoType": //信息类型
|
|
|
+ return UpdateInfoType(types, this.InfoTypeArr)
|
|
|
+ case "other_buyerclass":
|
|
|
+ return UpdateOtherBuyerClass(types, this.OtherBuyerclass)
|
|
|
+ case "keytip": //关键词升级弹窗提示(一个用户只提示一次)
|
|
|
+ return UpdateKeyTip(types)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ }()
|
|
|
+ flag := true
|
|
|
+ if types == "o_jy" {
|
|
|
+ // setMap["o_jy.i_newfree"] = 1 //老免费用户=>新订阅设置页面 20211122
|
|
|
+ }
|
|
|
+ if setMap != nil {
|
|
|
+ if positionType == 1 {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": this.EntUserId,
|
|
|
+ "i_entid": this.EntId,
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ if db.Mgo.Update("entniche_rule", query, map[string]interface{}{
|
|
|
+ "$set": setMap,
|
|
|
+ }, true, false) {
|
|
|
+ flag = true
|
|
|
+ //清楚缓存
|
|
|
+ jy.ClearBigVipUserPower(this.UserId)
|
|
|
+ }
|
|
|
+ SetLog(this.UserId, types, positionType, this.Session)
|
|
|
+ } else {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": this.EntUserId,
|
|
|
+ "i_entid": this.EntId,
|
|
|
+ }
|
|
|
+ setMap["l_updatetime"] = time.Now().Unix()
|
|
|
+ flag = db.Mgo.Update("entniche_rule", query, bson.M{"$set": setMap}, true, false)
|
|
|
+ if flag {
|
|
|
+ flag = true
|
|
|
+ //清楚缓存
|
|
|
+ jy.ClearBigVipUserPower(this.UserId)
|
|
|
+ }
|
|
|
+ SetLog(this.UserId, types, positionType, this.Session)
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag, "msg": ""}
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func UpdateProjectMatch(types string, pmindex int) map[string]interface{} {
|
|
|
- return map[string]interface{}{
|
|
|
- types + ".i_projectmatch": pmindex,
|
|
|
- }
|
|
|
+ return map[string]interface{}{
|
|
|
+ types + ".i_projectmatch": pmindex,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func UpdateSaveSeniorset(types string, matchtype int) map[string]interface{} {
|
|
|
- return map[string]interface{}{
|
|
|
- types + ".i_matchway": matchtype,
|
|
|
- }
|
|
|
+ return map[string]interface{}{
|
|
|
+ types + ".i_matchway": matchtype,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func UpdateInfoType(types string, infotype string) map[string]interface{} {
|
|
|
- if infotype != "" {
|
|
|
- return map[string]interface{}{
|
|
|
- types + ".a_infotype": strings.Split(infotype, ","),
|
|
|
- }
|
|
|
- } else {
|
|
|
- return map[string]interface{}{
|
|
|
- types + ".a_infotype": []string{},
|
|
|
- }
|
|
|
- }
|
|
|
+ if infotype != "" {
|
|
|
+ return map[string]interface{}{
|
|
|
+ types + ".a_infotype": strings.Split(infotype, ","),
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return map[string]interface{}{
|
|
|
+ types + ".a_infotype": []string{},
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func UpdateOtherBuyerClass(types string, other int) map[string]interface{} {
|
|
|
- return map[string]interface{}{
|
|
|
- types + ".i_matchbuyerclass_other": other,
|
|
|
- }
|
|
|
+ return map[string]interface{}{
|
|
|
+ types + ".i_matchbuyerclass_other": other,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//UpdateKeyTip 关键词升级提示
|
|
|
func UpdateKeyTip(types string) map[string]interface{} {
|
|
|
- return map[string]interface{}{
|
|
|
- types + ".b_keytip": true,
|
|
|
- }
|
|
|
+ return map[string]interface{}{
|
|
|
+ types + ".b_keytip": true,
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func directSubKWS(updateItems string, keys string, userId string, session *httpsession.Session) map[string]interface{} {
|
|
|
- flag := "n"
|
|
|
- positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
- if positionType == 0 {
|
|
|
- data, ok := db.Mgo.FindById("user", userId, fmt.Sprintf(`{"%s":1}`, updateItems))
|
|
|
- var repleat = false
|
|
|
- var classify_index = -1
|
|
|
- var kwsCount = 0
|
|
|
- if len([]rune(keys)) > 20 {
|
|
|
- keys = qutil.SubString(keys, 0, 20)
|
|
|
- }
|
|
|
- if ok && data != nil && len(*data) > 0 && keys != "" {
|
|
|
- updateObj, _ := (*data)[updateItems].(map[string]interface{})
|
|
|
- if updateObj["a_items"] != nil {
|
|
|
- a_items := updateObj["a_items"].([]interface{})
|
|
|
- for k, v := range a_items {
|
|
|
- tmp := qutil.ObjToMap(v.(map[string]interface{}))
|
|
|
- a_key := (*tmp)["a_key"].([]interface{})
|
|
|
- kwsCount = kwsCount + len(a_key)
|
|
|
- if (*tmp)["s_item"] == "未分类" {
|
|
|
- classify_index = k
|
|
|
- }
|
|
|
- for _, n := range a_key {
|
|
|
- ntmp := qutil.ObjToMap(n.(interface{}))
|
|
|
- nkey := qutil.ObjArrToStringArr((*ntmp)["key"].([]interface{}))
|
|
|
- if strings.Join(nkey, " ") == keys {
|
|
|
- repleat = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if repleat {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if classify_index == -1 {
|
|
|
- classify_index = len(a_items)
|
|
|
- }
|
|
|
- } else {
|
|
|
- //无关键词 直接添加
|
|
|
- if ok := db.Mgo.UpdateById("user", userId, bson.M{"$set": bson.M{fmt.Sprintf("%s.a_items", updateItems): bson.A{bson.M{"s_item": "未分类",
|
|
|
- "a_key": bson.A{bson.M{"key": bson.A{keys}}},
|
|
|
- "l_modifydate": time.Now().Unix()}}}}); ok {
|
|
|
- flag = "y"
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag}
|
|
|
- }
|
|
|
- if repleat {
|
|
|
- flag = "o"
|
|
|
- } else if kwsCount >= 300 {
|
|
|
- flag = "m"
|
|
|
- } else {
|
|
|
- var _key = make(map[string]interface{})
|
|
|
- var a_key = make([]map[string]interface{}, 1)
|
|
|
- classify_name := "未分类"
|
|
|
- _key["key"] = strings.Split(keys, " ")
|
|
|
- a_key[0] = _key
|
|
|
- if len(a_key) > 0 {
|
|
|
- ok := db.Mgo.UpdateById("user", userId, bson.M{
|
|
|
- "$push": bson.M{
|
|
|
- updateItems + ".a_items." + strconv.Itoa(classify_index) + ".a_key": bson.M{
|
|
|
- "$each": a_key,
|
|
|
- },
|
|
|
- },
|
|
|
- "$set": bson.M{
|
|
|
- updateItems + ".l_modifydate": time.Now().Unix(),
|
|
|
- updateItems + ".a_items." + strconv.Itoa(classify_index) + ".s_item": classify_name,
|
|
|
- },
|
|
|
- })
|
|
|
- if ok {
|
|
|
- flag = "y"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- updateItems = "o_entniche"
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
- var repleat = false
|
|
|
- var classify_index = -1
|
|
|
- var kwsCount = 0
|
|
|
- if len([]rune(keys)) > 20 {
|
|
|
- keys = qutil.SubString(keys, 0, 20)
|
|
|
- }
|
|
|
- if ok && data != nil && len(*data) > 0 && keys != "" {
|
|
|
- updateObj, _ := (*data)[0]["o_entniche"].(map[string]interface{})
|
|
|
- if updateObj["a_items"] != nil {
|
|
|
- a_items := updateObj["a_items"].([]interface{})
|
|
|
- for k, v := range a_items {
|
|
|
- tmp := qutil.ObjToMap(v.(map[string]interface{}))
|
|
|
- a_key := (*tmp)["a_key"].([]interface{})
|
|
|
- kwsCount = kwsCount + len(a_key)
|
|
|
- if (*tmp)["s_item"] == "未分类" {
|
|
|
- classify_index = k
|
|
|
- }
|
|
|
- for _, n := range a_key {
|
|
|
- ntmp := qutil.ObjToMap(n.(interface{}))
|
|
|
- nkey := qutil.ObjArrToStringArr((*ntmp)["key"].([]interface{}))
|
|
|
- if strings.Join(nkey, " ") == keys {
|
|
|
- repleat = true
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if repleat {
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- if classify_index == -1 {
|
|
|
- classify_index = len(a_items)
|
|
|
- }
|
|
|
- } else {
|
|
|
- //无关键词 直接添加
|
|
|
- if ok := db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{"o_entniche.a_items": bson.A{bson.M{"s_item": "未分类",
|
|
|
- "a_key": bson.A{bson.M{"key": bson.A{keys}}},
|
|
|
- "updatetime": time.Now().Unix()}},
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- }}, true, false); ok {
|
|
|
- flag = "y"
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag}
|
|
|
- }
|
|
|
- if repleat {
|
|
|
- flag = "o"
|
|
|
- } else if kwsCount >= 300 {
|
|
|
- flag = "m"
|
|
|
- } else {
|
|
|
- var _key = make(map[string]interface{})
|
|
|
- var a_key = make([]map[string]interface{}, 1)
|
|
|
- classify_name := "未分类"
|
|
|
- _key["key"] = strings.Split(keys, " ")
|
|
|
- a_key[0] = _key
|
|
|
- if len(a_key) > 0 {
|
|
|
- ok := db.Mgo.Update("entniche_rule", query, bson.M{
|
|
|
+ flag := "n"
|
|
|
+ positionType := qutil.Int64All(session.Get("positionType"))
|
|
|
+ if positionType == 0 {
|
|
|
+ data, ok := db.Mgo.FindById("user", userId, fmt.Sprintf(`{"%s":1}`, updateItems))
|
|
|
+ var repleat = false
|
|
|
+ var classify_index = -1
|
|
|
+ var kwsCount = 0
|
|
|
+ if len([]rune(keys)) > 20 {
|
|
|
+ keys = qutil.SubString(keys, 0, 20)
|
|
|
+ }
|
|
|
+ if ok && data != nil && len(*data) > 0 && keys != "" {
|
|
|
+ updateObj, _ := (*data)[updateItems].(map[string]interface{})
|
|
|
+ if updateObj["a_items"] != nil {
|
|
|
+ a_items := updateObj["a_items"].([]interface{})
|
|
|
+ for k, v := range a_items {
|
|
|
+ tmp := qutil.ObjToMap(v.(map[string]interface{}))
|
|
|
+ a_key := (*tmp)["a_key"].([]interface{})
|
|
|
+ kwsCount = kwsCount + len(a_key)
|
|
|
+ if (*tmp)["s_item"] == "未分类" {
|
|
|
+ classify_index = k
|
|
|
+ }
|
|
|
+ for _, n := range a_key {
|
|
|
+ ntmp := qutil.ObjToMap(n.(interface{}))
|
|
|
+ nkey := qutil.ObjArrToStringArr((*ntmp)["key"].([]interface{}))
|
|
|
+ if strings.Join(nkey, " ") == keys {
|
|
|
+ repleat = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if repleat {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if classify_index == -1 {
|
|
|
+ classify_index = len(a_items)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //无关键词 直接添加
|
|
|
+ if ok := db.Mgo.UpdateById("user", userId, bson.M{"$set": bson.M{fmt.Sprintf("%s.a_items", updateItems): bson.A{bson.M{"s_item": "未分类",
|
|
|
+ "a_key": bson.A{bson.M{"key": bson.A{keys}}},
|
|
|
+ "l_modifydate": time.Now().Unix()}}}}); ok {
|
|
|
+ flag = "y"
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag}
|
|
|
+ }
|
|
|
+ if repleat {
|
|
|
+ flag = "o"
|
|
|
+ } else if kwsCount >= 300 {
|
|
|
+ flag = "m"
|
|
|
+ } else {
|
|
|
+ var _key = make(map[string]interface{})
|
|
|
+ var a_key = make([]map[string]interface{}, 1)
|
|
|
+ classify_name := "未分类"
|
|
|
+ _key["key"] = strings.Split(keys, " ")
|
|
|
+ a_key[0] = _key
|
|
|
+ if len(a_key) > 0 {
|
|
|
+ ok := db.Mgo.UpdateById("user", userId, bson.M{
|
|
|
+ "$push": bson.M{
|
|
|
+ updateItems + ".a_items." + strconv.Itoa(classify_index) + ".a_key": bson.M{
|
|
|
+ "$each": a_key,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "$set": bson.M{
|
|
|
+ updateItems + ".l_modifydate": time.Now().Unix(),
|
|
|
+ updateItems + ".a_items." + strconv.Itoa(classify_index) + ".s_item": classify_name,
|
|
|
+ },
|
|
|
+ })
|
|
|
+ if ok {
|
|
|
+ flag = "y"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ updateItems = "o_entniche"
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ data, ok := db.Mgo.Find("entniche_rule", query, `{"o_entniche.a_items":1}`, nil, false, -1, -1)
|
|
|
+ var repleat = false
|
|
|
+ var classify_index = -1
|
|
|
+ var kwsCount = 0
|
|
|
+ if len([]rune(keys)) > 20 {
|
|
|
+ keys = qutil.SubString(keys, 0, 20)
|
|
|
+ }
|
|
|
+ if ok && data != nil && len(*data) > 0 && keys != "" {
|
|
|
+ updateObj, _ := (*data)[0]["o_entniche"].(map[string]interface{})
|
|
|
+ if updateObj["a_items"] != nil {
|
|
|
+ a_items := updateObj["a_items"].([]interface{})
|
|
|
+ for k, v := range a_items {
|
|
|
+ tmp := qutil.ObjToMap(v.(map[string]interface{}))
|
|
|
+ a_key := (*tmp)["a_key"].([]interface{})
|
|
|
+ kwsCount = kwsCount + len(a_key)
|
|
|
+ if (*tmp)["s_item"] == "未分类" {
|
|
|
+ classify_index = k
|
|
|
+ }
|
|
|
+ for _, n := range a_key {
|
|
|
+ ntmp := qutil.ObjToMap(n.(interface{}))
|
|
|
+ nkey := qutil.ObjArrToStringArr((*ntmp)["key"].([]interface{}))
|
|
|
+ if strings.Join(nkey, " ") == keys {
|
|
|
+ repleat = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if repleat {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if classify_index == -1 {
|
|
|
+ classify_index = len(a_items)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //无关键词 直接添加
|
|
|
+ if ok := db.Mgo.Update("entniche_rule", query, bson.M{"$set": bson.M{"o_entniche.a_items": bson.A{bson.M{"s_item": "未分类",
|
|
|
+ "a_key": bson.A{bson.M{"key": bson.A{keys}}},
|
|
|
+ "updatetime": time.Now().Unix()}},
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ }}, true, false); ok {
|
|
|
+ flag = "y"
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag}
|
|
|
+ }
|
|
|
+ if repleat {
|
|
|
+ flag = "o"
|
|
|
+ } else if kwsCount >= 300 {
|
|
|
+ flag = "m"
|
|
|
+ } else {
|
|
|
+ var _key = make(map[string]interface{})
|
|
|
+ var a_key = make([]map[string]interface{}, 1)
|
|
|
+ classify_name := "未分类"
|
|
|
+ _key["key"] = strings.Split(keys, " ")
|
|
|
+ a_key[0] = _key
|
|
|
+ if len(a_key) > 0 {
|
|
|
+ ok := db.Mgo.Update("entniche_rule", query, bson.M{
|
|
|
|
|
|
- "$push": bson.M{
|
|
|
- updateItems + ".a_items." + strconv.Itoa(classify_index) + ".a_key": bson.M{
|
|
|
- "$each": a_key,
|
|
|
- },
|
|
|
- },
|
|
|
- "$set": bson.M{
|
|
|
- "l_updatetime": time.Now().Unix(),
|
|
|
- updateItems + ".a_items." + strconv.Itoa(classify_index) + ".s_item": classify_name,
|
|
|
- updateItems + ".a_items." + strconv.Itoa(classify_index) + ".updatetime": time.Now().Unix(),
|
|
|
- },
|
|
|
- }, true, false)
|
|
|
- if ok {
|
|
|
- flag = "y"
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return map[string]interface{}{"flag": flag}
|
|
|
+ "$push": bson.M{
|
|
|
+ updateItems + ".a_items." + strconv.Itoa(classify_index) + ".a_key": bson.M{
|
|
|
+ "$each": a_key,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "$set": bson.M{
|
|
|
+ "l_updatetime": time.Now().Unix(),
|
|
|
+ updateItems + ".a_items." + strconv.Itoa(classify_index) + ".s_item": classify_name,
|
|
|
+ updateItems + ".a_items." + strconv.Itoa(classify_index) + ".updatetime": time.Now().Unix(),
|
|
|
+ },
|
|
|
+ }, true, false)
|
|
|
+ if ok {
|
|
|
+ flag = "y"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map[string]interface{}{"flag": flag}
|
|
|
}
|
|
|
|
|
|
//订阅设置记录
|
|
|
func SetLog(userid, types string, power int64, session *httpsession.Session) {
|
|
|
- if power == 1 {
|
|
|
- query := map[string]interface{}{
|
|
|
- "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
- "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
- "i_type": 1,
|
|
|
- }
|
|
|
- res, _ := db.Mgo.FindOne("entniche_rule", query)
|
|
|
- if res != nil && len(*res) > 0 {
|
|
|
- (*res)["userid"] = userid
|
|
|
- (*res)["type"] = types
|
|
|
- (*res)["createtime"] = time.Now().Unix()
|
|
|
- db.Mgo_Log.Save("ovipjy_log", res)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if data, ok := db.Mgo.FindById("user", userid, `{"o_vipjy":1,"o_member_jy":1,"o_jy":1}`); len(*data) > 0 && ok && data != nil {
|
|
|
- (*data)["userid"] = userid
|
|
|
- (*data)["type"] = types
|
|
|
- (*data)["createtime"] = time.Now().Unix()
|
|
|
- db.Mgo_Log.Save("ovipjy_log", data)
|
|
|
- }
|
|
|
- }
|
|
|
+ if power == 1 {
|
|
|
+ query := map[string]interface{}{
|
|
|
+ "i_userid": qutil.IntAll(session.Get("entUserId")),
|
|
|
+ "i_entid": qutil.IntAll(session.Get("entId")),
|
|
|
+ "i_type": 1,
|
|
|
+ }
|
|
|
+ res, _ := db.Mgo.FindOne("entniche_rule", query)
|
|
|
+ if res != nil && len(*res) > 0 {
|
|
|
+ (*res)["userid"] = userid
|
|
|
+ (*res)["type"] = types
|
|
|
+ (*res)["createtime"] = time.Now().Unix()
|
|
|
+ db.Mgo_Log.Save("ovipjy_log", res)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if data, ok := db.Mgo.FindById("user", userid, `{"o_vipjy":1,"o_member_jy":1,"o_jy":1}`); len(*data) > 0 && ok && data != nil {
|
|
|
+ (*data)["userid"] = userid
|
|
|
+ (*data)["type"] = types
|
|
|
+ (*data)["createtime"] = time.Now().Unix()
|
|
|
+ db.Mgo_Log.Save("ovipjy_log", data)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|