Browse Source

feature(报表统计): 业绩指标统计,包括回款金额(月度、年度)和签约合同金额(月度、年度)

lk 2 years ago
parent
commit
2c33de61c3

+ 28 - 0
opms_parent/app/handler/proj/report.go

@@ -0,0 +1,28 @@
+package base
+
+import (
+	"context"
+
+	"dashoo.cn/common_definition/comm_def"
+	model "dashoo.cn/micro/app/model/proj"
+	service "dashoo.cn/micro/app/service/proj"
+	"github.com/gogf/gf/frame/g"
+)
+
+type BusinessReportHandler struct{}
+
+// QueryBusinessNum 业绩指标-当月新增项目
+func (c *BusinessReportHandler) QueryBusinessNum(ctx context.Context, req *model.QueryNumReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("ContractReport.QueryBusinessNum request %#v ", *req)
+	s, err := service.NewBusinessReportService(ctx)
+	if err != nil {
+		return err
+	}
+	data, err := s.QueryBusinessNum(req.Date)
+	if err != nil {
+		return err
+	}
+
+	rsp.Data = data
+	return nil
+}

+ 5 - 0
opms_parent/app/model/proj/report.go

@@ -0,0 +1,5 @@
+package model
+
+type QueryNumReq struct {
+	Date string `json:"date"`
+}

+ 38 - 10
opms_parent/app/service/contract/report.go

