Browse Source

fix状态及共享销售展示

zwxi 11 months ago
parent
commit
0d7154cd31

+ 20 - 13
controllers/company.go

@@ -369,7 +369,7 @@ func (this *CompanyController) SearchList() {
 
 		btnItem := new(company.ButtonPermission)
 		if item.CompanyId != 1 {
-			*btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
+			*btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
 			//根据销售"领取客户"的权限对部分按钮做限制
 			btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
 		}
@@ -1317,7 +1317,7 @@ func (this *CompanyController) List() {
 		//按钮显示控制
 		btnItem := new(company.ButtonPermission)
 		if item.CompanyId != 1 {
-			*btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
+			*btnItem = services.GetCompanyPermissionButton(roleTypeCode, itemStatus, item.GroupIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
 			//根据销售"领取客户"的权限对部分按钮做限制
 			btnItem = services.GetCompanyPermissionButtonByReceiveEnabled(btnItem, receiveEnabled)
 		}
@@ -1591,7 +1591,7 @@ func (this *CompanyController) List() {
 			//viewTotal:=GetviewTotal(v.CompanyId)
 
 			//活跃(客户状态)
-			if v.IsShare != 1  {
+			if v.IsShare != 1 {
 				if v.BtnItem.BtnModifySeller == true {
 					v.BtnItem.BtnModifySeller = false
 				}
@@ -1745,13 +1745,20 @@ func (this *CompanyController) List() {
 				IsShare:         v.IsShare,
 				CloseTime:       v.CloseTime,
 				CloseReason:     v.CloseReason,
-				ShareSeller:     v.ShareSeller,
-				ShareSellerId:   v.ShareSellerId,
-			}
-			if v.ShareSellerId != 0 {
-				shareSeller := adminMap[v.ShareSellerId]
-				if shareSeller != nil {
-					companyList.ShareSeller = shareSeller.RealName + "(" + shareSeller.GroupName + ")"
+				ShareSellerIds:  v.ShareSellerIds,
+			}
+			if v.ShareSellerIds != "" {
+				shareSellerIds := strings.Split(v.ShareSellerIds, ",")
+				for _, idStr := range shareSellerIds {
+					shareSellerId ,e:= strconv.Atoi(idStr)
+					if e != nil {
+						err = e
+						return
+					}
+					shareSeller := adminMap[shareSellerId]
+					if shareSeller != nil {
+						companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")"
+					}
 				}
 			}
 			companyLists = append(companyLists, companyList)
@@ -3081,7 +3088,7 @@ func (this *CompanyController) Detail() {
 	shareSellerId := 0
 	var productItem *company.CompanyProduct
 	if productId > 0 {
-		var  e  error
+		var e error
 		productItem, e = company.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
 		if e != nil && e.Error() != utils.ErrNoRow() {
 			br.Msg = "客户信息有误"
@@ -3335,7 +3342,7 @@ func (this *CompanyController) Detail() {
 				resp.IsButtonShow = 1
 			}
 		}
-		btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId), item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, shareSellerId)
+		btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId), item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, shareSellerId, "")
 		//if itemLen > 1 {
 		//	btnDetailItem.BtnEdit = false
 		//	btnDetailItem.BtnDelete = false
@@ -3705,7 +3712,7 @@ func (this *CompanyController) DetailByCreditCode() {
 			}
 		}
 		btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
-			item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
+			item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
 		//if itemLen > 1 {
 		//	btnDetailItem.BtnEdit = false
 		//	btnDetailItem.BtnDelete = false

+ 49 - 1
controllers/company_share.go

@@ -337,6 +337,17 @@ func (this *CompanyController) CompanyShareList() {
 		sortStr += " DESC "
 	}
 
+	sysUserList, err := system.GetAdminList()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
+		return
+	}
+	adminMap := make(map[int]*system.Admin, 0)
+	for _, v := range sysUserList {
+		adminMap[v.AdminId] = v
+	}
+
 	list, err := company.GetShareCompanyList(condition, sortStr, pars, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取失败"
@@ -639,6 +650,20 @@ func (this *CompanyController) CompanyShareList() {
 				LastServiceTime: v.LastServiceTime,
 				ServiceTimes:    v.ServiceTimes,
 			}
+			if v.ShareSellerIds != "" {
+				shareSellerIds := strings.Split(v.ShareSellerIds, ",")
+				for _, idStr := range shareSellerIds {
+					shareSellerId ,e:= strconv.Atoi(idStr)
+					if e != nil {
+						err = e
+						return
+					}
+					shareSeller := adminMap[shareSellerId]
+					if shareSeller != nil {
+						companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")"
+					}
+				}
+			}
 			companyLists = append(companyLists, companyList)
 		}
 	}
@@ -970,7 +995,16 @@ func (this *CompanyController) CompanyShareListByCity() {
 		br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
 		return
 	}
-
+	sysUserList, err := system.GetAdminList()
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
+		return
+	}
+	adminMap := make(map[int]*system.Admin, 0)
+	for _, v := range sysUserList {
+		adminMap[v.AdminId] = v
+	}
 	sortStr := ` `
 	//if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
 	//	sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
@@ -1091,6 +1125,20 @@ func (this *CompanyController) CompanyShareListByCity() {
 				LastServiceTime: v.LastServiceTime,
 				ServiceTimes:    v.ServiceTimes,
 			}
+			if v.ShareSellerIds != "" {
+				shareSellerIds := strings.Split(v.ShareSellerIds, ",")
+				for _, idStr := range shareSellerIds {
+					shareSellerId ,e:= strconv.Atoi(idStr)
+					if e != nil {
+						err = e
+						return
+					}
+					shareSeller := adminMap[shareSellerId]
+					if shareSeller != nil {
+						companyList.ShareSeller += shareSeller.RealName + "(" + shareSeller.GroupName + ")"
+					}
+				}
+			}
 			companyLists = append(companyLists, companyList)
 		}
 	}

