ソースを参照

同步、登录查询修改

jiaojiao7 4 年 前
コミット
e74e327b56

+ 53 - 0
src/client/client.go

@@ -24,6 +24,8 @@ type Client struct {
 	departEdit     xweb.Mapper `xweb:"/client/depart/edit"`      //保存和修改部门
 	setupDepart    xweb.Mapper `xweb:"/client/customer/setup"`   //部门列表中启用、禁用
 	cuserRuleEdit  xweb.Mapper `xweb:"/client/cuser/rule/Edit"`
+	//同步
+	synEuser xweb.Mapper `xweb:"/client/cuser/synchronous"`
 }
 
 func (this *Client) Index() {
@@ -226,3 +228,54 @@ func (c *Client) CuserRuleEdit() {
 	c.T["scopeClass"] = ScopeClassMap
 	c.Render("client/cuser_rule_edit.html", &c.T)
 }
+
+//同步
+func (c *Client) SynEuser() {
+	defer qu.Catch()
+	_id := c.GetString("_id")
+	cuser, _ := Mgo.FindById("cuser", _id, nil)
+	nowTime := time.Now().Unix()
+	(*cuser)["i_lastsynctime"] = nowTime //同步时间
+	set := bson.M{
+		"$set": bson.M{
+			"i_lastsynctime": nowTime,
+		},
+	}
+	b := Mgo.Update("cuser", bson.M{"_id": mongoutil.StringTOBsonId(_id)}, set, false, false)
+	if !b {
+		c.ServeJson(map[string]interface{}{
+			"rep": b,
+		})
+		return
+	}
+	b = Mgo.Update("euser", bson.M{"_id": mongoutil.StringTOBsonId(_id)}, cuser, true, false)
+	if !b {
+		c.ServeJson(map[string]interface{}{
+			"rep": b,
+		})
+		return
+	}
+	departMap, _ := Mgo.Find("cuserdepart", bson.M{"s_userid": _id, "b_delete": false}, nil, nil, false, -1, -1)
+	//Mgo.SaveBulk("euserdepart", *departMap...)
+	update := [][]map[string]interface{}{}
+	for _, v := range *departMap {
+		idAndSet := []map[string]interface{}{}
+		idAndSet = append(idAndSet, bson.M{"_id": v["_id"]}) //查询条件
+		idAndSet = append(idAndSet, v)                       //修改的数据
+		update = append(update, idAndSet)
+	}
+	Mgo.UpSertBulk("euserdepart", update...)
+	ruleMap, _ := Mgo.Find("cuserdepartrule", bson.M{"s_userid": _id, "b_delete": false}, nil, nil, false, -1, -1)
+	//b = Mgo.SaveBulk("euserdepartrule", *ruleMap...)
+	update2 := [][]map[string]interface{}{}
+	for _, v := range *ruleMap {
+		idAndSet := []map[string]interface{}{}
+		idAndSet = append(idAndSet, bson.M{"_id": v["_id"]}) //查询条件
+		idAndSet = append(idAndSet, v)                       //修改的数据
+		update2 = append(update2, idAndSet)
+	}
+	b = Mgo.UpSertBulk("euserdepartrule", update2...)
+	c.ServeJson(map[string]interface{}{
+		"rep": b,
+	})
+}

+ 1 - 2
src/front/front.go

@@ -44,7 +44,6 @@ type Front struct {
 	roleSave       xweb.Mapper `xweb:"/front/role/edit/save"`   //权限编辑保存
 	roleDel        xweb.Mapper `xweb:"/front/role/edit/del"`    //权限编辑删除
 	roleSecondEdit xweb.Mapper `xweb:"/front/role/second/edit"` //二级权限编辑
-
 }
 
 func (f *Front) Login() {
@@ -73,7 +72,7 @@ func (f *Front) Login() {
 			UserMenu[email] = GetUserMenu(qu.ObjToString((*user)["s_role"]))
 			if (*user)["s_role"] == "3" {
 				log.Println("users", (*user)["s_name"])
-				users, ok := Mgo.FindOne("cuser", map[string]interface{}{"s_name": (*user)["s_name"]})
+				users, ok := Mgo.FindOne("cuser", map[string]interface{}{"s_name": (*user)["s_name"], "b_delete": false})
 				log.Println("users", users)
 				if users != nil && ok {
 					s_id = mongoutil.BsonIdToSId((*users)["_id"])

+ 2 - 0
src/web/templates/client/customer_tag_rule.html

@@ -385,7 +385,9 @@
                     processData: false,// 使数据不做处理
                     success: function (r) {
                         if (r.rep) {
+                            console.log(o_list)
                             o_list = r.rdata["o_rules"]
+                            // o_list = o_list.concat(r.rdata["o_rules"])
                             $('#keywords').dataTable().fnClearTable();
                             $('#keywords').dataTable().fnAddData(o_list);
                             showTip("导入成功", 1000);

+ 22 - 0
src/web/templates/client/index.html

@@ -32,6 +32,9 @@
                                         <div class="box-header with-border">
                                             <i class="fa fa-tag"></i>
                                             <h3 class="box-title">企业客户信息</h3>
+                                            <a class="btn btn-primary btn-sm syncUpdate"
+                                               style="float: right;margin-top: 7px;margin-right: 10px"
+                                               onclick=""><span class="glyphicon glyphicon-refresh"></span> 同步</a>
                                             <a class="btn btn-primary btn-sm"
                                                style="float: right;margin-top: 7px;margin-right: 10px"
                                                onclick="saveCuser()"><i class="fa fa-fw fa-file-text fa-lg"></i>保存</a>
@@ -286,6 +289,7 @@
     $(document).ready(function () {
         if (dataMap.i_state == 0) {
             $('.tab_2').hide()
+            $('.syncUpdate').hide()
             // $('#pushDiv').hide()
         }
         tagruleArr = {{.T.tagrule}}
@@ -826,4 +830,22 @@
             }
         })
     }
+    //同步信息
+    function SynEnt(val) {
+        showConfirm("确认同步企业信息吗?", function() {
+            $.ajax({
+                url: "/client/cuser/synchronous",
+                type: "post",
+                data: {"_id": val},
+                success: function(r){
+                    if(r.rep){
+                        showTip("同步成功", 1000);
+                        ttable.ajax.reload()
+                    }else{
+                        showTip("同步失败", 1000);
+                    }
+                }
+            })
+        })
+    }
 </script>