|
@@ -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")))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//物业业态
|