Browse Source

no message

zhangchuanxing 1 week ago
parent
commit
d9506a2d91
3 changed files with 163 additions and 37 deletions
  1. 154 36
      controllers/cygx/rai_serve.go
  2. 4 1
      models/cygx/rai_serve_bill.go
  3. 5 0
      models/cygx/rai_serve_company.go

+ 154 - 36
controllers/cygx/rai_serve.go

@@ -357,7 +357,7 @@ func (this *RaiServeCoAntroller) List() {
 	isExport, _ := this.GetBool("IsExport")
 	resp := new(cygx.CygxRaiServeCompanyListResp)
 	if isExport {
-		pageSize = 999
+		pageSize = 9999
 	}
 	var startSize int
 	if pageSize <= 0 {
@@ -441,10 +441,13 @@ func (this *RaiServeCoAntroller) List() {
 		companyIds = append(companyIds, v.CompanyId)
 	}
 
-	mapWeekAmount := make(map[string]float64) //周度服务量
+	mapWeekAmount := make(map[string]float64)  //周度服务量
+	mapMonthAmount := make(map[string]float64) //月度服务量
 	weeks := 4
+	months := 3
 	if isExport {
 		weeks = 12 // 下载获取近12周的数据
+		months = 6
 	}
 	lencompanyIds := len(companyIds)
 	if lencompanyIds > 0 {
@@ -475,14 +478,21 @@ func (this *RaiServeCoAntroller) List() {
 		}
 
 		now := time.Now()
-
 		for _, v := range listBill {
 			for i := 0; i < weeks; i++ {
 				// 计算当前周的周一
 				monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
 				weekmonday := monday.Format(utils.FormatDate)
 				if v.WeekStartDate == weekmonday {
-					mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
+					mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
+				}
+			}
+			for i := 0; i < months; i++ {
+				// 计算当前月的第一天
+				monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, -i, 0)
+				monthFirstDay := monthday.Format(utils.FormatDate)
+				if v.MonthStartDate == monthFirstDay {
+					mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)] += v.ServeCount
 				}
 			}
 		}
