Sfoglia il codice sorgente

Merge branch 'dev/1.0.4.2_wjh' into hotfix/v1.0.4.2

* dev/1.0.4.2_wjh:
  xg
Jianghan 1 anno fa
parent
commit
5ae48eba27

+ 21 - 18
api/internal/service/CoopHistoryService.go

@@ -63,10 +63,10 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 	propertyForm := T.NetworkCom.GetMyProbusfor(req.EntAccountId)
 	// firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
 	// 1、同甲异业数据/ 3、招标代理机构渠道
-	if req.ChannelType == "0" || req.ChannelType == "1" || req.ChannelType == "3" {
-		r1, r2 := GetData(propertyForm, pTmp.BuyerId)
-		if (req.ChannelType == "0" || req.ChannelType == "1") && r1 != nil && len(r1) > 0 {
-			size_1 = int64(len(r1))
+	r1, r2 := GetData(propertyForm, pTmp.BuyerId)
+	if r1 != nil && len(r1) > 0 {
+		size_1 = int64(len(r1))
+		if req.ChannelType == "0" || req.ChannelType == "1" {
 			for _, m := range r1 {
 				near, zbtime := LastTimeCoop(pTmp.BuyerId, common.ObjToString(m["name"]), "adiffb")
 				tmp := ResultData{
@@ -81,8 +81,10 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 				result = append(result, &tmp)
 			}
 		}
-		if req.ChannelType == "0" || req.ChannelType == "3" && r2 != nil && len(r2) > 0 {
-			size_3 = int64(len(r2))
+	}
+	if r2 != nil && len(r2) > 0 {
+		size_3 = int64(len(r2))
+		if req.ChannelType == "0" || req.ChannelType == "3" {
 			for _, m := range r2 {
 				near, zbtime := LastTimeCoop(pTmp.BuyerId, common.ObjToString(m["name"]), "agency")
 				tmp := ResultData{
@@ -99,13 +101,14 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 		}
 	}
 	if pTmp.BuyerId != "" {
-		if req.ChannelType == "0" || req.ChannelType == "4" {
-			// 中间人可介绍业主
-			var r3 []map[string]interface{}
-			r3 = FindMiddleman([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, req.PositionId, r3)
-			if r3 != nil && len(r3) > 0 {
+
+		// 中间人可介绍业主
+		var r3 []map[string]interface{}
+		r3 = FindMiddleman([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, req.PositionId, r3)
+		if r3 != nil && len(r3) > 0 {
+			size_4 = int64(len(r3))
+			if req.ChannelType == "0" || req.ChannelType == "4" {
 				for _, m := range r3 {
-					size_4 = int64(len(r3))
 					tmp := ResultData{
 						SourceType:   "middleman",
 						EntName:      common.ObjToString(m["b_name"]),
@@ -118,12 +121,12 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 				}
 			}
 		}
-		if req.ChannelType == "0" || req.ChannelType == "2" {
-			// 关联单位
-			var r4 []map[string]interface{}
-			r4 = Findfirstparty([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, r4)
-			if r4 != nil && len(r4) > 0 {
-				size_2 = int64(len(r4))
+		// 关联单位
+		var r4 []map[string]interface{}
+		r4 = Findfirstparty([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, r4)
+		if r4 != nil && len(r4) > 0 {
+			size_2 = int64(len(r4))
+			if req.ChannelType == "0" || req.ChannelType == "2" {
 				for _, m := range r4 {
 					tmp := ResultData{
 						SourceType:   "sup_sub",

+ 64 - 20
api/internal/service/plistService.go

@@ -8,6 +8,7 @@ import (
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 	"context"
 	"fmt"
+	"github.com/gogf/gf/v2/util/gconv"
 	"github.com/shopspring/decimal"
 	"strconv"
 	"strings"
@@ -59,8 +60,12 @@ type ProjectEntry struct {
 }
 
 func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasNextPage bool, total int) {
-	buyerM := BuyerList(req.PartyA, req.Supplier, req.Heterotophy, req.Intermediary, req.Agency, req.PositionId)
-	if len(*buyerM) <= 0 {
+	buyerM := BuyerList(req.PartyA, req.Supplier, req.Heterotophy, "", req.Agency, req.PositionId)
+	var plist []string
+	if req.Intermediary != "" {
+		plist = getIyProList(req.Intermediary, req.PositionId)
+	}
+	if len(*buyerM) <= 0 && len(plist) <= 0 {
 		return []*ProjectEntry{}, false, 0
 	}
 	mmp := MonitorStatus(req.UserId) // 项目监控
@@ -73,7 +78,7 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 	if req.SaleStatus == "0" {
 		isSqlPage = true // 是否sql分页
 	}
-	countSql, findSql := getQuerySql(req, isSqlPage, buyerArr)
+	countSql, findSql := getQuerySql(req, isSqlPage, buyerArr, plist)
 	rows, err := T.ClickhouseConn.Query(context.TODO(), findSql)
 	defer rows.Close()
 	if err != nil {
@@ -127,15 +132,45 @@ func preSalesStatus(posid int64) (m1 map[string]interface{}) {
 	return m1
 }
 
-func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (countSql, findSql string) {
+// 中间人 直接查询可介绍项目
+func getIyProList(iy string, positionId int64) (array []string) {
+	wh, args := common.WhArgs(strings.Split(iy, ","))
+	args = append(args, positionId)
+	intermediaryArr := T.CrmMysql.SelectBySql(`select b.relate_id as relate_id,b.relate_name as relate_name from crm.connection a inner join crm.connection_introduce b on ( a.id in (`+wh+`) and  a.position_id=?  and a.id=b.connection_id and b.itype=2)`, args...)
+	for _, m := range *intermediaryArr {
+		pid := gconv.String(m["relate_id"])
+		array = append(array, pid)
+	}
+	return
+}
+
+func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr, plist []string) (countSql, findSql string) {
 	querys := []string{}
 	// 左侧选中的业主id
-	if len(buyerArr) > 0 {
-		var arr []string
-		for _, s := range buyerArr {
-			arr = append(arr, fmt.Sprintf("'%s'", s))
+	if len(buyerArr) > 0 || len(plist) > 0 {
+		if len(buyerArr) > 0 && len(plist) > 0 {
+			var arr []string
+			for _, s := range buyerArr {
+				arr = append(arr, fmt.Sprintf("'%s'", s))
+			}
+			var arr1 []string
+			for _, s := range plist {
+				arr1 = append(arr1, fmt.Sprintf("'%s'", s))
+			}
+			querys = append(querys, fmt.Sprintf(" (a.buyer_id in (%s) or a.project_id in (%s)) ", strings.Join(arr, ","), strings.Join(arr1, ",")))
+		} else if len(buyerArr) > 0 {
+			var arr []string
+			for _, s := range buyerArr {
+				arr = append(arr, fmt.Sprintf("'%s'", s))
+			}
+			querys = append(querys, fmt.Sprintf(" a.buyer_id in (%s) ", strings.Join(arr, ",")))
+		} else if len(plist) > 0 {
+			var arr1 []string
+			for _, s := range plist {
+				arr1 = append(arr1, fmt.Sprintf("'%s'", s))
+			}
+			querys = append(querys, fmt.Sprintf(" a.project_id in (%s) ", strings.Join(arr1, ",")))
 		}
-		querys = append(querys, fmt.Sprintf(" a.buyer_id in (%s) ", strings.Join(arr, ",")))
 	}
 	//	商机类型
 	if req.BusinessType != "" && req.BusinessType != "全部" {
@@ -188,17 +223,26 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 		}
 		querys = append(querys, arr...)
 	}
-	// 项目金额
-	if req.Amount != "" && strings.Contains(req.Amount, "-") {
-		minPriceStr, maxPriceStr := strings.Split(req.Amount, "-")[0], strings.Split(req.Amount, "-")[1]
-		minPrice := common.Int64All(common.Float64All(minPriceStr) * 10000) //换成元
-		maxPrice := common.Int64All(common.Float64All(maxPriceStr) * 10000) //换成元
-		if minPriceStr != "" && maxPriceStr != "" {
-			querys = append(querys, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", minPrice, maxPrice))
-		} else if minPriceStr != "" {
-			querys = append(querys, fmt.Sprintf("(a.project_money>=%d)", minPrice))
-		} else if maxPriceStr != "" {
-			querys = append(querys, fmt.Sprintf("(a.project_money<=%d)", maxPrice))
+	// 项目金额 0: 全部,1: 50万以下,2: 50-100万, 3: 100-200万, 4: 200-500万, 5:500万以上
+	if req.Amount != "" {
+		if !strings.Contains(req.Amount, "0") {
+			var tempArr []string
+			for _, s := range strings.Split(req.Amount, ",") {
+				if s == "1" {
+					tempArr = append(tempArr, fmt.Sprintf("(a.project_money<=%d)", 500000))
+				} else if s == "2" {
+					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", 500000, 1000000))
+				} else if s == "3" {
+					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", 1000000, 2000000))
+				} else if s == "4" {
+					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d and a.project_money<=%d))", 2000000, 5000000))
+				} else if s == "5" {
+					tempArr = append(tempArr, fmt.Sprintf("((a.project_money>=%d))", 5000000))
+				}
+			}
+			if len(tempArr) > 0 {
+				querys = append(querys, fmt.Sprintf("(%s)", strings.Join(tempArr, "or")))
+			}
 		}
 	}
 	//物业业态