package controllers import ( "fmt" "hongze/hongze_mobile_admin/models/tables/system" "hongze/hongze_mobile_admin/services" "hongze/hongze_mobile_admin/utils" ) // CompanySellerController 销售管理 type CompanySellerController struct { BaseAuth } // RoadshowFiccList // @Title 路演FICC销售列表 // @Description 路演FICC销售列表 // @Success 200 {object} system.RoadshowGroupResp // @router /seller/roadshow_ficc/list [get] func (c *CompanySellerController) RoadshowFiccList() { sysUser := c.AdminWx resp := new(system.RoadshowGroupResp) productId := services.GetProductId(sysUser.RoleTypeCode) if productId == utils.COMPANY_PRODUCT_RAI_ID { c.OkDetailed(resp, "获取成功") return } // 分组 departmentId := 2 groups, e := system.GetGroupByDepartmentId(departmentId) if e != nil { c.FailWithMessage("获取失败", "获取FICC分组失败, Err: "+e.Error()) return } teamGroupId := make(map[int]int, 0) // 小组ID对应的大组ID var list []system.RoadshowGroups for _, g := range groups { if g.ParentId > 0 { teamGroupId[g.GroupId] = g.ParentId continue } // 大组 list = append(list, system.RoadshowGroups{ GroupId: g.GroupId, GroupName: g.GroupName, }) } // 销售 roleArr := []string{ utils.ROLE_TYPE_CODE_FICC_ADMIN, utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_SELLER, } cond := fmt.Sprintf(` AND role_type_code IN (%s)`, utils.GetOrmInReplace(len(roleArr))) pars := make([]interface{}, 0) pars = append(pars, roleArr) sellers, e := system.GetSysUserItemsOrderByCreated(cond, pars) if e != nil { c.FailWithMessage("获取失败", "获取FICC销售失败, Err: "+e.Error()) return } groupIdChild := make(map[int][]system.RoadshowGroupSellers) // 大组ID对应的销售 for _, s := range sellers { var seller system.RoadshowGroupSellers seller.AdminId = s.AdminId seller.AdminName = s.RealName gid := teamGroupId[s.GroupId] if gid > 0 { // 小组 seller.GroupId = gid seller.TeamId = s.GroupId } else { // 大组 seller.GroupId = s.GroupId } groupIdChild[seller.GroupId] = append(groupIdChild[seller.GroupId], seller) } // 根据当前角色过滤可选项 for _, v := range list { // 如果是销售、组长、主管, 那么过滤掉自己大组外的其他组 if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER { if sysUser.GroupId != v.GroupId && teamGroupId[sysUser.GroupId] != v.GroupId { continue } } child := groupIdChild[v.GroupId] // 如果是小组长, 那么只能看到自己小组的信息 if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM { var team []system.RoadshowGroupSellers for _, c := range child { if c.TeamId == sysUser.GroupId { team = append(team, c) } } v.Child = team resp.List = append(resp.List, v) continue } // 如果是普通销售, 那么只能看到分组中的自己 if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER { var self []system.RoadshowGroupSellers for _, c := range child { if c.AdminId == sysUser.AdminId { self = append(self, c) break } } v.Child = self resp.List = append(resp.List, v) continue } // 非以上两种情况, 可见该大组所有销售 v.Child = child resp.List = append(resp.List, v) } c.OkDetailed(resp, "获取成功") }