|
|
@@ -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
|