Explorar el Código

feature(): 1、产品经理创建归属自己的客户 2、产品线经理可以看到产品线的跟进记录 3、报错处理

ZZH-wl hace 2 años
padre
commit
a05b069d56

+ 96 - 34
opms_parent/app/dao/work/internal/work_order.go

@@ -722,56 +722,45 @@ func (d *WorkOrderDao) DataScope(ctx context.Context, args ...interface{}) *Work
 	cs := ctx.Value("contextService")
 	dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
 	if dataScope != nil {
-		var specialFlag bool
-		var tableAs string
-		if d.TableAs != "" && len(args) <= 1 {
-			tableAs = d.TableAs + "."
-		}
-		if len(args) > 1 {
-			specialFlag = true
-			if val, ok := args[1].(string); ok {
-				tableAs = val + "."
+		// 销售工程师判断
+		var salesEngineerFlag bool
+		if roles, ok := dataScope["roles"]; ok {
+			arr := garray.NewArrayFrom(roles.([]interface{}), true)
+			if arr.Len() == 1 && arr.Contains("SalesEngineer") {
+				salesEngineerFlag = true
 			}
 		}
 		userIds, ok := dataScope["userIds"]
-		delete(dataScope, "userIds")
+		specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args)
+
 		var orColumns []string
 		var orValues []interface{}
 		if ok && userIds != "-1" {
-			column := "created_by"
-			if len(args) > 0 {
-				column = args[0].(string)
+			columns := []string{"created_by"}
+			if len(userCols) > 0 {
+				columns = userCols
 			}
-			if ok, _ := d.M.HasField(column); ok || specialFlag {
-				orColumns = append(orColumns, tableAs+column+" IN (?) ")
-				orValues = append(orValues, userIds)
+			for _, column := range columns {
+				if ok, _ := d.M.HasField(column); ok || specialFlag {
+					orColumns = append(orColumns, column+" IN (?) ")
+					orValues = append(orValues, userIds)
+				}
 			}
 		}
-		// 销售工程师判断
-		var salesEngineerFlag bool
-		if roles, ok := dataScope["roles"]; ok {
-			delete(dataScope, "roles")
-			delete(dataScope, "posts")
-			arr := garray.NewArrayFrom(roles.([]interface{}), true)
-			if arr.Len() == 1 && arr.Contains("SalesEngineer") {
-				salesEngineerFlag = true
+		for col, params := range orColsMap {
+			if ok, _ := d.M.HasField(col); ok || specialFlag {
+				orColumns = append(orColumns, col+" IN (?) ")
+				orValues = append(orValues, params)
 			}
 		}
-		// 非销售工程师权限加成
+
+		// 销售工程师权限加成
 		if !salesEngineerFlag {
-			bigColumns := "is_big"
-			if ok, _ := d.M.HasField("is_big"); ok || specialFlag {
-				if val, ok := dataScope[bigColumns]; ok && val != "" {
-					orColumns = append(orColumns, tableAs+bigColumns+" = ? ")
-					orValues = append(orValues, val)
-				}
-				delete(dataScope, bigColumns)
-			}
 			var andColumns []string
 			var andValues []interface{}
 			for k, v := range dataScope {
 				if ok, _ := d.M.HasField(k); ok || specialFlag {
-					andColumns = append(andColumns, tableAs+k+" IN (?) ")
+					andColumns = append(andColumns, k+" IN (?) ")
 					andValues = append(andValues, v)
 				}
 			}
@@ -787,3 +776,76 @@ func (d *WorkOrderDao) DataScope(ctx context.Context, args ...interface{}) *Work
 	}
 	return d
 }
+
+// args 1、字段
+// args 2、字段、表名
+// args 3、字段对应关系
+func (d *WorkOrderDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
+	var tableAs string
+	var specialFlag bool
+	var userCols []string
+	var orColsMap map[string]interface{}
+	var colsContrast map[string]interface{}
+
+	if d.TableAs != "" && len(args) <= 1 {
+		tableAs = d.TableAs + "."
+	}
+	if len(args) > 1 {
+		specialFlag = true
+		if val, ok := args[1].(string); ok {
+			tableAs = val + "."
+		}
+	}
+	if len(args) > 0 {
+		if column, ok := args[0].(string); ok {
+			userCols = []string{tableAs + column}
+		}
+		if cols, ok := args[0].([]string); ok {
+			for _, v := range cols {
+				userCols = append(userCols, tableAs+v)
+			}
+		}
+		if val, ok := args[0].(map[string]interface{}); ok {
+			specialFlag = true
+			colsContrast = val
+			if orcols, ok := val["orcols"]; ok && val[orcols.(string)] != "" {
+				if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
+					orColsMap[col] = val[col]
+					delete(colsContrast, col)
+				}
+				if cols, ok := orcols.([]string); ok {
+					for _, col := range cols {
+						if gconv.String(val[col]) == "" {
+							continue
+						}
+						orColsMap[col] = val[col]
+						delete(colsContrast, col)
+					}
+				}
+			}
+		}
+	}
+	bigColumns := "is_big"
+	if isBig, ok := dataScope[bigColumns]; ok && isBig.(bool) {
+		if bigCol, ok := colsContrast[bigColumns]; ok {
+			orColsMap[bigCol.(string)] = isBig
+			delete(colsContrast, bigCol.(string))
+		} else {
+			orColsMap[tableAs+bigColumns] = isBig
+		}
+	}
+
+	delete(dataScope, "userIds")
+	delete(dataScope, "roles")
+	delete(dataScope, "posts")
+	delete(dataScope, bigColumns)
+	for k, v := range colsContrast {
+		if data, ok := dataScope[k]; ok {
+			dataScope[v.(string)] = data
+			delete(dataScope, k)
+		} else {
+			dataScope[k] = v
+		}
+	}
+	return specialFlag, userCols, orColsMap
+}

+ 11 - 11
opms_parent/app/service/contract/ctr_contract_collection.go

@@ -66,36 +66,36 @@ func (s CtrContractCollectionService) List(ctx context.Context, req *model.CtrCo
 
 	if req.SearchText != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.SearchText)
-		dao = dao.Where("(cust_name LIKE ? || contract_code LIKE ?)", likestr, likestr)
+		dao = dao.Where("(collection.cust_name LIKE ? || collection.contract_code LIKE ?)", likestr, likestr)
 	}
 	if req.PlanId != 0 {
-		dao = dao.Where("plan_id = ?", req.PlanId)
+		dao = dao.Where("collection.plan_id = ?", req.PlanId)
 	}
 	if req.CustId != 0 {
-		dao = dao.Where("cust_id = ?", req.CustId)
+		dao = dao.Where("collection.cust_id = ?", req.CustId)
 	}
 	if req.CustName != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.CustName)
-		dao = dao.Where("cust_name like ?", likestr)
+		dao = dao.Where("collection.cust_name like ?", likestr)
 	}
 	if req.ContractId != 0 {
-		dao = dao.Where("contract_id = ?", req.ContractId)
+		dao = dao.Where("collection.contract_id = ?", req.ContractId)
 	}
 	if req.ContractCode != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.ContractCode)
