package cygx

import (
	"errors"
	"hongze/hz_crm_api/models/cygx"
	"hongze/hz_crm_api/models/system"
	"strconv"
)

// 获取这个销售所能查看的手机号权限
func GetAdminLookUserMobile(adminInfo *system.Admin) (mapMobile map[string]string, err error) {
	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 {
		//组员查看自己
		conditionMobile = ` SELECT mobile FROM user_seller_relation WHERE seller_id  = ` + strconv.Itoa(adminInfo.AdminId)
	}
	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
}
