Browse Source

提交登录页面修改

fuwencai 4 years ago
parent
commit
fd8b6b2792
3 changed files with 114 additions and 137 deletions
  1. 73 131
      src/front/front.go
  2. 35 0
      src/util/cost_util.go
  3. 6 6
      src/web/templates/login.html

+ 73 - 131
src/front/front.go

@@ -1,6 +1,7 @@
 package front
 
 import (
+	"fmt"
 	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
 	"github.com/gorilla/sessions"
@@ -143,74 +144,9 @@ func (f *Front) Login() {
 			return
 
 		}
-		// 4.如果只有一个企业 则验证企业是否有使用该系统的权限
-		// 确认该企业有使用该系统的权限 查询 datatag_export_config 验证ent_id 确认是否有使用该系统的权限
-		query2 := bson.M{
-			"ent_id": (*loginUser)[0]["ent_id"],
-		}
-		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
-		}
-		// 5. 根据用户的企业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"])
-		if len(*entInfo) == 0 {
-			f.ServeJson(map[string]interface{}{
-				"code":    0,
-				"status":  false,
-				"message": "企业信息查询失败",
-			})
-			return
-		}
-		var role int // 角色  1 管理员  3 普通用户
-		// 5.1 判断当前用户手机号是否是管理员手机号
-		if phone != qu.ObjToString((*entInfo)[0]["phone"]) {
-			role = 3
-		} else {
-			role = 1
-		}
-		// 5.2 查询mongo企业信息库 获取appid
-		query := bson.M{
-			"phone":    qu.ObjToString((*entInfo)[0]["phone"]),
-			"username": qu.ObjToString((*entInfo)[0]["name"]),
-		}
-		entMgoInfo, ok := MgoCus.FindOne("user", query)
-		if !ok {
-			//	企业信息查询失败
-			f.ServeJson(map[string]interface{}{
-				"code":    0,
-				"status":  false,
-				"message": "appid查询失败",
-			})
-			return
-		}
-		// 5.3 相关信息存入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"],
-				"messageVerify": true,
-			})
-			//UserMenu[email] = GetUserMenu(qu.ObjToString((*user)["s_role"]))
-
-		}
-		f.ServeJson(map[string]interface{}{
-			"code":    0,
-			"status":  true,
-			"role":    role,
-			"message": "",
-		})
+		fmt.Println()
+		LoginCheck(f, strconv.Itoa(int((*loginUser)[0]["ent_id"].(int64))), (*loginUser)[0], phone)
+		return
 	} else {
 		f.Render("login.html")
 	}
@@ -230,20 +166,7 @@ func (f *Front) ChooseEnt() {
 	}
 	if f.Method() == "POST" {
 		entId := f.GetString("ent_id")
-		// 1. 确认该企业有使用该系统的权限 查询配置文件appid 确认是否有使用该系统的权限
-		query2 := bson.M{
-			"ent_id": entId,
-		}
-		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
-		}
+
 		// 2. 确认该手机号有数据导出权限
 		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 {
@@ -254,55 +177,8 @@ func (f *Front) ChooseEnt() {
 			})
 			return
 		}
-		// 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
-		}
-		// 4. mongo库查询与之关联的企业appid
-		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
-		}
-		// 5. 确认用户角色
-		var role int // 角色  1 管理员  3 普通用户
-		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": "",
-		})
+		LoginCheck(f, entId, (*loginUser)[0], info["phone"].(string))
+		return
 	} else { // get 请求时铺企业页面
 		// 查询 企业信息  name  ent_id
 		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"])
@@ -590,3 +466,69 @@ func SendSMS(tplcode /*模板代码*/, mobile /*手机号码*/ string, param map
 	sms.SendSms(mobile, tplcode, text)
 }
 
+func LoginCheck(f *Front, entId string, loginUser map[string]interface{}, userPhone string) {
+	// 1. 确认该企业有使用该系统的权限 查询配置文件appid 确认是否有使用该系统的权限
+	query2 := bson.M{
+		"ent_id": entId,
+	}
+	log.Println(entId)
+	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
+	}
+	// 3. 查询企业管理员信息及手机号
+	entInfo := JyMysql.SelectBySql("select phone,name from entniche_info WHERE id = ?", loginUser["ent_id"])
+	if len(*entInfo) == 0 {
+		f.ServeJson(map[string]interface{}{
+			"code":    0,
+			"status":  false,
+			"message": "企业信息查询失败",
+		})
+		return
+	}
+	// 4. mongo库查询与之关联的企业appid
+	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
+	}
+	// 5. 确认用户角色
+	var role int // 角色  1 管理员  3 普通用户
+	if userPhone != qu.ObjToString((*entInfo)[0]["phone"]) {
+		role = 3
+	} else {
+		role = 1
+	}
+
+	// 确认用户角色  存session
+	f.SetSession("user", map[string]interface{}{
+		"name":   loginUser["name"],
+		"phone":  userPhone,
+		"role":   role,
+		"appid":  (*entMgoInfo)["appid"],
+		"ent_id": entId,
+		"id":     loginUser["id"],
+	})
+	//	返回
+	f.ServeJson(map[string]interface{}{
+		"code":    0,
+		"status":  true,
+		"role":    role,
+		"message": "",
+	})
+}

+ 35 - 0
src/util/cost_util.go

@@ -60,3 +60,38 @@ func DeductNum2(entId int, newCount int, userId int, exportId int64) bool {
 	log.Println("扣费结束")
 	return flag
 }
+
+// 存导出日志
+func SaveExportLog2(entId, entUserId, count, newCount, remain_nums, export_nums int, xlsxUrl, types, filterStr string) (exportId int64) {
+	query := map[string]interface{}{
+		"id":     entUserId,
+		"ent_id": entId,
+	}
+	set := map[string]interface{}{
+		"remain_nums": remain_nums - newCount,
+		"export_nums": export_nums + newCount,
+	}
+	ok := JyMysql.Update("entniche_export_limit", map[string]interface{}{"ent_id": entId, "user_id": entUserId}, set)
+	if !ok {
+		log.Println("修改导出条数失败", query, remain_nums, newCount)
+	}
+	userData := JyMysql.FindOne("entniche_user", query, "name,phone", "")
+	if userData != nil {
+		name := util.ObjToString((*userData)["name"])
+		phone := util.ObjToString((*userData)["phone"])
+		now := time.Now()
+		exportId = JyMysql.Insert("entniche_export_log", map[string]interface{}{
+			"user_name":    name,
+			"export_time":  util.FormatDate(&now, util.Date_Full_Layout),
+			"data_source":  "1",
+			"export_num":   count,
+			"deduct_num":   newCount,
+			"download_url": xlsxUrl,
+			"ent_id":       entId,
+			"phone":        phone,
+			"user_id":      entUserId,
+			"filter":       filterStr,
+		})
+	}
+	return
+}

+ 6 - 6
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 () {