Prechádzať zdrojové kódy

新增客户状态统计

hongze 1 rok pred
rodič
commit
c5105b6869
1 zmenil súbory, kde vykonal 86 pridanie a 0 odobranie
  1. 86 0
      controllers/overseas_custom/custom.go

+ 86 - 0
controllers/overseas_custom/custom.go

@@ -420,3 +420,89 @@ func (this *OverseasCustomController) CustomOverseasLabelSet() {
 	br.Success = true
 	br.Msg = "设置成功"
 }
+
+// @Title 海外客户统计数据
+// @Description 海外客户统计数据
+// @Param   Keywords	query	string	false	"关键词:客户名称/社会信用码/联系人手机号/邮箱"
+// @Param   SellerId	query	int		false	"销售ID"
+// @Success 200 {object} models.EnglishCompanyPageListResp
+// @router /custom/statistics [get]
+func (this *OverseasCustomController) CustomStatistics() {
+	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 cond string
+	var pars []interface{}
+	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...)
+
+		cond += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
+		pars = append(pars, companyIds)
+	}
+	if sellerId > 0 {
+		cond = ` AND m.seller_id=? `
+		pars = append(pars, sellerId)
+	}
+
+	list, err := obj.GetCustomTotal(cond, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
+		return
+	}
+
+	statisticsDataStatusList := make([]*overseas_custom.CustomTotal, 0)
+	statisticsDataMap := make(map[string]int)
+	for _, v := range list {
+		statisticsDataMap[v.CompanyStatus] = v.Total
+	}
+
+	var statusArr = [3]string{"试用", "正式", "关闭"}
+
+	for _, v := range statusArr {
+		item := new(overseas_custom.CustomTotal)
+		item.CompanyStatus = v
+		if val, ok := statisticsDataMap[v]; ok {
+			item.Total = val
+		}
+		statisticsDataStatusList = append(statisticsDataStatusList, item)
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = statisticsDataStatusList
+}