@@ -504,16 +514,29 @@ func (this *RaiServeCoAntroller) List() {
 		item.Status = v.Status
 		item.PermissionName = v.PermissionName
 		item.IsUserMaker = v.IsUserMaker
-		item.ThisWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 0)]
-		item.LastWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 1)]
-		item.TwoWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 2)]
-		item.ThreeWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 3)]
+		item.ThisWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 0)]
+		item.LastWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 1)]
+		item.TwoWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 2)]
+		item.ThreeWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 3)]
+
+		item.ThisMonthAmount = mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 0)]
+		item.LastMonthAmount = mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]
+		item.TwoMonthAmount = mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)]
+		if item.TwoMonthAmount == 0 || item.LastMonthAmount-item.TwoMonthAmount == 0 {
+			item.LastMonthQoq = "0%" //上月环比=(上月服务量-上上月服务量)/上上月服务量,当数值≤-20%时,用红色字显示
+		} else {
+			item.LastMonthQoq = fmt.Sprint(utils.SubFloatToString((item.LastMonthAmount-item.TwoMonthAmount)/item.TwoMonthAmount*100, 2)) + "%"
+			if (item.LastMonthAmount-item.TwoMonthAmount)/item.TwoMonthAmount <= 0.2 {
+				item.LastMonthQoqIsRed = true
+			}
+		}
+
 		resp.List = append(resp.List, item)
 	}
 
 	//导出excel
 	if isExport {
-		RaiServeListExport(this, resp, mapWeekAmount, br)
+		RaiServeListExport(this, resp, mapWeekAmount, mapMonthAmount, br)
 		return
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
@@ -525,10 +548,13 @@ func (this *RaiServeCoAntroller) List() {
 }
 
 // EnterScoreScoreListExport 导出Excel
-func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, br *models.BaseResponse) {
+func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, mapMonthAmount map[string]float64, br *models.BaseResponse) {
 	weeks := 12 // 下载获取近12周的数据
+	months := 6 // 下载获取近6个月的数据
 	mapWeekFormat := make(map[int]string)
+	mapMonthFormat := make(map[int]string)
 	now := time.Now()
+
 	for i := 0; i < weeks; i++ {
 		// 计算当前周的周一
 		monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
@@ -537,7 +563,11 @@ func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompan
 		weeksunday := sunday.Format(utils.FormatMonthDayUnSpace2)
 		mapWeekFormat[i] = weekmonday + "~" + weeksunday
 	}
-
+	for i := 0; i < months; i++ {
+		// 处理月份
+		monthday := now.AddDate(0, -i, 0)
+		mapMonthFormat[i] = fmt.Sprint(int(monthday.Month()), "月")
+	}
 	dir, err := os.Executable()
 	exPath := filepath.Dir(dir)
 	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
@@ -605,6 +635,32 @@ func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompan
 	cellF.SetStyle(style)
 	cellF.SetValue("合同金额")
 
+	cellMonth1 := titleRow.AddCell()
+	cellMonth1.SetStyle(style)
+	cellMonth1.SetValue("本月服务量")
+
+	cellMonthQoQ := titleRow.AddCell()
+	cellMonthQoQ.SetStyle(style)
+	cellMonthQoQ.SetValue("上月环比")
+
+	cellMonth2 := titleRow.AddCell()
+	cellMonth2.SetStyle(style)
+	cellMonth2.SetValue("上月服务量")
+
+	cellMonth3 := titleRow.AddCell()
+	cellMonth3.SetStyle(style)
+	cellMonth3.SetValue("上上月服务量")
+
+	for i := 0; i < months; i++ {
+		if i < 3 {
+			continue
+		}
+		// 计算当前周的周一
+		cellMonthi := titleRow.AddCell()
+		cellMonthi.SetStyle(style)
+		cellMonthi.SetValue(mapMonthFormat[i])
+	}
+
 	cellG := titleRow.AddCell()
 	cellG.SetStyle(style)
 	cellG.SetValue("签约套餐")
@@ -639,46 +695,72 @@ func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompan
 		dataRow := sheel.AddRow()
 		dataRow.SetHeight(20)
 
-		cellA := dataRow.AddCell()
+		cellAData := dataRow.AddCell()
 		if v.IsUserMaker == -1 {
-			cellA.SetStyle(redStyle)
+			cellAData.SetStyle(redStyle)
 		} else {
-			cellA.SetStyle(style)
+			cellAData.SetStyle(style)
 		}
-		cellA.SetValue(v.CompanyName)
+		cellAData.SetValue(v.CompanyName)
 
 		cellWeekData := dataRow.AddCell()
 		cellWeekData.SetStyle(style)
 		cellWeekData.SetValue(v.ServeCoverageRate)
 
-		cellB := dataRow.AddCell()
-		cellB.SetStyle(style)
-		cellB.SetValue(v.Status)
+		cellBData := dataRow.AddCell()
+		cellBData.SetStyle(style)
+		cellBData.SetValue(v.Status)
+
+		cellCData := dataRow.AddCell()
+		cellCData.SetStyle(style)
+		cellCData.SetValue(v.SellerName)
+
+		cellDData := dataRow.AddCell()
+		cellDData.SetStyle(style)
+		cellDData.SetValue(v.ShareSeller)
 
-		cellC := dataRow.AddCell()
-		cellC.SetStyle(style)
-		cellC.SetValue(v.SellerName)
+		cellEData := dataRow.AddCell()
+		cellEData.SetStyle(style)
+		cellEData.SetValue(v.StartDate + "~" + v.EndDate)
 
-		cellD := dataRow.AddCell()
-		cellD.SetStyle(style)
-		cellD.SetValue(v.ShareSeller)
+		cellFData := dataRow.AddCell()
+		cellFData.SetStyle(style)
+		cellFData.SetValue(v.Money)
 
-		cellE := dataRow.AddCell()
-		cellE.SetStyle(style)
-		cellE.SetValue(v.StartDate + "~" + v.EndDate)
+		cellMonth1Data := dataRow.AddCell()
+		cellMonth1Data.SetStyle(style)
+		cellMonth1Data.SetValue(mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 0)])
 
