xiziwen 3 月之前
父节点
当前提交
8efadf9e49
共有 3 个文件被更改,包括 52 次插入21 次删除
  1. 18 17
      controller/census/income_list.go
  2. 30 0
      models/fms/contract_invoice.go
  3. 4 4
      models/fms/invoice_payment_summary.go

+ 18 - 17
controller/census/income_list.go

@@ -667,9 +667,17 @@ func getPaymentIncomeChartList(ch chan models.CensusIncomeChartResp, req fms.Inc
 		historyCond += ` AND new_company = 0 `
 	}
 
+	var earliestTime time.Time
+	EarliestinvoiceItem, err := fms.GetEarliestPaymentIncome(cond, pars)
+	if err != nil && err != utils.ErrNoRow {
+		err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
+		return
+	}
+	earliestTime = EarliestinvoiceItem.InvoiceDate
+
 	var latestTime time.Time
 
-	invoiceItem, err := fms.GetLatestIncome(cond, pars)
+	invoiceItem, err := fms.GetLatestPaymentIncome(cond, pars)
 	if err != nil && err != utils.ErrNoRow {
 		err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
 		return
@@ -733,8 +741,8 @@ func getPaymentIncomeChartList(ch chan models.CensusIncomeChartResp, req fms.Inc
 			monthNum = int(reqEndDate.Month() - reqStartDate.Month())
 		}
 	} else {
-		yearNum = latestTime.Year() - 2020
-		monthNum = int(latestTime.Month() - 1)
+		yearNum = latestTime.Year() - earliestTime.Year()
+		monthNum = int(latestTime.Month() - earliestTime.Month())
 	}
 
 	numMonth := yearNum*12 + monthNum //共存在多少个月
@@ -1114,20 +1122,17 @@ func getPaymentIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseDat
 
 	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)
-	}
+		st := fmt.Sprint(req.StartDate, "-01 00:00:00")
+		ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
 
-	//结束日期
-	if req.StartDate != "" && req.EndDate != "" {
-		endDate = reqEndDate.Format(utils.FormatDate)
+		reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
+		reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
+
+		startDate = reqStartDate.Format(utils.FormatDate)
+		endDate = reqEndDate.AddDate(0, 1, -1).Format(utils.FormatDate)
 	}
 
 	cond := `1 = 1`
@@ -1355,8 +1360,6 @@ func getCensusIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData
 			page.SetCurrent(1)
 		}
 
-
-
 		//校验日期,分段查询
 		st := fmt.Sprint(startDate, " 00:00:00")
 		ed := fmt.Sprint(endDate, " 23:59:59")
@@ -1557,7 +1560,6 @@ func getCensusIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData
 				page.SetTotal(int64(len(respItems)))
 				baseData.SetPage(page)
 
-
 				start := (page.GetCurrent() - 1) * page.PageSize
 				end := start + page.PageSize
 				if end > int64(len(respItems)) {
@@ -1640,7 +1642,6 @@ func getCensusIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData
 			page.SetTotal(int64(len(respItems)))
 			baseData.SetPage(page)
 
-
 			start := (page.GetCurrent() - 1) * page.PageSize
 			end := start + page.PageSize
 			if end > int64(len(respItems)) {

+ 30 - 0
models/fms/contract_invoice.go

@@ -842,3 +842,33 @@ type IncomeListReq struct {
 	Keyword      string `json:"keyword" form:"keyword" description:"搜索关键字"`
 	base.PageReq
 }
+
+// 获取最新的到款日期
+func GetLatestPaymentIncome(condition string, pars []interface{}) (result *ContractInvoice, err error) {
+	sql := `SELECT
+	a.* 
+FROM
+	contract_invoice AS a
+	INNER JOIN contract_register AS b ON a.contract_register_id = b.contract_register_id 
+WHERE
+	a.is_deleted = 0 AND a.invoice_type IN (2,4) `
+	sql += condition
+	sql += `ORDER BY a.invoice_time DESC  `
+	err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
+	return
+}
+
+// 获取最早的到款日期
+func GetEarliestPaymentIncome(condition string, pars []interface{}) (result *ContractInvoice, err error) {
+	sql := `SELECT
+	a.* 
+FROM
+	contract_invoice AS a
+	INNER JOIN contract_register AS b ON a.contract_register_id = b.contract_register_id 
+WHERE
+	a.is_deleted = 0 AND a.invoice_type IN (2,4) `
+	sql += condition
+	sql += `ORDER BY a.invoice_time ASC  `
+	err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
+	return
+}

+ 4 - 4
models/fms/invoice_payment_summary.go

@@ -204,7 +204,7 @@ type IncomeSummaryItem struct {
 	SellerGroupId   int       `json:"seller_group_id" description:"销售分组ID"`
 	SellerGroupName int       `json:"seller_group_name" description:"销售分组名称"`
 	CurrencyUnit    string    `json:"currency_unit" description:"货币单位"`
-	ServicesName       string `json:"services" description:"套餐名称"`
+	ServicesName    string    `json:"services" description:"套餐名称"`
 }
 
 // GetContractSummaryIncomeAmount 获取汇总金额合计信息
@@ -414,7 +414,7 @@ type IncomeSummaryRespItem struct {
 	SellerName    string  `json:"seller_name" description:"销售名称"`
 	FinalSellerId int     `json:"final_seller_id" description:"最终销售ID"`
 	UnitName      string  `json:"unit_name" description:"货币单位名称"`
-	ServicesName       string `json:"services_name" description:"套餐名称"`
+	ServicesName  string  `json:"services_name" description:"套餐名称"`
 }
 
 // GetContractSummaryPaymentIncomeAmountPage 获取汇总金额合计信息-到款收入统计
@@ -423,7 +423,7 @@ func GetContractSummaryPaymentIncomeAmountPage(condition string, pars []interfac
 		Select("d.origin_amount, d.amount AS amount,d.currency_unit, d.invoice_time AS invoice_date,"+
 			" c.contract_type,c.company_name,d.seller_name,"+
 			" d.seller_id AS final_seller_id").
-		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
+		Joins("JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
 		Joins("JOIN contract_register AS c ON a.register_id = c.contract_register_id AND c.is_deleted = 0").
 		Where(condition, pars...).Group("id")
 	//nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
@@ -434,7 +434,7 @@ func GetContractSummaryPaymentIncomeAmountPage(condition string, pars []interfac
 		Select("d.origin_amount, d.amount AS amount,d.currency_unit, d.invoice_time AS invoice_date,"+
 			" c.contract_type,c.company_name,d.seller_name,"+
 			" d.seller_id AS final_seller_id, GROUP_CONCAT(s.title) AS services_name ").
-		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
+		Joins("JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
 		Joins("JOIN contract_register AS c ON a.register_id = c.contract_register_id AND c.is_deleted = 0").
 		Joins("LEFT JOIN contract_service AS s ON s.contract_register_id = c.contract_register_id").
 		Where(condition, pars...).Group("id")