+ 1 - 1
controllers/full_company.go

@@ -2470,7 +2470,7 @@ func (this *FullCompanyController) Detail() {
 			}
 		}
 		btnItem := services.GetCompanyPermissionButton(roleTypeCode, item.Status, strconv.Itoa(item.SellerId), strconv.Itoa(item.GroupId),
-			item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
+			item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId, "")
 		//if itemLen > 1 {
 		//	btnDetailItem.BtnEdit = false
 		//	btnDetailItem.BtnDelete = false

+ 16 - 6
models/company/company.go

@@ -89,7 +89,8 @@ type CompanySearchItem struct {
 	FreezeEndDate   string `description:"冻结结束日期"`
 	RegionType      string `description:"地区类型,国内,国外"`
 	ShareSeller     string `description:"共享销售员"`
-	ShareSellerId   int    `description:"共享销售员id"`
+	ShareSellerId   string `description:"共享销售员id"`
+	ShareSellerIds  string `description:"共享销售员id"`
 	IsShare         int    `description:"0:非共享用户,1:共享客户"`
 	IsScrounge      int    `description:"是否白嫖 0不是 1是"`
 	Nation          string `description:"所属国家"`
@@ -160,7 +161,8 @@ type CompanyItem struct {
 	SellerId         int    `description:"销售ID"`
 	SellerIds        string `description:"销售ID集合,包含ficc和权益的销售id"`
 	ShareSeller      string `description:"共享销售员"`
-	ShareSellerId    int    `description:"共享销售员id"`
+	ShareSellerId    string `description:"共享销售员id"`
+	ShareSellerIds   string `description:"共享销售员ids"`
 	PackageTypes     string `description:"套餐类型集合,包含ficc和权益的套餐类型" json:"-"`
 	FiccPackageType  int    `description:"ficc的套餐类型"`
 	ExpireDay        string `description:"到期天数"`
@@ -268,7 +270,8 @@ type CompanyListItem struct {
 	WeekViewActive   int                  `description:"周阅读活跃: 0-七日内无阅读; 1-活跃"`
 	IsShare          int                  `description:"0:非共享用户,1:共享客户"`
 	ShareSeller      string               `description:"共享销售员"`
-	ShareSellerId    int                  `description:"共享销售员id"`
+	ShareSellerId    string               `description:"共享销售员id"`
+	ShareSellerIds   string               `description:"共享销售员ids"`
 	LastServiceTime  string               `description:"最后服务时间"`
 	ServiceTimes     int                  `description:"服务次数"`
 	CloseReason      string               `description:"关闭客户原因"`
@@ -369,7 +372,8 @@ as sort_todo_end_time,
 			b.view_total,
 			b.last_view_time,
 			GROUP_CONCAT(DISTINCT b.share_seller ORDER BY b.product_id ASC SEPARATOR '/') AS share_seller,
-			b.share_seller_id,
+			GROUP_CONCAT(DISTINCT b.share_seller_id ORDER BY b.product_id ASC SEPARATOR ',') AS share_seller_ids,
+			b.share_seller_id ,
 			MAX(b.last_view_time) as max_last_view_time,
 			MIN(b.last_view_time) as min_last_view_time,
 			MAX(b.end_date) as max_end_date,
@@ -1723,7 +1727,7 @@ func GetShareCompanyList(condition, sortStr string, pars []interface{}, startSiz
 	t := time.Now().Local().AddDate(0, 0, -7).Format(utils.FormatDate)
 
 	sql := `SELECT a.company_id,a.company_name,a.credit_code,a.company_code,a.created_time,a.province,a.city,
-a.address,a.region_type,b.group_id,b.road_show_total,b.is_share,b.share_seller_id,b.share_seller,
+a.address,a.region_type,b.group_id,b.road_show_total,b.is_share,
 			CASE 
      WHEN GROUP_CONCAT(b.status) LIKE "%永续%" THEN 1
 	 WHEN GROUP_CONCAT(b.status) LIKE "%正式%" THEN 2
@@ -1743,7 +1747,10 @@ CASE
      WHEN GROUP_CONCAT(b.todo_status) LIKE "%未完成%" AND GROUP_CONCAT(b.todo_end_time) is not null THEN GROUP_CONCAT(b.todo_end_time)
 		 ELSE "9999-01-01" END
 as sort_todo_end_time,
-			GROUP_CONCAT(b.status ORDER BY b.product_id ASC SEPARATOR '/') AS status,
+			GROUP_CONCAT(CASE 
+            WHEN b.is_share = 1 THEN CONCAT(b.status, '(共享)')
+            ELSE b.status 
+        END ORDER BY b.product_id ASC SEPARATOR '/') AS status,
 			GROUP_CONCAT(DISTINCT b.seller_name ORDER BY b.product_id ASC SEPARATOR '/') AS seller_name,
 			GROUP_CONCAT(DISTINCT b.seller_id ORDER BY b.product_id ASC SEPARATOR '/') AS seller_ids,
 			GROUP_CONCAT(DISTINCT b.package_type ORDER BY b.product_id ASC SEPARATOR '/') AS package_types,
@@ -1773,6 +1780,9 @@ as sort_todo_end_time,
             b.freeze_time,b.freeze_reason,b.renewal_reason,
 			b.view_total,
 			b.last_view_time,
+			GROUP_CONCAT(DISTINCT b.share_seller ORDER BY b.product_id ASC SEPARATOR '/') AS share_seller,
+			GROUP_CONCAT(DISTINCT b.share_seller_id ORDER BY b.product_id ASC SEPARATOR ',') AS share_seller_ids,
+			b.share_seller_id ,
 			MAX(b.last_view_time) as max_last_view_time,
 			MIN(b.last_view_time) as min_last_view_time,
 			MAX(b.end_date) as max_end_date,

+ 7 - 5
services/company.go

@@ -820,7 +820,7 @@ func CheckAdminIsSeller(roleTypeCode string) (isSeller bool) {
 //}
 //
 
-func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupIdS string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId, shareSellerId int) (button company.ButtonPermission) {
+func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupIdS string, itemGroupId, sysUserGroupId, itemSellerId, sysUserId, authority, productId, shareSellerId int, shareSellerIds string) (button company.ButtonPermission) {
 	//产品状态map
 	productStatusMap := make(map[int]string)
 	if productId == 1 {
@@ -860,6 +860,8 @@ func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupId
 		groupIdMap[2], _ = strconv.Atoi(groupIdSlice[1])
 	}
 
+	shareSellerIdArr := strings.Split(shareSellerIds, ",")
+
 	if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN { //超级管理员
 		button.BtnView = true //查看详情权限
 		if !strings.Contains(status, "/") {
@@ -984,7 +986,7 @@ func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupId
 
 			//如果是自己客户,那么拥有查看权限
 			if hasSellerId {
-				if sellerId == sysUserId || shareSellerId == sysUserId {
+				if sellerId == sysUserId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
 					button.BtnView = true                             //显示权限、详情
 					if productStatus == utils.COMPANY_STATUS_FORMAL { //正式
 						button.BtnUpdate = true       //服务更新
@@ -1042,7 +1044,7 @@ func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupId
 					button.BtnRemarkView = true
 					//button.BtnThaw = false
 				} else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
-					if sellerId == sysUserId || groupId == sysUserGroupId || shareSellerId == sysUserId {
+					if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
 						button.BtnApplyReceive = true
 					} else {
 						button.BtnReceive = true
@@ -1082,7 +1084,7 @@ func GetCompanyPermissionButton(roleTypeCode, status, itemSellerIds, itemGroupId
 					button.BtnRemarkView = true
 					//button.BtnThaw = false
 				} else if productStatus == utils.COMPANY_STATUS_LOSE { //流失
-					if sellerId == sysUserId || groupId == sysUserGroupId || shareSellerId == sysUserId {
+					if sellerId == sysUserId || groupId == sysUserGroupId || utils.InArrayByStr(shareSellerIdArr, strconv.Itoa(sysUserId)) || shareSellerId == sysUserId {
 						button.BtnApplyReceive = true
 					} else {
 						button.BtnReceive = true
@@ -2443,7 +2445,7 @@ func GetShareCompanyPermissionButton(roleTypeCode, statuses string, productId in
 		button.BtnRemarkView = true
 		button.BtnServiceRecord = true
 	}
-	companyButton := GetCompanyPermissionButton(roleTypeCode, statuses, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, item.ShareSellerId)
+	companyButton := GetCompanyPermissionButton(roleTypeCode, statuses, item.SellerIds, item.GroupIds, item.GroupId, sysUser.GroupId, item.SellerId, sysUser.AdminId, sysUser.Authority, item.ProductId, -1, item.ShareSellerIds)
 	if companyButton.BtnShare == true {
 		button.BtnShare = true
 	}

+ 0 - 1
services/statistic_report/company.go

@@ -555,7 +555,6 @@ func CompanyList(sysUser *system.Admin, req statisticModels.IncrementalCompanyLi
 				Deadline:        tmpDeadline,
 				IsShow:          isShow,
 				TryStageSlice:   tryStageSlice,
-				ShareSellerId:   v.ShareSellerId,
 				ShareSeller:     v.ShareSeller,
 			}
 			if strings.Contains(companyList.ApproveStatus, "已审批") {