-		dao = dao.Where("contract_code like ?", likestr)
+		dao = dao.Where("collection.contract_code like ?", likestr)
 	}
 	if req.CollectionType != "" {
-		dao = dao.Where("collection_type = ?", req.CollectionType)
+		dao = dao.Where("collection.collection_type = ?", req.CollectionType)
 	}
 	if req.ApproStatus != "" {
-		dao = dao.Where("appro_status = ?", req.ApproStatus)
+		dao = dao.Where("collection.appro_status = ?", req.ApproStatus)
 	}
 	if req.BeginTime != "" {
-		dao = dao.Where("created_time > ?", req.BeginTime)
+		dao = dao.Where("collection.created_time > ?", req.BeginTime)
 	}
 	if req.EndTime != "" {
-		dao = dao.Where("created_time < ?", req.EndTime)
+		dao = dao.Where("collection.created_time < ?", req.EndTime)
 	}
 
 	total, err := dao.Count()
@@ -105,7 +105,7 @@ func (s CtrContractCollectionService) List(ctx context.Context, req *model.CtrCo
 	if req.PageNum != 0 {
 		dao = dao.Page(req.GetPage())
 	}
-	orderby := "created_time desc"
+	orderby := "collection.created_time desc"
 	if req.OrderBy != "" {
 		orderby = req.OrderBy
 	}

+ 9 - 9
opms_parent/app/service/contract/ctr_contract_collection_plan.go

@@ -83,30 +83,30 @@ func (s CtrContractCollectionPlanService) List(ctx context.Context, req *model.C
 		DataScope(ctx, "incharge_id", "contract")
 	if req.SearchText != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.SearchText)
-		dao = dao.Where("(cust_name LIKE ? || contract_code LIKE ?)", likestr, likestr)
+		dao = dao.Where("(plan.cust_name LIKE ? || plan.contract_code LIKE ?)", likestr, likestr)
 	}
 	if req.CustId != 0 {
-		dao = dao.Where("cust_id = ?", req.CustId)
+		dao = dao.Where("plan.cust_id = ?", req.CustId)
 	}
 	if req.CustName != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.CustName)
