|
@@ -7,6 +7,7 @@ import (
|
|
|
"hongze/hz_crm_api/models"
|
|
|
"hongze/hz_crm_api/models/company"
|
|
|
"hongze/hz_crm_api/models/response"
|
|
|
+ "hongze/hz_crm_api/models/system"
|
|
|
"hongze/hz_crm_api/services"
|
|
|
cygxService "hongze/hz_crm_api/services/cygx"
|
|
|
"os"
|
|
@@ -1808,6 +1809,319 @@ func (this *StatisticCompanyMergerController) CompanyContractPercentageListV2()
|
|
|
br.Data = resp
|
|
|
}
|
|
|
|
|
|
+// @Title 权益客户未续约率下载
|
|
|
+// @Description 权益客户未续约率下载接口
|
|
|
+// @Param AdminId query string true "销售id,多个用英文逗号隔开,空字符串为全部"
|
|
|
+// @Param StartDate query string false "开始日期"
|
|
|
+// @Param EndDate query string false "结束日期"
|
|
|
+// @Param ExportType query int true "下载类型 1:下载当前销售的合同明细数据;2:下载所有销售未续约数据列表"
|
|
|
+// @Success 200 {object} response.IncrementalCompanyListResp
|
|
|
+// @router /merge_company/company_contract_percentage/list_export [get]
|
|
|
+func (this *StatisticCompanyMergerController) CompanyContractPercentageListExport() {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ pageSize, _ := this.GetInt("PageSize")
|
|
|
+ currentIndex, _ := this.GetInt("CurrentIndex")
|
|
|
+ exportType, _ := this.GetInt("ExportType")
|
|
|
+ adminId := this.GetString("AdminId")
|
|
|
+ contractDataType := this.GetString("ContractDataType")
|
|
|
+ startDate := this.GetString("StartDate")
|
|
|
+ endDate := this.GetString("EndDate")
|
|
|
+ //initendDate := this.GetString("EndDate")
|
|
|
+ if startDate == "" || endDate == "" {
|
|
|
+ br.Msg = "开始时间或结束时间不能为空"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断结束时间是否晚于当前时间,如果晚于当前时间,那么就把当前时间作为截止时间。
|
|
|
+ endDateTime, _ := time.Parse(utils.FormatDate, endDate)
|
|
|
+ if endDateTime.After(time.Now()) {
|
|
|
+ endDate = time.Now().Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+ //fmt.Println("endDate", endDate)
|
|
|
+ if contractDataType == "" {
|
|
|
+ contractDataType = "续约合同"
|
|
|
+ }
|
|
|
+
|
|
|
+ var startSize int
|
|
|
+ if pageSize <= 0 {
|
|
|
+ pageSize = 10000
|
|
|
+ }
|
|
|
+ if currentIndex <= 0 {
|
|
|
+ currentIndex = 1
|
|
|
+ }
|
|
|
+ startSize = utils.StartIndex(currentIndex, pageSize)
|
|
|
+
|
|
|
+ var condition string
|
|
|
+ var pars []interface{}
|
|
|
+
|
|
|
+ if exportType == 1 {
|
|
|
+ //条件
|
|
|
+ if adminId != "" {
|
|
|
+ condition += ` AND a.seller_id_init in (` + adminId + `) `
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //权益有效合同
|
|
|
+ condition += ` AND c.product_id = 2 AND a.status = 1 `
|
|
|
+
|
|
|
+ //var list []*models.IncrementalList
|
|
|
+
|
|
|
+ condition1 := condition
|
|
|
+ pars1 := pars
|
|
|
+ condition1 += ` AND a.end_date >= ? AND a.end_date <= ? `
|
|
|
+ pars1 = append(pars1, startDate, endDate)
|
|
|
+ condition1 += ` AND a.company_ascribe_id > 0 AND a.company_ascribe_id !=9 ` // 已确认未续约
|
|
|
+
|
|
|
+ //if contractDataType == "续约合同" || contractDataType == "确认不续约合同" {
|
|
|
+ //不续约列表数据
|
|
|
+ listRenewal, err := models.GetIncrementalCompanyMergeListEnd(condition1, pars1, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //}
|
|
|
+
|
|
|
+ conditionEnd1 := condition
|
|
|
+ parsEnd1 := pars
|
|
|
+
|
|
|
+ conditionEnd1 += ` AND a.end_date >= ? AND a.end_date <= ? AND a.company_ascribe_id !=9 `
|
|
|
+ parsEnd1 = append(parsEnd1, startDate, endDate)
|
|
|
+
|
|
|
+ //if contractDataType == "到期合同" {
|
|
|
+ //到期列表数据
|
|
|
+ listEndDate, err := models.GetIncrementalCompanyMergeListEnd(conditionEnd1, parsEnd1, startSize, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var companyContractIds []int
|
|
|
+ for _, v := range listRenewal {
|
|
|
+ companyContractIds = append(companyContractIds, v.CompanyContractId)
|
|
|
+ v.SellerId = v.SellerIdInit
|
|
|
+ }
|
|
|
+ for _, v := range listEndDate {
|
|
|
+ companyContractIds = append(companyContractIds, v.CompanyContractId)
|
|
|
+ v.SellerId = v.SellerIdInit
|
|
|
+ }
|
|
|
+
|
|
|
+ //合同归因标签
|
|
|
+ mapGetCompanyAscribeContent, mapContent := services.GetCompanyContractAscribeContentMap(companyContractIds)
|
|
|
+
|
|
|
+ //合并合同所对应的权限
|
|
|
+ mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range listRenewal {
|
|
|
+ v.PermissionName = mappermissionName[v.CompanyContractId]
|
|
|
+ if mapGetCompanyAscribeContent[v.CompanyContractId] != "" {
|
|
|
+ v.Content = mapContent[v.CompanyContractId]
|
|
|
+ v.AscribeContent = mapGetCompanyAscribeContent[v.CompanyContractId]
|
|
|
+ v.IsShowNoRenewedNote = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for _, v := range listEndDate {
|
|
|
+ v.PermissionName = mappermissionName[v.CompanyContractId]
|
|
|
+ if mapGetCompanyAscribeContent[v.CompanyContractId] != "" {
|
|
|
+ v.Content = mapContent[v.CompanyContractId]
|
|
|
+ v.AscribeContent = mapGetCompanyAscribeContent[v.CompanyContractId]
|
|
|
+ v.IsShowNoRenewedNote = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创建excel
|
|
|
+ dir, err := os.Executable()
|
|
|
+ exPath := filepath.Dir(dir)
|
|
|
+ downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
|
|
|
+ xlsxFile := xlsx.NewFile()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "生成文件失败"
|
|
|
+ br.ErrMsg = "生成文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ style := xlsx.NewStyle()
|
|
|
+ alignment := xlsx.Alignment{
|
|
|
+ Horizontal: "center",
|
|
|
+ Vertical: "center",
|
|
|
+ WrapText: true,
|
|
|
+ }
|
|
|
+ style.Alignment = alignment
|
|
|
+ style.ApplyAlignment = true
|
|
|
+ if exportType == 1 {
|
|
|
+ for pidIndex := 0; pidIndex <= 1; pidIndex++ {
|
|
|
+ var sheetName string
|
|
|
+ var listDate []*models.IncrementalList
|
|
|
+ if pidIndex == 0 {
|
|
|
+ sheetName = "确认不续约合同"
|
|
|
+ listDate = listRenewal
|
|
|
+ } else {
|
|
|
+ sheetName = "到期合同"
|
|
|
+ listDate = listEndDate
|
|
|
+ }
|
|
|
+ sheet, err := xlsxFile.AddSheet(sheetName)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //标头
|
|
|
+ rowTitle := sheet.AddRow()
|
|
|
+ cellA := rowTitle.AddCell()
|
|
|
+ cellA.Value = "客户名称"
|
|
|
+ cellB := rowTitle.AddCell()
|
|
|
+ cellB.Value = "客户状态"
|
|
|
+ cellC := rowTitle.AddCell()
|
|
|
+ cellC.Value = "所属销售"
|
|
|
+ cellD := rowTitle.AddCell()
|
|
|
+ cellD.Value = "合同期限"
|
|
|
+ cellE := rowTitle.AddCell()
|
|
|
+ cellE.Value = "签约套餐"
|
|
|
+ cellF := rowTitle.AddCell()
|
|
|
+ cellF.Value = "合同金额"
|
|
|
+
|
|
|
+ if pidIndex == 0 {
|
|
|
+ cellG := rowTitle.AddCell()
|
|
|
+ cellG.Value = "不续约归因"
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, item := range listDate {
|
|
|
+ row := sheet.AddRow()
|
|
|
+ cellAData := row.AddCell()
|
|
|
+ cellAData.Value = item.CompanyName
|
|
|
+ cellBData := row.AddCell()
|
|
|
+ cellBData.Value = item.ProductStatus
|
|
|
+ cellCData := row.AddCell()
|
|
|
+ cellCData.Value = item.SellerName
|
|
|
+ cellDData := row.AddCell()
|
|
|
+ cellDData.Value = item.StartDate + "~" + item.EndDate
|
|
|
+ cellEData := row.AddCell()
|
|
|
+ cellEData.Value = item.PermissionName
|
|
|
+ cellFData := row.AddCell()
|
|
|
+ cellFData.Value = fmt.Sprint(item.Money)
|
|
|
+ if pidIndex == 0 {
|
|
|
+ cellGData := row.AddCell()
|
|
|
+ cellGData.Value = item.Content
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存文件失败"
|
|
|
+ br.ErrMsg = "保存文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ var sheetName string
|
|
|
+ //var listDate []*models.IncrementalList
|
|
|
+ sheetName = "未续约率"
|
|
|
+ sheet, err := xlsxFile.AddSheet(sheetName)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "新增Sheet失败"
|
|
|
+ br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //标头
|
|
|
+ rowTitle := sheet.AddRow()
|
|
|
+ cellA := rowTitle.AddCell()
|
|
|
+ cellA.Value = "姓名"
|
|
|
+ cellB := rowTitle.AddCell()
|
|
|
+ cellB.Value = "确认不续约合同数"
|
|
|
+ cellC := rowTitle.AddCell()
|
|
|
+ cellC.Value = "确认不续约合同金额"
|
|
|
+ cellD := rowTitle.AddCell()
|
|
|
+ cellD.Value = "到期合同数"
|
|
|
+ cellE := rowTitle.AddCell()
|
|
|
+ cellE.Value = "到期合同金额"
|
|
|
+ cellF := rowTitle.AddCell()
|
|
|
+ cellF.Value = "确认不续约率"
|
|
|
+
|
|
|
+ listRaiSeller, err := system.GetSysuserRaiListNoServer()
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取权益销售信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //NoRenewalContractTotal int `description:"确认不续约合同数"`
|
|
|
+ //NoRenewalContractMoney int `description:"确认不续约合同金额"`
|
|
|
+ //ExpireRenewalContractTotal int `description:"到期合同数量"`
|
|
|
+ //ExpireRenewalContractMoney int `description:"到期合同总金额"`
|
|
|
+ //NoRenewalContractPercentage string `description:"确认不续约率"`
|
|
|
+ mapNoRenewalContractTotal := make(map[int]int)
|
|
|
+ mapNoRenewalContractMoney := make(map[int]float64)
|
|
|
+ mapExpireRenewalContractTotal := make(map[int]int)
|
|
|
+ mapExpireRenewalContractMoney := make(map[int]float64)
|
|
|
+
|
|
|
+ //mapData := make(map[int]*response.IncrementalCompanyPercentageExportResp)
|
|
|
+ for _, v := range listRenewal {
|
|
|
+ mapNoRenewalContractTotal[v.SellerId]++
|
|
|
+ mapNoRenewalContractMoney[v.SellerId] += v.Money
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range listEndDate {
|
|
|
+ mapExpireRenewalContractTotal[v.SellerId]++
|
|
|
+ mapExpireRenewalContractMoney[v.SellerId] += v.Money
|
|
|
+ }
|
|
|
+ for _, item := range listRaiSeller {
|
|
|
+ row := sheet.AddRow()
|
|
|
+ cellAData := row.AddCell()
|
|
|
+ cellAData.Value = item.RealName
|
|
|
+ cellBData := row.AddCell()
|
|
|
+ cellBData.Value = fmt.Sprint(mapNoRenewalContractTotal[item.AdminId])
|
|
|
+ cellCData := row.AddCell()
|
|
|
+ cellCData.Value = fmt.Sprint(mapNoRenewalContractMoney[item.AdminId])
|
|
|
+
|
|
|
+ cellEData := row.AddCell()
|
|
|
+ cellEData.Value = fmt.Sprint(mapExpireRenewalContractTotal[item.AdminId])
|
|
|
+ cellFData := row.AddCell()
|
|
|
+ cellFData.Value = fmt.Sprint(mapExpireRenewalContractMoney[item.AdminId])
|
|
|
+
|
|
|
+ cellGData := row.AddCell()
|
|
|
+
|
|
|
+ //分子或者分母为零的时候,不做计算
|
|
|
+ if mapNoRenewalContractMoney[item.AdminId] == 0 || mapExpireRenewalContractMoney[item.AdminId] == 0 {
|
|
|
+ cellGData.Value = "0%"
|
|
|
+ } else {
|
|
|
+ cellGData.Value = fmt.Sprint(utils.SubFloatToString(float64(mapNoRenewalContractMoney[item.AdminId])/float64(mapExpireRenewalContractMoney[item.AdminId])*100, 2), "%")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ err = xlsxFile.Save(downLoadnFilePath)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存文件失败"
|
|
|
+ br.ErrMsg = "保存文件失败"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
|
|
|
+ downloadFileName := "未续约率明细" + randStr + ".xlsx"
|
|
|
+ this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
|
|
|
+ defer func() {
|
|
|
+ os.Remove(downLoadnFilePath)
|
|
|
+ }()
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "导出成功"
|
|
|
+}
|
|
|
+
|
|
|
func init213() {
|
|
|
var condition string
|
|
|
var pars []interface{}
|