瀏覽代碼

Merge branch 'pool_369' into fms_2.5

# Conflicts:
#	models/fms/contract_register.go
ziwen 2 年之前
父節點
當前提交
b80b1fe817

+ 28 - 1
controller/contract/register.go

@@ -3161,13 +3161,40 @@ func (rg *RegisterController) CheckContractName(c *gin.Context) {
 			return
 		}
 		if existCond != "" {
-			existCond += ` or (start_date =? and end_date=?)`
+			existCond += ` AND (start_date =? and end_date=?)`
 		} else {
 			existCond = ` start_date = ? and end_date=?`
 		}
 
 		existPars = append(existPars, startDate, endDate)
 	}
+	if req.SellerIds != "" {
+		admin := new(crm.Admin)
+		sellerIds := strings.Split(req.SellerIds, ",")
+		if len(sellerIds) > 2 {
+			resp.Fail("最多只能选择两个销售", c)
+			return
+		}
+		var pars []interface{}
+		cond := ` admin_id in (?) `
+		pars = append(pars, sellerIds)
+		sellers, e := admin.List(cond, pars)
+		if e != nil {
+			resp.FailMsg("获取销售信息失败", "获取销售信息失败, Err: "+e.Error(), c)
+			return
+		}
+		var sellerId, raiSellerId int
+		for _, v := range sellers {
+			if v.DepartmentId == crm.SellerDepartmentId {
+				sellerId = v.AdminId
+			} else if v.DepartmentId == crm.RaiSellerDepartmentId {
+				raiSellerId = v.AdminId
+			}
+		}
+		existCond += ` AND (seller_id =? and rai_seller_id=?)`
+		existPars = append(existPars, sellerId, raiSellerId)
+	}
+
 	if existCond == "" {
 		resp.Fail("请输入合同名称或者合同有效期", c)
 		return

+ 18 - 0
controller/crm/company_seller.go

@@ -66,3 +66,21 @@ func (rg *CompanySellerController) GroupList(c *gin.Context) {
 	}
 	resp.OkData("获取成功", list, c)
 }
+
+// List
+// @Title 销售列表
+// @Description 销售列表
+// @Success 200 {object} crm.SellerAdminWithGroupList
+// @router /crm/company_seller/all_list [get]
+func (rg *CompanySellerController) AllList(c *gin.Context) {
+	ficcList, raiLits, e := crmService.GetSellerDepartmentListWithGroupAndTeamByDepartment()
+	if e != nil {
+		resp.FailData("获取销售失败", "Err:"+e.Error(), c)
+		return
+	}
+	respItem := crm.AllSellerResp{
+		FiccSeller: ficcList,
+		RaiSeller:  raiLits,
+	}
+	resp.OkData("获取成功", respItem, c)
+}

+ 5 - 0
models/crm/sys_group.go

@@ -36,3 +36,8 @@ func (m *SysGroup) Count(condition string, pars []interface{}) (total int64, err
 		Count(&total).Error
 	return
 }
+
+type AllSellerResp struct {
+	FiccSeller []*SellerAdminWithGroupTeam
+	RaiSeller []*SellerAdminWithGroupTeam
+}

+ 1 - 0
models/fms/contract_register.go

@@ -553,6 +553,7 @@ type CheckContractNameReq struct {
 	CompanyName string `json:"company_name" form:"company_name" description:"客户名称"`
 	StartDate   string `json:"start_date" form:"start_date" description:"合同开始日期"`
 	EndDate     string `json:"end_date" form:"end_date" description:"合同结束日期"`
+	SellerIds   string `json:"seller_ids" form:"seller_ids" binding:"required" description:"CRM系统-销售ID"`
 }
 
 type CheckContractNameResp struct {

+ 1 - 0
routers/crm.go

@@ -19,4 +19,5 @@ func InitCrm(rg *gin.RouterGroup) {
 	slGroup := rg.Group("company_seller/").Use(middleware.Token())
 	slGroup.GET("list", sl.List)
 	slGroup.GET("group_list", sl.GroupList)
+	slGroup.GET("all_list", sl.AllList)
 }

+ 64 - 1
services/crm/company_seller.go

@@ -200,4 +200,67 @@ func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
 	resp.FiccList = ficcList
 	resp.RaiList = raiList
 	return
-}
+}
+
+// GetSellerDepartmentAndGroupMap 获取销售部门列表-包含大组和小组
+func GetSellerDepartmentListWithGroupAndTeamByDepartment() (ficcList []*crm.SellerAdminWithGroupTeam,raiList []*crm.SellerAdminWithGroupTeam, err error) {
+	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+	ficcList = make([]*crm.SellerAdminWithGroupTeam, 0)
+	raiList = make([]*crm.SellerAdminWithGroupTeam, 0)
+	// 获取组别列表
+	groupCond := "department_id in (?)"
+	groupPars := make([]interface{}, 0)
+	groupPars = append(groupPars, departmentIds)
+	groupOB := new(crm.SysGroup)
+	groupList, e := groupOB.List(groupCond, groupPars)
+	if e != nil {
+		err = errors.New("获取组别列表失败, Err: " + e.Error())
+		return
+	}
+	groupMap := make(map[int]*crm.SysGroup)
+	for i := range groupList {
+		groupMap[groupList[i].GroupId] = groupList[i]
+	}
+
+	// 获取销售部门所有销售信息
+	adminCond := "department_id in (?) AND enabled = 1"
+	adminPars := make([]interface{}, 0)
+	adminPars = append(adminPars, departmentIds)
+	adminOB := new(crm.Admin)
+	adminList, e := adminOB.List(adminCond, adminPars)
+	if e != nil {
+		err = errors.New("获取销售列表失败, Err: " + e.Error())
+		return
+	}
+
+	// 销售列表
+	for i := range adminList {
+		v := new(crm.SellerAdminWithGroupTeam)
+		v.DepartmentId = adminList[i].DepartmentId
+		v.SellerId = adminList[i].AdminId
+		v.SellerName = adminList[i].RealName
+		g := groupMap[adminList[i].GroupId]
+		if g != nil {
+			if g.ParentId > 0 {
+				// 三级分组
+				p := groupMap[g.ParentId]
+				if p != nil {
+					v.GroupId = p.GroupId
+					v.GroupName = p.GroupName
+					v.TeamId = g.GroupId
+					v.TeamName = g.GroupName
+				}
+			} else {
+				// 二级分组
+				v.GroupId = g.GroupId
+				v.GroupName = g.GroupName
+			}
+		}
+		if v.DepartmentId == crm.SellerDepartmentId {
+			ficcList = append(ficcList, v)
+		} else {
+			raiList = append(raiList, v)
+		}
+	}
+	return
+}