-		dao = dao.Where("cust_name like ?", likestr)
+		dao = dao.Where("plan.cust_name like ?", likestr)
 	}
 	if req.ContractId != 0 {
-		dao = dao.Where("contract_id = ?", req.ContractId)
+		dao = dao.Where("plan.contract_id = ?", req.ContractId)
 	}
 	if req.ContractCode != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.ContractCode)
-		dao = dao.Where("contract_code like ?", likestr)
+		dao = dao.Where("plan.contract_code like ?", likestr)
 	}
 	if req.ContractStatus != "" {
-		dao = dao.Where("contract_status = ?", req.ContractStatus)
+		dao = dao.Where("plan.contract_status = ?", req.ContractStatus)
 	}
 	if req.BeginTime != "" {
-		dao = dao.Where("created_time > ?", req.BeginTime)
+		dao = dao.Where("plan.created_time > ?", req.BeginTime)
 	}
 	if req.EndTime != "" {
-		dao = dao.Where("created_time < ?", req.EndTime)
+		dao = dao.Where("plan.created_time < ?", req.EndTime)
 	}
 
 	total, err := dao.Count()
@@ -116,7 +116,7 @@ func (s CtrContractCollectionPlanService) List(ctx context.Context, req *model.C
 	if req.PageNum != 0 {
 		dao = dao.Page(req.GetPage())
 	}
-	orderby := "created_time desc"
+	orderby := "plan.created_time desc"
 	if req.OrderBy != "" {
 		orderby = req.OrderBy
 	}

+ 12 - 12
opms_parent/app/service/contract/ctr_contract_invoice.go

@@ -68,40 +68,40 @@ func (s CtrContractInvoiceService) List(ctx context.Context, req *model.CtrContr
 		DataScope(ctx, "incharge_id", "contract")
 	if req.SearchText != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.SearchText)
-		dao = dao.Where("(cust_name LIKE ? || contract_code LIKE ?)", likestr, likestr)
+		dao = dao.Where("(invoice.cust_name LIKE ? || invoice.contract_code LIKE ?)", likestr, likestr)
 	}
 	if req.CustId != 0 {
-		dao = dao.Where("cust_id = ?", req.CustId)
+		dao = dao.Where("invoice.cust_id = ?", req.CustId)
 	}
 	if req.CustName != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.CustName)
-		dao = dao.Where("cust_name like ?", likestr)
+		dao = dao.Where("invoice.cust_name like ?", likestr)
 	}
 	if req.ContractId != 0 {
-		dao = dao.Where("contract_id = ?", req.ContractId)
+		dao = dao.Where("invoice.contract_id = ?", req.ContractId)
 	}
 	if req.ContractCode != "" {
 		likestr := fmt.Sprintf("%%%s%%", req.ContractCode)
-		dao = dao.Where("contract_code like ?", likestr)
+		dao = dao.Where("invoice.contract_code like ?", likestr)
 	}
 	if req.InvoiceType != "" {
-		dao = dao.Where("invoice_type = ?", req.InvoiceType)
+		dao = dao.Where("invoice.invoice_type = ?", req.InvoiceType)
 	}
 	if req.ApproStatus != "" {
-		dao = dao.Where("appro_status = ?", req.ApproStatus)
+		dao = dao.Where("invoice.appro_status = ?", req.ApproStatus)
 	}
 	if req.InvoiceCode != "" {
-		dao = dao.Where("invoice_code = ?", req.InvoiceCode)
+		dao = dao.Where("invoice.invoice_code = ?", req.InvoiceCode)
 	}
 	if req.CourierCode != "" {
-		dao = dao.Where("courier_code = ?", req.CourierCode)
+		dao = dao.Where("invoice.courier_code = ?", req.CourierCode)
 	}
 
 	if req.BeginTime != "" {
-		dao = dao.Where("created_time > ?", req.BeginTime)
+		dao = dao.Where("invoice.created_time > ?", req.BeginTime)
 	}
 	if req.EndTime != "" {
-		dao = dao.Where("created_time < ?", req.EndTime)
+		dao = dao.Where("invoice.created_time < ?", req.EndTime)
 	}
 
 	total, err := dao.Count()
