zwxi 1 year ago
parent
commit
8ecbe42a67
1 changed files with 40 additions and 29 deletions
  1. 40 29
      controller/census/seller.go

+ 40 - 29
controller/census/seller.go

@@ -232,8 +232,8 @@ func ExportGroupInvoiceList(c *gin.Context, list []*fms.CensusSellerGroupInvoice
 }
 
 // InvoiceList
-// @Title 销售开票统计列表
-// @Description 销售开票统计列表
+// @Title 销售开票统计列表-弃用
+// @Description 销售开票统计列表-弃用
 // @Param   GroupId			query	int		false	"组别ID"
 // @Param   StartDate		query	string	false	"开始日期"
 // @Param   EndDate			query	string	false	"结束日期"
@@ -449,13 +449,6 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		page.SetCurrent(1)
 	}
 
-	//收入统计
-	//获取最新的开票到款日期
-	cond1 := ``
-	historyCond := ``
-	//pars1 := make([]interface{}, 0)
-	//historyPars1 := make([]interface{}, 0)
-
 	//if req.SellerIds != "" {
 	//	sellerIds := strings.Split(req.SellerIds, ",")
 	//	cond += ` AND (a.seller_id in ? ) `
@@ -463,13 +456,7 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 	//	pars = append(pars, sellerIds)
 	//	historyPars = append(historyPars, sellerIds)
 	//}
-	if req.CompanyType == 1 {
-		cond1 += ` AND b.contract_type = 1 `
-		historyCond += ` AND new_company = 1 `
-	} else if req.CompanyType == 2 {
-		cond1 += ` AND b.contract_type IN (2,3,4) `
-		historyCond += ` AND new_company = 0 `
-	}
+
 	var departmentId int
 	if req.SellerType == 1 {
 		departmentId = crm.SellerDepartmentId
@@ -496,10 +483,6 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 
 	// 累计值
 	var accumulate float64
-	//dataList := make([]*fms.IncomeSummaryItem, 0)
-	//historydataList := make([]*fms.IncomeSummaryItem, 0)
-
-	//timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
 
 	var prevStartDate string
 	var startDate, endDate string
@@ -518,17 +501,47 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		endDate = reqEndDate.Format("2006-01")
 	}
 
-	cond := `1 = 1`
-	histrtyCond := `1 = 1`
+	cond := ` 1 = 1 `
+	historyCond := ` 1=1 `
 	pars := make([]interface{}, 0)
 	historyPars := make([]interface{}, 0)
 
 	if req.CompanyType == 1 {
 		cond += ` AND b.contract_type = 1 `
-		histrtyCond += ` AND new_company = 1 `
+		historyCond += ` AND new_company = 1 `
 	} else if req.CompanyType == 2 {
 		cond += ` AND b.contract_type IN (2,3,4) `
-		histrtyCond += ` AND new_company = 0 `
+		historyCond += ` AND new_company = 0 `
+	}
+
+	if req.GroupId > 0 {
+		// 筛选组别时, 查询当前组别的下级组(因为admin表存的group_id, 有三级的存的是子ID, 只有二级的存的才是父ID =_=!)
+		groupCond := `parent_id = ?`
+		groupPars := make([]interface{}, 0)
+		groupPars = append(groupPars, req.GroupId)
+		groupOB := new(crm.SysGroup)
+		groupList, e := groupOB.List(groupCond, groupPars)
+		if e != nil {
+			resp.FailMsg("获取失败", "获取组别下级组列表失败, Err: "+e.Error(), c)
+			return
+		}
+		groupIds := make([]int, 0)
+		groupIds = append(groupIds, req.GroupId)
+		for i := range groupList {
+			groupIds = append(groupIds, groupList[i].GroupId)
+		}
+		cond += ` AND c.seller_group_id IN (?) AND d.seller_group_id IN (?)`
+		pars = append(pars, groupIds, groupIds)
+		historyCond += ` AND group_id IN (?) `
+		historyPars = append(historyPars, groupIds)
+	}
+
+	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 `
 	}
 
 	//if req.SellerIds != "" {
@@ -600,13 +613,11 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 			amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 			accumulate += amountTotal
 
-			//var amountTotal float64
-			results, e = fms.GetIncomeHistory(histrtyCond, historyPars)
+			results, e = fms.GetIncomeHistory(historyCond, historyPars)
 			if e != nil {
 				resp.FailMsg("查询错误", fmt.Sprintf("获取汇总数据失败, Err: %s", e.Error()), c)
 				return
 			}
-			//dataList = append(dataList, results...)
 			for _, result := range results {
 				amountSum += result.Amount
 				if _, ok := groupInvoiceMap[result.SellerGroupId]; ok {
@@ -688,14 +699,14 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		//fmt.Println("st:",st)
 		//fmt.Println("ed:",ed)
 		if st != "" && ed != "" {
-			histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
+			historyCond += ` AND (invoice_time BETWEEN ? AND ? )`
 			historyPars = append(historyPars, st, ed)
 		}
 		//fmt.Println("st:",st)
 		//fmt.Println("ed:",ed)
 		// 开票到款金额合计(换算后)
 		var amountTotal float64
-		results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
+		results, e := fms.GetIncomeHistory(historyCond, historyPars)
 		if e != nil {
 			resp.FailMsg("查询错误", fmt.Sprintf("获取汇总数据失败, Err: %s", e.Error()), c)
 			return