Kaynağa Gözat

多个企业时选择企业

fuwencai 4 yıl önce
ebeveyn
işleme
da2f4197db

+ 3 - 0
src/filter/sessfilter.go

@@ -33,6 +33,9 @@ func (s *sessfilter) Do(w http.ResponseWriter, req *http.Request) bool {
 					b = false
 				}
 			}
+			if user["role"] == ""{
+				b = false
+			}
 		} else {
 			b = false
 		}

+ 127 - 13
src/front/front.go

@@ -1,7 +1,6 @@
 package front
 
 import (
-	"fmt"
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
 	"github.com/gorilla/sessions"
@@ -27,6 +26,7 @@ type Front struct {
 	login          xweb.Mapper `xweb:"/"`               //登录页面
 	code           xweb.Mapper `xweb:"/code"`           //获取图片验证码
 	sendVerifyCode xweb.Mapper `xweb:"/sendVerifyCode"` //获取手机验证码
+	chooseEnt      xweb.Mapper `xweb:"/chooseEnt"`      //选择企业
 
 	index     xweb.Mapper `xweb:"/front/index"`     //index页面
 	logout    xweb.Mapper `xweb:"/front/logout"`    //注销
@@ -123,8 +123,8 @@ func (f *Front) Login() {
 		log.Println("验证码验证通过")
 		// 3. 验证用户导出权限  确认认用户是否有数据导出权限
 		loginUser := JyMysql.SelectBySql("select id, name,ent_id,phone,export_power,name from entniche_user where phone=? and export_power=1", phone)
-		if len(*loginUser) == 0 || ((*loginUser)[0])["phone"] != phone {
-			log.Println("无权限")
+		if len(*loginUser) == 0 {
+			log.Println("该用户数据导出权限")
 			f.ServeJson(map[string]interface{}{
 				"code":    0,
 				"status":  false,
@@ -132,6 +132,19 @@ func (f *Front) Login() {
 			})
 			return
 		}
+		// 手机号 如果用户在多个企业并且都有剑鱼库里都有数据导出权限,则让用户选择企业
+		if len(*loginUser) > 1 {
+			f.SetSession("user", map[string]interface{}{
+				"phone": phone,
+			})
+			f.ServeJson(map[string]interface{}{
+				"code":    1,
+				"status":  true,
+				"message": "",
+			})
+			return
+
+		}
 		// 4. 根据用户的企业id查询对应的管理员手机号  根据管理员手机号查询jyqyfw的企业表对应的appid 放到session里  以及确认用户角色
 		log.Println((*loginUser)[0]["ent_id"], "=====================")
 		entInfo := JyMysql.SelectBySql("select phone,name from entniche_info WHERE id = ?", (*loginUser)[0]["ent_id"])
@@ -158,22 +171,27 @@ func (f *Front) Login() {
 		entMgoInfo, ok := MgoCus.FindOne("user", query)
 		if !ok {
 			//	企业信息查询失败
+			f.ServeJson(map[string]interface{}{
+				"code":    0,
+				"status":  false,
+				"message": "appid查询失败",
+			})
 			return
 		}
 		//相关信息存入session
 		if entMgoInfo != nil && len(*entMgoInfo) > 0 {
 			f.SetSession("user", map[string]interface{}{
-				"name":   (*loginUser)[0]["name"],
-				"phone":  phone,
-				"role":   role,
-				"appid":  (*entMgoInfo)["appid"],
-				"ent_id": (*loginUser)[0]["entid"],
-				"id":     (*loginUser)[0]["id"],
+				"name":          (*loginUser)[0]["name"],
+				"phone":         phone,
+				"role":          role,
+				"appid":         (*entMgoInfo)["appid"],
+				"ent_id":        (*loginUser)[0]["entid"],
+				"id":            (*loginUser)[0]["id"],
+				"messageVerify": true,
 			})
 			//UserMenu[email] = GetUserMenu(qu.ObjToString((*user)["s_role"]))
 
 		}
-		fmt.Println("role", role)
 		f.ServeJson(map[string]interface{}{
 			"code":    0,
 			"status":  true,
@@ -184,7 +202,106 @@ func (f *Front) Login() {
 		f.Render("login.html")
 	}
 }
+func (f *Front) ChooseEnt() {
+	defer qu.Catch()
+	//选择页面
+	// 根据session信息查询
+	tempSession := f.GetSession("user")
+	if tempSession == nil || tempSession == "" {
+		f.Redirect("/", 302)
+		return
+	}
+	info := tempSession.(map[string]interface{})
+	if info["phone"] == "" || info["phone"] == nil {
+		f.Redirect("/", 302)
+		return
+	}
+	if f.Method() == "GET" {
+		rs := JyMysql.SelectBySql("select a.ent_id, b.name ent_name from entniche_user a, entniche_info b WHERE a.phone =? and export_power=1 and a.ent_id=b.id", info["phone"])
+		// 企业信息  name  ent_id
+		//铺页面
+		f.T["ent_info"] = rs
+		f.Render("choose_ent.html", &f.T)
+	} else {
 
+		entId := f.GetString("ent_id")
+		log.Println(entId, "entId")
+		log.Println(info["phone"], "info[\"phone\"]")
+		//确认该手机号有数据导出权限
+		loginUser := JyMysql.SelectBySql("select id, name,ent_id,phone,export_power,name from entniche_user where phone=? and export_power=1 and ent_id=?", info["phone"], entId)
+		if len(*loginUser) == 0 {
+			f.ServeJson(map[string]interface{}{
+				"code":    0,
+				"status":  false,
+				"message": "无权限",
+			})
+			return
+		}
+
+		var role int // 角色  1 管理员  3 普通用户
+		// 判断当前用户手机号是否是管理员手机号
+		entInfo := JyMysql.SelectBySql("select phone,name from entniche_info WHERE id = ?", (*loginUser)[0]["ent_id"])
+		if len(*entInfo) == 0 {
+			f.ServeJson(map[string]interface{}{
+				"code":    0,
+				"status":  false,
+				"message": "企业信息查询失败",
+			})
+			return
+		}
+		query := bson.M{
+			"phone":    (*entInfo)[0]["phone"],
+			"username": (*entInfo)[0]["name"],
+		}
+		entMgoInfo, ok := MgoCus.FindOne("user", query)
+		if !ok {
+			//	企业信息查询失败
+			f.ServeJson(map[string]interface{}{
+				"code":    0,
+				"status":  false,
+				"message": "appid查询失败",
+			})
+			return
+		}
+		// 确认该企业有使用该系统的权限 查询配置文件appid 确认是否有使用该系统的权限
+		query2 := bson.M{
+			"app_id": (*entMgoInfo)["appid"],
+		}
+		isExist, _ := Mgo.FindOne("datatag_export_config", query2)
+		log.Println(isExist)
+		if len((*isExist)) == 0 {
+			f.ServeJson(map[string]interface{}{
+				"code":    0,
+				"status":  false,
+				"message": "该企业无权限",
+			})
+			return
+		}
+		if info["phone"] != qu.ObjToString((*entInfo)[0]["phone"]) {
+			role = 3
+		} else {
+			role = 1
+		}
+
+		// 确认用户角色  存session
+		f.SetSession("user", map[string]interface{}{
+			"name":   (*loginUser)[0]["name"],
+			"phone":  info["phone"],
+			"role":   role,
+			"appid":  (*entMgoInfo)["appid"],
+			"ent_id": (*loginUser)[0]["entid"],
+			"id":     (*loginUser)[0]["id"],
+		})
+		//	返回
+		f.ServeJson(map[string]interface{}{
+			"code":    0,
+			"status":  true,
+			"role":    role,
+			"message": "",
+		})
+	}
+
+}
 func (f *Front) Index() {
 	defer qu.Catch()
 	f.Render("index.html")
@@ -387,8 +504,6 @@ func (f *Front) SendVerifyCode() {
 			})
 			return
 		}
-		fmt.Println("code", code)
-		fmt.Println("img", imgCode)
 		if !captcha.VerifyString(code, imgCode) {
 			log.Printf("图片验证码错误-%s \n", phone)
 			f.ServeJson(map[string]interface{}{
@@ -400,7 +515,6 @@ func (f *Front) SendVerifyCode() {
 		}
 		//3. 验证手机号是否存在
 		user := JyMysql.SelectBySql("select * from entniche_user where phone=? and export_power=1", phone)
-		fmt.Println(user, "-----------------================")
 		// 确认用户是否存在
 		if len(*user) == 0 || ((*user)[0])["phone"] != phone {
 			log.Println("没有数据导出权限")

+ 68 - 0
src/web/templates/choose_ent.html

@@ -0,0 +1,68 @@
+{{include "com/inc.html"}}
+<!-- Main Header -->
+{{include "com/header.html"}}
+
+
+<!-- Content Wrapper. Contains page content -->
+<div class="content-wrapper">
+    <!-- Main content -->
+    <section class="content">
+    </section>
+
+    <div class="modal " tabindex="-1" role="dialog" id="myModal" aria-hidden="true" data-backdrop="static">
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h4 class="modal-title">您加入了多个企业,请先选择企业</h4>
+                </div>
+                <div class="modal-body" id="radioBody">
+                    <p></p>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-primary" id="submitChoose">确认</button>
+                </div>
+            </div><!-- /.modal-content -->
+        </div><!-- /.modal-dialog -->
+    </div><!-- /.modal -->
+</div>
+
+
+<script>
+    var entInfo = {{.T.ent_info}}
+    <!--   页面加载时-->
+    $(document).ready(function () {
+        for (let i = 0; i < entInfo.length; i++) {
+            $("#radioBody").append('<div class="radio" style="margin-top: 10px">\
+            <label><input type="radio" name="optionsRadios" id=' + entInfo[i]["ent_id"] + " value=" + entInfo[i]["ent_id"] + '>' + entInfo[i]["ent_name"] + ' </label></div>')
+        }
+        $('#myModal').modal();
+    });
+    // 提交选择信息
+    $("#submitChoose").click(function () {
+        // 获取选择信息
+        let entId = $("input[name='optionsRadios']:checked").val();
+        // 提交
+        $.ajax({
+                url: "/chooseEnt",
+                data: {"ent_id": entId},
+                method: "post",
+                success: function (r) {
+                    // 结果 判断
+                    if (r.status) {
+                        if (r.role === 1) {
+                            window.location.href = "/admin/index";
+                        } else if (r.role === 3) {
+                            window.location.href = "/personnel/index";
+                        } else {
+                            alert("身份信息无效")
+                        }
+                    } else {
+                        alert(r.message)
+                    }
+                }
+            }
+        )
+    })
+</script>
+<!-- footer -->
+{{include "com/footer.html"}}

+ 15 - 9
src/web/templates/login.html

@@ -80,12 +80,12 @@
 <script src="/plugins/iCheck/icheck.min.js"></script>
 <script>
     <!--   页面加载时加载cookie-->
-    $(document).ready(function () {
-        v = getCookieValue("SecondNum");//获取cookie值
-        if (v > 0) {
-            countDown();//开始倒计时
-        }
-    });
+    // $(document).ready(function () {
+    //     v = getCookieValue("SecondNum");//获取cookie值
+    //     if (v > 0) {
+    //         countDown();//开始倒计时
+    //     }
+    // });
 
     // 获取图片验证码
     $("#verifyImg").click(function () {
@@ -151,10 +151,16 @@
                 if (r.status === false) {
                     alert(r.message)
                 } else {
+                    if (r.code==1){
+                        window.location.href = "/chooseEnt";
+                        return
+                    }
                     if (r.role === 1) {
-                        window.location.href = "/front/index";
-                    } else {
-                        window.location.href = "/client/index";
+                        window.location.href = "/admin/index";
+                    } else if(r.role===3){
+                        window.location.href = "/personnel/index";
+                    }else {
+                        alert("身份信息无效")
                     }
                 }
             }