Browse Source

修改海外客户bug

hongze 1 năm trước cách đây
mục cha
commit
cd69606edd

+ 13 - 52
controllers/overseas_custom/custom.go

@@ -109,7 +109,7 @@ func (this *OverseasCustomController) CustomList() {
 	if companyStatus == "试用" {
 		condition += ` AND m.company_status='试用' AND m.overseas_status='' `
 	} else if companyStatus == "正式" {
-		condition += ` AND m.company_status='正式' `
+		condition += ` AND (m.company_status='正式' OR m.overseas_status='正式') `
 	}
 
 	total, err := obj.GetCustomListCount(condition, pars, companyStatus)
@@ -132,62 +132,11 @@ func (this *OverseasCustomController) CustomList() {
 		}
 	}
 
-	statisticsDataList, err := obj.GetCustomTotal(condition, 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 statisticsDataList {
-		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)
-	}
-
-	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)
-	}
-
 	page := paging.GetPaging(currentIndex, pageSize, total)
 
 	resp := new(overseas_custom.CustomListResp)
 	resp.Paging = page
 	resp.List = list
-	resp.StatisticsData = statisticsDataStatusList
-	resp.OverseasLabelData = labelList
 
 	br.Ret = 200
 	br.Success = true
@@ -493,6 +442,12 @@ func (this *OverseasCustomController) CustomStatistics() {
 		return
 	}
 
+	total, err := obj.GetCustomOverseasStatusTotal(condition, pars)
+	if err != nil && err.Error() == utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取海外客户总计状态失败, Err: " + err.Error()
+		return
+	}
 	statisticsDataStatusList := make([]*overseas_custom.CustomTotal, 0)
 	statisticsDataMap := make(map[string]int)
 	for _, v := range list {
@@ -507,6 +462,12 @@ func (this *OverseasCustomController) CustomStatistics() {
 		if val, ok := statisticsDataMap[v]; ok {
 			item.Total = val
 		}
+
+		if v == "正式" {
+			item.Total = item.Total + total
+		} else if v == "试用" {
+			item.Total = item.Total - total
+		}
 		statisticsDataStatusList = append(statisticsDataStatusList, item)
 	}
 

+ 49 - 4
models/overseas_custom/custom.go

@@ -75,6 +75,53 @@ func (obj *Custom) GetCustomTotal(condition string, pars []interface{}) (list []
 	return
 }
 
+func (obj *Custom) GetCustomOverseasStatusTotal(condition string, pars []interface{}) (total int, err error) {
+	o := orm.NewOrm()
+	sql := ``
+	var databaseName string
+	if utils.RunMode == "debug" {
+		databaseName = "test_v2_hongze_rddp"
+	} else {
+		databaseName = "hongze_rddp"
+	}
+
+	sql = `SELECT COUNT(1) AS total FROM (
+				SELECT a.company_id,a.company_name,a.nation,b.seller_id,b.seller_name,
+				CASE b.status 
+				WHEN '正式' THEN '正式'
+				WHEN '永续' THEN '正式'
+				WHEN '试用' THEN '试用'
+				ELSE '关闭' END AS company_status,
+				b.view_total,b.road_show_total,a.created_time AS create_time,b.last_view_time,a.is_hide,a.overseas_status,b.overseas_label
+				FROM company AS a
+				INNER JOIN company_product AS b ON a.company_id=b.company_id
+				INNER JOIN overseas_custom_seller AS c ON b.seller_id=c.seller_id
+				WHERE b.is_overseas = 0
+				UNION ALL
+				SELECT t.company_id+10000000,t.company_name,t.nation,t.seller_id,t.seller_name,
+				CASE t.enabled
+				WHEN 0 THEN '关闭'
+				ELSE '试用' END AS company_status,
+				t.view_total,0 AS road_show_total,t.create_time,'' AS last_view_time,t.is_hide,t.overseas_status,t.overseas_label
+				FROM %s.english_company AS t
+				INNER JOIN overseas_custom_seller AS n ON t.seller_id=n.seller_id
+				)AS m
+		WHERE 1=1
+ AND m.is_hide=0  
+AND m. overseas_status='正式' `
+
+	if condition != "" {
+		sql += condition
+	}
+
+	sql += ` GROUP BY m.overseas_status `
+
+	sql = fmt.Sprintf(sql, databaseName)
+
+	err = o.Raw(sql, pars).QueryRow(&total)
+	return
+}
+
 // GetCompanyIdsByKeyword 关键词获取客户IDs
 func (obj *Custom) GetCompanyIdsByKeyword(keyword string) (companyIds []int, err error) {
 	o := orm.NewOrm()
@@ -221,10 +268,8 @@ func (obj *Custom) GetCustomList(condition string, pars []interface{}, companySt
 }
 
 type CustomListResp struct {
-	Paging            *paging.PagingItem
-	List              []*Custom
-	StatisticsData    []*CustomTotal
-	OverseasLabelData []*OverseasLabelTotal
+	Paging *paging.PagingItem
+	List   []*Custom
 }
 
 type CustomHideReq struct {

+ 18 - 0
routers/commentsRouter.go

@@ -7198,6 +7198,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"],
+        beego.ControllerComments{
+            Method: "CustomLabelStatistics",
+            Router: `/custom/label/statistics`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"],
         beego.ControllerComments{
             Method: "CustomList",
@@ -7216,6 +7225,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"],
+        beego.ControllerComments{
+            Method: "CustomStatistics",
+            Router: `/custom/statistics`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/overseas_custom:OverseasCustomController"],
         beego.ControllerComments{
             Method: "CustomStatusSet",