ziwen 1 year ago
parent
commit
e346437d78
1 changed files with 24 additions and 25 deletions
  1. 24 25
      controller/census/invoice_payment.go

+ 24 - 25
controller/census/invoice_payment.go

@@ -997,7 +997,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	defer func() {
 		if err != nil {
 			global.LOG.Error(err)
-			go alarm_msg.SendAlarmMsg("获取近两年的收入统计数据异常,Err:"+err.Error(), 3)
+			go alarm_msg.SendAlarmMsg("获取业务收入金额统计数据异常,Err:"+err.Error(), 3)
 			//go utils.SendEmail(utils.APPNAME+"获取近12个月的收入统计数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
 		}
 		ch <- incomeChart
@@ -1032,23 +1032,22 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	var latestTime time.Time
 
 	invoiceItem, err := fms.GetLatestIncome(cond, pars)
-	if err != nil  && err != utils.ErrNoRow {
+	if err != nil && err != utils.ErrNoRow {
 		err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
 		return
 	}
 	latestTime = invoiceItem.InvoiceDate
 
-	if err == utils.ErrNoRow{
+	if err == utils.ErrNoRow {
 		historyItem, e := fms.GetLatestHistoryIncome(historyCond, historyPars)
-		if e != nil {
+		if e != nil && err != utils.ErrNoRow {
 			err = fmt.Errorf("获取最新的历史开票或到款日期, Err: %s", err.Error())
 			return
 		}
 		latestTime = historyItem.InvoiceDate
 	}
 
-
-	latestTime = latestTime.AddDate(0,0,-latestTime.Day()+1)
+	latestTime = latestTime.AddDate(0, 0, -latestTime.Day()+1)
 
 	var dateSlice []string
 	var totalMoneySlice, prevTotalMoneySlice []float64
@@ -1167,8 +1166,8 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 			historyPars = append(historyPars, sellerIds)
 			prevHistoryPars = append(prevHistoryPars, sellerIds)
 		}
-//fmt.Println("i:",i)
-//fmt.Println("j:",j)
+		//fmt.Println("i:",i)
+		//fmt.Println("j:",j)
 		{
 			//本期
 			st := fmt.Sprint(startDate, " 00:00:00")
@@ -1204,7 +1203,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					for _, result := range results {
 						incomeChart.DataList = append(incomeChart.DataList, result)
 						amountSum += result.Amount
-						fmt.Println("result.Amount:",result.Amount)
+						fmt.Println("result.Amount:", result.Amount)
 					}
 					amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 					accumulate += amountTotal
@@ -1220,8 +1219,8 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 						totalMoneySlice = append(totalMoneySlice, amountTotal)
 					} else if i > 0 || i == numMonth {
 						totalMoneySlice = append(totalMoneySlice, partAccumulate)
-						fmt.Println("partAccumulate:",partAccumulate)
-						partAccumulate  = 0.0
+						fmt.Println("partAccumulate:", partAccumulate)
+						partAccumulate = 0.0
 					}
 				}
 			} else if endDateTime.Before(historyTime) || endDateTime.Equal(historyTime) {
@@ -1260,7 +1259,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 						totalMoneySlice = append(totalMoneySlice, amountTotal)
 					} else if i > 0 || i == numMonth {
 						totalMoneySlice = append(totalMoneySlice, partAccumulate)
-						partAccumulate  = 0.0
+						partAccumulate = 0.0
 					}
 				}
 
@@ -1317,14 +1316,14 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
 					} else if i > 0 || i == numMonth {
 						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
-						fmt.Println("partHistoryAccumulate:",partHistoryAccumulate)
+						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
 						partHistoryAccumulate = 0.0
 					}
 				}
 			} else if prevEndDateTime.Before(historyTime) || prevEndDateTime.Equal(historyTime) {
 				//全部走旧查询
-				fmt.Println("prevSt:",prevSt)
-				fmt.Println("prevEd:",prevEd)
+				fmt.Println("prevSt:", prevSt)
+				fmt.Println("prevEd:", prevEd)
 				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`
 				prevHistoryPars = append(prevHistoryPars, prevSt, prevEd)
 				// 开票到款金额合计(换算后)
@@ -1353,14 +1352,14 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal)
 					} else if i > 0 || i == numMonth {
 						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate)
-						fmt.Println("partHistoryAccumulate:",partHistoryAccumulate)
+						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
 						partHistoryAccumulate = 0.0
 					}
 				}
 				//fmt.Println("partHistoryAccumulate:",partHistoryAccumulate)
 			}
 			if req.ListParam == "1" && i == j {
-				if i == 0{
+				if i == 0 {
 					dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01"))
 					j = j + 2
 				} else {
@@ -1368,7 +1367,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					j = j + 3
 				}
 			} else if req.ListParam == "2" && i == j {
-				if i == 0{
+				if i == 0 {
 					dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01"))
 					j = j + 5
 				} else {
@@ -1376,7 +1375,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 					j = j + 6
 				}
 			} else if req.ListParam == "3" && i == j {
-				if i == 0{
+				if i == 0 {
 					dateSlice = append(dateSlice, startDateTime.AddDate(0, 11, 0).Format("06/01"))
 					j = j + 11
 				} else {
@@ -1405,8 +1404,8 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 			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])
+			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)
 			}
@@ -1473,10 +1472,10 @@ func ExportIncomeList(c *gin.Context, list []*fms.IncomeSummaryItem) {
 		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)                           // 销售员
+		dataRow.AddCell().SetString(strconv.Itoa(newCompany)) // 新客户
+		dataRow.AddCell().SetString(v.CompanyName)            // 客户名称
+		dataRow.AddCell().SetString(fmt.Sprint(v.Amount))     // 金额
+		dataRow.AddCell().SetString(v.SellerName)             // 销售员
 	}
 
 	// 输出文件