xiziwen 3 月之前
父节点
当前提交
742c60507e
共有 1 个文件被更改,包括 193 次插入197 次删除
  1. 193 197
      controller/census/income_list.go

+ 193 - 197
controller/census/income_list.go

@@ -50,11 +50,7 @@ func (this *InvoicePaymentController) IncomeChartList(c *gin.Context) {
 		incomeList = v
 		close(ch)
 	}
-	// 是否导出
-	if req.IsExport == 1 {
-		ExportIncomeList(c, incomeList.DataList)
-		return
-	}
+
 	resp.OkData("获取成功", incomeList, c)
 }
 
@@ -1068,63 +1064,6 @@ func getPaymentIncomeChartList(ch chan models.CensusIncomeChartResp, req fms.Inc
 	return
 }
 
-// ExportIncomeList 导出业务收入统计列表
-func ExportIncomeList(c *gin.Context, list []*fms.IncomeSummaryItem) {
-	// 生成Excel文件
-	xlsxFile := xlsx.NewFile()
-	style := xlsx.NewStyle()
-	alignment := xlsx.Alignment{
-		Horizontal: "center",
-		Vertical:   "center",
-		WrapText:   true,
-	}
-	style.Alignment = alignment
-	style.ApplyAlignment = true
-
-	sheetName := "业务收入统计表"
-	sheet, err := xlsxFile.AddSheet(sheetName)
-	if err != nil {
-		resp.FailData("新增Sheet失败", "Err:"+err.Error(), c)
-		return
-	}
-
-	// 数据表头
-	rowTitle := []string{"开票日期", "新客户(1)", "客户名称", "金额", "销售"}
-	titleRow := sheet.AddRow()
-	for i := range rowTitle {
-		v := titleRow.AddCell()
-		v.SetString(rowTitle[i])
-		v.SetStyle(style)
-	}
-	incomeSummaryItemList := make(fms.IncomeSummaryItemList, 0)
-	incomeSummaryItemList = list
-	sort.Sort(incomeSummaryItemList)
-	// 填充数据
-	for _, v := range incomeSummaryItemList {
-		dataRow := sheet.AddRow()
-		dataRow.AddCell().SetString(v.InvoiceDate.Format(utils.FormatDate)) // 开票日期
-		newCompany := 0
-		if v.ContractType == 1 {
-			newCompany = 1
-		}
-		dataRow.AddCell().SetString(strconv.Itoa(newCompany)) // 新客户
-		dataRow.AddCell().SetString(v.CompanyName)            // 客户名称
-		dataRow.AddCell().SetString(fmt.Sprint(v.Amount))     // 金额
-		dataRow.AddCell().SetString(v.SellerName)             // 销售员
-	}
-
-	// 输出文件
-	var buffer bytes.Buffer
-	_ = xlsxFile.Write(&buffer)
-	content := bytes.NewReader(buffer.Bytes())
-	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
-	fileName := sheetName + randStr + ".xlsx"
-
-	c.Writer.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName))
-	c.Writer.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
-	http.ServeContent(c.Writer, c.Request, fileName, time.Now(), content)
-}
-
 // IncomeList
 // @Title 业务收入统计表
 // @Description 获取业务收入统计表接口
@@ -1163,6 +1102,152 @@ func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
 	resp.OkData("获取成功", incomeList, c)
 }
 