@@ -111,7 +111,7 @@ func (s CtrContractInvoiceService) List(ctx context.Context, req *model.CtrContr
 	if req.PageNum != 0 {
 		dao = dao.Page(req.GetPage())
 	}
-	orderby := "created_time desc"
+	orderby := "invoice.created_time desc"
 	if req.OrderBy != "" {
 		orderby = req.OrderBy
 	}

+ 5 - 1
opms_parent/app/service/cust/cust_customer.go

@@ -178,11 +178,15 @@ func (s *CustomerService) Create(req *model.CustomerAddSeq) (insertId int64, err
 	roles := s.GetCxtUserRoles()
 	isSales := false
 	for _, v := range roles {
-		if v == "SalesEngineer" { // 销售角色
+		if v == "SalesEngineer" || v == "ProductLineManager" { // 销售角色
 			isSales = true
 			break
 		}
 	}
+	if isBig, ok := s.DataScope["is_big"]; ok && isBig.(bool) {
+		isSales = true
+	}
+
 	// 销售角色
 	if isSales {
 		cusTomer.IsPublic = noPublic

+ 28 - 9
opms_parent/app/service/plat/plat_followup.go

@@ -2,16 +2,15 @@ package plat
 
 import (
 	"context"
+	"dashoo.cn/micro/app/dao/cust"
 	projdao "dashoo.cn/micro/app/dao/proj"
-	"database/sql"
-	"github.com/gogf/gf/container/garray"
-	"strconv"
-	"strings"
-
 	"dashoo.cn/opms_libary/myerrors"
+	"database/sql"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/os/gtime"
 	"github.com/gogf/gf/util/gconv"
+	"strconv"
+	"strings"
 
 	"dashoo.cn/micro/app/dao/plat"
 	model "dashoo.cn/micro/app/model/plat"
@@ -130,11 +129,31 @@ func (s *followupService) Create(req *model.AddPlatFollowupReq) (err error) {
 
 // 跟进记录信息列表:按照日期显示,并附带评论
 func (s *followupService) GetListByDay(req *model.SearchPlatFollowupReq) (total int, followupList []*model.FollowupInfoResp, err error) {
-	followupModel := s.Dao.M
-	// 用户仅有销售工程师角色展示自己的数据,其他人可以看到所有数据
-	if garray.NewStrArrayFrom(s.CxtUser.Roles, true).Contains("SalesEngineer") {
-		followupModel = followupModel.WhereIn("created_by", s.DataScope["userIds"])
+	filter := map[string]interface{}{}
+	if req.TargetType == "20" && req.TargetId != "" {
+		filter = map[string]interface{}{
+			"target_id": req.TargetId,
+			"orcols":    "target_id",
+		}
+	} else if req.CustId != "" {
+		filter = map[string]interface{}{
+			"cust_id": req.CustId,
+			"orcols":  "cust_id",
+		}
+	} else {
+		if s.DataScope["userIds"] != "-1" {
+			vals, _ := cust.NewCustCustomerDao(s.Tenant).DataScope(s.Ctx, "sales_id").Where("is_public", "20").Fields("id").Array()
+			filter = map[string]interface{}{
+				"cust_id": vals,
+				"orcols":  "cust_id",
+			}
+		}
 	}
+	followupModel := s.Dao.DataScope(s.Ctx, filter)
+	// 用户仅有销售工程师角色展示自己的数据,其他人可以看到所有数据
+	//if garray.NewStrArrayFrom(s.CxtUser.Roles, true).Contains("SalesEngineer") {
+	//	followupModel = followupModel.WhereIn("created_by", s.DataScope["userIds"])
+	//}
 	if req.CustId != "" {
 		followupModel = followupModel.Where("cust_id", req.CustId)
 	}