-		cellF := dataRow.AddCell()
-		cellF.SetStyle(style)
-		cellF.SetValue(v.Money)
+		cellMonthQoQData := dataRow.AddCell()
+		var cellMonthQoQStr string
+		if mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] == 0 || mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] == 0 {
+			cellMonthQoQStr = "0%"
+		} else {
+			cellMonthQoQStr = fmt.Sprint(utils.SubFloatToString((mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)])/mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)]*100, 2)) + "%"
+			if (mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]-mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)])/mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)] <= 0.2 {
+				cellMonthQoQData.SetStyle(redStyle) //小于0.2做标红处理
+			} else {
+				cellMonthQoQData.SetStyle(style)
+			}
+		}
+		cellMonthQoQData.SetValue(cellMonthQoQStr)
+		for i := 0; i < months; i++ {
+			if i == 0 {
+				continue
+			}
+			cellMonthData := dataRow.AddCell()
+			cellMonthData.SetStyle(style)
+			cellMonthData.SetValue(mapMonthAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)])
+		}
 
-		cellG := dataRow.AddCell()
-		cellG.SetStyle(style)
-		cellG.SetValue(v.PermissionName)
+		cellGData := dataRow.AddCell()
+		cellGData.SetStyle(style)
+		cellGData.SetValue(v.PermissionName)
 
 		for i := 0; i < weeks; i++ {
-			cellWei := dataRow.AddCell()
-			cellWei.SetStyle(style)
-			cellWei.SetValue(mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)])
+			cellWeiData := dataRow.AddCell()
+			cellWeiData.SetStyle(style)
+			cellWeiData.SetValue(mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", i)])
 		}
 
 	}