+func getPaymentIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData base.BaseData, err error) {
+	defer func() {
+		if err != nil {
+			global.LOG.Error(err)
+			if err != utils.ErrNoRow {
+				go alarm_msg.SendAlarmMsg("获取业务收入金额统计数据异常,Err:"+err.Error(), 3)
+			}
+		}
+		ch <- baseData
+	}()
+
+	var reqStartDate, reqEndDate time.Time
+
+	st := fmt.Sprint(req.StartDate, "-01 00:00:00")
+	ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
+	reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
+	reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
+
+	var startDate, endDate string
+	//开始日期
+	if req.StartDate != "" && req.EndDate != "" {
+		startDate = reqStartDate.Format(utils.FormatDate)
+	}
+
+	//结束日期
+	if req.StartDate != "" && req.EndDate != "" {
+		endDate = reqEndDate.Format(utils.FormatDate)
+	}
+
+	cond := `1 = 1`
+	pars := make([]interface{}, 0)
+
+	if req.CompanyType == 1 {
+		cond += ` AND b.contract_type = 1 `
+	} else if req.CompanyType == 2 {
+		cond += ` AND b.contract_type IN (2,3,4) `
+	} else if req.CompanyType == 3 {
+		//未续约收入金额=去年同期总收入金额(新客户+老客户)-当期老客户收入金额
+		cond += ` AND b.contract_type IN (2,3,4) `
+	}
+
+	if req.SellerIds != "" {
+		sellerIds := strings.Split(req.SellerIds, ",")
+		cond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
+		pars = append(pars, sellerIds, sellerIds)
+	}
+
+	// 套餐筛选
+	if req.ServiceTypes != "" {
+		serviceTypes := strings.Split(req.ServiceTypes, ",")
+		registerIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
+		if e != nil {
+			err = fmt.Errorf("获取合同登记IDs失败, Err: %s", e.Error())
+			return
+		}
+		if len(registerIds) > 0 {
+			cond += ` AND a.register_id IN ?`
+			pars = append(pars, registerIds)
+		} else {
+			cond += ` AND 1 = 2`
+		}
+	}
+
+	{
+		if startDate != "" && endDate != "" {
+			st := fmt.Sprint(startDate, " 00:00:00")
+			ed := fmt.Sprint(endDate, " 23:59:59")
+			cond += ` AND (d.invoice_time BETWEEN ? AND ?)`
+			pars = append(pars, st, ed, st, ed)
+		}
+
+		if req.Keyword != "" {
+			cond += ` AND b.company_name LIKE ?`
+			pars = append(pars, "%"+req.Keyword+"%")
+		}
+
+		summaryIds, e := fms.GetPaymentCensusSummaryDataIds(cond, pars)
+		if e != nil {
+			return
+		}
+
+		if len(summaryIds) > 0 {
+			amountCond := `a.id IN ? `
+			amountPars := make([]interface{}, 0)
+			amountPars = append(amountPars, summaryIds)
+			if req.SellerIds != "" {
+				sellerIds := strings.Split(req.SellerIds, ",")
+				amountCond += `AND ( d.seller_id IN ? AND  a.payment_id <> 0 ) `
+				amountPars = append(amountPars, sellerIds)
+			} else {
+				amountCond += `AND (a.payment_id <> 0)`
+			}
+			page := new(base.Page)
+			page.SetPageSize(req.PageSize)
+			page.SetCurrent(req.Current)
+
+			if req.SortType == "asc" {
+				page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: true})
+			} else {
+				page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: false})
+			}
+
+			results, total, e := fms.GetContractSummaryPaymentIncomeAmountPage(amountCond, amountPars, page)
+			if e != nil {
+				err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+				return
+			}
+
+			// 货币列表
+			currencyOB := new(fms.CurrencyUnit)
+			currencyCond := `enable = 1`
+			currencyPars := make([]interface{}, 0)
+			currencyList, e := currencyOB.List(currencyCond, currencyPars)
+			if e != nil {
+				err = fmt.Errorf("获取货币列表失败, Err: %s", e.Error())
+				return
+			}
+			unitMap := make(map[string]string)
+			for i := range currencyList {
+				unitMap[currencyList[i].Code] = currencyList[i].UnitName
+			}
+
+			respItems := make([]*fms.IncomeSummaryRespItem, 0)
+			for _, v := range results {
+				respItem := &fms.IncomeSummaryRespItem{
+					CompanyName:   v.CompanyName,
+					ContractType:  v.ContractType,
+					InvoiceDate:   v.InvoiceDate.Format(utils.FormatDate),
+					Amount:        v.Amount,
+					SellerName:    v.SellerName,
+					FinalSellerId: v.FinalSellerId,
+					OriginAmount:  v.OriginAmount,
+					UnitName:      unitMap[v.CurrencyUnit],
+					ServicesName: v.ServicesName,
+				}
+				respItems = append(respItems, respItem)
+			}
+			page.SetTotal(total)
+			baseData.SetPage(page)
+			baseData.SetList(respItems)
+		}
+	}
+
+	return
+}
+
 //func getCensusIncomeList(ch chan models.CensusIncomeChartResp, req fms.IncomeListReq) (incomeChart models.CensusIncomeChartResp, err error) {
 //	defer func() {
 //		if err != nil {
