|
@@ -108,7 +108,7 @@ func (f *Front) Code() {
|
|
|
|
|
|
func (f *Front) Logout() {
|
|
|
f.DelSession("user")
|
|
|
- f.Redirect("/")
|
|
|
+ _ = f.Redirect("/")
|
|
|
}
|
|
|
|
|
|
func (f *Front) UserGroup() {
|
|
@@ -165,13 +165,15 @@ func (f *Front) UserGroupNew() {
|
|
|
m1["i_updatetime"] = currenttime
|
|
|
m1["i_state"] = true
|
|
|
m1["b_delete"] = false
|
|
|
+ m1["check_size"] = qu.IntAll(user["u1_size"])
|
|
|
+ m1["user_size"] = qu.IntAll(user["u2_size"])
|
|
|
Mgo.Save("s_user", m1)
|
|
|
// 2、质检员账号
|
|
|
for i := 0; i < qu.IntAll(user["u1_size"]); i++ {
|
|
|
m := make(map[string]interface{})
|
|
|
m["s_groupid"] = gid
|
|
|
m["s_name"] = ""
|
|
|
- m["s_login"] = qu.ObjToString(group["s_name"]) + "_zj_" + strconv.Itoa(i)
|
|
|
+ m["s_login"] = qu.ObjToString(group["s_name"]) + "_zj_" + strconv.Itoa(i+1)
|
|
|
m["s_password"] = qu.SE.EncodeString(qu.ObjToString(user["u1_pwd"]))
|
|
|
m["i_role"] = "3"
|
|
|
m["s_phone"] = ""
|
|
@@ -186,7 +188,7 @@ func (f *Front) UserGroupNew() {
|
|
|
m := make(map[string]interface{})
|
|
|
m["s_groupid"] = gid
|
|
|
m["s_name"] = ""
|
|
|
- m["s_login"] = qu.ObjToString(group["s_name"]) + "_" + strconv.Itoa(i)
|
|
|
+ m["s_login"] = qu.ObjToString(group["s_name"]) + "_" + strconv.Itoa(i+1)
|
|
|
m["s_password"] = qu.SE.EncodeString(qu.ObjToString(user["u2_pwd"]))
|
|
|
m["i_role"] = "4"
|
|
|
m["s_phone"] = ""
|
|
@@ -210,6 +212,21 @@ func (f *Front) UserGroupNew() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (f *Front) GroupModify() {
|
|
|
+ defer qu.Catch()
|
|
|
+ if f.Method() == "POST" {
|
|
|
+ data := GetPostForm(f.Request)
|
|
|
+ id := qu.ObjToString(data["id"])
|
|
|
+ delete(data, "id")
|
|
|
+ qu.Debug(data, id)
|
|
|
+ data["i_updatetime"] = time.Now().Unix()
|
|
|
+ b := Mgo.UpdateById("s_group", id, map[string]interface{}{"$set": data})
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "rep": b,
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *Front) UserGroupState() {
|
|
|
defer qu.Catch()
|
|
|
if f.Method() == "POST" {
|
|
@@ -228,7 +245,28 @@ func (f *Front) UserGroupStateBulk() {
|
|
|
qu.Debug(data)
|
|
|
ids := strings.Split(qu.ObjToString(data["ids"]), ",")
|
|
|
for _, k := range ids {
|
|
|
- b := Mgo.UpdateById("s_group", k, map[string]interface{}{"$set": map[string]interface{}{"i_state": data["state"]}})
|
|
|
+ m := map[string]interface{}{"i_state": data["state"], "i_updatetime": time.Now().Unix()}
|
|
|
+ b := Mgo.UpdateById("s_group", k, map[string]interface{}{"$set": m})
|
|
|
+ if !b {
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "rep": b,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "rep": true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func (f *Front) UserStateBulk() {
|
|
|
+ defer qu.Catch()
|
|
|
+ if f.Method() == "POST" {
|
|
|
+ data := GetPostForm(f.Request)
|
|
|
+ ids := strings.Split(qu.ObjToString(data["ids"]), ",")
|
|
|
+ for _, k := range ids {
|
|
|
+ m := map[string]interface{}{"i_state": data["state"], "i_updatetime": time.Now().Unix()}
|
|
|
+ b := Mgo.UpdateById("s_user", k, map[string]interface{}{"$set": m})
|
|
|
if !b {
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"rep": b,
|
|
@@ -246,7 +284,8 @@ func (f *Front) UserGroupDel() {
|
|
|
if f.Method() == "POST" {
|
|
|
data := GetPostForm(f.Request)
|
|
|
qu.Debug(data)
|
|
|
- b := Mgo.UpdateById("s_group", qu.ObjToString(data["id"]), map[string]interface{}{"$set": map[string]interface{}{"b_delete": true}})
|
|
|
+ m := map[string]interface{}{"b_delete": true, "i_updatetime": time.Now().Unix()}
|
|
|
+ b := Mgo.UpdateById("s_group", qu.ObjToString(data["id"]), map[string]interface{}{"$set": m})
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"rep": b,
|
|
|
})
|
|
@@ -285,7 +324,8 @@ func (f *Front) UserState() {
|
|
|
defer qu.Catch()
|
|
|
if f.Method() == "POST" {
|
|
|
data := GetPostForm(f.Request)
|
|
|
- b := Mgo.UpdateById("s_user", qu.ObjToString(data["id"]), map[string]interface{}{"$set": map[string]interface{}{"i_state": data["state"]}})
|
|
|
+ m := map[string]interface{}{"i_state": data["state"], "i_updatetime": time.Now().Unix()}
|
|
|
+ b := Mgo.UpdateById("s_user", qu.ObjToString(data["id"]), map[string]interface{}{"$set": m})
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"rep": b,
|
|
|
})
|
|
@@ -294,6 +334,7 @@ func (f *Front) UserState() {
|
|
|
|
|
|
func (f *Front) UserAll() {
|
|
|
defer qu.Catch()
|
|
|
+ gid := f.GetString("gid")
|
|
|
if f.Method() == "POST" {
|
|
|
start, _ := f.GetInteger("start")
|
|
|
limit, _ := f.GetInteger("length")
|
|
@@ -304,9 +345,10 @@ func (f *Front) UserAll() {
|
|
|
"b_delete": false,
|
|
|
}
|
|
|
user := f.GetSession("user").(map[string]interface{})
|
|
|
- gid := qu.ObjToString(user["s_groupid"])
|
|
|
- if user["i_role"] == "0" || user["i_role"] == "1" {
|
|
|
-
|
|
|
+ if gid == "" {
|
|
|
+ if user["i_role"] != "0" && user["i_role"] != "1" {
|
|
|
+ query["s_groupid"] = qu.ObjToString(user["s_groupid"])
|
|
|
+ }
|
|
|
} else {
|
|
|
query["s_groupid"] = gid
|
|
|
}
|
|
@@ -316,7 +358,7 @@ func (f *Front) UserAll() {
|
|
|
bson.M{"s_login": bson.M{"$regex": search}},
|
|
|
}
|
|
|
}
|
|
|
- data, _ := Mgo.Find("s_user", query, `{"i_createtime":-1}`, nil, false, start, limit)
|
|
|
+ data, _ := Mgo.Find("s_user", query, `{"i_updatetime":-1}`, nil, false, start, limit)
|
|
|
count := Mgo.Count("s_user", query)
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"draw": draw,
|
|
@@ -325,7 +367,8 @@ func (f *Front) UserAll() {
|
|
|
"recordsTotal": count,
|
|
|
})
|
|
|
} else {
|
|
|
- _ = f.Render("user/user_list.html")
|
|
|
+ f.T["gid"] = gid
|
|
|
+ _ = f.Render("user/user_list.html", &f.T)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -333,7 +376,8 @@ func (f *Front) UserDel() {
|
|
|
defer qu.Catch()
|
|
|
if f.Method() == "POST" {
|
|
|
data := GetPostForm(f.Request)
|
|
|
- b := Mgo.UpdateById("s_user", qu.ObjToString(data["id"]), map[string]interface{}{"$set": map[string]interface{}{"b_delete": true}})
|
|
|
+ m := map[string]interface{}{"b_delete": true, "i_updatetime": time.Now().Unix()}
|
|
|
+ b := Mgo.UpdateById("s_user", qu.ObjToString(data["id"]), map[string]interface{}{"$set": m})
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"rep": b,
|
|
|
})
|
|
@@ -344,13 +388,72 @@ func (f *Front) UserModify() {
|
|
|
defer qu.Catch()
|
|
|
if f.Method() == "POST" {
|
|
|
data := GetPostForm(f.Request)
|
|
|
- b := Mgo.UpdateById("s_user", qu.ObjToString(data["id"]), map[string]interface{}{"$set": map[string]interface{}{"s_name": data["s_name"], "s_phone": data["s_phone"]}})
|
|
|
+ id := qu.ObjToString(data["id"])
|
|
|
+ delete(data, "id")
|
|
|
+ data["i_updatetime"] = time.Now().Unix()
|
|
|
+ b := Mgo.UpdateById("s_user", id, map[string]interface{}{"$set": map[string]interface{}{"s_name": data["s_name"], "s_phone": data["s_phone"]}})
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"rep": b,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func (f *Front) UserNew() {
|
|
|
+ defer qu.Catch()
|
|
|
+ if f.Method() == "POST" {
|
|
|
+ user := f.GetSession("user").(map[string]interface{})
|
|
|
+ role := qu.ObjToString(user["i_role"])
|
|
|
+ gid := qu.ObjToString(user["s_groupid"])
|
|
|
+ currenttime := time.Now().Unix()
|
|
|
+ newUser := make(map[string]interface{})
|
|
|
+ var login, pwd = "", ""
|
|
|
+ if role == "0" || role == "1" {
|
|
|
+ newUser["i_role"] = "1"
|
|
|
+ login = f.GetString("login")
|
|
|
+ pwd = f.GetString("pwd")
|
|
|
+ } else {
|
|
|
+ irole := f.GetString("i_role")
|
|
|
+ info, _ := Mgo.FindById("s_group", gid, map[string]interface{}{"check_size": 1, "user_size": 1, "s_name": 1})
|
|
|
+ if len(*info) > 0 {
|
|
|
+ newUser["i_role"] = irole
|
|
|
+ if irole == "3" {
|
|
|
+ i := qu.IntAll((*info)["check_size"])
|
|
|
+ i++
|
|
|
+ login = qu.ObjToString((*info)["s_name"]) + "_zj_" + strconv.Itoa(i)
|
|
|
+ Mgo.UpdateById("s_group", gid, map[string]interface{}{"$set": map[string]interface{}{"check_size": i}})
|
|
|
+ } else if irole == "4" {
|
|
|
+ i := qu.IntAll((*info)["user_size"])
|
|
|
+ i++
|
|
|
+ login = qu.ObjToString((*info)["s_name"]) + "_" + strconv.Itoa(i)
|
|
|
+ Mgo.UpdateById("s_group", gid, map[string]interface{}{"$set": map[string]interface{}{"user_size": i}})
|
|
|
+ }
|
|
|
+ pwd = Password
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newUser["s_name"] = f.GetString("name")
|
|
|
+ newUser["s_phone"] = f.GetString("phone")
|
|
|
+ newUser["s_groupid"] = gid
|
|
|
+ newUser["s_login"] = login
|
|
|
+ newUser["s_password"] = qu.SE.EncodeString(pwd)
|
|
|
+ newUser["i_createtime"] = currenttime
|
|
|
+ newUser["i_updatetime"] = currenttime
|
|
|
+ newUser["i_state"] = true
|
|
|
+ newUser["b_delete"] = false
|
|
|
+ id := Mgo.Save("s_user", newUser)
|
|
|
+ if id != "" {
|
|
|
+ qu.Debug(id)
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "rep": true,
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "rep": false,
|
|
|
+ "msg": "新增保存失败",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func (f *Front) GroupList() {
|
|
|
qu.Catch()
|
|
|
query := map[string]interface{}{"b_delete": false, "i_state": true}
|
|
@@ -371,7 +474,7 @@ func (f *Front) UserList() {
|
|
|
gid := qu.ObjToString(user["s_groupid"])
|
|
|
query := map[string]interface{}{"s_groupid": gid, "b_delete": false, "i_state": true, "i_role": "4"}
|
|
|
field := map[string]interface{}{"s_login": 1, "s_groupid": 1, "s_name": 1}
|
|
|
- info, b := Mgo.Find("s_user", query, nil, field, false, -1, -1)
|
|
|
+ info, b := Mgo.Find("s_user", query, `{"_id": -1}`, field, false, -1, -1)
|
|
|
if b && len(*info) > 0 {
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"rep": b,
|