Browse Source

新增标签统计

hongze 1 year ago
parent
commit
6e32ddedae
1 changed files with 100 additions and 4 deletions
  1. 100 4
      controllers/overseas_custom/custom.go

+ 100 - 4
controllers/overseas_custom/custom.go

@@ -444,10 +444,11 @@ func (this *OverseasCustomController) CustomStatistics() {
 
 	keywords := this.GetString("Keywords", "")
 	sellerId, _ := this.GetInt("SellerId", 0)
+	customType, _ := this.GetInt("CustomType", 0)
 
 	obj := new(overseas_custom.Custom)
 
-	var cond string
+	var condition string
 	var pars []interface{}
 	if keywords != "" {
 		k := "%" + keywords + "%"
@@ -469,15 +470,23 @@ func (this *OverseasCustomController) CustomStatistics() {
 
 		companyIds = append(companyIds, enCompanyIds...)
 
-		cond += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
+		condition += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
 		pars = append(pars, companyIds)
 	}
 	if sellerId > 0 {
-		cond = ` AND m.seller_id=? `
+		condition += ` AND m.seller_id=? `
 		pars = append(pars, sellerId)
 	}
 
-	list, err := obj.GetCustomTotal(cond, pars)
+	if customType == 2 {
+		condition += ` AND m.is_hide=? `
+		pars = append(pars, 1)
+	} else {
+		condition += ` AND m.is_hide=? `
+		pars = append(pars, 0)
+	}
+
+	list, err := obj.GetCustomTotal(condition, pars)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
@@ -506,3 +515,90 @@ func (this *OverseasCustomController) CustomStatistics() {
 	br.Msg = "获取成功"
 	br.Data = statisticsDataStatusList
 }
+
+// @Title 海外客户标签统计数据
+// @Description 海外客户标签统计数据
+// @Param   Keywords	query	string	false	"关键词:客户名称/社会信用码/联系人手机号/邮箱"
+// @Param   SellerId	query	int		false	"销售ID"
+// @Success 200 {object} models.EnglishCompanyPageListResp
+// @router /custom/label/statistics [get]
+func (this *OverseasCustomController) CustomLabelStatistics() {
+	br := new(models.BaseResponse).Init()
+	br.IsSendEmail = false
+	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
+	}
+
+	keywords := this.GetString("Keywords", "")
+	sellerId, _ := this.GetInt("SellerId", 0)
+
+	obj := new(overseas_custom.Custom)
+
+	var condition string
+	var pars []interface{}
+
+	condition += " AND m.company_status = '试用' AND m.overseas_status='' "
+	if keywords != "" {
+		k := "%" + keywords + "%"
+		enCompanyIds, e := models.GetEnCompanyIdsByKeyword(k)
+		if e != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
+			return
+		}
+
+		//获取中文客户
+
+		companyIds, err := obj.GetCompanyIdsByKeyword(k)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
+			return
+		}
+
+		companyIds = append(companyIds, enCompanyIds...)
+
+		condition += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
+		pars = append(pars, companyIds)
+	}
+	if sellerId > 0 {
+		condition += ` AND m.seller_id=? `
+		pars = append(pars, sellerId)
+	}
+	overseasLabelDataList, err := obj.GetCustomOverseasLabelTotal(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取子标签总数失败, Err: " + err.Error()
+		return
+	}
+
+	labelDataMap := make(map[int]int)
+	for _, v := range overseasLabelDataList {
+		labelDataMap[v.OverseasLabel] = v.Total
+	}
+
+	var labelArr = [4]int{1, 2, 3, 4}
+
+	labelList := make([]*overseas_custom.OverseasLabelTotal, 0)
+
+	for _, v := range labelArr {
+		item := new(overseas_custom.OverseasLabelTotal)
+		item.OverseasLabel = v
+		if val, ok := labelDataMap[v]; ok {
+			item.Total = val
+		}
+		labelList = append(labelList, item)
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = labelList
+}