|
@@ -58,9 +58,9 @@ type Customer struct {
|
|
|
saveHistoryRule xweb.Mapper `xweb:"/service/customer/history/saverule"` //保存历史规则
|
|
|
historyRuleCreate xweb.Mapper `xweb:"/service/cuser/rule/history/edit"`
|
|
|
historyCuserRuleList xweb.Mapper `xweb:"/service/tag/history/ruleList"` //私有标签关联历史规则
|
|
|
- historyTagDel xweb.Mapper `xweb:"/service/tag/history/del"` //历史任务删除私有标签
|
|
|
- historyTagEdit xweb.Mapper `xweb:"/service/tag/history/edit"` //历史任务修改私有标签
|
|
|
- addhistoryrule xweb.Mapper `xweb:"/service/rule/history/add"` //新增历史任务
|
|
|
+ historyTagDel xweb.Mapper `xweb:"/service/tag/history/del"` //历史任务删除私有标签
|
|
|
+ historyTagEdit xweb.Mapper `xweb:"/service/tag/history/edit"` //历史任务修改私有标签
|
|
|
+ addhistoryrule xweb.Mapper `xweb:"/service/rule/history/add"` //新增历史任务
|
|
|
|
|
|
}
|
|
|
|
|
@@ -859,23 +859,37 @@ func (c *Customer) TagAssociated() {
|
|
|
func (c *Customer) CustomerHistory() {
|
|
|
defer qu.Catch()
|
|
|
id := c.GetString("id")
|
|
|
+ user := c.GetSession("user").(map[string]interface{})
|
|
|
query := bson.M{}
|
|
|
query["_id"] = qu.StringTOBsonId(id)
|
|
|
- data, _ := Mgo.FindOneByField("cuser", query, `{}`)
|
|
|
- depart, _ := Mgo.Find("cuserdepart", bson.M{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1)
|
|
|
+ data, _ := Mgo.FindOneByField("euser", query, `{}`)
|
|
|
+ depart, _ := Mgo.Find("euserdepart", bson.M{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1)
|
|
|
(*data)["_id"] = qu.BsonIdToSId((*data)["_id"])
|
|
|
if (*data)["i_state"] == 1 {
|
|
|
tagRule, _ := Mgo.Find("eusertagrule", bson.M{"s_userid": id, "b_delete": false}, nil, nil, false, -1, -1)
|
|
|
c.T["tagrule"] = *tagRule
|
|
|
}
|
|
|
- history_id:=Mgo.Save("historylog",map[string]interface{}{
|
|
|
- "createtime":time.Now().Unix(),
|
|
|
- })
|
|
|
- if history_id!=""{
|
|
|
- c.T["history_id"] = history_id
|
|
|
+ hid := c.GetString("hid")
|
|
|
+ history_id := ""
|
|
|
+ if hid != "" {
|
|
|
+ history_id = hid
|
|
|
+ hData, ok := Mgo.FindOne("historylog", bson.M{"_id": qu.StringTOBsonId(history_id)})
|
|
|
+ if ok && hData != nil && len(*hData) > 0 {
|
|
|
+ // (*hData)["dep_rules"]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ history_id = Mgo.Save("historylog", map[string]interface{}{
|
|
|
+ "createtime": time.Now().Unix(),
|
|
|
+ "updatetime": time.Now().Unix(),
|
|
|
+ "user_id": id,
|
|
|
+ "create_user": user["name"],
|
|
|
+ "state": 0,
|
|
|
+ })
|
|
|
+ c.T["data"] = *data
|
|
|
+ c.T["depart"] = *depart
|
|
|
}
|
|
|
- c.T["data"] = *data
|
|
|
- c.T["depart"] = *depart
|
|
|
+
|
|
|
+ c.T["history_id"] = history_id
|
|
|
c.Render("private/customer_history.html", &c.T)
|
|
|
}
|
|
|
|
|
@@ -889,7 +903,7 @@ func (c *Customer) CustomerAllRule() {
|
|
|
}
|
|
|
inc_query := bson.M{
|
|
|
"user_id": customerId,
|
|
|
- "_id":qu.StringTOBsonId(history_id),
|
|
|
+ "_id": qu.StringTOBsonId(history_id),
|
|
|
}
|
|
|
//获取新增历史规则
|
|
|
inc_rules := []map[string]interface{}{}
|
|
@@ -909,7 +923,7 @@ func (c *Customer) CustomerAllRule() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- data, _ := Mgo.Find("cuserdepart", query, `{"i_createtime":-1}`, nil, false, 0, 0)
|
|
|
+ data, _ := 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 {
|
|
@@ -951,14 +965,12 @@ func (c *Customer) SaveHistoryRule() {
|
|
|
if userid != "" {
|
|
|
//user_rules := make(map[string]interface{})
|
|
|
user_history, _ := Mgo.FindOne("historylog", map[string]interface{}{
|
|
|
- "_id":qu.StringTOBsonId(history_id),
|
|
|
+ "_id": qu.StringTOBsonId(history_id),
|
|
|
})
|
|
|
- log.Println("user_history",user_history)
|
|
|
if *user_history != nil && len(*user_history) != 0 {
|
|
|
//获取私有标签
|
|
|
usertags := getTserTag(userid)
|
|
|
- log.Println("$$$$$")
|
|
|
- if _,ok:=(*user_history)["dep_rules"];ok{
|
|
|
+ if _, ok := (*user_history)["dep_rules"]; ok {
|
|
|
dep_rules := (*user_history)["dep_rules"].([]interface{})
|
|
|
for _, m := range dep_rules {
|
|
|
if strings.Contains(rules_id, m.(map[string]interface{})["_id"].(bson.ObjectId).Hex()) {
|
|
@@ -986,13 +998,13 @@ func (c *Customer) SaveHistoryRule() {
|
|
|
set := bson.M{
|
|
|
"$set": bson.M{
|
|
|
"dep_rules": dep_rules,
|
|
|
- "tag_rules":usertags,
|
|
|
+ "tag_rules": usertags,
|
|
|
"updatetime": time.Now().Unix(),
|
|
|
},
|
|
|
}
|
|
|
isupdata := Mgo.Update("historylog", map[string]interface{}{
|
|
|
"user_id": userid,
|
|
|
- "_id":qu.StringTOBsonId(history_id),
|
|
|
+ "_id": qu.StringTOBsonId(history_id),
|
|
|
}, set, false, false)
|
|
|
if isupdata {
|
|
|
c.ServeJson(map[string]interface{}{
|
|
@@ -1005,7 +1017,7 @@ func (c *Customer) SaveHistoryRule() {
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
rules_id_list := strings.Split(rules_id, ",")
|
|
|
dep_rules := []map[string]interface{}{}
|
|
|
for _, rule := range rules_id_list {
|
|
@@ -1028,13 +1040,13 @@ func (c *Customer) SaveHistoryRule() {
|
|
|
set := bson.M{
|
|
|
"$set": bson.M{
|
|
|
"dep_rules": dep_rules,
|
|
|
- "tag_rules":usertags,
|
|
|
+ "tag_rules": usertags,
|
|
|
"updatetime": time.Now().Unix(),
|
|
|
},
|
|
|
}
|
|
|
isupdata := Mgo.Update("historylog", map[string]interface{}{
|
|
|
"user_id": userid,
|
|
|
- "_id":qu.StringTOBsonId(history_id),
|
|
|
+ "_id": qu.StringTOBsonId(history_id),
|
|
|
}, set, false, false)
|
|
|
if isupdata {
|
|
|
c.ServeJson(map[string]interface{}{
|
|
@@ -1050,8 +1062,8 @@ func (c *Customer) SaveHistoryRule() {
|
|
|
|
|
|
}
|
|
|
c.ServeJson(map[string]interface{}{
|
|
|
- "status": "fail",
|
|
|
- })
|
|
|
+ "status": "fail",
|
|
|
+ })
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1192,8 +1204,11 @@ func getTserTag(userid string) *[]map[string]interface{} {
|
|
|
func AddHistoryLog(ruleData map[string]interface{}, isUpdate bool, id string) bool {
|
|
|
history_id := qu.StringTOBsonId(ruleData["history_id"].(string))
|
|
|
hData, ok := Mgo.FindOne("historylog", bson.M{"_id": history_id})
|
|
|
- if ok && hData != nil && *hData != nil {
|
|
|
- dep_rules := qu.ObjArrToMapArr((*hData)["dep_rules"].([]interface{}))
|
|
|
+ if ok && hData != nil && *hData != nil && len(*hData) > 0 {
|
|
|
+ dep_rules := []map[string]interface{}{}
|
|
|
+ if (*hData)["dep_rules"] != nil {
|
|
|
+ dep_rules = qu.ObjArrToMapArr((*hData)["dep_rules"].([]interface{}))
|
|
|
+ }
|
|
|
ruleData["is_new"] = true
|
|
|
if isUpdate {
|
|
|
for _, v := range dep_rules {
|
|
@@ -1211,38 +1226,36 @@ func AddHistoryLog(ruleData map[string]interface{}, isUpdate bool, id string) bo
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//历史任务删除私有标签
|
|
|
-func (c *Customer)HistoryTagDel(){
|
|
|
+func (c *Customer) HistoryTagDel() {
|
|
|
defer qu.Catch()
|
|
|
userid := c.GetString("userid")
|
|
|
tagid := c.GetString("tagid")
|
|
|
- if userid!=""&&tagid!=""{
|
|
|
- user_info,_:=Mgo.FindOne("historylog",map[string]interface{}{"user_id":userid})
|
|
|
- if user_info!=nil&&len(*user_info)!=0{
|
|
|
+ if userid != "" && tagid != "" {
|
|
|
+ user_info, _ := Mgo.FindOne("historylog", map[string]interface{}{"user_id": userid})
|
|
|
+ if user_info != nil && len(*user_info) != 0 {
|
|
|
user_tag_rules := (*user_info)["tag_rules"].([]interface{})
|
|
|
- for _,m:=range user_tag_rules{
|
|
|
- if m.(map[string]interface{})["_id"].(bson.ObjectId).Hex() == tagid{
|
|
|
+ for _, m := range user_tag_rules {
|
|
|
+ if m.(map[string]interface{})["_id"].(bson.ObjectId).Hex() == tagid {
|
|
|
m.(map[string]interface{})["b_delete"] = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- is_updata :=Mgo.Update("historylog",bson.M{"user_id": userid}, bson.M{"$set": bson.M{"tag_rules": user_tag_rules}},false,false)
|
|
|
- if is_updata{
|
|
|
+ is_updata := Mgo.Update("historylog", bson.M{"user_id": userid}, bson.M{"$set": bson.M{"tag_rules": user_tag_rules}}, false, false)
|
|
|
+ if is_updata {
|
|
|
c.ServeJson(map[string]interface{}{
|
|
|
- "rep":true,
|
|
|
+ "rep": true,
|
|
|
})
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
c.ServeJson(map[string]interface{}{
|
|
|
- "rep":false,
|
|
|
+ "rep": false,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func (c *Customer)HistoryTagEdit(){
|
|
|
+func (c *Customer) HistoryTagEdit() {
|
|
|
defer qu.Catch()
|
|
|
_id := c.GetString("_id")
|
|
|
userid := c.GetString("userid")
|
|
@@ -1272,39 +1285,38 @@ func (c *Customer)HistoryTagEdit(){
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func (c *Customer)Addhistoryrule(){
|
|
|
+func (c *Customer) Addhistoryrule() {
|
|
|
defer qu.Catch()
|
|
|
if c.Method() == "POST" {
|
|
|
his_id := c.GetString("history_id")
|
|
|
- log.Println("hisid",his_id)
|
|
|
- if his_id != ""{
|
|
|
+ log.Println("hisid", his_id)
|
|
|
+ if his_id != "" {
|
|
|
//newHistory["tag_rules"] = usertags
|
|
|
set := bson.M{
|
|
|
- "$set":bson.M{
|
|
|
- "i_pushmodel":c.GetString("send_mode"),
|
|
|
- "s_customername":c.GetString("s_customername"),
|
|
|
- "s_salesperson":c.GetString("salename"),
|
|
|
- "s_name":c.GetString("s_name"),
|
|
|
- "i_pushtype":c.GetString("push_type"),
|
|
|
- "s_extends":c.GetString("expand_type"),
|
|
|
- "i_updatetime":c.GetString("i_updatetime"),
|
|
|
-
|
|
|
+ "$set": bson.M{
|
|
|
+ "i_pushmodel": c.GetString("send_mode"),
|
|
|
+ "s_customername": c.GetString("s_customername"),
|
|
|
+ "s_salesperson": c.GetString("salename"),
|
|
|
+ "s_name": c.GetString("s_name"),
|
|
|
+ "i_pushtype": c.GetString("push_type"),
|
|
|
+ "s_extends": c.GetString("expand_type"),
|
|
|
+ "i_updatetime": c.GetString("i_updatetime"),
|
|
|
},
|
|
|
}
|
|
|
- isupdata :=Mgo.UpdateById("historylog",his_id,set)
|
|
|
- if isupdata{
|
|
|
+ isupdata := Mgo.UpdateById("historylog", his_id, set)
|
|
|
+ if isupdata {
|
|
|
c.ServeJson(map[string]interface{}{
|
|
|
- "history_id":his_id,
|
|
|
- "rep":true,
|
|
|
+ "history_id": his_id,
|
|
|
+ "rep": true,
|
|
|
})
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
log.Println(666)
|
|
|
c.ServeJson(map[string]interface{}{
|
|
|
- "history_id":"",
|
|
|
- "rep":false,
|
|
|
+ "history_id": "",
|
|
|
+ "rep": false,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-}
|
|
|
+}
|