소스 검색

freature(首页): 个人销售金额统计、个人销售回款统计、总部销售金额统计、总部销售回款统计

likai 3 년 전
부모
커밋
abfc1d8531

+ 7 - 0
opms_parent/app/model/home/report.go

@@ -0,0 +1,7 @@
+package home
+
+type ReportData struct {
+	XData       []string  `json:"xData"`
+	YDataTarget []float64 `json:"yDataTarget"`
+	YDataReal   []float64 `json:"yDataReal"`
+}

+ 20 - 5
opms_parent/app/service/home/home.go

@@ -50,7 +50,7 @@ func (s *HomeService) QueryHomeNumReportData(param *home.SearchNumReportData) (r
 	for _, v := range param.ReportId {
 		numReport := new(home.NumReportResponse)
 		numReport.Id = v
-		value, _ := getReportData(v)
+		value, _ := s.getReportData(v, nil)
 		numReport.Data = value
 		numConfig = append(numConfig, numReport)
 	}
@@ -61,8 +61,9 @@ func (s *HomeService) QueryHomeNumReportData(param *home.SearchNumReportData) (r
 }
 
 func (s *HomeService) QueryHomeDataReportData(param *home.SearchDataReportData) (resp *home.DataReportResponse, err error) {
+	resp = new(home.DataReportResponse)
 	resp.Id = param.ReportId
-	value, err := getReportData(param.ReportId)
+	value, err := s.getReportData(param.ReportId, &param.Params)
 	if err != nil {
 		return nil, err
 	}
@@ -71,12 +72,26 @@ func (s *HomeService) QueryHomeDataReportData(param *home.SearchDataReportData)
 	return
 }
 
-func getReportData(id int64) (interface{}, error) {
+// 10000-20000之间:个人看板数据 TODO 疑似与 sys_report 表对应?
+// 20000-30000之间:报表数据 TODO 疑似与 sys_report 表对应?
+func (s *HomeService) getReportData(id int64, params *map[string]interface{}) (interface{}, error) {
 	switch id {
-	case 0:
+	case 10000:
+		// 个人看板数据
 		return nil, nil
+	case 20000:
+		// 报表数据   个人销售金额
+		return getPersonalContractReportData(s.ContextService.Ctx, "CONTRACT", params)
+	case 20001:
+		// 报表数据   个人销售回款
+		return getPersonalContractReportData(s.ContextService.Ctx, "COLLECTION", params)
+	case 20002:
+		// 报表数据   总部销售金额
+		return getCompanyContractReportData(s.ContextService.Ctx, "CONTRACT", params)
+	case 20003:
+		// 报表数据   总部销售回款
+		return getCompanyContractReportData(s.ContextService.Ctx, "COLLECTION", params)
 	default:
 		return nil, nil
-
 	}
 }

+ 156 - 0
opms_parent/app/service/home/report.go

@@ -0,0 +1,156 @@
+package home
+
+import (
+	"context"
+	"dashoo.cn/micro/app/model/home"
+	contractService "dashoo.cn/micro/app/service/contract"
+	"dashoo.cn/opms_libary/micro_srv"
+	"database/sql"
+	"fmt"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gconv"
+)
+
+// getPersonalContractReportData 获取个人数据
+// dataType:collection为回款;其他为合同
+func getPersonalContractReportData(ctx context.Context, dataType string, params *map[string]interface{}) (*home.ReportData, error) {
+	var reportData home.ReportData
+	targetMap := make(map[int]gdb.Record, 0)
+	realMap := make(map[int][]*gdb.Record, 0)
+	targetField := "sales_target"
+	realField := "contract_amount"
+	year := gtime.Now().Format("Y")
+	if params != nil && (*params)["year"] != nil {
+		year = gconv.String((*params)["year"])
+	}
+	// 统计字段
+	if dataType == "COLLECTION" {
+		targetField = "collection_target"
+		realField = "collection_amount"
+	}
+
+	srv, err := contractService.NewCtrContractService(ctx)
+	if err != nil {
+		return nil, err
+	}
+	// 获取用户信息
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
+	}
+
+	targets, err := srv.Dao.DB.Model("rpt_sales_target").Where("sale_user_id", userInfo.Id).Order("monthly ASC").FindAll()
+	if err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	for index, target := range targets {
+		targetMap[target["monthly"].Int()] = targets[index]
+	}
+	// 统计12个月份的数据
+	// 统计目标值
+	for index := 1; index <= 12; index++ {
+		reportData.XData = append(reportData.XData, fmt.Sprintf("%v月", index))
+		if target, ok := targetMap[index]; ok {
+			reportData.YDataTarget = append(reportData.YDataTarget, target[targetField].Float64())
+		} else {
+			reportData.YDataTarget = append(reportData.YDataTarget, 0)
+		}
+	}
+	// 统计合同值
+	contractModel := srv.Dao.DB.Model("ctr_contract").Where("ctr_contract.incharge_id", userInfo.Id)
+	if dataType != "COLLECTION" {
+		contracts, err := contractModel.Where("ctr_contract.contract_start_time LIKE ?", year+"-%").Order("ctr_contract.contract_start_time ASC").FindAll()
+		if err != nil && err != sql.ErrNoRows {
+			return nil, err
+		}
+		for index, contract := range contracts {
+			realMap[contract["contract_start_time"].GTime().Month()] = append(realMap[contract["contract_start_time"].GTime().Month()], &contracts[index])
+		}
+	} 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+"-%").Order("ctr_contract_collection.collection_datetime ASC").Fields("ctr_contract_collection.*").FindAll()
+		if err != nil && err != sql.ErrNoRows {
+			return nil, err
+		}
+		for index, collection := range collections {
+			realMap[collection["collection_datetime"].GTime().Month()] = append(realMap[collection["collection_datetime"].GTime().Month()], &collections[index])
+		}
+	}
+	// 统计12个月份的数据
+	// 统计实际值
+	for index := 1; index <= 12; index++ {
+		if realData, ok := realMap[index]; ok {
+			realAmount := float64(0)
+			for _, data := range realData {
+				realAmount += (*data)[realField].Float64()
+			}
+			reportData.YDataReal = append(reportData.YDataReal, realAmount)
+		} else {
+			reportData.YDataReal = append(reportData.YDataReal, 0)
+		}
+	}
+
+	return &reportData, nil
+}
+
+// getCompanyContractReportData 获取个人数据
+// dataType:collection为回款;其他为合同
+func getCompanyContractReportData(ctx context.Context, dataType string, params *map[string]interface{}) (*home.ReportData, error) {
+	var reportData home.ReportData
+	realMap := make(map[int]gdb.Record, 0)
+	targetField := "sales_target"
+	realField := "contract_amount"
+	year := gtime.Now().Format("Y")
+	if params != nil && (*params)["year"] != nil {
+		year = gconv.String((*params)["year"])
+	}
+	// 统计字段
+	if dataType == "COLLECTION" {
+		targetField = "collection_target"
+		realField = "collection_amount"
+	}
+
+	srv, err := contractService.NewCtrContractService(ctx)
+	if err != nil {
+		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()
+	if err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	// 统计合同值
+	contractModel := srv.Dao.DB.Model("ctr_contract").Group("ctr_contract.incharge_id").Order("ctr_contract.incharge_id ASC")
+	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()
+		if err != nil && err != sql.ErrNoRows {
+			return nil, err
+		}
+		for index, contract := range contracts {
+			realMap[contract["incharge_id"].Int()] = contracts[index]
+		}
+	} 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()
+		if err != nil && err != sql.ErrNoRows {
+			return nil, err
+		}
+		for index, collection := range collections {
+			realMap[collection["incharge_id"].Int()] = collections[index]
+		}
+	}
+
+	// 统计目标值和实际值
+	for _, target := range targets {
+		reportData.XData = append(reportData.XData, target["sale_user_name"].String())
+		reportData.YDataTarget = append(reportData.YDataTarget, target[targetField].Float64())
+		if realData, ok := realMap[target["sale_user_id"].Int()]; ok {
+			reportData.YDataReal = append(reportData.YDataReal, realData[realField].Float64())
+		} else {
+			reportData.YDataReal = append(reportData.YDataReal, 0)
+		}
+	}
+
+	return &reportData, nil
+}

+ 3 - 0
opms_parent/app/service/plat/plat_followup.go

@@ -127,6 +127,9 @@ func (s *followupService) GetListByDay(req *model.SearchPlatFollowupReq) (total
 	if req.ManagerId != "" {
 		followupModel = followupModel.Where("created_by", req.ManagerId)
 	}
+	if req.IsMyself == "1" {
+		followupModel = followupModel.Where("created_by", s.GetCxtUserId())
+	}
 	// 日期条件
 	if req.DaysBeforeToday >= 0 { // 获取前N天的跟进记录
 		now := gtime.Now()

+ 2 - 0
opms_parent/main.go

@@ -59,7 +59,9 @@ func main() {
 	s.RegisterName("DingUpload", new(dingtalk.DingUploadHandler), "")
 	s.RegisterName("Report", new(sysreport.SysReportHandler), "")
 	s.RegisterName("RoleReport", new(sysreport.SysRoleReportHandler), "")
+	// 首页
 	s.RegisterName("Home", new(home.HomeHandler), "")
+
 	// 钉钉回调接口
 	s.RegisterName("DingEvent", new(dingtalk.DingHandler), "")