zwxi 1 年之前
父节点
当前提交
866ead29cb
共有 3 个文件被更改,包括 162 次插入82 次删除
  1. 125 68
      controller/census/invoice_payment.go
  2. 21 1
      controller/census/seller.go
  3. 16 13
      models/fms/contract_invoice.go

+ 125 - 68
controller/census/invoice_payment.go

@@ -1050,6 +1050,9 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	} else if req.CompanyType == 2 {
 		cond += ` AND b.contract_type IN (2,3,4) `
 		historyCond += ` AND new_company = 0 `
+	} else if req.CompanyType == 3 {
+		cond += ` AND b.contract_type = 1 `
+		historyCond += ` AND new_company = 1 `
 	}
 
 	var latestTime time.Time
@@ -1302,16 +1305,16 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 
 		}
 
-		{ //去年同期,用于计算同比值
-			prevSt := fmt.Sprint(prevStartDate, " 00:00:00")
-			prevEd := fmt.Sprint(prevEndDate, " 23:59:59")
+		{ // 去年同期,用于计算同比值
+			prevSt := fmt.Sprint(prevStartDate, " 00:00:00") // 格式化上一年同一天的开始时间
+			prevEd := fmt.Sprint(prevEndDate, " 23:59:59")   // 格式化上一年同一天的结束时间
 
-			//校验日期,分段查询
+			// 校验日期,分段查询
 			if prevStartDateTime.After(historyTime) || prevStartDateTime.Equal(historyTime) {
-				//全部走新查询
-				prevCond += ` AND ((b.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
-				prevPars = append(prevPars, prevSt, prevEd, prevSt, prevEd)
-				prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)
+				// 全部走新查询
+				prevCond += ` AND ((b.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))` // 查询条件加入新的时间范围
+				prevPars = append(prevPars, prevSt, prevEd, prevSt, prevEd)                               // 添加时间参数到参数列表
+				prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)        // 获取摘要ID列表
 				if e != nil {
 					return
 				}
@@ -1320,20 +1323,20 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				var prevAmountTotal float64
 
 				if len(prevSummaryIds) > 0 {
-					amountCond := `a.id IN ? `
+					amountCond := `a.id IN ? ` // 查询条件为ID在给定的摘要ID列表中
 					amountPars := make([]interface{}, 0)
-					amountPars = append(amountPars, prevSummaryIds)
+					amountPars = append(amountPars, prevSummaryIds) // 将摘要ID列表添加到参数列表
 					if req.SellerIds != "" {
 						sellerIds := strings.Split(req.SellerIds, ",")
 						amountCond += ` AND (( b.seller_id IN ? AND a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
-						amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) `
-						amountPars = append(amountPars, sellerIds, prevSt, prevEd, sellerIds, prevSt, prevEd)
+						amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) ` // 根据卖家ID和发票/支付状态筛选时间范围
+						amountPars = append(amountPars, sellerIds, prevSt, prevEd, sellerIds, prevSt, prevEd)                                   // 将卖家ID列表添加到参数列表
 					} else {
 						amountCond += ` AND ((a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
-						amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))`
+						amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))` // 根据发票/支付状态筛选时间范围
 						amountPars = append(amountPars, prevSt, prevEd)
 					}
-					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
+					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars) // 获取合同摘要收入金额数据
 					if e != nil {
 						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
 						return
@@ -1341,35 +1344,35 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					var amountSum float64
 					//historydataList = append(historydataList, results...)
 					for _, result := range results {
-						amountSum += result.Amount
+						amountSum += result.Amount // 累计收入金额
 					}
-					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-					historyAccumulate += prevAmountTotal
-					partHistoryAccumulate += prevAmountTotal
+					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64) // 将累计金额转换为浮点数
+					historyAccumulate += prevAmountTotal                                        // 累计历史金额
+					partHistoryAccumulate += prevAmountTotal                                    // 累计部分历史金额
 				}
 				if i == j || i == numMonth {
 					if req.ListParam == "4" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate) // 将累计金额添加到总金额切片中
 						if prevStartDateTime.Month() == 12 {
-							historyAccumulate = 0
+							historyAccumulate = 0 // 如果是去年的12月份,则将历史金额清零
 						}
 					} else if req.ListParam == "0" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal) // 将部分历史金额添加到总金额切片中
 					} else if i > 0 || i == numMonth {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate) // 将部分历史金额添加到总金额切片中
 						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
-						partHistoryAccumulate = 0.0
+						partHistoryAccumulate = 0.0 // 清零部分历史金额
 					}
 				}
 			} else if prevEndDateTime.Before(historyTime) || prevEndDateTime.Equal(historyTime) {
-				//全部走旧查询
+				// 全部走旧查询
 				fmt.Println("prevSt:", prevSt)
 				fmt.Println("prevEd:", prevEd)
-				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`
-				prevHistoryPars = append(prevHistoryPars, prevSt, prevEd)
+				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`  // 查询条件加入旧的时间范围
+				prevHistoryPars = append(prevHistoryPars, prevSt, prevEd) // 添加时间参数到参数列表
 				// 开票到款金额合计(换算后)
 				var amountTotal float64
-				results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars)
+				results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars) // 获取历史收入数据
 				if e != nil {
 					err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
 					return
@@ -1377,42 +1380,69 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 				//historydataList = append(historydataList, results...)
 				var amountSum float64
 				for _, result := range results {
-					amountSum += result.Amount
+					amountSum += result.Amount // 累计收入金额
 				}
-				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
-				historyAccumulate += amountTotal
-				partHistoryAccumulate += amountTotal
+				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64) // 将累计金额转换为浮点数
+				historyAccumulate += amountTotal                                        // 累计历史金额
+				partHistoryAccumulate += amountTotal                                    // 累计部分历史金额
 
 				if i == j || i == numMonth {
 					if req.ListParam == "4" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate) // 将累计金额添加到总金额切片中
 						if prevStartDateTime.Month() == 12 {
-							historyAccumulate = 0
+							historyAccumulate = 0 // 如果是去年的12月份,则将历史金额清零
 						}
 					} else if req.ListParam == "0" {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal) // 将历史金额添加到总金额切片中
 					} else if i > 0 || i == numMonth {
-						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate) // 将部分历史金额添加到总金额切片中
 						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
-						partHistoryAccumulate = 0.0
+						partHistoryAccumulate = 0.0 // 清零部分历史金额
+					}
+				}
+				if req.ListParam == "1" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01")) // 添加下一个月份的开始日期到日期切片中
+						j = j + 2
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
+						j = j + 3
 					}
+				} else if req.ListParam == "2" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01")) // 添加下五个月份的开始日期到日期切片中
+						j = j + 5
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01")) // 添加下半年的开始日期到日期切片中
+						j = j + 6
+					}
+				} else if req.ListParam == "3" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 11, 0).Format("06/01")) // 添加下十一个月份的开始日期到日期切片中
+						j = j + 11
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 12, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
+						j = j + 12
+					}
+				} else if i == j {
+					dateSlice = append(dateSlice, startDateTime.Format("06/01")) // 添加当月开始日期到日期切片中
+					j++
 				}
-				//fmt.Println("partHistoryAccumulate:",partHistoryAccumulate)
 			}
 			if req.ListParam == "1" && i == j {
 				if i == 0 {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01")) // 添加下一个月份的开始日期到日期切片中
 					j = j + 2
 				} else {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
 					j = j + 3
 				}
 			} else if req.ListParam == "2" && i == j {
 				if i == 0 {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01")) // 添加下五个月份的开始日期到日期切片中
 					j = j + 5
 				} else {
-					dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01"))
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01")) // 添加下半年的开始日期到日期切片中
 					j = j + 6
 				}
 			} else if req.ListParam == "3" && i == j {
@@ -1433,27 +1463,55 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	fmt.Println("prevTotalMoneySlice:", len(prevTotalMoneySlice))
 	fmt.Println("totalMoneySlice:", len(totalMoneySlice))
 
-	//计算同比值
-	for i := range prevTotalMoneySlice {
-		var yoy float64
-		var yoyStr string
-		//fmt.Println("1:", prevTotalMoneySlice[i])
-		//fmt.Println("2:", totalMoneySlice[i])
-		//fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
-		totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalMoneySlice[i]), 64)
-		if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
-			yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
-			yoyStr = fmt.Sprintf("%.4f", yoy)
-
-			if i == len(prevTotalMoneySlice)-1 && i > 0 && req.ListParam == "3" {
-				fmt.Println("totalMoneySlice[i-1]:", totalMoneySlice[i-1])
-				yoy = (totalMoneySlice[i] - totalMoneySlice[i-1]) / totalMoneySlice[i-1]
+
+	if req.CompanyType != 3 {
+		//计算同比值
+		for i := range prevTotalMoneySlice {
+			var yoy float64
+			var yoyStr string
+			//fmt.Println("1:", prevTotalMoneySlice[i])
+			//fmt.Println("2:", totalMoneySlice[i])
+			//fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
+			totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalMoneySlice[i]), 64)
+			if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
+				yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
 				yoyStr = fmt.Sprintf("%.4f", yoy)
+
+				if i == len(prevTotalMoneySlice)-1 && i > 0 && req.ListParam == "3" {
+					fmt.Println("totalMoneySlice[i-1]:", totalMoneySlice[i-1])
+					yoy = (totalMoneySlice[i] - totalMoneySlice[i-1]) / totalMoneySlice[i-1]
+					yoyStr = fmt.Sprintf("%.4f", yoy)
+				}
 			}
+			yoySlice = append(yoySlice, yoyStr)
+		}
+	} else {
+		// 当筛选条件是”月度“时,并且客户是”未续约“客户,展示柱形图和曲线图
+		// 当筛选条件是”季度“、”半年度“、”年度“、”月度统计“时,并且客户是”未续约“时,仅展示柱形图,无曲线图
+		// 未续约客户收入:去年同期老客户收入金额  减  当期老客户收入金额
+		// 移动平均值:若是10月份,计算8月,9月,10月,这三个月的收入金额平均值
+		for i := range prevTotalMoneySlice {
+			var yoy float64
+			var yoyStr string
+			//fmt.Println("1:", prevTotalMoneySlice[i])
+			//fmt.Println("2:", totalMoneySlice[i])
+			//fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
+			totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalMoneySlice[i] - prevTotalMoneySlice[i]), 64)
+			if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
+				yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
+				yoyStr = fmt.Sprintf("%.4f", yoy)
+
+				if i == len(prevTotalMoneySlice)-1 && i > 0 && req.ListParam == "3" {
+					fmt.Println("totalMoneySlice[i-1]:", totalMoneySlice[i-1])
+					yoy = (totalMoneySlice[i] - totalMoneySlice[i-1]) / totalMoneySlice[i-1]
+					yoyStr = fmt.Sprintf("%.4f", yoy)
+				}
+			}
+			yoySlice = append(yoySlice, yoyStr)
 		}
-		yoySlice = append(yoySlice, yoyStr)
 	}
 
+
 	incomeChart.Title = "开票到款统计图"
 	incomeChart.Date = dateSlice
 	incomeChart.TotalMoney = totalMoneySlice
@@ -1710,7 +1768,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 
 			// 获取未进行过开票到款的合同数据,其实只用到了合同id和ProductIds用来补充不同的套餐信息
 			noSummaryCond += ` AND b.is_deleted = 0 AND b.contract_status <> 4 `
-			if len(notQueryRegisterIds) >0 {
+			if len(notQueryRegisterIds) > 0 {
 				noSummaryCond += ` AND b.contract_register_id IN ? AND b.contract_register_id NOT IN ?`
 				noSummaryPars = append(noSummaryPars, queryRegisterIds, notQueryRegisterIds)
 			} else {
@@ -1846,7 +1904,6 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				unitMap[currencyList[i].Code] = currencyList[i].UnitName
 			}
 
-
 			for registerId, list := range NotInvoiceSummaryMap {
 				for _, v := range list {
 					//fmt.Println("v.ContractRegisterId", v.ContractRegisterId)
@@ -1856,8 +1913,8 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 					if v.NotInvoicedAmountTotal == 0 {
 						if v.InvoiceAmountTotal > v.PaymentAmountTotal {
 							// 有合规登记或补录合同过的,有serviceAmountMap信息
-							if _,ok := serviceAmountMap[registerId]; ok {
-								if _,ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2{
+							if _, ok := serviceAmountMap[registerId]; ok {
+								if _, ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2 {
 									v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
 								}
 							} else {
@@ -1865,9 +1922,9 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 								v.NotInvoicedAmountTotal = v.InvoiceAmountTotal - v.PaymentAmountTotal
 							}
 						} else {
-							if _,ok := serviceAmountMap[registerId]; ok {
+							if _, ok := serviceAmountMap[registerId]; ok {
 								// 有合规登记或补录合同过的,有serviceAmountMap信息
-								if _,ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2{
+								if _, ok2 := serviceAmountMap[registerId][v.ServiceProductId]; ok2 {
 									v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.PaymentAmountTotal
 								}
 							} else {
@@ -2716,12 +2773,12 @@ func ExportNotPaymentCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 		// 开票到款信息
 		for _, v2 := range v.InvoicePaymentList {
 			rowData := []string{
-				v2.InvoiceDate,               // 开票日
+				v2.InvoiceDate,                  // 开票日
 				fmt.Sprint(v2.NotPaymentAmount), // 开票金额
-				v2.UnitName,                  // 开票金额
-				v2.SellerName,                // 销售
-				v2.SellerGroupName,           // 组别
-				sellerTypeMap[v2.SellerType], // 销售类型
+				v2.UnitName,                     // 开票金额
+				v2.SellerName,                   // 销售
+				v2.SellerGroupName,              // 组别
+				sellerTypeMap[v2.SellerType],    // 销售类型
 			}
 			for i := range rowData {
 				dataRow.AddCell().SetString(rowData[i])

+ 21 - 1
controller/census/seller.go

@@ -58,8 +58,11 @@ func (ct *SellerController) GroupInvoiceList(c *gin.Context) {
 	}
 	outCond := ` department_id = %d AND parent_id = 0 `
 	outCond = fmt.Sprintf(outCond, departmentId)
-	cond := ` (invoice_type = %d OR invoice_type = %d) AND is_deleted = 0 AND seller_group_id != 0 `
+	cond := ` (invoice_type = %d OR invoice_type = %d) AND a.is_deleted = 0 AND a.seller_group_id != 0 `
 	cond = fmt.Sprintf(cond, fms.ContractInvoiceTypeMake, fms.ContractInvoiceTypePreMake)
+
+	//adminCond := ` (invoice_type = %d OR invoice_type = %d) AND is_deleted = 0 AND seller_group_id != 0 `
+	//adminCond = fmt.Sprintf(cond, fms.ContractInvoiceTypeMake, fms.ContractInvoiceTypePreMake)
 	pars := make([]interface{}, 0)
 	// 开票日期
 	if req.StartDate != "" && req.EndDate != "" {
@@ -67,6 +70,17 @@ func (ct *SellerController) GroupInvoiceList(c *gin.Context) {
 		ed := fmt.Sprint(req.EndDate, " 23:59:59")
 		cond += ` AND (invoice_time BETWEEN '%s' AND '%s')`
 		cond = fmt.Sprintf(cond, st, ed)
+
+		//adminCond += ` AND (invoice_time BETWEEN '%s' AND '%s')`
+		//adminCond = fmt.Sprintf(cond, st, ed)
+	}
+
+	if req.CompanyType == 1 {
+		cond += ` AND b.contract_type = 1 `
+		//historyCond += ` AND new_company = 1 `
+	} else if req.CompanyType == 2 {
+		cond += ` AND b.contract_type IN (2,3,4) `
+		//historyCond += ` AND new_company = 0 `
 	}
 
 	page := new(base.Page)
@@ -250,6 +264,8 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
 		resp.Fail("请选择正确的销售类型", c)
 		return
 	}
+
+
 	pars := make([]interface{}, 0)
 	adminPars := make([]interface{}, 0)
 	outCond := ` a.department_id = %d `
@@ -259,6 +275,10 @@ func (ct *SellerController) InvoiceList(c *gin.Context) {
 	totalCond := ` department_id = %d `
 	totalCond = fmt.Sprintf(totalCond, departmentId)
 	totalPars := make([]interface{}, 0)
+
+	if !req.ShowResign {
+		adminCond += ` AND enabled = 0 `
+	}
 	if req.GroupId > 0 {
 		// 筛选组别时, 查询当前组别的下级组(因为admin表存的group_id, 有三级的存的是子ID, 只有二级的存的才是父ID =_=!)
 		groupCond := `parent_id = ?`

+ 16 - 13
models/fms/contract_invoice.go

@@ -93,8 +93,8 @@ func (c *ContractInvoice) Delete() (err error) {
 
 func (c *ContractInvoice) Sum(field, condition string, pars []interface{}) (total float64, err error) {
 	totalList := make([]float64, 0)
-	err = global.DEFAULT_MYSQL.Model(c).
-		Where("is_deleted = 0").
+	err = global.DEFAULT_MYSQL.Table("contract_invoice AS a").Joins("INNER JOIN contract_register AS b ON a.contract_register_id = b.contract_register_id ").
+		Where("a.is_deleted = 0").
 		Where(condition, pars...).
 		Pluck(field, &totalList).Error
 	for i := range totalList {
@@ -403,6 +403,7 @@ type CensusSellerGroupInvoiceListReq struct {
 	SortType   int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
 	IsExport   int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
 	SellerType int    `json:"seller_type" form:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
+	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户"`
 	base.PageReq
 }
 
@@ -449,6 +450,7 @@ type CensusSellerInvoiceListReq struct {
 	SortType   int    `json:"sort_type" form:"sort_type" description:"排序方式: 1-正序; 2-倒序"`
 	IsExport   int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
 	SellerType int    `json:"seller_type" form:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
+	ShowResign bool   `json:"show_resign" form:"show_resign" description:"是否显示离职销售"`
 	base.PageReq
 }
 
@@ -614,14 +616,14 @@ func (c *ContractInvoice) FetchByRegisterId(registerId int) (items []*ContractIn
 }
 
 // GetDuplicateContractInvoiceDetailItemListWithType 预登记列表详情用-获取开票到款列表
-func GetDuplicateContractInvoiceDetailItemListWithType(companyName, startDate, endDate string,contractType, hasPayment int) (itemList []*ContractInvoiceDetailItem, err error) {
+func GetDuplicateContractInvoiceDetailItemListWithType(companyName, startDate, endDate string, contractType, hasPayment int) (itemList []*ContractInvoiceDetailItem, err error) {
 	list := make([]*InvoiceDetailItem, 0)
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
 		Select(" a.*,IF(p.seller_id > 0, 1, 0) AS has_invoice_seller  ").
 		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
 		Joins("JOIN contract_pre_register AS p ON p.invoice_id = a.contract_invoice_id OR p.arrive_id = a.contract_invoice_id ").
-		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s'" +
-			" AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) " +
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s'"+
+			" AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) "+
 			"AND b.contract_type=? AND b.has_payment=?", companyName, startDate, endDate), contractType, hasPayment).
 		Order("a.contract_invoice_id ASC").
 		Find(&list).Error
@@ -664,7 +666,7 @@ type IncomeListReq struct {
 	EndDate     string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01" description:"结束日期"`
 	IsExport    int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
 	ListParam   string `json:"list_param" form:"list_param" description:"套餐类型: 0-月度; 1-季度; 2-半年度;3-年度;4-月度累计"`
-	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户"`
+	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户 3未续约"`
 }
 
 // 获取最新的开票或到款日期
@@ -723,17 +725,18 @@ type NotPaymentCensusInfo struct {
 }
 
 // GetCensusSellerGroupInvoicePageListV2 获取销售组开票统计列表-分页
-func GetCensusSellerGroupInvoicePageListV2(page base.IPage,groupStr, condition string, pars []interface{}, amountSum float64) (count int, results []*CensusSellerGroupInvoiceItem, err error) {
+func GetCensusSellerGroupInvoicePageListV2(page base.IPage, groupStr, condition string, pars []interface{}, amountSum float64) (count int, results []*CensusSellerGroupInvoiceItem, err error) {
 	sql := ` 
 				SELECT
 					seller_group_id AS group_id,
 					SUM(amount) AS invoice_amount,
 					SUM(amount) / %f AS group_rate
 				FROM
-					contract_invoice
+					contract_invoice AS a
+				INNER JOIN contract_register AS b ON a.contract_register_id = b.contract_register_id 
 				WHERE
 					%s
-				AND seller_group_id IN (`+groupStr+`)
+				AND seller_group_id IN (` + groupStr + `)
 				GROUP BY
 					seller_group_id  ORDER BY %s LIMIT %d,%d
 			`
@@ -743,7 +746,7 @@ func GetCensusSellerGroupInvoicePageListV2(page base.IPage,groupStr, condition s
 					contract_invoice
 				WHERE
 					%s
-				AND seller_group_id IN (`+groupStr+`)
+				AND seller_group_id IN (` + groupStr + `)
 				GROUP BY
 					seller_group_id  )as a
 			`
@@ -765,13 +768,13 @@ func GetCensusSellerInvoicePageListV2(page base.IPage, adminStr, inCond, conditi
 				SUM(c.amount) / %f AS seller_rate
 				FROM contract_invoice AS c 
 				WHERE %s
-				AND c.seller_id IN (`+adminStr+`)
+				AND c.seller_id IN (` + adminStr + `)
 				GROUP BY c.seller_id ORDER BY %s LIMIT %d,%d `
 
 	sqlCount := ` select count(1) as count from (SELECT * 
 				FROM contract_invoice AS c
 				WHERE %s
-				AND c.seller_id IN (`+adminStr+`) GROUP BY c.seller_id ) as a
+				AND c.seller_id IN (` + adminStr + `) GROUP BY c.seller_id ) as a
 				 `
 	sqlCount = fmt.Sprintf(sqlCount, condition)
 	err = global.DEFAULT_MYSQL.Raw(sqlCount, pars...).Find(&count).Error
@@ -812,4 +815,4 @@ func GetInvoiceCountByRegisterId(registerId int) (total int64, err error) {
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
 		Where("is_deleted = 0 AND contract_register_id = ?", registerId).Count(&total).Error
 	return
-}
+}