wcj 5 жил өмнө
parent
commit
5bd2657f98

+ 14 - 1
entbase/src/config.json

@@ -18,6 +18,19 @@
 		"maxOpenConns":2,
 		"maxIdleConns":2
     },
-    "userInEntLimit":9999,
+    "mail": [
+        {
+            "addr": "smtp.exmail.qq.com",
+            "port": 465,
+            "pwd": "ue9Rg9Sf4CVtdm5a",
+            "user": "public03@topnet.net.cn"
+        },
+        {
+            "addr": "smtp.exmail.qq.com",
+            "port": 465,
+            "pwd": "ue9Rg9Sf4CVtdm5a",
+            "user": "public03@topnet.net.cn"
+        }
+    ],
     "associationLimit":5
 }

+ 16 - 7
entbase/src/config/config.go

@@ -2,6 +2,7 @@ package config
 
 import (
 	qutil "qfw/util"
+	"qfw/util/mail"
 )
 
 type config struct {
@@ -24,13 +25,11 @@ type config struct {
 		MaxOpenConns int
 		MaxIdleConns int
 	}
-	PushMysql struct {
-		DbName       string
-		Address      string
-		UserName     string
-		PassWord     string
-		MaxOpenConns int
-		MaxIdleConns int
+	Mail []struct {
+		Addr string
+		Port int
+		Pwd  string
+		User string
 	}
 	UserInEntLimit   int64
 	AssociationLimit int
@@ -41,9 +40,19 @@ type timeTaskConfig struct {
 
 var Config *config
 var TimeTaskConfig *timeTaskConfig
+var GmailAuth []*mail.GmailAuth
 
 func init() {
 	//程序配置文件
 	qutil.ReadConfig(&Config)
 	qutil.ReadConfig("./timetask.json", &TimeTaskConfig)
+	for _, v := range Config.Mail {
+		mail := &mail.GmailAuth{
+			SmtpHost: v.Addr,
+			SmtpPort: v.Port,
+			User:     v.User,
+			Pwd:      v.Pwd,
+		}
+		GmailAuth = append(GmailAuth, mail)
+	}
 }

+ 1 - 0
entbase/src/filter/sessionfilter.go

@@ -21,6 +21,7 @@ type sessionfilter struct {
 //继承过滤器方法
 func (l *sessionfilter) Do(w http.ResponseWriter, req *http.Request) bool {
 	session := l.App.SessionManager.Session(req, w)
+	session.Set("userId", "5e6ce95ce138233ecffea93f")
 	if session.Get("userId") == nil {
 		R.ServeJson(w, req, &Result{Error_code_1001, Error_msg_1001, nil})
 		return false

+ 1 - 0
entbase/src/main.go

@@ -11,6 +11,7 @@ import (
 	"qfw/util/mysql"
 	"qfw/util/redis"
 	_ "service"
+	_ "service_external"
 	"timetask"
 
 	"github.com/go-xweb/xweb"

+ 2 - 2
entbase/src/service/department/department.go

@@ -20,7 +20,7 @@ type Action struct {
 	update    xweb.Mapper `xweb:"/department/update"`    //修改
 	persons   xweb.Mapper `xweb:"/department/persons"`   //设置部门管理员,选择员工列表
 	childrens xweb.Mapper `xweb:"/department/childrens"` //子部门
-	setadmin  xweb.Mapper `xweb:"/department/setadmin"`  //设置部门管理员
+	setAdmin  xweb.Mapper `xweb:"/department/setadmin"`  //设置部门管理员
 }
 
 //新增
@@ -183,7 +183,7 @@ func (a *Action) Childrens() {
 }
 
 //设置部门管理员
-func (a *Action) Setadmin() {
+func (a *Action) SetAdmin() {
 	if !R.CheckReqParam(a.ResponseWriter, a.Request, "did", "aid") {
 		return
 	}

+ 16 - 45
entbase/src/service/ent/ent.go

@@ -14,44 +14,32 @@ import (
 
 type Action struct {
 	*xweb.Action
-	myents      xweb.Mapper `xweb:"/ent/myents"`      //当前登录用户的所在的企业
-	entinfo     xweb.Mapper `xweb:"/ent/entinfo"`     //企业信息
-	selectent   xweb.Mapper `xweb:"/ent/selectent"`   //选择企业
+	myEnts      xweb.Mapper `xweb:"/ent/myents"`      //当前登录用户的所在的企业
+	entInfo     xweb.Mapper `xweb:"/ent/entinfo"`     //企业信息
+	selectEnt   xweb.Mapper `xweb:"/ent/selectent"`   //选择企业
 	framework   xweb.Mapper `xweb:"/ent/framework"`   //进入企业架构
 	association xweb.Mapper `xweb:"/ent/association"` //联想
-	isexists    xweb.Mapper `xweb:"/ent/isexists"`    //企业是否存在
+	isExists    xweb.Mapper `xweb:"/ent/isexists"`    //企业是否存在
 	//
-	mail          xweb.Mapper `xweb:"/ent/set/mail"`          //设置企业邮箱
 	industryclass xweb.Mapper `xweb:"/ent/set/industryclass"` //设置企业所属行业
 }
 
 //当前登录用户的所在的企业
-func (a *Action) Myents() {
+func (a *Action) MyEnts() {
 	userId, _ := a.GetSession("userId").(string)
-	entId := qutil.IntAll(a.GetSession("selectEntId"))
+	entId := qutil.IntAll(a.GetSession("entId"))
 	phone := VarCurrentUser.Phone(userId)
 	if phone == "" {
 		R.NoPermissionReq(a.ResponseWriter, a.Request, "手机号不存在")
 		return
 	}
-	data := M{
+	a.ServeJson(Result{Data: M{
 		"ents": VarEntInfo.MyEnts(phone, entId, true),
-	}
-	user, ok := MQFW.FindById("user", userId, `{"i_vip_status":1,"l_vip_starttime":1,"l_vip_endtime":1,"o_vipjy":1}`)
-	if ok && user != nil && qutil.IntAll((*user)["i_vip_status"]) > 0 {
-		o_vipjy, _ := (*user)["o_vipjy"].(map[string]interface{})
-		data["vip"] = M{
-			"area":       o_vipjy["o_area"],
-			"buyerclass": o_vipjy["a_buyerclass"],
-			"startdate":  (*user)["l_vip_starttime"],
-			"enddate":    (*user)["l_vip_endtime"],
-		}
-	}
-	a.ServeJson(Result{Data: data})
+	}})
 }
 
 //企业信息
-func (a *Action) Entinfo() {
+func (a *Action) EntInfo() {
 	userId, _ := a.GetSession("userId").(string)
 	entName, _ := a.GetSession("entName").(string)
 	entId := qutil.IntAll(a.GetSession("entId"))
@@ -71,17 +59,18 @@ func (a *Action) Entinfo() {
 		m["mail"] = entInfo.Ent.Mail
 		m["industryclass"] = entInfo.Ent.Industryclass
 		m["quota"] = entInfo.Ent.Quota
+		m["ent_auth_status"] = entInfo.Ent.Auth_status
+		m["ent_auth_reason"] = entInfo.Ent.Auth_reason
 		m["power_checked"] = Mysql.Count(Entniche_user, map[string]interface{}{"ent_id": entId, "power": 1})
 	}
 	a.ServeJson(Result{Data: m})
 }
 
 //切换所在的企业
-func (a *Action) Selectent() {
+func (a *Action) SelectEnt() {
 	if !R.CheckReqParam(a.ResponseWriter, a.Request, "id") {
 		return
 	}
-	a.SetSession("prevSelectEntId", a.GetSession("selectEntId"))
 	if a.GetString("id") == "0" {
 		ClearSess(a.Session())
 	} else {
@@ -91,7 +80,7 @@ func (a *Action) Selectent() {
 			R.NoPermissionReq(a.ResponseWriter, a.Request)
 			return
 		}
-		SetSess(a.Session(), true, ent["id"], ent["name"], ent["user_id"])
+		SetSess(a.Session(), ent["id"], ent["name"], ent["user_id"])
 	}
 	a.ServeJson(Result{Data: M{"status": 1}})
 }
@@ -107,7 +96,7 @@ func (a *Action) Framework() {
 		R.NoPermissionReq(a.ResponseWriter, a.Request)
 		return
 	}
-	SetSess(a.Session(), false, ent["id"], ent["name"], ent["user_id"])
+	SetSess(a.Session(), ent["id"], ent["name"], ent["user_id"])
 	a.ServeJson(Result{Data: M{"status": 1}})
 }
 
@@ -120,7 +109,7 @@ func (a *Action) Association() {
 }
 
 //企业是否存在
-func (a *Action) Isexists() {
+func (a *Action) IsExists() {
 	if !R.CheckReqParam(a.ResponseWriter, a.Request, "name") {
 		return
 	}
@@ -136,18 +125,6 @@ func (a *Action) Isexists() {
 	a.ServeJson(Result{Data: m})
 }
 
-//设置企业邮箱
-func (a *Action) Mail() {
-	if !R.CheckReqParam(a.ResponseWriter, a.Request, "mail") {
-		return
-	}
-	status := 0
-	if Mysql.UpdateOrDeleteBySql(`update entniche_info set mail=? where id=?`, a.GetString("mail"), qutil.IntAll(a.GetSession("entId"))) > -1 {
-		status = 1
-	}
-	a.ServeJson(Result{Data: M{"status": status}})
-}
-
 //设置企业所属行业
 func (a *Action) Industryclass() {
 	if !R.CheckReqParam(a.ResponseWriter, a.Request, "industryclass") {
@@ -161,18 +138,12 @@ func (a *Action) Industryclass() {
 }
 
 /****************************************************/
-func SetSess(sess *httpsession.Session, isSelect bool, entId, entName, entUserId interface{}) {
-	if isSelect {
-		sess.Set("selectEntId", entId)
-		sess.Set("selectEntName", entName)
-	}
+func SetSess(sess *httpsession.Session, entId, entName, entUserId interface{}) {
 	sess.Set("entId", entId)
 	sess.Set("entName", entName)
 	sess.Set("entUserId", entUserId)
 }
 func ClearSess(sess *httpsession.Session) {
-	sess.Del("selectEntId")
-	sess.Del("selectEntName")
 	sess.Del("entId")
 	sess.Del("entName")
 	sess.Del("entUserId")

+ 3 - 0
entbase/src/service/init.go

@@ -4,6 +4,7 @@ import (
 	"service/department"
 	"service/ent"
 	"service/framework"
+	"service/mail"
 	"service/person"
 	"service/phone"
 	"service/power"
@@ -18,4 +19,6 @@ func init() {
 	xweb.AddAction(&phone.Action{})
 	xweb.AddAction(&power.Action{})
 	xweb.AddAction(&framework.Action{})
+	xweb.AddAction(&mail.Action{})
+	xweb.AddAction(&Action{})
 }

+ 60 - 0
entbase/src/service/mail/mail.go

@@ -0,0 +1,60 @@
+//购买
+package mail
+
+import (
+	. "api"
+	. "config"
+	. "ent/entity"
+	. "ent/util"
+	qutil "qfw/util"
+
+	"github.com/dchest/captcha"
+	"github.com/go-xweb/xweb"
+)
+
+type Action struct {
+	*xweb.Action
+	bind          xweb.Mapper `xweb:"/mail/bind"`          //邮箱绑定
+	sendIdentCode xweb.Mapper `xweb:"/mail/sendidentcode"` //发送邮箱验证码
+	replace       xweb.Mapper `xweb:"/mail/replace"`       //更换邮箱
+}
+
+//绑定企业邮箱
+func (a *Action) Bind() {
+	if !R.CheckReqParam(a.ResponseWriter, a.Request, "code") {
+		return
+	}
+	status := 0
+	mail := CheckMailIdent(a.Session(), a.GetString("code"))
+	if mail == "" { //验证码不正确
+		status = -1
+	} else {
+		userId, _ := a.GetSession("userId").(string)
+		entId := qutil.IntAll(a.GetSession("entId"))
+		if VarEntInfo.GetById(entId).Mail != "" {
+			R.NoPermissionReq(a.ResponseWriter, a.Request, "该企业已经绑定过邮箱")
+			return
+		}
+		//查询是否绑定过微信号
+		if VarEntInfo.BindMail(userId, mail, entId) {
+			status = 1 //绑定成功
+		} else {
+			status = 0 //已经绑定过
+		}
+	}
+	a.ServeJson(Result{Data: M{"status": status, "mail": mail}})
+}
+
+//发送邮箱验证码
+func (a *Action) SendIdentCode() {
+	if !R.CheckReqParam(a.ResponseWriter, a.Request, "mail", "code") {
+		return
+	}
+	status := 0
+	if tmp := a.GetSession("checkCodeId"); tmp == nil || !captcha.VerifyString(tmp.(string), a.GetString("code")) {
+		status = -1
+	} else if mail := a.GetString("mail"); MailReg.MatchString(mail) && SendMailIdentCode(mail, GmailAuth, a.Session()) {
+		status = 1
+	}
+	a.ServeJson(Result{Data: M{"status": status}})
+}

+ 0 - 11
entbase/src/service/person/person.go

@@ -20,7 +20,6 @@ type Action struct {
 	move    xweb.Mapper `xweb:"/person/move"`    //移动
 	detail  xweb.Mapper `xweb:"/person/detail"`  //详情
 	update  xweb.Mapper `xweb:"/person/update"`  //修改
-	isquota xweb.Mapper `xweb:"/person/isquota"` //人数是否达到限额
 }
 
 //人员管理
@@ -216,13 +215,3 @@ func (a *Action) Update() {
 	}
 	a.ServeJson(Result{Data: M{"status": status}})
 }
-
-//人数是否达到限额
-func (a *Action) Isquota() {
-	status := 0
-	entId := qutil.IntAll(a.GetSession("entId"))
-	if VarEntInfo.IsQuota(entId) {
-		status = 1
-	}
-	a.ServeJson(Result{Data: M{"status": status}})
-}

+ 32 - 7
entbase/src/service/phone/phone.go

@@ -1,17 +1,21 @@
-//人员手机号绑定、更换
+//手机号绑定、更换
 package phone
 
 import (
 	. "api"
 	. "ent/entity"
 	. "ent/util"
+	"fmt"
+	"qfw/util"
 	"qfw/util/jy"
 
+	"github.com/dchest/captcha"
 	"github.com/go-xweb/xweb"
 )
 
 type Action struct {
 	*xweb.Action
+	bound         xweb.Mapper `xweb:"/phone/bound"`         //已绑定的手机号
 	bind          xweb.Mapper `xweb:"/phone/bind"`          //手机号绑定
 	sendIdentCode xweb.Mapper `xweb:"/phone/sendidentcode"` //发短信
 }
@@ -22,6 +26,7 @@ func (a *Action) Bind() {
 		return
 	}
 	status := 0
+	myents := []M{}
 	phone := jy.CheckPhoneIdent(a.Session(), a.GetString("code"))
 	if phone == "" { //验证码不正确
 		status = -1
@@ -32,14 +37,23 @@ func (a *Action) Bind() {
 			return
 		}
 		//查询是否绑定过微信号
-		if BindPhone(userId, phone) {
-			go jy.AutoMerge(MQFW, a.Session())
+		if VarCurrentUser.BindPhone(userId, phone) {
 			status = 1 //绑定成功
+			mylist := Mysql.SelectBySql(`SELECT id,name from entniche_info 
+				where phone=? and status=0 order by convert(name using gbk) COLLATE gbk_chinese_ci asc`, phone)
+			if mylist != nil {
+				for _, v := range *mylist {
+					myents = append(myents, M{
+						"name": v["name"],
+						"id":   util.SE.Encode2HexByCheck(fmt.Sprint(v["id"])),
+					})
+				}
+			}
 		} else {
 			status = 0 //已经绑定过
 		}
 	}
-	a.ServeJson(Result{Data: M{"status": status, "phone": phone}})
+	a.ServeJson(Result{Data: M{"status": status, "phone": phone, "myents": myents}})
 }
 
 //发短信
@@ -49,9 +63,20 @@ func (a *Action) SendIdentCode() {
 	}
 	status := 0
 	token := a.GetString("token")
-	phone := jy.CheckSendMsg(token)
-	if PhoneReg.MatchString(phone) && jy.SendPhoneIdentCode(phone, a.Session()) {
-		status = 1
+	if PhoneReg.MatchString(token) {
+		if !R.CheckReqParam(a.ResponseWriter, a.Request, "code") {
+			return
+		}
+		if tmp := a.GetSession("checkCodeId"); tmp == nil || !captcha.VerifyString(tmp.(string), a.GetString("code")) {
+			status = -1
+		} else if jy.SendPhoneIdentCode(token, a.Session()) {
+			status = 1
+		}
+	} else {
+		token = jy.CheckSendMsg(token)
+		if PhoneReg.MatchString(token) && jy.SendPhoneIdentCode(token, a.Session()) {
+			status = 1
+		}
 	}
 	a.ServeJson(Result{Data: M{"status": status}})
 }

+ 26 - 0
entbase/src/service/service.go

@@ -0,0 +1,26 @@
+//对内的接口
+package service
+
+import (
+	"github.com/dchest/captcha"
+	"github.com/go-xweb/xweb"
+)
+
+type Action struct {
+	*xweb.Action
+	captcha xweb.Mapper `xweb:"/captcha"` //生成验证码图片
+}
+
+func (a *Action) Captcha() error {
+	id := captcha.NewLen(4) //此id为生成验证码的ID,并不是实际显示的数字,在提交校验时,需要根据此ID进行查询。
+	a.SetSession("checkCodeId", id)
+	//校验时调用以下代码
+	//ccid,_:=a.GetSession("CheckCodeId").(string)
+	//captcha.VerifyString(ccid,"用户输入的校验码")//返回bool
+	w := a.ResponseWriter
+	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+	w.Header().Set("Pragma", "no-cache")
+	w.Header().Set("Expires", "0")
+	w.Header().Set("Content-Type", "image/png")
+	return captcha.WriteImage(w, id, 90, 30)
+}

+ 48 - 0
entbase/src/service_external/czfczj/czfczj.go

@@ -0,0 +1,48 @@
+//财政扶持资金接口
+package czfczj
+
+import (
+	. "api"
+	. "ent/entity"
+	. "ent/util"
+	"fmt"
+	"qfw/util"
+	. "service_external/util"
+
+	"github.com/go-xweb/xweb"
+)
+
+type Action struct {
+	*xweb.Action
+	firstuse xweb.Mapper `xweb:"/czfczj/firstuse"` //首次使用
+	authents xweb.Mapper `xweb:"/czfczj/authents"` //已认证过的企业
+}
+
+//首次使用
+func (a *Action) Firstuse() {
+	userId := CheckUserId(a.Action)
+	bindphone, entauth := 0, 0
+	phone := VarCurrentUser.Phone(userId)
+	if phone != "" {
+		bindphone = 1
+		if Mysql.CountBySql(`select count(1) as count from entniche_info where phone=? and auth_status=1`, phone) > 0 {
+			entauth = 1
+		}
+	}
+	a.ServeJson(Result{Data: M{"bindphone": bindphone, "entauth": entauth}})
+}
+
+//已认证过的企业
+func (a *Action) Authents() {
+	ents := []M{}
+	list := Mysql.Find(Entniche_info, map[string]interface{}{"auth_status": 1}, "id,name", "auth_time desc", 0, -1)
+	if list != nil {
+		for _, v := range *list {
+			ents = append(ents, M{
+				"id":   util.SE.Encode2HexByCheck(fmt.Sprint(v["id"])),
+				"name": v["name"],
+			})
+		}
+	}
+	a.ServeJson(Result{Data: M{"ents": ents}})
+}

+ 12 - 0
entbase/src/service_external/init.go

@@ -0,0 +1,12 @@
+//对外的接口
+package service_external
+
+import (
+	"service_external/czfczj"
+
+	"github.com/go-xweb/xweb"
+)
+
+func init() {
+	xweb.AddAction(&czfczj.Action{})
+}

+ 22 - 0
entbase/src/service_external/util/util.go

@@ -0,0 +1,22 @@
+//对外的接口
+package util
+
+import (
+	. "api"
+	qutil "qfw/util"
+
+	"github.com/go-xweb/xweb"
+)
+
+//校验userId
+func CheckUserId(a *xweb.Action) string {
+	if R.CheckReqParam(a.ResponseWriter, a.Request, "userId") {
+		return ""
+	}
+	userId := qutil.SE.Decode4HexByCheck(a.GetString("userId"))
+	if userId == "" {
+		R.InvalidReqParam(a.ResponseWriter, a.Request, "userId")
+		return ""
+	}
+	return userId
+}

+ 0 - 8
entniche/src/config/config.go

@@ -24,14 +24,6 @@ type config struct {
 		MaxOpenConns int
 		MaxIdleConns int
 	}
-	PushMysql struct {
-		DbName       string
-		Address      string
-		UserName     string
-		PassWord     string
-		MaxOpenConns int
-		MaxIdleConns int
-	}
 	UserInEntLimit   int64
 	AssociationLimit int
 }

+ 1 - 6
entniche/src/service/person/person.go

@@ -219,10 +219,5 @@ func (a *Action) Update() {
 
 //人数是否达到限额
 func (a *Action) Isquota() {
-	status := 0
-	entId := qutil.IntAll(a.GetSession("entId"))
-	if VarEntInfo.IsQuota(entId) {
-		status = 1
-	}
-	a.ServeJson(Result{Data: M{"status": status}})
+	a.ServeJson(Result{Data: M{"status": 0}})
 }

+ 1 - 1
entniche/src/service/phone/phone.go

@@ -32,7 +32,7 @@ func (a *Action) Bind() {
 			return
 		}
 		//查询是否绑定过微信号
-		if BindPhone(userId, phone) {
+		if VarCurrentUser.BindPhone(userId, phone) {
 			go jy.AutoMerge(MQFW, a.Session())
 			status = 1 //绑定成功
 		} else {

+ 0 - 8
nicheinsight/src/config/config.go

@@ -29,14 +29,6 @@ type config struct {
 		MaxOpenConns int
 		MaxIdleConns int
 	}
-	PushMysql struct {
-		DbName       string
-		Address      string
-		UserName     string
-		PassWord     string
-		MaxOpenConns int
-		MaxIdleConns int
-	}
 	UserInEntLimit   int64
 	QyhxSearchPool   int
 	AssociationLimit int

+ 1 - 6
nicheinsight/src/service/person/person.go

@@ -210,10 +210,5 @@ func (a *Action) Update() {
 
 //人数是否达到限额
 func (a *Action) Isquota() {
-	status := 0
-	entId := qutil.IntAll(a.GetSession("entId"))
-	if VarEntInfo.IsQuota(entId) {
-		status = 1
-	}
-	a.ServeJson(Result{Data: M{"status": status}})
+	a.ServeJson(Result{Data: M{"status": 0}})
 }

+ 1 - 1
nicheinsight/src/service/phone/phone.go

@@ -41,7 +41,7 @@ func (a *Action) Bind() {
 			return
 		}
 		//查询是否绑定过微信号
-		if BindPhone(userId, phone) {
+		if VarCurrentUser.BindPhone(userId, phone) {
 			go jy.AutoMerge(MQFW, a.Session())
 			status = 1 //绑定成功
 			//查询有没有所属的企业

+ 25 - 12
public/src/ent/entity/entinfo.go

@@ -73,15 +73,6 @@ func (e *EntInfo) GetUsersExcludeAdmin(entId int) *[]*User {
 	return users
 }
 
-//人员是否达到限额
-func (e *EntInfo) IsQuota(entId int) bool {
-	/*count := Mysql.CountBySql(`SELECT count(1) from entniche_user where ent_id=?`, entId)
-	if int(count) >= e.GetById(entId).Quota {
-		return true
-	}*/
-	return false
-}
-
 //根据id和手机号获取员工最新的一个企业
 func (e *EntInfo) GetMyLastEnt(phone string) *EntInfo {
 	r := Mysql.SelectBySql(`SELECT a.id,a.name,b.id as user_id from entniche_info a 
@@ -105,7 +96,7 @@ func (e *EntInfo) UserInEntLimit(phone string, limit int64) bool {
 //我的企业
 func (e *EntInfo) MyEnts(phone string, entId int, onlyBuy bool) []M {
 	ents := []M{}
-	sql := `SELECT a.id,a.name,a.phone,a.startdate,a.enddate,c.id as dept_id from entniche_info a 
+	sql := `SELECT a.id,a.name,a.phone,a.startdate,a.enddate,a.auth_status,c.id as dept_id from entniche_info a 
 			INNER JOIN entniche_user b on (`
 	if onlyBuy {
 		sql += `a.status<>0 and IF(a.phone<>b.phone,b.power=1,1=1) and `
@@ -128,6 +119,7 @@ func (e *EntInfo) MyEnts(phone string, entId int, onlyBuy bool) []M {
 				"enddate":      v["enddate"],
 				"admin_system": admin_system,
 				"checked":      entId == util.IntAll(v["id"]),
+				"auth_status":  util.IntAll(v["auth_status"]),
 			})
 		}
 	}
@@ -189,7 +181,7 @@ func (e *EntInfo) GetSelectEnt(encodeId, userId string, onlyBuy bool) map[string
 }
 
 //是否是管理员
-func (d *EntInfo) IsAdmin(userId int) bool {
+func (e *EntInfo) IsAdmin(userId int) bool {
 	return Mysql.CountBySql(`select count(1) as count from entniche_user_role where user_id=? and role_id=?`, userId, Role_admin_system) == 1
 }
 
@@ -197,7 +189,7 @@ func (d *EntInfo) IsAdmin(userId int) bool {
  *创建企业
  *name phone createtime 字段不能为空
  */
-func (d *EntInfo) Add(entinfo *EntInfo) bool {
+func (e *EntInfo) Add(entinfo *EntInfo) bool {
 	m := map[string]interface{}{
 		"status":      entinfo.Status,
 		"auth_status": entinfo.Auth_status,
@@ -303,3 +295,24 @@ func (d *EntInfo) Add(entinfo *EntInfo) bool {
 		return entinfo.Id > 0 && ok_2 > -1 && ok_3 > -1 && deptId > 0 && entinfo.User_id > 0 && deptUser > -1 && userRole > -1
 	})
 }
+
+//绑定邮箱
+func (e *EntInfo) BindMail(userId, mail string, entId int) bool {
+	user, ok := MQFW.FindById("user", userId, `{"i_appid":1}`)
+	if !ok || user == nil {
+		return false
+	}
+	if (*user)["i_appid"] == nil {
+		if MQFW.Count("user", map[string]interface{}{
+			"i_appid": map[string]interface{}{
+				"$exists": 0,
+			},
+			"s_m_mail": mail,
+		}) > 0 {
+			return false //已经绑定过
+		}
+	} else {
+		return false
+	}
+	return Mysql.UpdateOrDeleteBySql(`update entniche_info set mail=? where id=?`, mail, entId) > -1
+}

+ 48 - 5
public/src/ent/entity/entity.go

@@ -39,10 +39,10 @@ func (c *CurrentUser) EntInfo(userId string, entId int) *CurrentUser {
 		return currentUser
 	}
 	currentUser.Ent = VarEntInfo.GetById(entId)
-	if currentUser.Ent.Phone == phone {
+	if Mysql.CountBySql(`SELECT count(1) as count from entniche_user a LEFT JOIN entniche_user_role b on (a.id=b.user_id) where a.phone=? and a.ent_id=? and b.role_id=?`, phone, entId, Role_admin_system) > 0 {
 		currentUser.Role_admin_system = true
-		r := Mysql.SelectBySql(`SELECT id,name,subdis,nodiff from entniche_department where ent_id=? and pid=0`, entId)
-		if r != nil && len(*r) > 0 {
+		r := Mysql.SelectBySql(`SELECT id,name,subdis,nodiff from entniche_department where ent_id=? and pid=0 limit 1`, entId)
+		if r != nil && len(*r) == 1 {
 			department := JsonUnmarshal((*r)[0], &Department{}).(*Department)
 			if department != nil {
 				department.Pid = department.Id
@@ -56,8 +56,8 @@ func (c *CurrentUser) EntInfo(userId string, entId int) *CurrentUser {
 			LEFT JOIN entniche_department_user c on (a.id=c.user_id) 
 			LEFT JOIN entniche_department d on (d.ent_id=? and c.dept_id=d.id) 
 			LEFT JOIN entniche_department e on (e.ent_id=? and e.pid=0) 
-			where a.ent_id=? and a.phone=? order by a.id desc`, entId, entId, entId, phone)
-		if r != nil && len(*r) > 0 {
+			where a.ent_id=? and a.phone=? order by a.id desc limit 1`, entId, entId, entId, phone)
+		if r != nil && len(*r) == 1 {
 			role_id := qutil.IntAll((*r)[0]["role_id"])
 			if role_id == Role_admin_department {
 				currentUser.Role_admin_department = true
@@ -71,3 +71,46 @@ func (c *CurrentUser) EntInfo(userId string, entId int) *CurrentUser {
 	}
 	return currentUser
 }
+
+//绑定手机号
+func (c *CurrentUser) BindPhone(userId, phone string) bool {
+	user, ok := MQFW.FindById("user", userId, `{"i_appid":1}`)
+	if !ok || user == nil {
+		return false
+	}
+	if (*user)["i_appid"] == nil {
+		if MQFW.Count("user", map[string]interface{}{
+			"i_appid": map[string]interface{}{
+				"$exists": 0,
+			},
+			"s_m_phone": phone,
+		}) > 0 {
+			return false //已经绑定过
+		}
+	} else if qutil.IntAll((*user)["i_appid"]) == 2 {
+		//查询是否绑定过微信号
+		if MQFW.Count("user", map[string]interface{}{"i_appid": 2, "s_m_phone": phone}) > 0 {
+			return false //已经绑定过
+			//i_appid:2,i_type:{$ne:1},"$or":[{s_m_openid:{$exists:1}},{a_m_openid:{$exists:1}}]
+		} else if MQFW.Count("user", map[string]interface{}{
+			"i_appid": 2,
+			"s_phone": phone,
+			"i_type":  map[string]interface{}{"$ne": 1},
+			"$or": []map[string]interface{}{
+				map[string]interface{}{
+					"s_m_openid": map[string]interface{}{"$exists": 1},
+				},
+				map[string]interface{}{
+					"a_m_openid": map[string]interface{}{"$exists": 1},
+				},
+			},
+		}) > 0 {
+			return false //已经绑定过
+		}
+	} else {
+		return false
+	}
+	return MQFW.UpdateById("user", userId, map[string]interface{}{
+		"$set": map[string]interface{}{"s_m_phone": phone},
+	})
+}

+ 61 - 23
public/src/ent/util/util.go

@@ -2,13 +2,20 @@ package util
 
 import (
 	"encoding/json"
+	"fmt"
+	"log"
 	qutil "qfw/util"
+	"qfw/util/mail"
 	"regexp"
 	"strconv"
 	"strings"
+	"time"
+
+	"github.com/go-xweb/httpsession"
 )
 
 var PhoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
+var MailReg = regexp.MustCompile("^.+@.+$")
 
 //map转结构体
 func JsonUnmarshal(m interface{}, s interface{}) interface{} {
@@ -52,28 +59,59 @@ func DecodeEntId(encodeId string) int {
 	return id
 }
 
-func BindPhone(userId, phone string) bool {
-	//查询是否绑定过微信号
-	if MQFW.Count("user", map[string]interface{}{"i_appid": 2, "s_m_phone": phone}) > 0 {
-		return false //已经绑定过
-		//i_appid:2,i_type:{$ne:1},"$or":[{s_m_openid:{$exists:1}},{a_m_openid:{$exists:1}}]
-	} else if MQFW.Count("user", map[string]interface{}{
-		"i_appid": 2,
-		"s_phone": phone,
-		"i_type":  map[string]interface{}{"$ne": 1},
-		"$or": []map[string]interface{}{
-			map[string]interface{}{
-				"s_m_openid": map[string]interface{}{"$exists": 1},
-			},
-			map[string]interface{}{
-				"a_m_openid": map[string]interface{}{"$exists": 1},
-			},
-		},
-	}) > 0 {
-		return false //已经绑定过
-	} else {
-		return MQFW.UpdateById("user", userId, map[string]interface{}{
-			"$set": map[string]interface{}{"s_m_phone": phone},
-		})
+//发送邮箱验证码
+func SendMailIdentCode(to string, auth []*mail.GmailAuth, session *httpsession.Session) bool {
+	code := strings.ToUpper(qutil.GetComplexRandom(6, 3, 3))
+	lastSentTime := qutil.Int64All(session.Get("identCodeTime"))
+	//60秒之内不允许重复发
+	if lastSentTime > 0 && time.Now().Unix()-lastSentTime <= 60 {
+		return false
+	}
+	session.Set("mailIdentCodeValue", code)
+	session.Set("mailIdentCodeKey", to)
+	session.Set("mailIdentCodeTime", time.Now().Unix())
+	html := fmt.Sprintf(`<div>
+		<div>
+			%s,您好!
+		</div>
+		<div style="padding: 20px 70px 10px 70px;">
+			<p>您正在进行绑定邮箱地址验证,请在邮件验证码输入框输入下方验证码:</p>
+			<span style="font-weight: bold;font-size: x-large;">%s</span>
+			<p>请勿向任何人泄露您收到的验证码。</p>
+			<p>此为系统邮件,请勿回复。</p>
+		</div>
+	</div>`, to, code)
+
+	for k, v := range auth {
+		if mail.GSendMail("邮箱校验", to, "", "", "", html, "", "", v) {
+			log.Println(to, fmt.Sprintf("使用%s发送邮件成功", v.User))
+			return true
+		}
+		if k < len(auth)-1 {
+			log.Println(to, fmt.Sprintf("使用%s发送邮件失败!3s后使用其他邮箱尝试", v.User))
+		} else {
+			log.Println(to, fmt.Sprintf("使用%s发送邮件失败!", v.User))
+		}
+		time.Sleep(time.Second * 3)
 	}
+
+	return false
+}
+
+//短信验证码校验
+func CheckMailIdent(session *httpsession.Session, code string) string {
+	identCodeValue, _ := session.Get("identCodeValue").(string)
+	if identCodeValue != "" && identCodeValue == code {
+		identCodeKey, _ := session.Get("identCodeKey").(string)
+		ClearMailIdentSession(session)
+		return identCodeKey
+	}
+	return ""
+}
+
+//删除短信验证码有关的session
+func ClearMailIdentSession(session *httpsession.Session) {
+	session.Del("mailIdentCodeValue")
+	session.Del("mailIdentCodeKey")
+	session.Del("mailIdentCodeTime")
 }