@@ -41,17 +41,31 @@ type CollectionNumData struct {
 
 // QueryCollectionNum 业绩指标-回款金额
 func (s *ContractReportService) QueryCollectionNum(date string) (interface{}, error) {
+	where := ""
+	// 权限限制(销售工程师看自己的)
+	if service.StringsContains(s.CxtUser.Roles, "SalesEngineer") {
+		where = fmt.Sprintf("b.incharge_id='%v'", s.CxtUser.Id)
+	}
 	// 获取数据
 	var collectionInfos []*CollectionNumData
-	err := s.Dao.DB.Model("ctr_contract_collection a").InnerJoin("ctr_contract b", "a.contract_id=b.id").Where(fmt.Sprintf("collection_datetime LIKE '%v%%'", date)).Fields("a.*,b.incharge_id,b.incharge_name,b.product_line,SUM(a.collection_amount) total").Group("incharge_id, product_line").Order("incharge_id ASC, product_line ASC").Scan(&collectionInfos)
+	err := s.Dao.DB.Model("ctr_contract_collection a").InnerJoin("ctr_contract b", "a.contract_id=b.id").Where(fmt.Sprintf("collection_datetime LIKE '%v%%'", date)).Where(where).Fields("a.*,b.incharge_id,b.incharge_name,b.product_line,SUM(a.collection_amount) total").Group("incharge_id, product_line").Order("incharge_id ASC, product_line ASC").Scan(&collectionInfos)
 	if err != nil {
 		return nil, err
 	}
 	// 获取销售数据
-	userList, err := service.GetUserListByRoleCode(s.Ctx, []string{"SalesEngineer", "ProductLineManager"}, 1000)
+	userList, err := service.GetUserListByRoleCode(s.Ctx, []string{"SalesEngineer"}, 1000)
 	if err != nil {
 		return nil, err
 	}
+	// 权限限制(销售工程师看自己的)
+	if service.StringsContains(s.CxtUser.Roles, "SalesEngineer") {
+		userList = []map[string]interface{}{
+			{
+				"Id":       s.CxtUser.Id,
+				"NickName": s.CxtUser.NickName,
+			},
+		}
+	}
 	// BIOBANK CELLSOP LIMS+基因 其他
 	header, data := make([]g.Map, 0), make([]g.Map, 0)
 	header = append(header, g.Map{"prop": "userName", "label": "销售工程师"}, g.Map{"prop": "bio", "label": "BIOBANK"}, g.Map{"prop": "cell", "label": "CELLSOP"}, g.Map{"prop": "lims", "label": "LIMS+基因"}, g.Map{"prop": "other", "label": "其他"}, g.Map{"prop": "total", "label": "合计"})
@@ -109,35 +123,49 @@ func (s *ContractReportService) QueryContractNum(date string) (interface{}, erro
 		contract.CtrContract
 		Total float64 `orm:"total"` // 合计
 	}
+	where := ""
+	// 权限限制(销售工程师看自己的)
+	if service.StringsContains(s.CxtUser.Roles, "SalesEngineer") {
+		where = fmt.Sprintf("incharge_id='%v'", s.CxtUser.Id)
+	}
 	// 获取数据
 	var contractInfos []*ContractNumData
-	err := s.Dao.Where(fmt.Sprintf("contract_sign_time LIKE '%v%%'", date)).Fields("ctr_contract.*,SUM(contract_amount) total").Group("incharge_id, product_line").Order("incharge_id ASC, product_line ASC").Scan(&contractInfos)
+	err := s.Dao.Where(fmt.Sprintf("contract_sign_time LIKE '%v%%' AND appro_status='30'", date)).Where(where).Fields("ctr_contract.*,SUM(contract_amount) total").Group("incharge_id, product_line").Order("incharge_id ASC, product_line ASC").Scan(&contractInfos)
 	if err != nil {
 		return nil, err
 	}
 	// 获取销售数据
-	userList, err := service.GetUserListByRoleCode(s.Ctx, []string{"SalesEngineer", "ProductLineManager"}, 1000)
+	userList, err := service.GetUserListByRoleCode(s.Ctx, []string{"SalesEngineer"}, 1000)
 	if err != nil {
 		return nil, err
 	}
+	// 权限限制(销售工程师看自己的)
+	if service.StringsContains(s.CxtUser.Roles, "SalesEngineer") {
+		userList = []map[string]interface{}{
+			{
+				"Id":       s.CxtUser.Id,
+				"NickName": s.CxtUser.NickName,
+			},
+		}
+	}
 	// BIOBANK CELLSOP LIMS+基因 其他
 	header, data := make([]g.Map, 0), make([]g.Map, 0)
 	header = append(header, g.Map{"prop": "userName", "label": "销售工程师"}, g.Map{"prop": "bio", "label": "BIOBANK"}, g.Map{"prop": "cell", "label": "CELLSOP"}, g.Map{"prop": "lims", "label": "LIMS+基因"}, g.Map{"prop": "other", "label": "其他"}, g.Map{"prop": "total", "label": "合计"})
 
-	user2Collections := make(map[int][]*ContractNumData, 0)
+	user2Contracts := make(map[int][]*ContractNumData, 0)
 	total := float64(0)
 	for _, col := range contractInfos {
-		if _, ok := user2Collections[col.InchargeId]; !ok {
-			user2Collections[col.InchargeId] = make([]*ContractNumData, 0)
+		if _, ok := user2Contracts[col.InchargeId]; !ok {
+			user2Contracts[col.InchargeId] = make([]*ContractNumData, 0)
 		}
-		user2Collections[col.InchargeId] = append(user2Collections[col.InchargeId], col)
+		user2Contracts[col.InchargeId] = append(user2Contracts[col.InchargeId], col)
 		total += col.Total
 	}
 	// 统计数据
 	for _, user := range userList {
 		bio, cell, lims, other, tot := float64(0), float64(0), float64(0), float64(0), float64(0)
-		if len(user2Collections[user["Id"].(int)]) > 0 {
-			for _, col := range user2Collections[user["Id"].(int)] {
+		if len(user2Contracts[user["Id"].(int)]) > 0 {
+			for _, col := range user2Contracts[user["Id"].(int)] {
 				tot += col.Total
 				if col.ProductLine == "10" {
 					bio += col.Total

+ 2 - 2
opms_parent/app/service/home/report.go

@@ -758,7 +758,7 @@ func (s *HomeService) QuerySalesEngineerFollowUpNum(day *gtime.Time) (interface{
 		followUpMonthData = append(followUpMonthData, data)
 	}
 	// 409022238
-	userList, err := service.GetUsersByRoleCode(s.Ctx, []string{"SalesEngineer", "ProductLineManager"}, 100)
+	userList, err := service.GetUsersByRoleCode(s.Ctx, []string{"SalesEngineer"}, 100)
 	if err != nil {
 		return nil, err
 	}
@@ -810,7 +810,7 @@ func (s *HomeService) QueryPunchRecordsNum(day *gtime.Time) (interface{}, error)
 		punchRecordsMonthData = append(punchRecordsMonthData, data)
 	}
 	// 409022238
-	userList, err := service.GetUsersByRoleCode(s.Ctx, []string{"SalesEngineer", "ProductLineManager"}, 100)
+	userList, err := service.GetUsersByRoleCode(s.Ctx, []string{"SalesEngineer"}, 100)
 	if err != nil {
 		return nil, err
 	}

+ 114 - 0
opms_parent/app/service/proj/report.go

@@ -0,0 +1,114 @@
+package proj
+
+import (
+	"context"
+	dao "dashoo.cn/micro/app/dao/proj"
+	model "dashoo.cn/micro/app/model/proj"
+	"dashoo.cn/micro/app/service"
+	"dashoo.cn/opms_libary/micro_srv"
+	"dashoo.cn/opms_libary/myerrors"
+	"fmt"
+	"github.com/gogf/gf/frame/g"
+)
+
+type BusinessReportService struct {
+	Dao *dao.ProjBusinessDao
+	*service.ContextService
+}
+
+func NewBusinessReportService(ctx context.Context) (svc *BusinessReportService, err error) {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
+		return nil, err //fmt.Errorf("获取租户码异常:%s", err.Error())
+	}
+
+	svc = new(BusinessReportService)
+	if svc.ContextService, err = svc.Init(ctx); err != nil {
+		return nil, err
+	}
+	svc.Dao = dao.NewProjBusinessDao(tenant)
+	return svc, nil
+}
+
+// QueryBusinessNum 业绩指标-当月新增项目
+func (s *BusinessReportService) QueryBusinessNum(date string) (interface{}, error) {
+	type BusinessNumData struct {
+		model.ProjBusiness
+		Total float64 `orm:"total"` // 合计
+	}
+	where := ""
+	// 权限限制(销售工程师看自己的)
+	if service.StringsContains(s.CxtUser.Roles, "SalesEngineer") {
+		where = fmt.Sprintf("sale_id='%v'", s.CxtUser.Id)
+	}
+	// 获取数据  (储备转C,项目来源为 400热线 10、展会信息获取 50)不记作新增数据
+	var businessInfos []*BusinessNumData
+	err := s.Dao.Where(fmt.Sprintf("created_time LIKE '%v%%' AND appro_status='30' AND nbo_source<>'10' AND nbo_source<>'50'", date)).Where(where).Fields("proj_business.*,COUNT(1) total").Group("sale_id, product_line").Order("sale_id ASC, product_line ASC").Scan(&businessInfos)
+	if err != nil {
+		return nil, err
+	}
+	// 获取销售数据
+	userList, err := service.GetUserListByRoleCode(s.Ctx, []string{"SalesEngineer"}, 1000)
+	if err != nil {
+		return nil, err
+	}
+	// 权限限制(销售工程师看自己的)
+	if service.StringsContains(s.CxtUser.Roles, "SalesEngineer") {
+		userList = []map[string]interface{}{
+			{
+				"Id":       s.CxtUser.Id,
+				"NickName": s.CxtUser.NickName,
+			},
+		}
+	}
+	// BIOBANK CELLSOP LIMS+基因 其他
+	header, data := make([]g.Map, 0), make([]g.Map, 0)
+	header = append(header, g.Map{"prop": "userName", "label": "销售工程师"}, g.Map{"prop": "bio", "label": "BIOBANK"}, g.Map{"prop": "cell", "label": "CELLSOP"}, g.Map{"prop": "lims", "label": "LIMS+基因"}, g.Map{"prop": "other", "label": "其他"}, g.Map{"prop": "total", "label": "合计"})
+
+	user2Business := make(map[int][]*BusinessNumData, 0)
+	total := float64(0)
+	for _, col := range businessInfos {
+		if _, ok := user2Business[col.SaleId]; !ok {
+			user2Business[col.SaleId] = make([]*BusinessNumData, 0)
+		}
+		user2Business[col.SaleId] = append(user2Business[col.SaleId], col)
+		total += col.Total
+	}
+	// 统计数据
+	for _, user := range userList {
+		bio, cell, lims, other, tot := float64(0), float64(0), float64(0), float64(0), float64(0)
+		if len(user2Business[user["Id"].(int)]) > 0 {
+			for _, col := range user2Business[user["Id"].(int)] {
+				tot += col.Total
+				if col.ProductLine == "10" {
+					bio += col.Total
+				} else if col.ProductLine == "20" {
+					cell += col.Total
+				} else if col.ProductLine == "30" {
+					lims += col.Total
+				} else {
+					other += col.Total
+				}
+			}
+		}
+		data = append(data, g.Map{
+			"userName": user["NickName"],
+			"bio":      fmt.Sprintf("%v", bio),
+			"cell":     fmt.Sprintf("%v", cell),
+			"lims":     fmt.Sprintf("%v", lims),
+			"other":    fmt.Sprintf("%v", other),
+			"total":    fmt.Sprintf("%v", tot),
+		})
+	}
+	data = append(data, g.Map{
+		"userName": "",
+		"bio":      "",
+		"cell":     "",
+		"lims":     "",
+		"other":    "",
+		"total":    fmt.Sprintf("总计:%v个", total),
+	})
+
+	return g.Map{"header": header, "data": data}, nil
+}

+ 1 - 0
opms_parent/main.go

@@ -74,6 +74,7 @@ func main() {
 	s.RegisterName("Questionnaire", new(plat.QuestionnaireHandler), "")
 	s.RegisterName("TableColsConfig", new(plat.TableColsConfigHandler), "")
 	s.RegisterName("ContractReport", new(contract.ContractReportHandler), "")
+	s.RegisterName("BusinessReport", new(projHandler.BusinessReportHandler), "")
 
 	// 首页
 	s.RegisterName("Home", new(home.HomeHandler), "")