Browse Source

no message

Jianghan 5 năm trước cách đây
mục cha
commit
a9e046e0ee
2 tập tin đã thay đổi với 34 bổ sung41 xóa
  1. 16 27
      src/service/repair_rule.go
  2. 18 14
      src/web/templates/repair/jianyu_edit.html

+ 16 - 27
src/service/repair_rule.go

@@ -233,6 +233,7 @@ func (jy *RepairRule) RepairDelete() {
 
 //修改-mongo -es
 func (jy *RepairRule) RepairSave() {
+	defer qu.Catch()
 	if jy.Method() == "POST" {
 		request_data := GetPostForm(jy.Request)
 		updata := qu.ObjToMap(request_data["data"])
@@ -241,12 +242,12 @@ func (jy *RepairRule) RepairSave() {
 		old_data, _ := JYMgo.FindById(coll, id, "") //记录当前表的源数据
 		delete(*old_data, "_id")
 		reasons := qu.ObjToString(request_data["reasons"])
-		contenthtml := qu.ObjToString(request_data["contenthtml"])
-		detail := qu.ObjToString(request_data["detail"])
-		summary := qu.ObjToString(request_data["summary"])
+		//contenthtml := qu.ObjToString(request_data["contenthtml"])
+		//detail := qu.ObjToString(request_data["detail"])
+		//summary := qu.ObjToString(request_data["summary"])
 		modifyinfo := qu.ObjToMap(request_data["modifyinfo"])
-		(*updata)["contenthtml"] = contenthtml
-		(*updata)["detail"] = detailClear(detail)
+		//(*updata)["contenthtml"] = contenthtml
+		//(*updata)["detail"] = detailClear(detail)
 		//变更字段
 		if (*updata)["modifyinfo"] != nil {
 			tmpinfo := (*updata)["modifyinfo"].(map[string]interface{})
@@ -259,13 +260,6 @@ func (jy *RepairRule) RepairSave() {
 		}
 
 		//处理个别字段
-		if val, ok := (*updata)["comeintime"]; ok {
-			(*updata)["comeintime"] = qu.Int64All(val)
-		} else {
-			curtime := time.Now().Unix()
-			(*updata)["comeintime"] = curtime
-		}
-
 		if val, ok := (*updata)["publishtime"]; ok {
 			(*updata)["publishtime"] = qu.Int64All(val)
 		} else {
@@ -287,12 +281,7 @@ func (jy *RepairRule) RepairSave() {
 		delete(*updata, "_id")
 
 		var set map[string]interface{}
-		if summary != "" {
-			(*updata)["summary"] = summary
-			set = bson.M {
-				"$set": *updata,
-			}
-		}else {
+		if (*modifyinfo)["summary"] == nil {
 			delete(*updata, "summary")
 			set = bson.M {
 				"$set": *updata,
@@ -300,9 +289,15 @@ func (jy *RepairRule) RepairSave() {
 					"summary": "",
 				},
 			}
+		}else {
+			set = bson.M {
+				"$set": *updata,
+			}
 		}
-
-		rep := JYMgo.Update(coll, query, set, false, false)
+		for v, k := range *updata{
+			qu.Debug(v, k)
+		}
+		rep := JYMgo.Update(coll, query, set, true, false)
 		qu.Debug("mgo id:" + id + "------", rep)
 		if !rep {
 			jy.ServeJson(map[string]interface{}{
@@ -449,7 +444,7 @@ func (jy *RepairRule) SearchJyurl() {
 
 func detailClear(detail string) string {
 	cut := NewCut()
-	new_s := cut.ClearHtml(string(detail))
+	new_s := cut.ClearHtml(detail)
 	return new_s
 }
 
@@ -580,12 +575,6 @@ func ModifyData(tmp map[string]interface{}, user map[string]interface{}) (err ma
 	}else {
 		new_data["modifyinfo"] = modifyinfo
 	}
-	if val, ok := new_data["comeintime"]; ok {
-		new_data["comeintime"] = qu.Int64All(val)
-	} else {
-		curtime := time.Now().Unix()
-		new_data["comeintime"] = curtime
-	}
 
 	if val, ok := new_data["publishtime"]; ok {
 		new_data["publishtime"] = qu.Int64All(val)

+ 18 - 14
src/web/templates/repair/jianyu_edit.html

@@ -124,58 +124,62 @@
             return;
         }
 
+        var modifyinfo = {}
         var updata = {}
+        updata["_id"] = data["_id"]
         // 删除、修改
         for (let editDataKey in edit_data) {
             if (typeof edit_data[editDataKey] == "object") {
                 if (JSON.stringify(data[editDataKey]) != JSON.stringify(edit_data[editDataKey])) {
-                    updata[editDataKey] = true
+                    modifyinfo[editDataKey] = true
+                    updata[editDataKey] = data[editDataKey]
                 }
             }else {
                 if (data[editDataKey] != edit_data[editDataKey]) {
-                    updata[editDataKey] = true
+                    modifyinfo[editDataKey] = true
+                    updata[editDataKey] = data[editDataKey]
                 }
             }
         }
         //新增
         for (let dataKey in data) {
             if (edit_data[dataKey] == undefined) {
-                updata[dataKey] = true
+                modifyinfo[dataKey] = true
+                updata[dataKey] = data[dataKey]
             }
         }
         if (edit_detail != tmp_detail) {
-            updata["detail"] = true
+            modifyinfo["detail"] = true
+            updata["detail"] = tmp_detail
         }
         if (edit_contentHtml != tmp_content) {
-            updata["contenthtml"] = true
+            modifyinfo["contenthtml"] = true
+            updata["contenthtml"] = tmp_content
         }
         var tmp_summary = $('#summary').val();
         if (edit_summary != tmp_summary) {
-            updata["summary"] = true
+            modifyinfo["summary"] = true
+            updata["summary"] = tmp_summary
         }
 
         var str = ""
-        console.log(Object.keys(updata).length)
         if (Object.keys(updata).length == 0) {
             str = "没有修改任何字段信息!"
             showTip(str)
             return
         }else {
             str = "确定修改以下字段信息?" + "<br>"
-            for (const updataKey in updata) {
-                str = str + updataKey + ","
+            for (const modifyinfoKey in modifyinfo) {
+                str = str + modifyinfoKey + ","
             }
         }
         showConfirm(str, function() {
             $.ajax({
                 url: "/service/jianyu/save",
                 type: 'POST',
-                data: {"data": JSON.stringify(data),
-                    "modifyinfo": JSON.stringify(updata),
+                data: {"data": JSON.stringify(updata),
+                    "modifyinfo": JSON.stringify(modifyinfo),
                     "coll": edit_coll,
-                    "contenthtml": tmp_content,
-                    "detail": tmp_detail,
-                    "summary": tmp_summary,
                     "reasons": reason,
                 },
                 success: function (task) {