Преглед изворни кода

Merge branch 'dev1.2' of http://192.168.3.207:10080/jianyu/ent into dev1.2

wangshan пре 5 година
родитељ
комит
1e2a9e5f4c

+ 20 - 0
entbase/src/service/ent/ent.go

@@ -23,6 +23,7 @@ type Action struct {
 	isExists    xweb.Mapper `xweb:"/ent/isexists"`    //企业是否存在
 	dissolution xweb.Mapper `xweb:"/ent/dissolution"` //解散企业
 	signout     xweb.Mapper `xweb:"/ent/signout"`     //退出企业
+	add         xweb.Mapper `xweb:"/ent/add"`         //新增企业
 	//
 	industryclass xweb.Mapper `xweb:"/ent/set/industryclass"` //设置企业所属行业
 }
@@ -183,6 +184,25 @@ func (a *Action) Signout() {
 	}})
 }
 
+//新增企业
+func (a *Action) Add() {
+	if !R.CheckReqParam(a.ResponseWriter, a.Request, "name") {
+		return
+	}
+	name := a.GetString("name")
+	userId, _ := a.GetSession("userId").(string)
+	phone, _ := VarCurrentUser.Phone(userId)
+	status := 0
+	if Mysql.Count(Entniche_info, map[string]interface{}{"phone": phone, "name": name}) > 0 {
+		status = -1
+	} else if VarEntInfo.Add(&EntInfo{Name: name, Phone: phone, Createtime: qutil.NowFormat(qutil.Date_Full_Layout)}) {
+		status = 1
+	}
+	a.ServeJson(Result{Data: M{
+		"status": status,
+	}})
+}
+
 /****************************************************/
 func SetSess(sess *httpsession.Session, entId, entName, entUserId interface{}) {
 	sess.Set("entId", entId)

+ 1 - 1
entniche/src/config/config.go

@@ -36,7 +36,7 @@ type config struct {
 	AssociationLimit int
 }
 type timeTaskConfig struct {
-	CheckIsExpire string //定时更新用户状态
+	SyncEntModel string //定时更新用户状态
 }
 
 var Config *config

+ 4 - 3
entniche/src/service/customer/customer.go

@@ -168,6 +168,7 @@ func (this *CustomerAction) CustomerDetail() {
 	errMsg, rData := func() (string, map[string]interface{}) {
 		//获取请求参数
 		customer_id := qutil.SE.Decode4HexByCheck(this.GetString("customer_id")) //客户id
+		log.Println("detail customer_id", customer_id)
 		ent_id := qutil.IntAll(this.GetSession("entId"))
 		entUserId := qutil.IntAll(this.GetSession("entUserId"))
 		curUser := VarCurrentUser.EntInfo(ent_id, entUserId)
@@ -176,11 +177,11 @@ func (this *CustomerAction) CustomerDetail() {
 		if curUser.Role_admin_system { //查看企业所有客户信息
 			customerMsg = Mysql.FindOne(Entniche_customer, M{"id": customer_id, "ent_id": ent_id}, "name,industry,remarks,address", "")
 		} else if curUser.Role_admin_department { //部门管理员查看自己部门和下属部门客户信息
-			res := Mysql.SelectBySql(`SELECT b.name,b.industry,b.remarks,b.address
+			res := Mysql.SelectBySql(`SELECT b.name,b.industry,b.remarks,b.address,b.editperson,b.timestamp
 				FROM entniche_department_parent a 
 				INNER JOIN entniche_customer b on ( a.id=b.dept_id) 
 				WHERE b.ent_id=? and (a.id=? or a.pid=?) and b.id=? limit 1`, curUser.Ent.Id, curUser.Dept.Id, curUser.Dept.Id, customer_id)
-			if len(*res) == 1 {
+			if res != nil && len(*res) == 1 {
 				customerMsg = &(*res)[0]
 			}
 		} else { //员工只能查看自己客户
@@ -188,7 +189,7 @@ func (this *CustomerAction) CustomerDetail() {
 			res := Mysql.SelectBySql(`SELECT a.name,a.industry,a.remarks,a.address,a.editperson,a.timestamp FROM entniche_customer a 
 				JOIN entniche_user_customer b on (a.id=b.customer_id)
 				WHERE a.ent_id=? and b.user_id=? and a.id=? limit 1`, ent_id, entUserId, customer_id)
-			if len(*res) == 1 {
+			if res != nil && len(*res) == 1 {
 				customerMsg = &(*res)[0]
 			}
 		}

+ 21 - 12
entniche/src/service/customer/distribute.go

@@ -24,25 +24,28 @@ func (this *CustomerAction) DistributePersons() {
 		distributeUsers := VarCustomer.GetDistributeUser(ent_id, customer_id) //获取已分发人员id
 		//获取人员列表
 		var users []*User
-		var dept_id int
 		curUser := VarCurrentUser.EntInfo(ent_id, entUserId)
 		if curUser.Role_admin_department { //获取当前部门id
-			dept_id = curUser.Dept.Id
+			users = *VarDepartment.GetDisUsersDeptDetail(curUser.Ent.Id, curUser.Dept.Id)
 		} else if curUser.Role_admin_system { //查询客户所属的部门id
 			res := Mysql.FindOne(Entniche_customer, M{"id": customer_id, "ent_id": ent_id}, "dept_id", "")
-			if len(*res) == 0 {
+			if res == nil || len(*res) == 0 {
 				return "未找到客户", nil
 			}
-			dept_id = qutil.IntAll((*res)["dept_id"])
+			dept_id := qutil.IntAll((*res)["dept_id"])
+			if dept_id == curUser.Dept.Id { //当前客户是否所属于最顶级部门
+				users = *VarEntInfo.GetDisUsersDeptDetail(ent_id)
+			} else {
+				users = *VarDepartment.GetDisUsersDeptDetail(curUser.Ent.Id, dept_id)
+			}
 		} else {
 			return "没有权限", nil
 		}
-		users = *VarDepartment.GetDisUsersDeptDetail(curUser.Ent.Id, dept_id)
 
 		persons := map[string][]map[string]interface{}{}
 		if len(users) > 0 {
 			for _, v := range users {
-				distribute := 0
+				distribute := 2
 				for _, uid := range distributeUsers {
 					if v.Id == uid {
 						distribute = 1
@@ -52,6 +55,7 @@ func (this *CustomerAction) DistributePersons() {
 					"id":         qutil.SE.Encode2HexByCheck(fmt.Sprint(v.Id)),
 					"name":       v.Name,
 					"phone":      v.Phone,
+					"role":       v.Role,
 					"distribute": distribute,
 				}
 				if persons[v.Dept_name] == nil {
@@ -88,19 +92,24 @@ func (this *CustomerAction) DistributeSubmit() {
 		curUser := VarCurrentUser.EntInfo(ent_id, entUserId)
 		//获取人员列表
 		var users []*User
-		var dept_id int
 		if curUser.Role_admin_department { //获取当前部门id
-			dept_id = curUser.Dept.Id
+			users = *VarDepartment.GetDisUsers(curUser.Ent.Id, curUser.Dept.Id)
 		} else if curUser.Role_admin_system { //查询客户所属的部门id
 			res := Mysql.FindOne(Entniche_customer, M{"id": customer_id, "ent_id": ent_id}, "dept_id", "")
-			if len(*res) == 0 {
+			if res == nil || len(*res) == 0 {
 				return "未找到客户", nil
 			}
-			dept_id = qutil.IntAll((*res)["dept_id"])
+			dept_id := qutil.IntAll((*res)["dept_id"])
+			if dept_id == curUser.Dept.Id { //当前客户是否所属于最顶级部门
+				users = *VarEntInfo.GetDisUsers(ent_id)
+			} else {
+				users = *VarDepartment.GetDisUsers(curUser.Ent.Id, dept_id)
+			}
 		} else {
 			return "没有权限", nil
 		}
-		users = *VarDepartment.GetDisUsers(curUser.Ent.Id, dept_id)
+
+		log.Println("users", users)
 		ok := Mysql.ExecTx("客户分发", func(tx *sql.Tx) bool {
 			//清除之前选择
 			if !VarCustomer.ClearDistributeUser(tx, customer_id, users) {
@@ -116,7 +125,7 @@ func (this *CustomerAction) DistributeSubmit() {
 					}
 					for _, u := range users { //校验用户是否在管理范围内
 						if fmt.Sprint(u.Id) == qutil.SE.Decode4HexByCheck(id) {
-							final_checked_userIds = append(final_checked_userIds, id)
+							final_checked_userIds = append(final_checked_userIds, fmt.Sprint(u.Id))
 							break
 						}
 					}

+ 8 - 6
entniche/src/service/ent/ent.go

@@ -31,12 +31,14 @@ func (a *Action) Setmodel() {
 	}
 	entId := qutil.IntAll(a.GetSession("entId"))
 	status := 0
-	if Mysql.Insert(Entniche_entmodel, map[string]interface{}{
-		"ent_id":     entId,
-		"model":      model,
-		"createtime": time.Now().Unix(),
-	}) > 0 {
-		status = 1
+	if VarEntInfo.GetById(entId).Model == 0 {
+		if Mysql.UpdateOrDeleteBySql(`update entniche_info set model=? where id=?`, model, entId) > 0 {
+			status = 1
+		}
+	} else {
+		if Mysql.UpdateOrDeleteBySql(`replace into entniche_entmodel (ent_id,model,createtime) values (?,?,?)`, entId, model, time.Now().Unix()) > 0 {
+			status = 1
+		}
 	}
 	a.ServeJson(Result{Data: M{"status": status}})
 }

+ 1 - 1
entniche/src/timetask.json

@@ -1,3 +1,3 @@
 {
-	"checkIsExpire": "00:00"
+	"syncEntModel": "00:00"
 }

+ 42 - 3
entniche/src/timetask/timetask.go

@@ -2,6 +2,9 @@ package timetask
 
 import (
 	. "config"
+	"database/sql"
+	. "ent/entity"
+	. "ent/util"
 	"log"
 	qutil "qfw/util"
 	"strings"
@@ -13,13 +16,49 @@ const (
 )
 
 func Run() {
-	//go checkIsExpire()
+	go syncEntModel()
 }
 
 //每天0点 检查是否到期
-func checkIsExpire() {
-	crontab(true, TimeTaskConfig.CheckIsExpire, func() {
+func syncEntModel() {
+	crontab(false, TimeTaskConfig.SyncEntModel, func() {
 		defer qutil.Catch()
+		log.Println("开始同步订阅模式。。。")
+		now := time.Now()
+		today_unix := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.Local).Unix()
+		list := Mysql.SelectBySql(`select * from entniche_entmodel where createtime<?`, today_unix)
+		if list != nil {
+			for _, v := range *list {
+				entId := qutil.IntAll(v["ent_id"])
+				ent := Mysql.SelectBySql(`select model from entniche_info where id=?`, entId)
+				if ent == nil {
+					log.Println(entId, "同步订阅模式", "没有找到该企业")
+					continue
+				}
+				model := qutil.IntAll((*ent)[0]["model"])
+				newModel := qutil.IntAll(v["model"])
+				//由统一订阅变成个人订阅
+				if model == 1 && newModel == 2 {
+					log.Println(entId, "同步订阅模式", "新的订阅模式", newModel, "旧的订阅模式", model)
+					if Mysql.ExecTx("同步订阅模式", func(tx *sql.Tx) bool {
+						update := Mysql.UpdateOrDeleteBySql(`update entniche_info set model=? where id=?`, newModel, entId)
+						del := Mysql.UpdateOrDeleteBySqlByTx(tx, `delete from entniche_customer where ent_id=?`, entId)
+						return update > -1 && del > -1
+					}) {
+						del_ent_customer := Mysql.SelectBySql(`select * from entniche_customer where ent_id=?`, entId)
+						del_ent_customer_contact := Mysql.SelectBySql(`select a.* from entniche_customer_contact a inner join entniche_customer b on (b.ent_id=? and a.customer_id=b.id)`, entId)
+						del_ent_project := Mysql.SelectBySql(`select a.* from entniche_project a inner join entniche_customer b on (b.ent_id=? and a.customer_id=b.id)`, entId)
+						del_ent_project_track := Mysql.SelectBySql(`select a.* from entniche_project_track a inner join entniche_project b on (a.project_id=b.id) inner join entniche_customer c on (c.ent_id=? and b.customer_id=c.id)`, entId)
+						VarBackup.Save(Entniche_customer, del_ent_customer)
+						VarBackup.Save(Entniche_customer_contact, del_ent_customer_contact)
+						VarBackup.Save(Entniche_project, del_ent_project)
+						VarBackup.Save(Entniche_project_track, del_ent_project_track)
+					}
+				}
+			}
+		}
+		Mysql.UpdateOrDeleteBySql(`delete from entniche_entmodel where createtime<?`, today_unix)
+		log.Println("同步订阅模式结束。。。")
 	})
 }
 

+ 1 - 1
public/src/ent/entity/customer.go

@@ -171,7 +171,7 @@ func (this *Customer) GetDeptCustomerList(dept_id int, name, alloc, area string,
 		searchSql += ` HAVING staff_names IS NULL `
 	}
 	count = Mysql.CountBySql(`SELECT count(1) as total FROM (
-				SELECT GROUP_CONCAT(c.user_id)  as userids
+				SELECT GROUP_CONCAT(c.user_id)  as staff_names
 				FROM entniche_department_parent a 
 				INNER JOIN entniche_customer b on (a.id=b.dept_id) 
 				left JOIN entniche_user_customer c on (b.id=c.customer_id)

+ 7 - 5
public/src/ent/entity/department.go

@@ -78,10 +78,12 @@ func (d *Department) GetDisUsers(entId, deptId int) *[]*User {
 
 //获取部门下可以进行分发的人员(包含部门名称和部门id)
 func (d *Department) GetDisUsersDeptDetail(entId, deptId int) *[]*User {
-	r := Mysql.SelectBySql(`select DISTINCT a.id,c.id,c.name,c.phone,d.id as dept_id,d.name as dept_name from entniche_department_parent a 
+	r := Mysql.SelectBySql(`select DISTINCT a.id,c.id,c.name,c.phone,d.id as dept_id,d.name as dept_name,f.name as role from entniche_department_parent a 
 		INNER JOIN entniche_department_user b on ((a.id=? or a.pid=?) and a.id=b.dept_id) 
 		INNER JOIN entniche_user c on (c.power=1 and c.ent_id=? and b.user_id=c.id) 
 		INNER JOIN entniche_department d on (a.id = d.id)
+		LEFT JOIN entniche_user_role e on (c.id = e.user_id)
+		LEFT JOIN entniche_role f on (e.role_id = f.id)
 		order by convert(c.name using gbk) COLLATE gbk_chinese_ci asc`, deptId, deptId, entId)
 	users, _ := JsonUnmarshal(r, &[]*User{}).(*[]*User)
 	if users == nil {
@@ -192,10 +194,10 @@ func (d *Department) Del(entId int, deptId string) bool {
 			VarBackup.Save(Entniche_user, del_users)
 			VarBackup.Save(Entniche_department_user, del_dept_users)
 			VarBackup.Save(Entniche_department, del_dept)
-			VarBackup.Save(Ent_bank, del_ent_customer)
-			VarBackup.Save(Ent_bank, del_ent_customer_contact)
-			VarBackup.Save(Ent_bank, del_ent_project)
-			VarBackup.Save(Ent_bank, del_ent_project_track)
+			VarBackup.Save(Entniche_customer, del_ent_customer)
+			VarBackup.Save(Entniche_customer_contact, del_ent_customer_contact)
+			VarBackup.Save(Entniche_project, del_ent_project)
+			VarBackup.Save(Entniche_project_track, del_ent_project_track)
 		}()
 		if users != nil {
 			go func() {

+ 8 - 6
public/src/ent/entity/entinfo.go

@@ -62,11 +62,13 @@ func (e *EntInfo) GetDisUsers(entId int) *[]*User {
 	return users
 }
 
-//获取企业下所有的员工(包含部门名称和部门id)
+//获取企业下所有的员工(包含部门名称和部门id和职位名称)
 func (e *EntInfo) GetDisUsersDeptDetail(entId int) *[]*User {
-	r := Mysql.SelectBySql(`select a.id,a.name,a.phone,a.mail,c.id as dept_id,c.name as dept_name  from entniche_user a 
+	r := Mysql.SelectBySql(`select a.id,a.name,a.phone,a.mail,c.id as dept_id,c.name as dept_name ,e.name as role from entniche_user a 
 		INNER JOIN entniche_department_user b on (a.id=b.user_id)
 		INNER JOIN entniche_department c on (b.dept_id=c.id)
+		LEFT JOIN entniche_user_role d on (b.user_id = d.user_id)
+		LEFT JOIN entniche_role e on (d.role_id = e.id)
 		where a.ent_id=? and a.power=1 
 		order by convert(a.name using gbk) COLLATE gbk_chinese_ci asc`, entId)
 	users, _ := JsonUnmarshal(*r, &[]*User{}).(*[]*User)
@@ -341,10 +343,10 @@ func (e *EntInfo) Dissolution(entId int) int {
 				VarBackup.Save(Entniche_department, del_dept)
 				VarBackup.Save(Entniche_department_user, del_dept_user)
 				VarBackup.Save(Ent_bank, del_ent_bank)
-				VarBackup.Save(Ent_bank, del_ent_customer)
-				VarBackup.Save(Ent_bank, del_ent_customer_contact)
-				VarBackup.Save(Ent_bank, del_ent_project)
-				VarBackup.Save(Ent_bank, del_ent_project_track)
+				VarBackup.Save(Entniche_customer, del_ent_customer)
+				VarBackup.Save(Entniche_customer_contact, del_ent_customer_contact)
+				VarBackup.Save(Entniche_project, del_ent_project)
+				VarBackup.Save(Entniche_project_track, del_ent_project_track)
 			}()
 		}
 	}

+ 1 - 0
public/src/ent/util/constant.go

@@ -27,5 +27,6 @@ const (
 	Entniche_customer_contact = "entniche_customer_contact"
 	Entniche_customer_return  = "entniche_customer_return"
 	Entniche_project          = "entniche_project"
+	Entniche_project_track    = "entniche_project_track"
 	Entniche_entmodel         = "entniche_entmodel"
 )