@@ -1476,148 +1561,59 @@ func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
 //	return
 //}
 
-func getPaymentIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData base.BaseData, err error) {
-	defer func() {
-		if err != nil {
-			global.LOG.Error(err)
-			if err != utils.ErrNoRow {
-				go alarm_msg.SendAlarmMsg("获取业务收入金额统计数据异常,Err:"+err.Error(), 3)
-			}
-		}
-		ch <- baseData
-	}()
-
-	var reqStartDate, reqEndDate time.Time
-
-	st := fmt.Sprint(req.StartDate, "-01 00:00:00")
-	ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
-	reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
-	reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
-
-	var startDate, endDate string
-	//开始日期
-	if req.StartDate != "" && req.EndDate != "" {
-		startDate = reqStartDate.Format(utils.FormatDate)
-	}
-
-	//结束日期
-	if req.StartDate != "" && req.EndDate != "" {
-		endDate = reqEndDate.Format(utils.FormatDate)
+// ExportIncomeList 导出业务收入统计列表
+func ExportIncomeList(c *gin.Context, list []*fms.IncomeSummaryItem) {
+	// 生成Excel文件
+	xlsxFile := xlsx.NewFile()
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
 	}
+	style.Alignment = alignment
+	style.ApplyAlignment = true
 
-	cond := `1 = 1`
-	pars := make([]interface{}, 0)
-
-	if req.CompanyType == 1 {
-		cond += ` AND b.contract_type = 1 `
-	} else if req.CompanyType == 2 {
-		cond += ` AND b.contract_type IN (2,3,4) `
-	} else if req.CompanyType == 3 {
-		//未续约收入金额=去年同期总收入金额(新客户+老客户)-当期老客户收入金额
-		cond += ` AND b.contract_type IN (2,3,4) `
+	sheetName := "业务收入统计表"
+	sheet, err := xlsxFile.AddSheet(sheetName)
+	if err != nil {
+		resp.FailData("新增Sheet失败", "Err:"+err.Error(), c)
+		return
 	}
 
-	if req.SellerIds != "" {
-		sellerIds := strings.Split(req.SellerIds, ",")
-		cond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
-		pars = append(pars, sellerIds, sellerIds)
+	// 数据表头
+	rowTitle := []string{"开票日期", "新客户(1)", "客户名称", "金额", "销售"}
+	titleRow := sheet.AddRow()
+	for i := range rowTitle {
+		v := titleRow.AddCell()
+		v.SetString(rowTitle[i])
+		v.SetStyle(style)
 	}
-
-	// 套餐筛选
-	if req.ServiceTypes != "" {
-		serviceTypes := strings.Split(req.ServiceTypes, ",")
-		registerIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
-		if e != nil {
-			err = fmt.Errorf("获取合同登记IDs失败, Err: %s", e.Error())
-			return
-		}
-		if len(registerIds) > 0 {
-			cond += ` AND a.register_id IN ?`
-			pars = append(pars, registerIds)
-		} else {
-			cond += ` AND 1 = 2`
+	incomeSummaryItemList := make(fms.IncomeSummaryItemList, 0)
+	incomeSummaryItemList = list
+	sort.Sort(incomeSummaryItemList)
+	// 填充数据
+	for _, v := range incomeSummaryItemList {
+		dataRow := sheet.AddRow()
+		dataRow.AddCell().SetString(v.InvoiceDate.Format(utils.FormatDate)) // 开票日期
+		newCompany := 0
+		if v.ContractType == 1 {
+			newCompany = 1
 		}
+		dataRow.AddCell().SetString(strconv.Itoa(newCompany)) // 新客户
+		dataRow.AddCell().SetString(v.CompanyName)            // 客户名称
+		dataRow.AddCell().SetString(fmt.Sprint(v.Amount))     // 金额
+		dataRow.AddCell().SetString(v.SellerName)             // 销售员
 	}
 
-	{
-		if startDate != "" && endDate != "" {
-			st := fmt.Sprint(startDate, " 00:00:00")
-			ed := fmt.Sprint(endDate, " 23:59:59")
-			cond += ` AND (d.invoice_time BETWEEN ? AND ?)`
-			pars = append(pars, st, ed, st, ed)
-		}
-
-		if req.Keyword != "" {
-			cond += ` AND b.company_name LIKE ?`
-			pars = append(pars, "%"+req.Keyword+"%")
-		}
-
-		summaryIds, e := fms.GetPaymentCensusSummaryDataIds(cond, pars)
-		if e != nil {
-			return
-		}
-
-		if len(summaryIds) > 0 {
-			amountCond := `a.id IN ? `
-			amountPars := make([]interface{}, 0)
-			amountPars = append(amountPars, summaryIds)
-			if req.SellerIds != "" {
-				sellerIds := strings.Split(req.SellerIds, ",")
-				amountCond += `AND ( d.seller_id IN ? AND  a.payment_id <> 0 ) `
-				amountPars = append(amountPars, sellerIds)
-			} else {
-				amountCond += `AND (a.payment_id <> 0)`
-			}
-			page := new(base.Page)
-			page.SetPageSize(req.PageSize)
-			page.SetCurrent(req.Current)
-
-			if req.SortType == "asc" {
-				page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: true})
-			} else {
-				page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: false})
-			}
-
-			results, total, e := fms.GetContractSummaryPaymentIncomeAmountPage(amountCond, amountPars, page)
-			if e != nil {
-				err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
-				return
-			}
-
-			// 货币列表
-			currencyOB := new(fms.CurrencyUnit)
-			currencyCond := `enable = 1`
-			currencyPars := make([]interface{}, 0)
-			currencyList, e := currencyOB.List(currencyCond, currencyPars)
-			if e != nil {
-				err = fmt.Errorf("获取货币列表失败, Err: %s", e.Error())
-				return
-			}
-			unitMap := make(map[string]string)
-			for i := range currencyList {
-				unitMap[currencyList[i].Code] = currencyList[i].UnitName
-			}
-
-			respItems := make([]*fms.IncomeSummaryRespItem, 0)
-			for _, v := range results {
-				respItem := &fms.IncomeSummaryRespItem{
-					CompanyName:   v.CompanyName,
-					ContractType:  v.ContractType,
-					InvoiceDate:   v.InvoiceDate.Format(utils.FormatDate),
-					Amount:        v.Amount,
-					SellerName:    v.SellerName,
-					FinalSellerId: v.FinalSellerId,
-					OriginAmount:  v.OriginAmount,
-					UnitName:      unitMap[v.CurrencyUnit],
-					ServicesName: v.ServicesName,
-				}
-				respItems = append(respItems, respItem)
-			}
-			page.SetTotal(total)
-			baseData.SetPage(page)
-			baseData.SetList(respItems)
-		}
-	}
+	// 输出文件
+	var buffer bytes.Buffer
+	_ = xlsxFile.Write(&buffer)
+	content := bytes.NewReader(buffer.Bytes())
+	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
+	fileName := sheetName + randStr + ".xlsx"
 
-	return
+	c.Writer.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName))
+	c.Writer.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
+	http.ServeContent(c.Writer, c.Request, fileName, time.Now(), content)
 }