zouyuxuan 5 سال پیش
والد
کامیت
398b1039ae
3فایلهای تغییر یافته به همراه142 افزوده شده و 101 حذف شده
  1. 109 94
      src/service/customer_service.go
  2. 1 1
      src/web/templates/private/customer_edit_euser.html
  3. 32 6
      src/web/templates/private/customer_history.html

+ 109 - 94
src/service/customer_service.go

@@ -59,7 +59,8 @@ type Customer struct {
 	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/del"` //历史任务修改私有标签
+	historyTagEdit 		 xweb.Mapper `xweb:"/service/tag/history/edit"` //历史任务修改私有标签
+	addhistoryrule 		 xweb.Mapper `xweb:"/service/rule/history/add"` //新增历史任务
 
 }
 
@@ -867,6 +868,12 @@ func (c *Customer) CustomerHistory() {
 		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
+	}
 	c.T["data"] = *data
 	c.T["depart"] = *depart
 	c.Render("private/customer_history.html", &c.T)
@@ -875,13 +882,14 @@ func (c *Customer) CustomerHistory() {
 //选择历史规则
 func (c *Customer) CustomerAllRule() {
 	customerId := c.GetString("c_id")
-	log.Println("cid",customerId)
+	history_id := c.GetString("hid")
 	query := bson.M{
 		"s_userid": customerId,
 		"b_delete": false,
 	}
 	inc_query := bson.M{
 		"user_id": customerId,
+		"_id":qu.StringTOBsonId(history_id),
 	}
 	//获取新增历史规则
 	inc_rules := []map[string]interface{}{}
@@ -938,22 +946,69 @@ func (c *Customer) CustomerAllRule() {
 //保存历史规则
 func (c *Customer) SaveHistoryRule() {
 	rules_id := c.GetString("rulesid")
-	//rules_id := c.GetSlice("rulesid")
+	history_id := c.GetString("hid")
 	userid := c.GetString("userid")
 	if userid != "" {
-		user_rules := make(map[string]interface{})
+		//user_rules := make(map[string]interface{})
 		user_history, _ := Mgo.FindOne("historylog", map[string]interface{}{
-			"user_id": userid,
+			"_id":qu.StringTOBsonId(history_id),
 		})
+		log.Println("user_history",user_history)
 		if *user_history != nil && len(*user_history) != 0 {
-			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()) {
-					continue
+			//获取私有标签
+			usertags := getTserTag(userid)
+			log.Println("$$$$$")
+			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()) {
+						continue
+					}
+					rules_id_list := strings.Split(rules_id, ",")
+					for _, rule := range rules_id_list {
+						//dep_rule := make(map[string]interface{})
+						query := bson.M{
+							"_id":      bson.ObjectIdHex(rule),
+							"b_delete": false,
+						}
+						res, _ := Mgo.FindOne("euserdepartrule", query)
+						if res != nil && len(*res) != 0 {
+							//获取规则所属部门信息
+							department_info, _ := Mgo.FindOne("euserdepart", map[string]interface{}{
+								"_id":      bson.ObjectIdHex((*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 := Mgo.Update("historylog", map[string]interface{}{
+						"user_id": userid,
+						"_id":qu.StringTOBsonId(history_id),
+					}, set, false, false)
+					if isupdata {
+						c.ServeJson(map[string]interface{}{
+							"status": "success",
+						})
+					} else {
+						c.ServeJson(map[string]interface{}{
+							"status": "fail",
+						})
+					}
+					return
 				}
+			}else{
 				rules_id_list := strings.Split(rules_id, ",")
+				dep_rules := []map[string]interface{}{}
 				for _, rule := range rules_id_list {
-					//dep_rule := make(map[string]interface{})
 					query := bson.M{
 						"_id":      bson.ObjectIdHex(rule),
 						"b_delete": false,
@@ -973,11 +1028,13 @@ func (c *Customer) SaveHistoryRule() {
 				set := bson.M{
 					"$set": bson.M{
 						"dep_rules":  dep_rules,
+						"tag_rules":usertags,
 						"updatetime": time.Now().Unix(),
 					},
 				}
 				isupdata := Mgo.Update("historylog", map[string]interface{}{
 					"user_id": userid,
+					"_id":qu.StringTOBsonId(history_id),
 				}, set, false, false)
 				if isupdata {
 					c.ServeJson(map[string]interface{}{
@@ -988,93 +1045,14 @@ func (c *Customer) SaveHistoryRule() {
 						"status": "fail",
 					})
 				}
-			}
-		} else {
-			//获取私有标签
-			usertags := getTserTag(userid)
-			user_rules["tag_rules"] = usertags
-			userinfo, _ := Mgo.FindOne("euer", map[string]interface{}{
-				"s_userid": userid,
-			})
-			if userinfo != nil && len(*userinfo) != 0 {
-				user_rules["s_name"] = (*userinfo)["s_customername"]
-				user_rules["s_appid"] = (*userinfo)["s_appid"]
-			}
-			//获取用户规则
-			if rules_id != "" {
-				dep_rules := []interface{}{}
-				rules_id_list := strings.Split(rules_id, ",")
-				for _, rule := range rules_id_list {
-					//dep_rule := make(map[string]interface{})
-					query := bson.M{
-						"_id":      bson.ObjectIdHex(rule),
-						"b_delete": false,
-					}
-					res, _ := Mgo.FindOne("cuserdepartrule", query)
-					if res != nil && len(*res) != 0 {
-						//获取规则所属部门信息
-						department_info, _ := Mgo.FindOne("cuserdepart", map[string]interface{}{
-							"_id":      bson.ObjectIdHex((*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)
-					}
-				}
-				user_rules["dep_rules"] = dep_rules
-				user_rules["user_id"] = userid
-				user_rules["createtime"] = time.Now().Unix()
-				user_rules["state"] = 0
-
-				userinfo, _ := Mgo.FindOne("euer", map[string]interface{}{
-					"s_userid": userid,
-				})
-				if userinfo != nil && len(*userinfo) != 0 {
-					log.Println("s_name", user_rules["s_name"])
-					user_rules["s_name"] = (*userinfo)["s_customername"]
-					user_rules["s_appid"] = (*userinfo)["s_appid"]
-				}
-			}
-			//获取用户规则
-			if rules_id != "" {
-				dep_rules := []interface{}{}
-				for _, rule := range strings.Split(rules_id, ",") {
-					//dep_rule := make(map[string]interface{})
-					query := bson.M{
-						"_id":      bson.ObjectIdHex(rule),
-						"b_delete": false,
-					}
-					res, _ := Mgo.FindOne("cuserdepartrule", query)
-					if res != nil && len(*res) != 0 {
-						//获取规则所属部门信息
-						department_info, _ := Mgo.FindOne("cuserdepart", map[string]interface{}{
-							"_id":      bson.ObjectIdHex((*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)
-					}
-				}
-				//获取私有标签
-				usertags := getTserTag(userid)
-				user_rules["dep_rules"] = dep_rules
-				user_rules["tag_rules"] = usertags
-				user_rules["createtime"] = time.Now().Unix()
-			}
-			issave := Mgo.Save("historylog", user_rules)
-			if issave != "" {
-				c.ServeJson(map[string]interface{}{
-					"status": "success",
-				})
-			} else {
-				c.ServeJson(map[string]interface{}{
-					"status": "fail",
-				})
+				return
 			}
 
 		}
+		c.ServeJson(map[string]interface{}{
+				"status": "fail",
+			})
+
 	}
 
 }
@@ -1292,4 +1270,41 @@ func (c *Customer)HistoryTagEdit(){
 		"id":  cid,
 		"rep": rep,
 	})
+}
+
+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 != ""{
+			//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"),
+
+				},
+			}
+			isupdata :=Mgo.UpdateById("historylog",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,
+				})
+			}
+		}
+
+	}
 }

+ 1 - 1
src/web/templates/private/customer_edit_euser.html

@@ -70,7 +70,7 @@
                                                     <select class="form-control selectpicker" id="pushModelSelect" disabled>
                                                         <option value=0>全局模式</option>
                                                         <option value=1>部门模式</option>
-                                                        <option value=2>便签模式</option>
+                                                        <option value=2>签模式</option>
                                                         <option value=3>部门+标签模式</option>
                                                         <option value=4>规则模式(不去重)</option>
                                                     </select>

+ 32 - 6
src/web/templates/private/customer_history.html

@@ -63,7 +63,7 @@
                                                     <select class="form-control selectpicker" id="pushModelSelect">
                                                         <option value=0>全局模式</option>
                                                         <option value=1>部门模式</option>
-                                                        <option value=3>部门+标签模式</option>
+                                                        <option value=2>标签模式</option>
                                                         <option value=4>规则模式(不去重)</option>
                                                     </select>
                                                 </div>
@@ -199,7 +199,7 @@
     var dataMap = {{.T.data}}
     var tagruleArr = []
     var ruleArr = []
-
+    var history_id = {{.T.history_id}}
     var selectIndex = [];               //选中的编号
 
     $(document).ready(function () {
@@ -363,9 +363,34 @@
             }
         })
     }
-
     function showDepart() {
-        window.location.href="/service/cuser/rule/history/edit?id="+c_id
+        console.log("history_id",history_id)
+        if (history_id != ""){
+            var send_mode = document.getElementById("pushModelSelect").selectedIndex;
+            var push_type = document.getElementById("pushTypeSelect").selectedIndex;
+            var expand_type = document.getElementById("expandSelect").selectedIndex;
+            var s_name = dataMap.s_name
+            var salename = dataMap.s_salesperson
+            var s_customername = dataMap.s_customername
+            var i_updatetime = dataMap.i_updatetime
+
+            $.ajax({
+                url: "/service/rule/history/add",
+                type: 'POST',
+                data: {"send_mode":send_mode,"push_type":push_type,"expand_type":expand_type,"s_name":s_name,"salename":salename,"s_customername":s_customername,"i_updatetime":i_updatetime,"history_id":history_id,"c_id":c_id},
+                success: function (r) {
+                    if (r.rep) {
+                        history_id = r.history_id
+                        // window.location.replace("/service/cuser/rule/history/edit?hid="+history_id+"&id="+c_id)
+                    } else {
+                        showTip("保存失败", 500);
+                    }
+                }
+            })
+        }else{
+            window.location.replace("/service/cuser/rule/history/edit?hid="+history_id+"&id="+c_id)
+        }
+
     }
     function setupTag(val, bol) {
         var msg = ""
@@ -450,12 +475,13 @@
         })
     }
     var c_id = getParam("id")
+    var hid = getParam("hid")
     function select_Depart() {
         //获取用户自定义规则
         $.ajax({
            url:"/service/customer/history/allrule",
            type:"POST",
-           data:{"c_id":c_id},
+           data:{"c_id":c_id,"history_id":hid},
            success:function (r) {
                 if (r.status=="success"){
                     var html = ""
@@ -580,7 +606,7 @@
         $.ajax({
             url:"/service/customer/history/saverule",
             type:"POST",
-            data:{'rulesid':rules_id.join(','),'userid':c_id,},
+            data:{'rulesid':rules_id.join(','),'userid':c_id,"hid":history_id},
             traditional:true,
             success:function (r) {
                 if (r.status == "success"){