Ver código fonte

续约异常统计

xyxie 1 ano atrás
pai
commit
eb6b7a180b

+ 86 - 0
controllers/statistic_report.go

@@ -6357,3 +6357,89 @@ func (this *StatisticReportController) UnusualRenewCompanyStatistics() {
 	br.Msg = "获取成功"
 	br.Data = companyRenewRecordResp
 }
+
+// UnusualRenewCompanyList
+// @Title 获取未续约的公司合同列表
+// @Description 合同套餐列表
+// @Param   ProductId  query  int  false  "套餐类型: 1-FICC(默认); 2-权益"
+// @Param   StartDate   query   string  true       "开始日期,格式:2022-04"
+// @Param   EndDate   query   string  true       "结束日期,格式:2022-04"
+// @Success 200 {object} company.GetUnusualRenewListGroupMonthResp
+// @router /report/unusual_renew_company/chart [get]
+func (this *StatisticReportController) UnusualRenewCompanyList() {
+	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
+	}
+	// 起始日期
+	// 截止日期
+	productId, _ := this.GetInt("ProductId", 1)
+	startDate := this.GetString("StartDate")
+	endDate := this.GetString("EndDate")
+
+	if startDate == `` || endDate == `` {
+		br.Msg = "开始日期或结束日期不能为空"
+		return
+	}
+	allList := make([]*company.GetUnusualRenewListGroupMonth, 0)
+	resp := new(company.GetUnusualRenewListGroupMonthResp)
+	resp.List = allList
+	newStartDate := startDate + "-01"
+	newEndDate := endDate + "-01"
+
+	startDateTimer, _ := time.ParseInLocation(utils.FormatDate, newStartDate, time.Local)
+	endDateTimer, _ := time.ParseInLocation(utils.FormatDate, newEndDate, time.Local)
+	endDateTimer = endDateTimer.AddDate(0, 1, 0).Add(-1 * time.Second) //本月最后一天
+
+	// 按月分组
+	monthMap := make(map[string]int)
+	monthList := make([]string, 0)
+	tmpDate, _ := time.ParseInLocation(utils.FormatYearMonthDate, startDate, time.Local)
+	tmpEndDate, _ := time.ParseInLocation(utils.FormatYearMonthDate, endDate, time.Local)
+	for tmpDate.Before(tmpEndDate) || tmpDate == tmpEndDate {
+		monthMap[tmpDate.Format(utils.FormatYearMonthDate)] = 0
+		monthList = append(monthList, tmpDate.Format(utils.FormatYearMonthDate))
+		tmpDate = tmpDate.AddDate(0, 1, 0)
+
+	}
+
+	list, err := company.GetUnusualRenewList(startDateTimer, endDateTimer, productId)
+	if err != nil {
+		br.Msg = "数据异常"
+		br.ErrMsg = "数据异常,Err:" + err.Error()
+		return
+	}
+	if len(list) > 0 {
+		for _, v := range list {
+			t := v.ModifyTime.Format(utils.FormatYearMonthDate)
+			if num, ok := monthMap[t]; ok {
+				monthMap[t] = num + 1
+			}
+		}
+	}
+
+	for _, v := range monthList {
+		n, _ := monthMap[v]
+		tmp := &company.GetUnusualRenewListGroupMonth{
+			Date:       v,
+			CompanyNum: n,
+		}
+		allList = append(allList, tmp)
+	}
+	resp = &company.GetUnusualRenewListGroupMonthResp{
+		List: allList,
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 27 - 0
models/company/company_renewal_record.go

@@ -67,3 +67,30 @@ func (item *CompanyRenewalRecord) Add() (err error) {
 
 	return
 }
+
+type GetUnusualRenewListGroupMonth struct {
+	Date       string
+	CompanyNum int
+}
+
+type GetUnusualRenewListGroupMonthResp struct {
+	List []*GetUnusualRenewListGroupMonth
+}
+
+// GetUnusualRenewList 获取未续约公司列表
+func GetUnusualRenewList(startDate, endDate time.Time, productId int) (list []*CompanyRenewalRecord, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	* 
+FROM
+	company_renewal_record 
+WHERE
+	source = 1 
+	AND modify_time BETWEEN ? 
+	AND ? 
+	AND product_id = ?
+`
+	_, err = o.Raw(sql, startDate, endDate, productId).QueryRows(&list)
+
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -10546,6 +10546,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:StatisticReportController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:StatisticReportController"],
+        beego.ControllerComments{
+            Method: "UnusualRenewCompanyList",
+            Router: `/report/unusual_renew_company/chart`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:StatisticReportController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:StatisticReportController"],
         beego.ControllerComments{
             Method: "StackCompanyList",