ziwen 1 year ago
parent
commit
1c5f0023ed
3 changed files with 239 additions and 4 deletions
  1. 226 0
      controllers/company_share.go
  2. 4 4
      models/company/company.go
  3. 9 0
      routers/commentsRouter.go

+ 226 - 0
controllers/company_share.go

@@ -786,4 +786,230 @@ func (this *CompanyController) CompanyShareMark() {
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "编辑成功"
+}
+
+// @Title 共享客户列表-同城
+// @Description 共享客户列表接口
+// @Param   Keyword   query   string  true       "搜索关键词"
+// @Param   ListParam   query   int  false       "筛选字段参数,用来筛选的字段, 枚举值:0:全部 、 1:已分配 、 2:未分配  "
+// @Param   SortParam   query   string  false       "排序字段参数,用来排序的字段, 枚举值:'viewTotal':总阅读次数 、 'viewTime':阅读时间 、 'roadShowTotal':累计路演次数 、`expireDay:到期时间` 、 `createTime:创建时间` 、 'formalTime': 转正时间 、 'freezeTime':冻结时间 、'lossTime':流失时间  、'tryOutDay':试用天数"
+// @Param   SortType   query   string  true       "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success Ret=200 设置成功
+// @router /share/list/city [get]
+func (this *CompanyController) CompanyShareListByCity() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	keyword := this.GetString("Keyword")
+	province := this.GetString("Province")
+	city := this.GetString("City")
+	//排序参数
+	//sortParam := this.GetString("SortParam")
+	//listParam, _ := this.GetInt("ListParam")
+	//sortType := this.GetString("SortType")
+
+	var total int
+	page := paging.GetPaging(currentIndex, pageSize, total)
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = paging.StartIndex(currentIndex, pageSize)
+	var condition string
+	var pars []interface{}
+
+	if keyword != "" {
+		companyIdStr, err := company.GetCompanyIdByKeyWord(keyword)
+		if err != nil {
+			br.Msg = "获取客户信息失败"
+			br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
+			return
+		}
+		if companyIdStr != "" {
+			condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' OR a.company_id IN(` + companyIdStr + `)) `
+		} else {
+			condition += ` AND (a.company_name LIKE '%` + keyword + `%' OR a.credit_code LIKE '%` + keyword + `%' ) `
+		}
+	}
+
+	condition += ` AND a.is_share=1 `
+	if province != "" {
+		var provinceSql string
+		slice := strings.Split(province, ",")
+		for _, v := range slice {
+			provinceSql += "'" + v + "'" + ","
+		}
+		provinceSql = strings.TrimRight(provinceSql, ",")
+		condition += ` AND a.province IN (` + provinceSql + `) `
+	}
+
+	if city != "" {
+		var citySql string
+		slice := strings.Split(city, ",")
+		for _, v := range slice {
+			citySql += "'" + v + "'" + ","
+		}
+		citySql = strings.TrimRight(citySql, ",")
+		condition += ` AND a.city IN (` + citySql + `) `
+	}
+
+	total, err := company.GetShareCompanyListCount(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据总数失败,Err:" + err.Error()
+		return
+	}
+
+	sortStr := ` `
+	//if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
+	//	sortStr = " ORDER BY sort_status asc, all_view_total desc, a.created_time "
+	//} else {
+	//	sortStr = " ORDER BY sort_status asc, b.view_total desc, a.created_time  "
+	//}
+
+	list, err := company.GetShareCompanyList(condition, sortStr, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取数据失败,Err:" + err.Error()
+		return
+	}
+	//企业用户数组切片
+	companyIds := make([]int, 0)
+	companyIdSlice := make([]string, 0)
+	for _, v := range list {
+		companyIds = append(companyIds, v.CompanyId)
+		companyIdSlice = append(companyIdSlice, strconv.Itoa(v.CompanyId))
+	}
+
+	//企业用户产品开通数
+	companyIdStr := strings.Join(companyIdSlice, ",")
+	companyProductTotalList, _ := company.GetCountProductByCompanyIds(companyIdStr)
+	companyProductTotalMap := make(map[int]*company.CompanyProductTotalSlice)
+	for _, companyProductTotal := range companyProductTotalList {
+		companyProductTotalMap[companyProductTotal.CompanyId] = companyProductTotal
+	}
+
+	// 客户产品详细信息
+	companyProductMap := make(map[string]*company.CompanyProduct)
+	var companyProductCondition string
+	var companyProductPars []interface{}
+
+	companyProductList, err := company.GetCompanyProductsByCompanyIds(companyIdStr, companyProductCondition, companyProductPars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取客户产品数据失败,Err:" + err.Error()
+		return
+	}
+	for _, companyProduct := range companyProductList {
+		key := fmt.Sprint(companyProduct.CompanyId, "_", companyProduct.ProductId)
+		companyProductMap[key] = companyProduct
+	}
+
+	companyLists := make([]*company.CompanyListItem, 0)
+	//查询阅读次数
+	if list == nil {
+		companyLists = make([]*company.CompanyListItem, 0)
+	} else {
+		for _, v := range list {
+			//viewTotal:=GetviewTotal(v.CompanyId)
+
+			//活跃(客户状态)
+			tmpStatus := v.Status
+			if v.IsShare == 1 {
+				tmpStatus = v.Status + "(共享)"
+			}
+
+			companyList := &company.CompanyListItem{
+				CompanyId:        v.CompanyId,
+				CompanyName:      v.CompanyName,
+				CreditCode:       v.CreditCode,
+				CompanyCode:      v.CompanyCode,
+				StartDate:        v.StartDate,
+				EndDate:          v.EndDate,
+				LoseReason:       v.LoseReason,
+				RenewalReason:    v.RenewalReason,
+				FreezeReason:     v.FreezeReason,
+				LossTime:         v.LossTime,
+				Status:           tmpStatus,
+				CompanyType:      v.CompanyType,
+				ApproveStatus:    v.ApproveStatus,
+				SellerName:       v.SellerName,
+				SellerId:         v.SellerId,
+				SellerIds:        v.SellerIds,
+				ExpireDay:        v.ExpireDay,
+				FreezeTime:       v.FreezeTime,
+				GroupId:          v.GroupId,
+				GroupIds:         v.GroupIds,
+				DepartmentId:     v.DepartmentId,
+				IndustryName:     v.IndustryName,
+				IsSuspend:        v.IsSuspend,
+				CreatedTime:      v.CreatedTime,
+				Source:           v.Source,
+				Province:         v.Province,
+				City:             v.City,
+				Address:          v.Address,
+				Reasons:          v.Reasons,
+				FreezeStartDate:  v.FreezeStartDate,
+				FreezeEndDate:    v.FreezeEndDate,
+				FreezeExpireDays: v.FreezeExpireDays,
+				BtnItem:          v.BtnItem,
+				ProductId:        v.ProductId,
+				FormalTime:       v.FormalTime,
+				IsShared:         v.IsShared,
+				RegionType:       v.RegionType,
+				FiccPackageType:  v.FiccPackageType,
+				FiccLastViewTime: v.FiccLastViewTime,
+				RaiLastViewTime:  v.RaiLastViewTime,
+				//FiccView:         viewTotal[0],
+				//RaiView:          viewTotal[1],
+				//FiccView: ficcViewTotal,
+				//RaiView:  raiViewTotal,
+				FiccView:        v.FiccView,
+				RaiView:         v.RaiView,
+				FiccTryOutDay:   v.FiccTryOutDay,
+				RaiTryOutDay:    v.RaiTryOutDay,
+				AllViewTotal:    v.AllViewTotal,
+				RoadShowTotal:   v.RoadShowTotal,
+				TryStageSlice:   v.TryStageSlice,
+				Deadline:        v.Deadline,
+				WeekViewActive:  v.WeekViewActive,
+				IsShare:         v.IsShare,
+				ShareSeller:     v.ShareSeller,
+				ShareSellerId:   v.ShareSellerId,
+				LastServiceTime: v.LastServiceTime,
+				ServiceTimes:    v.ServiceTimes,
+			}
+			companyLists = append(companyLists, companyList)
+		}
+	}
+	if companyLists == nil {
+		companyLists = make([]*company.CompanyListItem, 0)
+	}
+	page = paging.GetPaging(currentIndex, pageSize, total)
+	resp := new(company.CompanyListResp)
+	resp.List = companyLists
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+
 }

+ 4 - 4
models/company/company.go

@@ -1549,9 +1549,9 @@ type RemarkResp struct {
 	Remark                 string `description:"未续约说明"`
 	ProductName            string `description:"客户产品:ficc:权益:"`
 	CreateTime             string `description:"添加时间"`
-	CompanyProductRemakrId int
-	Mark                   int `description:"是否标记 0不是 1是"`
-	ButtonDel   bool   `description:"删除权限"`
+	CompanyProductRemarkId int
+	Mark                   int  `description:"是否标记 0不是 1是"`
+	ButtonDel              bool `description:"删除权限"`
 }
 
 type RoadShowTotalSlice struct {
@@ -1908,4 +1908,4 @@ func GetCompanyListByCondition(condition string, pars []interface{}, fieldArr []
 	sql := fmt.Sprintf(`SELECT %s FROM company WHERE 1=1 %s %s`, fields, condition, order)
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
-}
+}

+ 9 - 0
routers/commentsRouter.go

@@ -8530,6 +8530,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyController"],
+        beego.ControllerComments{
+            Method: "CompanyShareListByCity",
+            Router: `/share/list/city`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyController"],
         beego.ControllerComments{
             Method: "CompanyShareMark",