|
@@ -89,21 +89,43 @@ func getPersonalContractReportData(ctx context.Context, dataType string, params
|
|
|
} else {
|
|
} else {
|
|
|
reportData.YDataReal = append(reportData.YDataReal, 0)
|
|
reportData.YDataReal = append(reportData.YDataReal, 0)
|
|
|
}
|
|
}
|
|
|
|
|
+ if reportData.YDataTarget[index-1] == 0 {
|
|
|
|
|
+ reportData.PercentData = append(reportData.PercentData, 0)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reportData.PercentData = append(reportData.PercentData, reportData.YDataReal[index-1]*100/reportData.YDataTarget[index-1])
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return &reportData, nil
|
|
return &reportData, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// getCompanyContractReportData 获取个人数据
|
|
|
|
|
|
|
+// getCompanyContractReportData 获取总部数据
|
|
|
// dataType:collection为回款;其他为合同
|
|
// dataType:collection为回款;其他为合同
|
|
|
func getCompanyContractReportData(ctx context.Context, dataType string, params *map[string]interface{}) (*home.ReportData, error) {
|
|
func getCompanyContractReportData(ctx context.Context, dataType string, params *map[string]interface{}) (*home.ReportData, error) {
|
|
|
var reportData home.ReportData
|
|
var reportData home.ReportData
|
|
|
realMap := make(map[int]gdb.Record, 0)
|
|
realMap := make(map[int]gdb.Record, 0)
|
|
|
targetField := "sales_target"
|
|
targetField := "sales_target"
|
|
|
realField := "contract_amount"
|
|
realField := "contract_amount"
|
|
|
- year := gtime.Now().Format("Y")
|
|
|
|
|
- if params != nil && (*params)["year"] != nil {
|
|
|
|
|
- year = gconv.String((*params)["year"])
|
|
|
|
|
|
|
+ dateWhere1 := "" // 查询条件
|
|
|
|
|
+ dateWhere2 := "" // 查询条件
|
|
|
|
|
+ dateWhere3 := ""
|
|
|
|
|
+ date := gtime.Now()
|
|
|
|
|
+ if params != nil && (*params)["date"] != nil {
|
|
|
|
|
+ date = gconv.GTime((*params)["date"])
|
|
|
|
|
+ }
|
|
|
|
|
+ dateWhere1 = fmt.Sprintf("ctr_contract.contract_start_time LIKE '%v'", date.Format("Y")+"-%")
|
|
|
|
|
+ dateWhere2 = fmt.Sprintf("ctr_contract_collection.collection_datetime LIKE '%v'", date.Format("Y")+"-%")
|
|
|
|
|
+ if params != nil && (*params)["searchType"] != nil {
|
|
|
|
|
+ searchType := gconv.String((*params)["searchType"])
|
|
|
|
|
+ if searchType == "month" {
|
|
|
|
|
+ dateWhere1 = fmt.Sprintf("ctr_contract.contract_start_time LIKE '%v'", date.Format("Y-m")+"-%")
|
|
|
|
|
+ dateWhere2 = fmt.Sprintf("ctr_contract_collection.collection_datetime LIKE '%v'", date.Format("Y-m")+"-%")
|
|
|
|
|
+ dateWhere3 = fmt.Sprintf("monthly=%v", date.Month())
|
|
|
|
|
+ } else if searchType == "quarter" {
|
|
|
|
|
+ dateWhere1 = getQuarterWhere(date, "ctr_contract.contract_start_time")
|
|
|
|
|
+ dateWhere2 = getQuarterWhere(date, "ctr_contract_collection.collection_datetime")
|
|
|
|
|
+ dateWhere3 = getQuarterMonthWhere(date, "monthly")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
// 统计字段
|
|
// 统计字段
|
|
|
if dataType == "COLLECTION" {
|
|
if dataType == "COLLECTION" {
|
|
@@ -116,14 +138,14 @@ func getCompanyContractReportData(ctx context.Context, dataType string, params *
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- targets, err := srv.Dao.DB.Model("rpt_sales_target").Order("sale_user_id ASC").Group("sale_user_id").Fields(fmt.Sprintf("sale_user_id, sale_user_name, SUM(%v) %v", targetField, targetField)).FindAll()
|
|
|
|
|
|
|
+ targets, err := srv.Dao.DB.Model("rpt_sales_target").Where(dateWhere3).Order("sale_user_id ASC").Group("sale_user_id").Fields(fmt.Sprintf("sale_user_id, sale_user_name, SUM(%v) %v", targetField, targetField)).FindAll()
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
|
// 统计合同值
|
|
// 统计合同值
|
|
|
contractModel := srv.Dao.DB.Model("ctr_contract").Group("ctr_contract.incharge_id").Order("ctr_contract.incharge_id ASC")
|
|
contractModel := srv.Dao.DB.Model("ctr_contract").Group("ctr_contract.incharge_id").Order("ctr_contract.incharge_id ASC")
|
|
|
if dataType != "COLLECTION" {
|
|
if dataType != "COLLECTION" {
|
|
|
- contracts, err := contractModel.Where("ctr_contract.contract_start_time LIKE ?", year+"-%").Fields("ctr_contract.incharge_id, ctr_contract.incharge_name, SUM(ctr_contract.contract_amount) contract_amount").FindAll()
|
|
|
|
|
|
|
+ contracts, err := contractModel.Where(dateWhere1).Fields("ctr_contract.incharge_id, ctr_contract.incharge_name, SUM(ctr_contract.contract_amount) contract_amount").FindAll()
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
@@ -132,7 +154,7 @@ func getCompanyContractReportData(ctx context.Context, dataType string, params *
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// 回款数据统计
|
|
// 回款数据统计
|
|
|
- collections, err := contractModel.InnerJoin("ctr_contract_collection", "ctr_contract.id=ctr_contract_collection.contract_id").Where("ctr_contract_collection.appro_status", "20").Where("ctr_contract_collection.collection_datetime LIKE ?", year+"-%").Fields("ctr_contract.incharge_id, ctr_contract.incharge_name, SUM(ctr_contract_collection.collection_amount) collection_amount").FindAll()
|
|
|
|
|
|
|
+ collections, err := contractModel.InnerJoin("ctr_contract_collection", "ctr_contract.id=ctr_contract_collection.contract_id").Where("ctr_contract_collection.appro_status", "20").Where(dateWhere2).Fields("ctr_contract.incharge_id, ctr_contract.incharge_name, SUM(ctr_contract_collection.collection_amount) collection_amount").FindAll()
|
|
|
if err != nil && err != sql.ErrNoRows {
|
|
if err != nil && err != sql.ErrNoRows {
|
|
|
return nil, err
|
|
return nil, err
|
|
|
}
|
|
}
|
|
@@ -142,7 +164,7 @@ func getCompanyContractReportData(ctx context.Context, dataType string, params *
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 统计目标值和实际值
|
|
// 统计目标值和实际值
|
|
|
- for _, target := range targets {
|
|
|
|
|
|
|
+ for index, target := range targets {
|
|
|
reportData.XData = append(reportData.XData, target["sale_user_name"].String())
|
|
reportData.XData = append(reportData.XData, target["sale_user_name"].String())
|
|
|
reportData.YDataTarget = append(reportData.YDataTarget, target[targetField].Float64())
|
|
reportData.YDataTarget = append(reportData.YDataTarget, target[targetField].Float64())
|
|
|
if realData, ok := realMap[target["sale_user_id"].Int()]; ok {
|
|
if realData, ok := realMap[target["sale_user_id"].Int()]; ok {
|
|
@@ -150,7 +172,38 @@ func getCompanyContractReportData(ctx context.Context, dataType string, params *
|
|
|
} else {
|
|
} else {
|
|
|
reportData.YDataReal = append(reportData.YDataReal, 0)
|
|
reportData.YDataReal = append(reportData.YDataReal, 0)
|
|
|
}
|
|
}
|
|
|
|
|
+ if reportData.YDataTarget[index] == 0 {
|
|
|
|
|
+ reportData.PercentData = append(reportData.PercentData, 0)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reportData.PercentData = append(reportData.PercentData, reportData.YDataReal[index]*100/reportData.YDataTarget[index])
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return &reportData, nil
|
|
return &reportData, nil
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func getQuarterWhere(date *gtime.Time, field string) string {
|
|
|
|
|
+ if date.Month() >= 1 && date.Month() <= 3 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= '%v' AND %v < '%v'", field, date.Format("Y-")+"01-01 00:00:00", field, date.Format("Y-")+"04-01 00:00:00")
|
|
|
|
|
+ } else if date.Month() >= 4 && date.Month() <= 6 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= '%v' AND %v < '%v'", field, date.Format("Y-")+"04-01 00:00:00", field, date.Format("Y-")+"07-01 00:00:00")
|
|
|
|
|
+ } else if date.Month() >= 7 && date.Month() <= 9 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= '%v' AND %v < '%v'", field, date.Format("Y-")+"07-01 00:00:00", field, date.Format("Y-")+"10-01 00:00:00")
|
|
|
|
|
+ } else if date.Month() >= 10 && date.Month() <= 12 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= '%v' AND %v <= '%v'", field, date.Format("Y-")+"10-01 00:00:00", field, date.Format("Y-")+"12-31 23:59:59")
|
|
|
|
|
+ }
|
|
|
|
|
+ return ""
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func getQuarterMonthWhere(date *gtime.Time, field string) string {
|
|
|
|
|
+ if date.Month() >= 1 && date.Month() <= 3 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= %v AND %v < %v", field, 1, field, 4)
|
|
|
|
|
+ } else if date.Month() >= 4 && date.Month() <= 6 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= %v AND %v < %v", field, 4, field, 7)
|
|
|
|
|
+ } else if date.Month() >= 7 && date.Month() <= 9 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= %v AND %v < %v", field, 7, field, 10)
|
|
|
|
|
+ } else if date.Month() >= 10 && date.Month() <= 12 {
|
|
|
|
|
+ return fmt.Sprintf("%v >= %v AND %v <= %v", field, 10, field, 12)
|
|
|
|
|
+ }
|
|
|
|
|
+ return ""
|
|
|
|
|
+}
|