123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853 |
- package client
- import (
- "cmplatform/util"
- "encoding/json"
- "fmt"
- "io"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/encrypt"
- "app.yhyue.com/moapp/jybase/go-xweb/xweb"
- "app.yhyue.com/moapp/jybase/mongodb"
- "github.com/lauyoume/gopinyin"
- "go.mongodb.org/mongo-driver/bson"
- "go.mongodb.org/mongo-driver/bson/primitive"
- "log"
- "strconv"
- "strings"
- "time"
- )
- type OwnTag struct {
- *xweb.Action
- customerSave xweb.Mapper `xweb:"/client/customer/save"` //客户信息保存
- euserTagEdit xweb.Mapper `xweb:"/client/customer/tag/edit"` //客户信息保存
- euserImport xweb.Mapper `xweb:"/client/customer/tag/import"` //私有标签导入关键词
- customerHistory xweb.Mapper `xweb:"/client/customer/history"` //私有标签导入关键词
- customerEdit xweb.Mapper `xweb:"/client/customer/edit"` //编辑客户信息
- tagSetup xweb.Mapper `xweb:"/client/customer/tag/setup"` //标签的启用禁用
- tagDel xweb.Mapper `xweb:"/client/customer/tag/del"` //删除标签
- cuserRuleList xweb.Mapper `xweb:"/client/tag/ruleList"` //规则列表 客户
- tagAssociated xweb.Mapper `xweb:"/client/customer/tag/associated"` //私有标签关联规则
- addhistoryrule xweb.Mapper `xweb:"/client/rule/history/add"` //新增历史任务
- historyRuleCreate xweb.Mapper `xweb:"/client/customer/rule/history/edit"` //新增历史任务规则
- historyTagDel xweb.Mapper `xweb:"/client/tag/history/del"` //历史任务删除私有标签
- historyTagAssociated xweb.Mapper `xweb:"/client/customer/historytag/associated"` //私有标签关联历史规则
- saveHistoryRule xweb.Mapper `xweb:"/client/customer/history/saverule"` //保存历史规则
- delHistoryRule xweb.Mapper `xweb:"/client/customer/history/delrule"` //删除历史任务规则
- historyRuleEdit xweb.Mapper `xweb:"/client/historyRule/edit"` //编辑历史规则
- customerAllRule xweb.Mapper `xweb:"/client/customer/history/allrule"` //用户历史规则
- }
- // 保存客户信息
- func (c *OwnTag) CustomerSave() {
- defer common.Catch()
- if c.Method() == "POST" {
- //data := GetPostForm(c.Request)
- data := map[string]interface{}{}
- err := json.Unmarshal(c.Body(), &data)
- if err != nil {
- log.Println("err", err)
- }
- log.Println("接收数据:", data)
- id := common.ObjToString(data["id"])
- delete(data, "id")
- i_createtime := time.Now().Unix()
- data["i_updatetime"] = i_createtime
- var rep = false
- if id == "" {
- departArr := []map[string]interface{}{}
- departArrStr := data["depart"].(string)
- json.Unmarshal([]byte(departArrStr), &departArr)
- delete(data, "depart")
- data["b_delete"] = false
- data["i_createtime"] = i_createtime
- data["i_state"] = 0
- id = util.Mgo.Save("cuser", data)
- if id != "" {
- for _, v := range departArr {
- v["s_userid"] = id
- v["i_createtime"] = time.Now().Unix()
- v["i_updatetime"] = time.Now().Unix()
- v["i_isuse"] = common.IntAll(v["i_isuse"])
- v["b_delete"] = false
- }
- if len(departArr) == 0 {
- rep = true
- } else {
- rep = util.Mgo.SaveBulk("cuserdepart", departArr...)
- }
- } else {
- rep = false
- }
- } else {
- if data["mails"] != nil {
- mailsMap := map[string]interface{}{}
- mails := common.ObjArrToStringArr(data["mails"].([]interface{}))
- for _, val := range mails {
- mailArr := strings.Split(val, "+")
- mailsMap[mailArr[0]] = mailArr[1]
- }
- log.Println(mailsMap)
- appid := common.ObjToString(data["s_appid"])
- q := bson.M{
- "appid": appid,
- }
- setMap := map[string]interface{}{
- "mails": mailsMap,
- }
- rep = util.MgoCus.Update("user", q, bson.M{"$set": setMap}, false, false)
- c.ServeJson(map[string]interface{}{
- "rep": rep,
- })
- return
- }
- delete(data, "mails")
- query := bson.M{
- "_id": mongodb.StringTOBsonId(id),
- }
- rep = util.Mgo.Update("cuser", query, bson.M{"$set": data}, false, false)
- }
- c.ServeJson(map[string]interface{}{
- "rep": rep,
- })
- }
- }
- // 新建/编辑标签
- func (c *OwnTag) EuserTagEdit() {
- defer common.Catch()
- if c.Method() == "POST" {
- _id := c.GetString("_id")
- data := util.GetPostForm(c.Request)
- cid := common.ObjToString(data["s_userid"])
- createTime := time.Now().Unix()
- o_rules := []map[string]interface{}{}
- o_rulesStr := data["o_list"].(string)
- json.Unmarshal([]byte(o_rulesStr), &o_rules)
- data["o_list"] = o_rules
- hid := common.ObjToString(data["hid"])
- var rep = true
- if hid == "" {
- if _id == "" {
- data["i_createtime"] = createTime
- data["i_updatetime"] = createTime
- data["b_delete"] = false
- _id = util.Mgo.Save("eusertagrule", data)
- } else {
- query := bson.M{
- "_id": mongodb.StringTOBsonId(_id),
- }
- rep = util.Mgo.Update("eusertagrule", query, bson.M{"$set": data}, false, false)
- }
- } else {
- if _id == "" {
- data["i_createtime"] = createTime
- data["i_updatetime"] = createTime
- data["i_type"] = "historyData"
- data["b_delete"] = true
- _id = util.Mgo.Save("eusertagrule", data)
- rep = AddHistoryLogTag(data, false, _id)
- } else {
- query := bson.M{
- "_id": mongodb.StringTOBsonId(_id),
- }
- reps := util.Mgo.Update("eusertagrule", query, bson.M{"$set": data}, false, false)
- if reps {
- rep = AddHistoryLogTag(data, true, _id)
- }
- }
- }
- c.ServeJson(map[string]interface{}{
- "id": cid,
- "rep": rep,
- })
- } else {
- if c.GetString("id") != "" {
- data, _ := util.Mgo.FindById("eusertagrule", c.GetString("id"), nil)
- c.T["tagrule"] = *data
- }
- cid := c.GetString("cid")
- c.T["cid"] = cid
- c.T["matchTypeMap"] = util.MatchTypeMap3
- c.T["hid"] = c.GetString("hid")
- c.Render("client/customer_tag_rule.html", &c.T)
- }
- }
- func (c *OwnTag) CustomerHistory() {
- defer common.Catch()
- id := c.GetString("id")
- user := c.GetSession("user").(map[string]interface{})
- query := bson.M{}
- query["_id"] = mongodb.StringTOBsonId(id)
- hid := c.GetString("hid")
- history_id := ""
- if hid != "" {
- history_id = hid
- hData, ok := util.Mgo.FindOne("historylog", bson.M{"_id": mongodb.StringTOBsonId(history_id)})
- if ok && hData != nil && len(*hData) > 0 {
- c.T["history_rule"] = (*hData)["dep_rules"]
- c.T["tagrule"] = (*hData)["tag_rules"]
- (*hData)["_id"] = id
- c.T["data"] = *hData
- }
- } else {
- var user_name, user_customername, user_salesperson, appid = "", "", "", ""
- var push_model, push_type, i_push = 0, 0, 0
- userInfo, ok := util.Mgo.FindOne("euser", query)
- if ok && userInfo != nil && *userInfo != nil {
- user_name = common.ObjToString((*userInfo)["s_name"])
- user_customername = common.ObjToString((*userInfo)["s_customername"])
- user_salesperson = common.ObjToString((*userInfo)["s_salesperson"])
- push_model = common.IntAll((*userInfo)["i_pushmodel"])
- push_type = common.IntAll((*userInfo)["i_pushtype"])
- i_push = common.IntAll((*userInfo)["i_push"])
- appid = common.ObjToString((*userInfo)["s_appid"])
- }
- history_id = util.Mgo.Save("historylog", map[string]interface{}{
- "createtime": time.Now().Unix(),
- "updatetime": time.Now().Unix(),
- "user_id": id,
- "create_user": user["name"],
- "state": 0,
- "s_name": user_name,
- "s_customername": user_customername,
- "s_salesperson": user_salesperson,
- "i_pushmodel": push_model,
- "i_pushtype": push_type,
- "i_push": i_push,
- "s_appid": appid,
- })
- c.Redirect("/client/customer/history?id=" + id + "&hid=" + history_id)
- return
- }
- c.T["history_id"] = history_id
- c.Render("client/customer_history.html", &c.T)
- }
- // 导入关键词
- func (c *OwnTag) EuserImport() {
- defer common.Catch()
- if c.Method() == "POST" {
- mf, _, err := c.GetFile("xlsx")
- if err == nil {
- binary, err := io.ReadAll(mf)
- if err == nil {
- rdata, err := util.Parsxlsx1(binary)
- if err == nil {
- c.ServeJson(map[string]interface{}{
- "rdata": rdata,
- "rep": true,
- })
- return
- }
- }
- }
- c.ServeJson(map[string]interface{}{
- "rep": false,
- })
- }
- }
- // 编辑客户信息
- func (c *OwnTag) CustomerEdit() {
- defer common.Catch()
- id := c.GetString("id")
- query := bson.M{}
- query["_id"] = mongodb.StringTOBsonId(id)
- data, _ := util.Mgo.FindOneByField("cuser", query, `{}`)
- depart, _ := util.Mgo.Find("cuserdepart", bson.M{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1)
- (*data)["_id"] = mongodb.BsonIdToSId((*data)["_id"])
- if (*data)["i_state"] == 1 {
- tagRule, _ := util.Mgo.Find("eusertagrule", bson.M{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1)
- c.T["tagrule"] = *tagRule
- }
- c.T["data"] = *data
- c.T["depart"] = *depart
- c.Render("client/index.html", &c.T)
- }
- // 标签的启用禁用
- func (c *OwnTag) TagSetup() {
- defer common.Catch()
- if c.Method() == "POST" {
- _id := c.GetString("_id")
- i_isuse, _ := c.GetInt("i_isuse")
- set := bson.M{
- "$set": bson.M{
- "i_isuse": i_isuse,
- },
- }
- b := util.Mgo.UpdateById("eusertagrule", _id, set)
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- }
- // 删除标签
- func (c *OwnTag) TagDel() {
- defer common.Catch()
- _id := c.GetString("_id")
- set := bson.M{
- "$set": bson.M{
- "b_delete": true,
- },
- }
- b := util.Mgo.UpdateById("eusertagrule", _id, set)
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- // 关联规则列表
- func (c *OwnTag) CuserRuleList() {
- defer common.Catch()
- if c.Method() == "POST" {
- eid := c.GetString("eid")
- start, _ := c.GetInt("start")
- limit, _ := c.GetInt("length")
- draw, _ := c.GetInt("draw")
- searchStr := c.GetString("search[value]")
- search := strings.TrimSpace(searchStr)
- query := bson.M{
- "s_userid": eid,
- "i_isuse": 1,
- "b_delete": false,
- }
- if search != "" {
- query["$or"] = []interface{}{
- bson.M{"s_name": bson.M{"$regex": search}},
- }
- }
- data, _ := util.Mgo.Find("euserdepartrule", query, `{"i_createtime":-1}`, nil, false, int(start), int(limit))
- for _, v := range *data {
- d, _ := util.Mgo.FindById("euserdepart", common.ObjToString(v["s_departid"]), nil)
- v["s_depart"] = common.ObjToString((*d)["s_name"])
- }
- count := util.Mgo.Count("euserdepartrule", query)
- c.ServeJson(map[string]interface{}{
- "draw": draw,
- "data": data,
- "recordsFiltered": count,
- "recordsTotal": count,
- })
- }
- }
- func (c *OwnTag) TagAssociated() {
- defer common.Catch()
- _id := c.GetString("_id")
- ids := c.GetString("ids")
- set := bson.M{
- "$set": bson.M{
- "o_departruleids": ids,
- },
- }
- b := util.Mgo.UpdateById("eusertagrule", _id, set)
- c.ServeJson(map[string]interface{}{
- "rep": b,
- })
- }
- func (c *OwnTag) Addhistoryrule() {
- defer common.Catch()
- if c.Method() == "POST" {
- his_id := c.GetString("history_id")
- //log.Println("hisid", his_id)
- if his_id != "" {
- //newHistory["tag_rules"] = usertags
- push_model, _ := strconv.Atoi(c.GetString("send_mode"))
- push_type, _ := strconv.Atoi(c.GetString("push_type"))
- isDup, _ := strconv.Atoi(c.GetString("isDup"))
- i_updatetime, _ := strconv.ParseInt(c.GetString("i_updatetime"), 10, 64)
- i_extfieldstype, _ := strconv.Atoi(c.GetString("i_extfieldstype"))
- set := bson.M{
- "$set": bson.M{
- "i_pushmodel": push_model,
- "s_customername": c.GetString("s_customername"),
- "s_salesperson": c.GetString("s_salesperson"),
- "s_name": c.GetString("s_name"),
- "i_pushtype": push_type,
- "s_extends": c.GetString("s_extends"),
- "i_updatetime": i_updatetime,
- "sendMail": c.GetString("sendMail"),
- "isDup": isDup,
- "i_extfieldstype": i_extfieldstype,
- },
- }
- isupdata := util.Mgo.UpdateById("historylog", mongodb.StringTOBsonId(his_id), set)
- if isupdata {
- c.ServeJson(map[string]interface{}{
- "history_id": his_id,
- "rep": true,
- })
- } else {
- //log.Println(666)
- c.ServeJson(map[string]interface{}{
- "history_id": "",
- "rep": false,
- })
- }
- }
- }
- }
- func (c *OwnTag) HistoryRuleCreate() {
- defer common.Catch()
- if c.Method() == "POST" {
- user := c.GetSession("user").(map[string]interface{})
- data := util.GetPostForm(c.Request)
- o_rules := []map[string]interface{}{}
- o_rulesStr := data["o_rules"].(string)
- json.Unmarshal([]byte(o_rulesStr), &o_rules)
- data["o_rules"] = o_rules
- id := common.ObjToString(data["id"])
- user_id := data["ids"]
- delete(data, "id")
- delete(data, "ids")
- if common.IntAll(data["i_esquerytype"]) == 1 { //自动生成es
- data["s_esquery"] = util.Utiltags(data, id)
- }
- i_createtime := time.Now().Unix()
- data["i_updatetime"] = i_createtime
- data["s_updateuser"] = user["name"]
- data["s_depart_name"] = data["departmentName"]
- var rep = false
- s_id := ""
- if id == "" { //新建
- dData, ok := util.Mgo.FindOne("euserdepart", bson.M{"s_userid": user_id, "s_name": data["departmentName"]})
- if dData == nil || *dData == nil || !ok {
- d_data := map[string]interface{}{
- "i_isuse": 1,
- "s_userid": user_id,
- "s_name": data["s_depart_name"],
- "i_createtime": time.Now().Unix(),
- "i_updatetime": time.Now().Unix(),
- "b_delete": true,
- "i_type": "historyData",
- }
- s_id = util.Mgo.Save("euserdepart", d_data)
- } else {
- s_id = mongodb.BsonIdToSId((*dData)["_id"])
- }
- data["s_userid"] = user_id
- data["s_departid"] = s_id
- data["i_createtime"] = i_createtime
- data["s_createuser"] = user["name"]
- s_namekey := gopinyin.Convert(common.ObjToString(data["s_name"]), false)
- data["s_namekey"] = s_namekey
- data["b_delete"] = true
- data["s_dataid"] = encrypt.SE.EncodeString(fmt.Sprintf("%v", i_createtime) + s_namekey + s_id)
- data["i_type"] = "historyData"
- id = util.Mgo.Save("euserdepartrule", data)
- if id != "" {
- rep = AddHistoryLogDep(data, false, id)
- } else {
- rep = false
- }
- } else {
- query := bson.M{
- "_id": mongodb.StringTOBsonId(id),
- }
- reps := util.Mgo.Update("euserdepartrule", query, bson.M{"$set": data}, false, false)
- if reps {
- rep = AddHistoryLogDep(data, true, id)
- }
- }
- c.ServeJson(map[string]interface{}{
- "id": id,
- "rep": rep,
- "s_esquery": data["s_esquery"],
- "s_dataid": data["s_dataid"],
- })
- } else {
- id := c.GetString("id")
- c.T["did"] = id //部门id
- c.T["cid"] = id //客户id
- c.T["ids"] = id
- c.T["history_id"] = c.GetString("hid")
- c.T["province"] = util.Province
- c.T["city"] = util.ProvinceCitys
- c.T["district"] = util.CityDistricts
- c.T["topTypeArr"] = util.TopTypeArr
- c.T["subTypeArr"] = util.SubTypeArr
- c.T["matchTypeMap"] = util.MatchTypeMap
- c.T["matchTypeMap2"] = util.MatchTypeMap2
- c.T["existField"] = util.ExistFiled
- c.T["buyerClass"] = util.BuyerClass
- c.T["scopeClass"] = util.ScopeClassMap
- c.Render("client/cuser_rule_history_edit.html", &c.T)
- }
- }
- // 历史任务删除私有标签
- func (c *OwnTag) HistoryTagDel() {
- defer common.Catch()
- // userid := c.GetString("userid")
- tagid := c.GetString("tagid")
- hid := c.GetString("hid")
- user_info, _ := util.Mgo.FindOne("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)})
- if user_info != nil && *user_info != nil {
- if (*user_info)["tag_rules"] != nil {
- user_tag_rules := common.ObjArrToMapArr((*user_info)["tag_rules"].([]interface{}))
- ruleMap := map[string]bool{tagid: true}
- ruleArr := []map[string]interface{}{}
- for _, m := range user_tag_rules {
- if !ruleMap[mongodb.BsonIdToSId(m["_id"])] {
- ruleArr = append(ruleArr, m)
- }
- }
- is_updata := util.Mgo.Update("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)}, bson.M{"$set": bson.M{"tag_rules": ruleArr}}, false, false)
- c.ServeJson(map[string]interface{}{
- "rep": is_updata,
- })
- }
- return
- }
- c.ServeJson(map[string]interface{}{
- "rep": false,
- })
- }
- // 私有标签关联数据
- func (c *OwnTag) HistoryTagAssociated() {
- defer common.Catch()
- userid := c.GetString("userid")
- rule_id := c.GetString("_id")
- tags := c.GetString("ids")
- hid := c.GetString("hid")
- if userid != "" {
- user_info, _ := util.Mgo.FindOne("historylog", map[string]interface{}{
- "_id": mongodb.StringTOBsonId(hid),
- })
- if user_info != nil && *user_info != nil {
- tagrules := (*user_info)["tag_rules"]
- if tagrules != nil {
- tagrulesArr := common.ObjArrToMapArr(tagrules.([]interface{}))
- for _, m := range tagrulesArr {
- if rule_id == mongodb.BsonIdToSId(m["_id"]) {
- m["o_departruleids"] = tags
- }
- }
- set := bson.M{
- "$set": bson.M{
- "tag_rules": tagrulesArr,
- },
- }
- is_updata := util.Mgo.Update("historylog", map[string]interface{}{
- "_id": mongodb.StringTOBsonId(hid),
- }, set, false, false)
- c.ServeJson(map[string]interface{}{
- "rep": is_updata,
- })
- }
- }
- }
- }
- // 保存历史规则
- func (c *OwnTag) SaveHistoryRule() {
- rules_id := c.GetString("rulesid")
- history_id := c.GetString("hid")
- // userid := c.GetString("userid")
- if history_id != "" {
- user_history, _ := util.Mgo.FindOne("historylog", map[string]interface{}{
- "_id": mongodb.StringTOBsonId(history_id),
- })
- if *user_history != nil && user_history != nil {
- //获取私有标签
- // usertags := getTserTag(userid)
- if (*user_history)["dep_rules"] != nil {
- dep_rules := common.ObjArrToMapArr((*user_history)["dep_rules"].([]interface{}))
- dep_new_rules := []map[string]interface{}{}
- ruleMap := map[string]bool{}
- if len(dep_rules) > 0 {
- for _, r := range dep_rules {
- dep_new_rules = append(dep_new_rules, r)
- ruleMap[mongodb.BsonIdToSId(r["_id"])] = true
- }
- }
- rules_id_list := strings.Split(rules_id, ",")
- for _, rule := range rules_id_list {
- if !ruleMap[rule] {
- query := bson.M{
- "_id": mongodb.StringTOBsonId(rule),
- "b_delete": false,
- }
- res, _ := util.Mgo.FindOne("euserdepartrule", query)
- if res != nil && len(*res) != 0 {
- //获取规则所属部门信息
- department_info, _ := util.Mgo.FindOne("euserdepart", map[string]interface{}{
- "_id": mongodb.StringTOBsonId((*res)["s_departid"].(string)),
- "b_delete": false,
- })
- (*res)["is_new"] = false
- (*res)["s_depart_name"] = (*department_info)["s_name"]
- dep_new_rules = append(dep_new_rules, *res)
- }
- }
- }
- set := bson.M{
- "$set": bson.M{
- "dep_rules": dep_new_rules,
- // "tag_rules": usertags,
- "updatetime": time.Now().Unix(),
- },
- }
- ok := util.Mgo.Update("historylog", map[string]interface{}{
- "_id": mongodb.StringTOBsonId(history_id),
- }, set, false, false)
- //log.Println("ok", ok)
- c.ServeJson(map[string]interface{}{
- "status": ok,
- })
- return
- } else {
- rules_id_list := strings.Split(rules_id, ",")
- dep_rules := []map[string]interface{}{}
- for _, rule := range rules_id_list {
- query := bson.M{
- "_id": mongodb.StringTOBsonId(rule),
- "b_delete": false,
- }
- res, _ := util.Mgo.FindOne("euserdepartrule", query)
- if res != nil && *res != nil {
- //获取规则所属部门信息
- department_info, _ := util.Mgo.FindOne("euserdepart", map[string]interface{}{
- "_id": mongodb.StringTOBsonId((*res)["s_departid"].(string)),
- "b_delete": false,
- })
- (*res)["is_new"] = false
- (*res)["s_depart_name"] = (*department_info)["s_name"]
- dep_rules = append(dep_rules, *res)
- }
- }
- set := bson.M{
- "$set": bson.M{
- "dep_rules": dep_rules,
- // "tag_rules": usertags,
- "updatetime": time.Now().Unix(),
- },
- }
- isupdata := util.Mgo.Update("historylog", map[string]interface{}{
- "_id": mongodb.StringTOBsonId(history_id),
- }, set, false, false)
- c.ServeJson(map[string]interface{}{
- "status": isupdata,
- })
- return
- }
- }
- c.ServeJson(map[string]interface{}{
- "status": "fail",
- })
- }
- }
- func (c *OwnTag) DelHistoryRule() {
- id := c.GetString("id")
- hid := c.GetString("hid")
- if hid != "" {
- data, ok := util.Mgo.FindOne("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)})
- if ok && data != nil && *data != nil {
- if (*data)["dep_rules"] != nil {
- dep_rules := common.ObjArrToMapArr((*data)["dep_rules"].([]interface{}))
- ruleMap := map[string]bool{id: true}
- ruleArr := []map[string]interface{}{}
- for _, m := range dep_rules {
- if !ruleMap[mongodb.BsonIdToSId(m["_id"])] {
- ruleArr = append(ruleArr, m)
- }
- }
- ok := util.Mgo.Update("historylog", bson.M{"_id": mongodb.StringTOBsonId(hid)}, bson.M{"$set": bson.M{"dep_rules": ruleArr}}, false, false)
- c.ServeJson(map[string]interface{}{
- "success": ok,
- })
- }
- }
- }
- }
- func (c *OwnTag) HistoryRuleEdit() {
- hid := c.GetString("hid")
- rid := c.GetString("rid")
- if c.Method() == "POST" {
- data := util.GetPostForm(c.Request)
- o_rules := []map[string]interface{}{}
- o_rulesStr := data["o_rules"].(string)
- json.Unmarshal([]byte(o_rulesStr), &o_rules)
- data["o_rules"] = o_rules
- data["_id"] = mongodb.StringTOBsonId(rid)
- if common.IntAll(data["i_esquerytype"]) == 1 { //自动生成es
- data["s_esquery"] = util.Utiltags(data, rid)
- }
- datas, ok := util.Mgo.FindOne("historylog", map[string]interface{}{"_id": mongodb.StringTOBsonId(hid)})
- if ok && datas != nil && *datas != nil {
- dep_rules := common.ObjArrToMapArr((*datas)["dep_rules"].([]interface{}))
- for k, v := range dep_rules {
- if rid == mongodb.BsonIdToSId(v["_id"]) {
- dep_rules[k] = data
- }
- }
- rep := util.Mgo.Update("historylog", map[string]interface{}{"_id": mongodb.StringTOBsonId(hid)}, map[string]interface{}{"$set": map[string]interface{}{"dep_rules": dep_rules}}, false, false)
- c.ServeJson(map[string]interface{}{
- "rep": rep,
- "s_esquery": data["s_esquery"],
- })
- }
- } else {
- id := c.GetString("id")
- data, ok := util.Mgo.FindOne("historylog", map[string]interface{}{"_id": mongodb.StringTOBsonId(hid)})
- if ok && data != nil && *data != nil {
- dep_rules := common.ObjArrToMapArr((*data)["dep_rules"].([]interface{}))
- for _, v := range dep_rules {
- if rid == mongodb.BsonIdToSId(v["_id"]) {
- c.T["data"] = v
- }
- }
- }
- c.T["did"] = id //部门id
- c.T["cid"] = id //客户id
- c.T["ids"] = id
- c.T["history_id"] = hid
- c.T["rid"] = rid
- c.T["province"] = util.Province
- c.T["city"] = util.ProvinceCitys
- c.T["district"] = util.CityDistricts
- c.T["topTypeArr"] = util.TopTypeArr
- c.T["subTypeArr"] = util.SubTypeArr
- c.T["matchTypeMap"] = util.MatchTypeMap
- c.T["matchTypeMap2"] = util.MatchTypeMap2
- c.T["existField"] = util.ExistFiled
- c.T["buyerClass"] = util.BuyerClass
- c.T["scopeClass"] = util.ScopeClassMap
- c.Render("private/history_rule_edit.html", &c.T)
- }
- }
- // 选择历史规则
- func (c *OwnTag) CustomerAllRule() {
- customerId := c.GetString("c_id")
- history_id := c.GetString("hid")
- query := bson.M{
- "s_userid": customerId,
- "b_delete": false,
- }
- inc_query := bson.M{
- "user_id": customerId,
- "_id": mongodb.StringTOBsonId(history_id),
- }
- //获取新增历史规则
- inc_rules := []map[string]interface{}{}
- inc_rule := make(map[string]interface{})
- inc_data, _ := util.Mgo.FindOne("historylog", inc_query)
- if inc_data != nil && *inc_data != nil {
- for _, t := range (*inc_data)["dep_rules"].([]interface{}) {
- if !t.(map[string]interface{})["is_new"].(bool) {
- inc_rule["id"] = t.(map[string]interface{})["_id"].(primitive.ObjectID).Hex() //规则id
- inc_rule["s_depart_name"] = t.(map[string]interface{})["s_depart_name"]
- inc_rule["s_name"] = t.(map[string]interface{})["s_name"]
- inc_rule["s_depart_status"] = t.(map[string]interface{})["s_depart_status"]
- inc_rule["s_rule_status"] = t.(map[string]interface{})["s_rule_status"]
- inc_rule["rule_updatetime"] = t.(map[string]interface{})["i_updatetime"]
- inc_rule["isinc"] = true
- inc_rules = append(inc_rules, inc_rule)
- }
- }
- }
- data, _ := util.Mgo.Find("euserdepart", query, `{"i_createtime":-1}`, nil, false, 0, 0)
- if data != nil && len(*data) != 0 {
- res := []map[string]interface{}{}
- for _, m := range *data {
- history_rule_data := make(map[string]interface{})
- q := bson.M{
- "s_departid": m["_id"].(primitive.ObjectID).Hex(),
- "b_delete": false,
- }
- history_rule_data["department_isuse"] = m["i_isuse"]
- history_rule_data["depart_name"] = m["s_name"]
- depart_rule_data, _ := util.Mgo.Find("euserdepartrule", q, `{"i_createtime":-1}`, `{"s_name":1,"i_updatetime":1,"i_isuse":1,"_id":1}`, false, 0, 0)
- if depart_rule_data != nil && len(*depart_rule_data) != 0 {
- for _, j := range *depart_rule_data {
- j["_id"] = j["_id"].(primitive.ObjectID).Hex()
- }
- history_rule_data["department_rule"] = depart_rule_data
- history_rule_data["is_slected"] = true
- }
- res = append(res, history_rule_data)
- }
- c.ServeJson(map[string]interface{}{
- "status": "success",
- "data": res,
- "inc_rules": inc_rules,
- })
- } else {
- c.ServeJson(map[string]interface{}{
- "status": "fail",
- "data": "",
- })
- }
- }
- func AddHistoryLogTag(ruleData map[string]interface{}, isUpdate bool, id string) bool {
- history_id := mongodb.StringTOBsonId(common.ObjToString(ruleData["hid"]))
- hData, ok := util.Mgo.FindOne("historylog", bson.M{"_id": history_id})
- if ok && hData != nil && *hData != nil && len(*hData) > 0 {
- tag_rules := []map[string]interface{}{}
- if (*hData)["tag_rules"] != nil {
- tag_rules = common.ObjArrToMapArr((*hData)["tag_rules"].([]interface{}))
- }
- ruleData["is_new"] = true
- if isUpdate {
- for k, v := range tag_rules {
- if mongodb.BsonIdToSId(v["_id"]) == id {
- tag_rules[k] = ruleData
- }
- }
- } else {
- tag_rules = append(tag_rules, ruleData)
- }
- return util.Mgo.Update("historylog", bson.M{"_id": history_id}, bson.M{"$set": bson.M{"tag_rules": tag_rules}}, false, false)
- } else {
- return false
- }
- }
- func AddHistoryLogDep(ruleData map[string]interface{}, isUpdate bool, id string) bool {
- history_id := mongodb.StringTOBsonId(ruleData["history_id"].(string))
- hData, ok := util.Mgo.FindOne("historylog", bson.M{"_id": history_id})
- if ok && hData != nil && *hData != nil && len(*hData) > 0 {
- dep_rules := []map[string]interface{}{}
- if (*hData)["dep_rules"] != nil {
- dep_rules = common.ObjArrToMapArr((*hData)["dep_rules"].([]interface{}))
- }
- ruleData["is_new"] = true
- if isUpdate {
- for k, v := range dep_rules {
- if mongodb.BsonIdToSId(v["_id"]) == id {
- dep_rules[k] = ruleData
- }
- }
- } else {
- dep_rules = append(dep_rules, ruleData)
- }
- return util.Mgo.Update("historylog", bson.M{"_id": history_id}, bson.M{"$set": bson.M{"dep_rules": dep_rules}}, false, false)
- } else {
- return false
- }
- }
|