@@ -889,6 +971,7 @@ func (this *RaiServeCoAntroller) CoverageRate() {
 // @Param   TagId   query   int  false       "标签ID"
 // @Param   ServeTypeId   int   int	  false       "服务类型ID"
 // @Param   WhatWeek   query   int  false       "哪一周 ,1:本周、2:上周、3:上上周、4上三周"
+// @Param   WhatMonth   query   int  false       "哪一月 ,1:本月、2:上月、3:上上月"
 // @Success 200 {object} cygx.RaiServeTagListResp
 // @router /rai_serve/bill_list [get]
 func (this *RaiServeCoAntroller) BillList() {
@@ -911,6 +994,7 @@ func (this *RaiServeCoAntroller) BillList() {
 	tagId, _ := this.GetInt("TagId")
 	serveTypeId, _ := this.GetInt("ServeTypeId")
 	whatWeek, _ := this.GetInt("WhatWeek")
+	whatMonth, _ := this.GetInt("WhatMonth")
 
 	var startSize int
 	if pageSize <= 0 {
@@ -943,6 +1027,14 @@ func (this *RaiServeCoAntroller) BillList() {
 		pars = append(pars, monday.Format(utils.FormatDate))
 	}
 
+	if whatMonth > 0 {
+		now := time.Now()
+		// 计算所选月份的第一天
+		monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, -whatMonth+1, 0)
+		condition += " AND  month_start_date = ? "
+		pars = append(pars, monthday.Format(utils.FormatDate))
+	}
+
 	condition += " AND  company_id = ? "
 	pars = append(pars, companyId)
 	if serveTypeId > 0 {
@@ -983,6 +1075,13 @@ func (this *RaiServeCoAntroller) BillList() {
 				activitySpecialIds = append(activitySpecialIds, v.SourceId)
 			case utils.CYGX_OBJ_RS_CALENDAR:
 				rsCalendarIds = append(rsCalendarIds, v.SourceId)
+			case utils.CYGX_OBJ_ACTIVITYVIDEO:
+				activityIds = append(activityIds, v.ActivityId)
+			case utils.CYGX_OBJ_ACTIVITYVOICE:
+				activityIds = append(activityIds, v.ActivityId)
+			}
+			if v.ServeTypeName == "阅读uv" {
+				v.ServeTypeName = "报告阅读uv" //服务类型名称做一下,映射修改
 			}
 		}
 
@@ -1041,7 +1140,26 @@ func (this *RaiServeCoAntroller) BillList() {
 				} else {
 					v.Tag = strings.Join(mapRsCalendarLabel[v.SourceId], ",")
 				}
+			case utils.CYGX_OBJ_ACTIVITYVIDEO:
+				if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
+					v.Tag = v.ChartPermissionName
+				} else {
+					v.Tag = strings.Join(mapActivityIndustrialLabel[v.ActivityId], ",")
+					if len(mapActivitySubjectLabel[v.ActivityId]) > 0 {
+						v.Tag += "," + strings.Join(mapActivitySubjectLabel[v.ActivityId], ",")
+					}
+				}
+			case utils.CYGX_OBJ_ACTIVITYVOICE:
+				if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
+					v.Tag = v.ChartPermissionName
+				} else {
+					v.Tag = strings.Join(mapActivityIndustrialLabel[v.ActivityId], ",")
+					if len(mapActivitySubjectLabel[v.ActivityId]) > 0 {
+						v.Tag += "," + strings.Join(mapActivitySubjectLabel[v.ActivityId], ",")
+					}
+				}
 			}
+
 		}
 		resp.List = list
 	}

+ 4 - 1
models/cygx/rai_serve_bill.go

@@ -130,6 +130,7 @@ type CygxRaiServeBillResp struct {
 	ViewTime            string  `comment:"浏览时间"`
 	ChartPermissionId   int     `description:"行业id"`
 	ChartPermissionName string  `description:"行业名称"`
+	ActivityId          int     `description:"活动ID"`
 }
 
 type CygxRaiServeBillListResp struct {
@@ -154,7 +155,7 @@ func GetCygxRaiServeBillRespList(condition string, pars []interface{}, startSize
 	if condition != "" {
 		sql += condition
 	}
-	sql += ` ORDER BY bill_id DESC   LIMIT ?,? `
+	sql += ` ORDER BY view_time DESC   LIMIT ?,? `
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
@@ -178,6 +179,8 @@ type CygxRaiServeBill struct {
 	Source           string    `comment:"来源 "`
 	WeekStartDate    string    `comment:"周一开始日期"`
 	WeekEndDate      string    `comment:"周日结束日期"`
+	MonthStartDate   string    `comment:"月份开始日期"`
+	MonthEndDate     string    `comment:"月份结束日期"`
 	CreateTime       time.Time `comment:"创建时间"`
 	ViewTime         string    `comment:"浏览时间"`
 }

+ 5 - 0
models/cygx/rai_serve_company.go

@@ -42,6 +42,11 @@ type CygxRaiServeCompanyResp struct {
 	LastWeekAmount    float64 `comment:"上周互动量"`
 	TwoWeekAmount     float64 `comment:"上上周互动量"`
 	ThreeWeekAmount   float64 `comment:"上三周互动量"`
+	ThisMonthAmount   float64 `comment:"本月互动量"`
+	LastMonthAmount   float64 `comment:"上月互动量"`
+	LastMonthQoq      string  `comment:"上月环比"`
+	LastMonthQoqIsRed bool    `comment:"上月环比是否标红"`
+	TwoMonthAmount    float64 `comment:"上上月互动量"`
 }
 
 type CygxRaiServeCompanyListResp struct {