123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- package cygx
- import (
- "errors"
- "hongze/hz_crm_api/models/company"
- "hongze/hz_crm_api/models/cygx"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/utils"
- "strconv"
- "strings"
- )
- // 获取这个销售所能查看的手机号权限
- func GetAdminLookUserMobile(adminInfo *system.Admin) (mapMobile map[string]string, err error) {
- //sellerIds, e := company.GetCompanyProductSellerIdByShareSellerId(adminInfo.AdminId)
- //if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetCompanyProductSellerIdByShareSellerId 根据共享销售id查被共享的公司销售id, Err: " + e.Error())
- // return
- //}
- var companyIds []string
- var adminIds []string
- //如果是组长获取所属组员的ID
- if adminInfo.RoleTypeCode == "rai_group" {
- adminList, e := system.GetAdminListByGroupId(adminInfo.GroupId)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetAdminListByGroupId, Err: " + e.Error())
- return
- }
- for _, v := range adminList {
- adminIds = append(adminIds, strconv.Itoa(v.AdminId))
- }
- } else {
- adminIds = append(adminIds, strconv.Itoa(adminInfo.AdminId))
- }
- //再获取组员下被共享的公司
- var pars []interface{}
- var condition string
- condition = " AND share_seller_id IN (" + strings.Join(adminIds, ",") + ") "
- listCompanyProduct, e := company.GetCompanyProductList(condition, pars)
- if e != nil {
- err = errors.New("GetCompanyProductList, Err: " + e.Error())
- return
- }
- for _, v := range listCompanyProduct {
- companyIds = append(companyIds, strconv.Itoa(v.CompanyId))
- }
- companyIds = append(companyIds, "0")
- var conditionMobile string
- //if adminInfo.RoleTypeCode == "rai_group" {
- //
- // //组长查看本组所有组员
- // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(adminInfo.AdminId) + ` )) `
- //} else {
- // //组员查看自己
- // if sellerIds != "" {
- // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id IN ( ` + strconv.Itoa(adminInfo.AdminId) + `,` + sellerIds + ` ) `
- // } else {
- // conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id IN ( ` + strconv.Itoa(adminInfo.AdminId) + ` ) `
- // }
- //}
- conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE 1=1 AND product_id = 2 AND (seller_id IN ( ` + strings.Join(adminIds, ",") + ` ) OR company_id IN (` + strings.Join(companyIds, ",") + `)) `
- mobileList, e := cygx.GetSellerUserMobile(conditionMobile)
- if e != nil {
- err = errors.New("GetSellerUserMobile 获取这个销售所能查看的手机号权限失败, Err: " + e.Error())
- return
- }
- mapUserMobile := make(map[string]string)
- for _, v := range mobileList {
- mapUserMobile[v.Mobile] = v.Mobile
- }
- mapMobile = mapUserMobile
- return
- }
- // 获取这个销售所能查看的手机号权限
- func GetAdminLookUserUserId(adminInfo *system.Admin) (userIds []int, err error) {
- var conditionMobile string
- if adminInfo.RoleTypeCode == "rai_group" {
- //组长查看本组所有组员
- conditionMobile = ` SELECT user_id FROM user_seller_relation WHERE seller_id IN (SELECT admin_id FROM admin WHERE group_id = (SELECT group_id FROM admin WHERE admin_id = ` + strconv.Itoa(adminInfo.AdminId) + ` )) `
- } else {
- //组员查看自己
- conditionMobile = ` SELECT user_id FROM user_seller_relation WHERE seller_id = ` + strconv.Itoa(adminInfo.AdminId)
- }
- conditionMobile += " LIMIT 10"
- userList, e := cygx.GetSellerUserMobile(conditionMobile)
- if e != nil {
- err = errors.New("GetSellerUserMobile 获取这个销售所能查看的手机号权限失败, Err: " + e.Error())
- return
- }
- userIds = make([]int, 0)
- for _, v := range userList {
- userIds = append(userIds, v.UserId)
- }
- return
- }
- //func init() {
- // sellerId, e := company.GetCompanyProductSellerIdByShareSellerId(163)
- // fmt.Println(e)
- // fmt.Println(sellerId)
- //}
- // 获取这个销售所能查看的手机号权限
- func GetAdminLookUserCompanyIds(sysUser *system.Admin) (companyIds []int, err error) {
- //如果不是管理员,权益管理员那么就对可见权限范围做处理
- adminIds := make([]int, 0)
- if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- //如果是权益的组长就获取下面的组员
- adminList, e := system.GetAdminListByGroupId(sysUser.GroupId)
- if e != nil {
- err = errors.New("GetAdminListByGroupId , Err: " + e.Error())
- return
- }
- for _, v := range adminList {
- adminIds = append(adminIds, v.AdminId)
- }
- } else {
- adminIds = append(adminIds, sysUser.AdminId)
- }
- //adminIds = append(adminIds, sysUser.AdminId)
- var adminIdGroup string
- for _, v := range adminIds {
- adminIdGroup += strconv.Itoa(v) + ","
- }
- adminIdGroup = strings.TrimRight(adminIdGroup, ",")
- companyProductList, e := company.GetCompanyProductsBySellerId(adminIdGroup)
- if e != nil {
- err = errors.New("GetCompanyProductsBySellerId , Err: " + e.Error())
- return
- }
- for _, v := range companyProductList {
- companyIds = append(companyIds, v.CompanyId)
- }
- }
- companyIds = append(companyIds, 0) //添加潜在客户
- return
- }
- // 获取这个销售所能查看的公司权限
- func GetAdminLookUserCompanyIdsBySelf(sysUser *system.Admin) (companyIds []int, err error) {
- //如果不是管理员,权益管理员那么就对可见权限范围做处理
- adminIds := make([]int, 0)
- if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_FINANCE {
- //if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
- // //如果是权益的组长就获取下面的组员
- // adminList, e := system.GetAdminListByGroupId(sysUser.GroupId)
- // if e != nil {
- // err = errors.New("GetAdminListByGroupId , Err: " + e.Error())
- // return
- // }
- // for _, v := range adminList {
- // adminIds = append(adminIds, v.AdminId)
- // }
- //} else {
- // adminIds = append(adminIds, sysUser.AdminId)
- //}
- adminIds = append(adminIds, sysUser.AdminId)
- var adminIdGroup string
- for _, v := range adminIds {
- adminIdGroup += strconv.Itoa(v) + ","
- }
- adminIdGroup = strings.TrimRight(adminIdGroup, ",")
- companyProductList, e := company.GetCompanyProductsBySellerId(adminIdGroup)
- if e != nil {
- err = errors.New("GetCompanyProductsBySellerId , Err: " + e.Error())
- return
- }
- for _, v := range companyProductList {
- companyIds = append(companyIds, v.CompanyId)
- }
- companyIds = append(companyIds, 0) //添加潜在客户
- }
- return
- }
- // 获取这个销售所能查看的公司权限(研究员)
- func GetAdminLookUserCompanyIdsByResearcher(sysUser *system.Admin) (companyIds []int, err error) {
- //如果不是管理员,权益管理员那么就对可见权限范围做处理
- adminIds := make([]int, 0)
- if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
- adminIds = append(adminIds, sysUser.AdminId)
- var adminIdGroup string
- for _, v := range adminIds {
- adminIdGroup += strconv.Itoa(v) + ","
- }
- adminIdGroup = strings.TrimRight(adminIdGroup, ",")
- companyProductList, e := company.GetCompanyProductsBySellerId(adminIdGroup)
- if e != nil {
- err = errors.New("GetCompanyProductsBySellerId , Err: " + e.Error())
- return
- }
- for _, v := range companyProductList {
- companyIds = append(companyIds, v.CompanyId)
- }
- companyIds = append(companyIds, 0) //添加潜在客户
- }
- return
- }
|