Procházet zdrojové kódy

Merge commit '2fc48db0a7da3f9f4544cc22b9cc479a5c7d5d2b' into feature/v1.0.4

* commit '2fc48db0a7da3f9f4544cc22b9cc479a5c7d5d2b':
  机会创建新增人脉信息

# Conflicts:
#	api/application_api
Jianghan před 1 rokem
rodič
revize
e2ed360eae

+ 15 - 11
api/application.api

@@ -53,6 +53,8 @@ type (
 		CustomId          int64   `json:"customId,optional"`          //客户id
 		CreateName        string  `json:"createName"`                 //创建人
 		ChanceSource      int64   `json:"chanceSource"`               //机会来源
+		OwnerId           int64   `json:"ownerId,optional"`           //潜客收录id(人脉)
+		BusinessId        int64   `json:"businessId,optional"`        //商机收录id(人脉)
 	}
 	EmployOperateReq {
 		AppId      string `header:"appId,default=10000"`
@@ -128,6 +130,8 @@ type (
 		Remarks              string  `json:"remarks,optional"`                 //备注
 		CreateName           string  `json:"createName"`                       //创建人
 		Source               string  `json:"source,optional"`                  //来源
+		OwnerId              int64   `json:"ownerId,optional"`                 //潜客收录id(人脉)
+		BusinessId           int64   `json:"businessId,optional"`              //商机收录id(人脉)
 	}
 	FileUploadReq {
 		AppId      string `header:"appId,default=10000"`
@@ -202,47 +206,47 @@ service crmApplication {
 	@doc "添加线索"
 	@handler clueAdd
 	post /crmApplication/clue/add (ClueAddReq) returns (Reply)
-	
+
 	@doc "创建销售机会"
 	@handler saleChanceAdd
 	post /crmApplication/saleChance/add (SaleChanceReq) returns (Reply)
-	
+
 	@doc "收录操作"
 	@handler employOperate
 	post /crmApplication/employ/operate (EmployOperateReq) returns (Reply)
-	
+
 	@doc "商业资讯的转办"
 	@handler transfer
 	post /crmApplication/information/transfer (TransferReq) returns (Reply)
-	
+
 	@doc "忽略操作"
 	@handler ignoreOperate
 	post /crmApplication/ignore/operate (IgnoreOperateReq) returns (Reply)
-	
+
 	@doc "收录情况"
 	@handler employInfo
 	post /crmApplication/employ/info (InfoEmployinfoReq) returns (InfoReply)
-	
+
 	@doc "创建客户"
 	@handler customAdd
 	post /crmApplication/custom/add (CustomAddReq) returns (Reply)
-	
+
 	@doc "文件上传"
 	@handler fileUpload
 	post /crmApplication/file/upload (FileUploadReq) returns (Reply)
-	
+
 	@doc "分发"
 	@handler employDistribute
 	post /crmApplication/employ/distribute (EmployDistributeReq) returns (Reply)
-	
+
 	@doc "企业详情"
 	@handler entinfo
 	post /crmApplication/ent/info (EntInfoReq) returns (Reply)
-	
+
 	@doc "消息推送"
 	@handler pushMsg
 	post /crmApplication/info/push (PushMsgReq) returns (Reply)
-	
+
 	@doc "是否可以创建"
 	@handler canAddReq
 	post /crmApplication/info/canAdd (CanAddReq) returns (Reply)

binární
api/application_api


+ 39 - 0
api/common/initconfig.go

@@ -2,8 +2,11 @@ package common
 
 import (
 	"app.yhyue.com/moapp/jypkg/middleground"
+	"context"
 	"flag"
+	"fmt"
 	"log"
+	"time"
 
 	. "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/mongodb"
@@ -14,6 +17,8 @@ import (
 	"bp.jydev.jianyu360.cn/CRM/application/entity"
 	"bp.jydev.jianyu360.cn/CRM/baseCenter/rpc/basecenter"
 	"bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform/rpc/social/social"
+	"github.com/ClickHouse/clickhouse-go/v2"
+	"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
 	"github.com/zeromicro/go-zero/core/conf"
 	"github.com/zeromicro/go-zero/core/logx"
 	"github.com/zeromicro/go-zero/zrpc"
@@ -45,6 +50,7 @@ var (
 	MgoProject        mongodb.MongodbSim
 	NiJian            *mysql.Mysql
 	Middleground      *middleground.Middleground
+	ClickhouseConn    driver.Conn
 )
 
 func init() {
@@ -169,5 +175,38 @@ func init() {
 	SocialPlatformRpc = social.NewSocial(zrpc.MustNewClient(C.SocialPlatformRpc))
 	Middleground = middleground.NewMiddleground(C.BaseCenterRpc.Etcd.Hosts).
 		RegResourceCenter(C.ResourceCenterKey)
+	/*	Middleground = middleground.NewMiddleground([]string{"192.168.3.206:2379"}).
+		RegResourceCenter(C.ResourceCenterKey)*/
 	conf.MustLoad(*pushFile, &Push)
+	connectClickhouse(DB.Clickhouse)
+}
+func connectClickhouse(cHouseConfig *config.CHouseConfig) error {
+	var (
+		ctx = context.Background()
+		err error
+	)
+	ClickhouseConn, err = clickhouse.Open(&clickhouse.Options{
+		Addr:         []string{cHouseConfig.Addr},
+		DialTimeout:  10 * time.Second,
+		MaxIdleConns: cHouseConfig.MaxIdleConns,
+		MaxOpenConns: cHouseConfig.MaxOpenConns,
+		Auth: clickhouse.Auth{
+			Database: cHouseConfig.DbName,
+			Username: cHouseConfig.UserName,
+			Password: cHouseConfig.Password,
+		},
+		Debugf: func(format string, v ...interface{}) {
+			fmt.Printf(format, v)
+		},
+	})
+	if err != nil {
+		return err
+	}
+	if err := ClickhouseConn.Ping(ctx); err != nil {
+		if exception, ok := err.(*clickhouse.Exception); ok {
+			fmt.Printf("Exception [%d] %s \n%s\n", exception.Code, exception.Message, exception.StackTrace)
+		}
+		return err
+	}
+	return nil
 }

+ 14 - 6
api/etc/db.yaml

@@ -1,32 +1,33 @@
 mysql:
     main:
         dbName: jianyu
-        address: 192.168.3.149:3306
+        address: 192.168.3.14:4000
         userName: root
-        passWord: Topnet123
+        passWord: =PDT49#80Z!RVv52_z
         maxOpenConns: 5
         maxIdleConns: 5
     baseService:
         dbName: base_service
-        address: 192.168.3.217:4000
+        address: 192.168.3.14:4000
         userName: root
         passWord: =PDT49#80Z!RVv52_z
         maxOpenConns: 5
         maxIdleConns: 5
     crmService:
         dbName: crm
-        address: 192.168.3.217:4000
+        address: 192.168.3.14:4000
         userName: root
         passWord: =PDT49#80Z!RVv52_z
         maxOpenConns: 5
         maxIdleConns: 5
     nijian:
         dbName: Jianyu_subjectdb
-        address: 192.168.3.217:4000
+        address: 192.168.3.14:4000
         userName: root
         passWord: =PDT49#80Z!RVv52_z
         maxOpenConns: 5
         maxIdleConns: 5
+
 mongo:
     main:
         dbName: qfw
@@ -63,4 +64,11 @@ es:
     size: 50
     version: v7
     userName: ""
-    password: ""
+    password: ""
+clickhouse:
+    Addr: 192.168.3.207:19000
+    UserName: jytop
+    Password: pwdTopJy123
+    DbName: jianyu
+    MaxIdleConns: 5
+    MaxOpenConns: 30

+ 12 - 4
api/internal/config/config.go

@@ -23,11 +23,19 @@ type Config struct {
 }
 
 type Db struct {
-	Mysql entity.Mysql    `json:"mysql"`
-	Mongo entity.Mongo    `json:"mongo"`
-	Es    entity.EsStruct `json:"es"`
+	Mysql      entity.Mysql    `json:"mysql"`
+	Mongo      entity.Mongo    `json:"mongo"`
+	Es         entity.EsStruct `json:"es"`
+	Clickhouse *CHouseConfig
+}
+type CHouseConfig struct {
+	Addr         string
+	UserName     string
+	Password     string
+	DbName       string
+	MaxIdleConns int
+	MaxOpenConns int
 }
-
 type Push struct {
 	TimeTaskSwitch    bool
 	StationMailHref   string

+ 1 - 0
api/internal/handler/routes.go

@@ -73,5 +73,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Handler: canAddReqHandler(serverCtx),
 			},
 		},
+		rest.WithMaxBytes(104857600),
 	)
 }

+ 2 - 0
api/internal/logic/customaddlogic.go

@@ -55,6 +55,8 @@ func (l *CustomAddLogic) CustomAdd(req *types.CustomAddReq) (resp *types.Reply,
 		Remarks:              req.Remarks,              //备注
 		CreateName:           req.CreateName,           //创建人
 		Source:               req.Source,               //来源
+		OwnerId:              req.OwnerId,
+		BusinessId:           req.BusinessId,
 	}
 
 	status, error_msg := service.CanAdd(req.EntId, "more_create_custom", req.EmployInfoId, req.EmployCustomId, req.PositionId)

+ 4 - 0
api/internal/types/types.go

@@ -56,6 +56,8 @@ type SaleChanceReq struct {
 	CustomId          int64   `json:"customId,optional"`          //客户id
 	CreateName        string  `json:"createName"`                 //创建人
 	ChanceSource      int64   `json:"chanceSource"`               //机会来源
+	OwnerId           int64   `json:"ownerId,optional"`           //潜客收录id(人脉)
+	BusinessId        int64   `json:"businessId,optional"`        //商机收录id(人脉)
 }
 
 type EmployOperateReq struct {
@@ -136,6 +138,8 @@ type CustomAddReq struct {
 	Remarks              string  `json:"remarks,optional"`                 //备注
 	CreateName           string  `json:"createName"`                       //创建人
 	Source               string  `json:"source,optional"`                  //来源
+	OwnerId              int64   `json:"ownerId,optional"`                 //潜客收录id(人脉)
+	BusinessId           int64   `json:"businessId,optional"`              //商机收录id(人脉)
 }
 
 type FileUploadReq struct {

+ 16 - 14
entity/db.go

@@ -47,18 +47,20 @@ type EsStruct struct {
 }
 
 const (
-	TASK                = "task"              //任务表
-	FOLLOW_RECORD       = "follow_record"     //跟进记录表
-	SALE_CHANCE         = "sale_chance"       //销售机会
-	CUSTOM              = "custom"            //客户表
-	EMPLOY_INFO         = "employ_info"       //商业资讯收录表
-	EMPLOY_CUSTOM       = "employ_custom"     //候选客户收录表
-	SALE_CLUE           = "sale_clue"         //销售线索
-	EMPLOY_SUMMARY      = "employ_summary"    //收录汇总表
-	TASK_EXECUTE_PLAN   = "task_execute_plan" //任务执行计划
-	TASK_TRANSFER       = "task_transfer"     //转办记录表
-	TASK_TEAM           = "task_team"         //任务团队
-	CONFIG_TPL_STAGE    = "config_tpl_stage"
-	CONFIG_STAGE_MATTER = "config_stage_matter"
-	SALES_FUNNEL        = "sales_funnel"
+	TASK                     = "task"              //任务表
+	FOLLOW_RECORD            = "follow_record"     //跟进记录表
+	SALE_CHANCE              = "sale_chance"       //销售机会
+	CUSTOM                   = "custom"            //客户表
+	EMPLOY_INFO              = "employ_info"       //商业资讯收录表
+	EMPLOY_CUSTOM            = "employ_custom"     //候选客户收录表
+	SALE_CLUE                = "sale_clue"         //销售线索
+	EMPLOY_SUMMARY           = "employ_summary"    //收录汇总表
+	TASK_EXECUTE_PLAN        = "task_execute_plan" //任务执行计划
+	TASK_TRANSFER            = "task_transfer"     //转办记录表
+	TASK_TEAM                = "task_team"         //任务团队
+	CONFIG_TPL_STAGE         = "config_tpl_stage"
+	CONFIG_STAGE_MATTER      = "config_stage_matter"
+	SALES_FUNNEL             = "sales_funnel"
+	CONNECTION_BUSINESS_INFO = "connection_business_info"
+	CONNECTION_OWNER_INFO    = "connection_owner_info"
 )

+ 4 - 0
go.mod

@@ -10,6 +10,7 @@ require (
 	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.14-0.20230821092053-934ffe439a9d
 	bp.jydev.jianyu360.cn/CRM/baseCenter v0.0.0-20230904054652-d86e21ec57f3
 	bp.jydev.jianyu360.cn/SocialPlatform/socialPlatform v0.0.0-20230529115950-b726dfbf171f
+	github.com/ClickHouse/clickhouse-go/v2 v2.2.0
 	github.com/RoaringBitmap/roaring v1.5.0
 	github.com/gogf/gf/v2 v2.0.6
 	github.com/zeromicro/go-zero v1.5.5
@@ -76,13 +77,16 @@ require (
 	github.com/olivere/elastic v6.2.37+incompatible // indirect
 	github.com/olivere/elastic/v7 v7.0.22 // indirect
 	github.com/openzipkin/zipkin-go v0.4.1 // indirect
+	github.com/paulmach/orb v0.7.1 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.9 // indirect
+	github.com/pierrec/lz4/v4 v4.1.17 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
 	github.com/prometheus/client_golang v1.16.0 // indirect
 	github.com/prometheus/client_model v0.3.0 // indirect
 	github.com/prometheus/common v0.42.0 // indirect
 	github.com/prometheus/procfs v0.10.1 // indirect
 	github.com/rivo/uniseg v0.2.0 // indirect
+	github.com/shopspring/decimal v1.3.1 // indirect
 	github.com/spaolacci/murmur3 v1.1.0 // indirect
 	github.com/xdg-go/pbkdf2 v1.0.0 // indirect
 	github.com/xdg-go/scram v1.1.2 // indirect

+ 5 - 0
go.sum

@@ -449,6 +449,7 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
 github.com/ClickHouse/clickhouse-go v1.5.1/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
 github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
 github.com/ClickHouse/clickhouse-go/v2 v2.0.14/go.mod h1:iq2DUGgpA4BBki2CVwrF8x43zqBjdgHtbexkFkh5a6M=
+github.com/ClickHouse/clickhouse-go/v2 v2.2.0 h1:dj00TDKY+xwuTJdbpspCSmTLFyWzRJerTHwaBxut1C0=
 github.com/ClickHouse/clickhouse-go/v2 v2.2.0/go.mod h1:8f2XZUi7XoeU+uPIytSi1cvx8fmJxi7vIgqpvYTF1+o=
 github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
 github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
@@ -1065,6 +1066,7 @@ github.com/openzipkin/zipkin-go v0.4.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0
 github.com/openzipkin/zipkin-go v0.4.1 h1:kNd/ST2yLLWhaWrkgchya40TJabe8Hioj9udfPcEO5A=
 github.com/openzipkin/zipkin-go v0.4.1/go.mod h1:qY0VqDSN1pOBN94dBc6w2GJlWLiovAyg7Qt6/I9HecM=
 github.com/paulmach/orb v0.5.0/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
+github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU=
 github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
 github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
 github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
@@ -1078,6 +1080,8 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi
 github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
 github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
 github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
+github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
+github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -1147,6 +1151,7 @@ github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q
 github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
 github.com/shopspring/decimal v0.0.0-20200227202807-02e2044944cc/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
 github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
+github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
 github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=

+ 56 - 8
service/custom.go

@@ -46,6 +46,8 @@ type CustomService struct {
 	Remarks              string  //备注
 	CreateName           string  //创建人
 	Source               string
+	OwnerId              int64 //潜客收录id(人脉)
+	BusinessId           int64 //商机收录id(人脉)
 }
 
 // Add 创建客户
@@ -79,22 +81,22 @@ func (this *CustomService) Add(ctx context.Context) (int64, string) {
 			baseUserIdArr = append(baseUserIdArr, resp.UserId)
 		}
 		//客户
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source)
+		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source, this.OwnerId, this.BusinessId)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
+		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.OwnerId, this.BusinessId, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
 		if customId < 0 {
 			return -1, groupId
 		}
 	} else if this.Types == 1 {
 		//客户
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source)
+		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source, this.OwnerId, this.BusinessId)
 		//任务s
 		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 2, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), nil, nil)
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, []int64{}, this.EntId, this.EntUserId, this.EntDeptId)
+		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.OwnerId, this.BusinessId, this.PositionId, this.CreateName, []int64{}, this.EntId, this.EntUserId, this.EntDeptId)
 		if customId < 0 {
 			return -1, groupId
 		}
@@ -114,10 +116,10 @@ func (this *CustomService) Add(ctx context.Context) (int64, string) {
 		transferArr := []int64{}
 		transferArr = append(transferArr, this.PositionId)
 		//客户
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source)
+		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, qu.If(this.CustomLevel == 0, nil, this.CustomLevel), this.CustomIndustry, this.CustomDetailIndustry, qu.If(this.Province == "", nil, this.Province), qu.If(this.City == "", nil, this.City), qu.If(this.District == "", nil, this.District), qu.If(this.Address == "", nil, this.Address), qu.If(this.CompanyPhone == "", nil, this.CompanyPhone), qu.If(this.Remarks == "", nil, this.Remarks), this.CreateName, nowtime, this.Source, this.OwnerId, this.BusinessId)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), nil, nil)
-		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
+		customId, taskId = SaveCustom(ctx, args, argsTask, argsTaskTeam, this.EmployInfoId, this.EmployCustomId, this.OwnerId, this.BusinessId, this.PositionId, this.CreateName, transferArr, this.EntId, this.EntUserId, this.EntDeptId)
 		if customId < 0 {
 			return -1, groupId
 		}
@@ -151,7 +153,7 @@ func (this *CustomService) Add(ctx context.Context) (int64, string) {
 }
 
 func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
-	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "employ_custom_id", "type", "full_name", "sort_name", "summary", "level", "industry", "subdivision_industry", "province", "city", "county", "address", "phone", "remark", "create_person", "create_time", "source"}
+	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "employ_custom_id", "type", "full_name", "sort_name", "summary", "level", "industry", "subdivision_industry", "province", "city", "county", "address", "phone", "remark", "create_person", "create_time", "source", "connection_owner_id", "connection_business_id"}
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.CUSTOM, fields, args)
 	return id
 }
@@ -227,7 +229,7 @@ func EmployUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64
 	return employ_info_id, employ_custom_id
 }
 
-func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, positionId int64, createPerson string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
+func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interface{}, employ_info_id, employ_custom_id, ownerId, connectionBusinessId, positionId int64, createPerson string, transferArr []int64, entId, entUserId, entDeptId int64) (int64, int64) {
 	customId := int64(-1)
 	taskId := int64(-1)
 	//存库
@@ -247,6 +249,10 @@ func SaveCustom(ctx context.Context, argsCustom, argsTask, argsTaskTeam []interf
 		taskId = TaskAdd(tx, argsTask, argsTaskTeam, transferArr, positionId)
 		//插入台账
 		ok2 := SaveLedger(ctx, positionId, customId, taskId, "创建客户", fmt.Sprintf("%s创建了客户", createPerson), createPerson)
+		//人脉信息添加
+		if ownerId != 0 || connectionBusinessId != 0 {
+			SaveConnection(tx, positionId, connectionBusinessId, ownerId, entId, entDeptId, entUserId)
+		}
 		if customId > 0 && taskId > 0 && ok2 {
 			return true
 		}
@@ -323,3 +329,45 @@ func GetOtherKey(key string) []string {
 	}
 	return parameters[key]
 }
+func SaveConnection(tx *sql.Tx, positionId, businessId, ownerId, entId, entDeptId, entUserId int64) bool {
+	if businessId != 0 || ownerId != 0 {
+		table := entity.CONNECTION_BUSINESS_INFO
+		key := "business_id"
+		key1 := "is_create_chancis_create_chance"
+		if businessId == 0 {
+			businessId = ownerId
+			table = entity.CONNECTION_OWNER_INFO
+			key = "owner_id"
+			key1 = "is_create_custom"
+		}
+		if cm.CrmMysql.Count(table, map[string]interface{}{
+			"position_id": positionId,
+			key:           businessId,
+		}) > 0 {
+			cm.CrmMysql.UpdateByTx(tx, table, map[string]interface{}{
+				"position_id": positionId,
+				key:           businessId,
+			}, map[string]interface{}{
+				"is_handle":   1,
+				key1:          1,
+				"update_time": time.Now().Format(date.Date_Full_Layout),
+				"updater":     positionId,
+			})
+			return true
+		} else {
+			id := cm.CrmMysql.InsertByTx(tx, entity.CONNECTION_BUSINESS_INFO, map[string]interface{}{
+				"position_id": positionId,
+				"ent_id":      entId,
+				"ent_dept_id": entDeptId,
+				"ent_user_id": entUserId,
+				key:           businessId,
+				"is_handle":   1,
+				key1:          1,
+				"create_time": positionId,
+				"creator":     positionId,
+			})
+			return id > 0
+		}
+	}
+	return true
+}

+ 14 - 8
service/sale_chance.go

@@ -42,6 +42,8 @@ type SaleChanceService struct {
 	CustomId          int64   //客户id
 	CreateName        string
 	ChanceSource      int64
+	OwnerId           int64 //潜客收录id(人脉)
+	BusinessId        int64 //商机收录id(人脉)
 }
 
 // Add 创建机会
@@ -82,24 +84,24 @@ func (this *SaleChanceService) Add(ctx context.Context) (int64, string) {
 			baseUserIdArr = append(baseUserIdArr, resp.UserId)
 		}
 
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource)
+		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource, this.OwnerId, this.BusinessId)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), this.BusinessType, stageId)
 
-		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, transferArr)
+		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, transferArr, this.OwnerId, this.BusinessId)
 
 		if chanceId < 0 {
 			return -1, groupId
 		}
 	} else if this.Types == 1 {
 		//线索机会
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource)
+		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource, this.OwnerId, this.BusinessId)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 2, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), this.BusinessType, stageId)
 		//任务团队
 		argsTaskTeam = append(argsTaskTeam, this.PositionId, this.EntUserId, this.CreateName, 1, nowtime)
 		//存库
-		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, []int64{})
+		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, []int64{}, this.OwnerId, this.BusinessId)
 		if chanceId < 0 {
 			return -1, groupId
 		}
@@ -118,10 +120,10 @@ func (this *SaleChanceService) Add(ctx context.Context) (int64, string) {
 	} else if this.Types == 3 {
 		transferArr := []int64{}
 		transferArr = append(transferArr, this.PositionId)
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource)
+		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, qu.If(this.ExpectedOrderTime == 0, nil, expect_deal_time), qu.If(this.ExpectedMoney == 0, nil, this.ExpectedMoney), qu.If(this.Remarks == "", nil, this.Remarks), nowtime, this.CreateName, this.ChanceSource, this.OwnerId, this.BusinessId)
 		//任务
 		argsTask = append(argsTask, this.EntId, this.ChanceName+"的跟进任务", 2, this.PositionId, 1, nowtime, 1, 0, qu.If(this.NextfollowUpTime == 0, nil, nextFollowTime), this.BusinessType, stageId)
-		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, transferArr)
+		chanceId, taskId = this.SaveChange(ctx, args, argsTask, argsTaskTeam, transferArr, this.OwnerId, this.BusinessId)
 		if chanceId < 0 {
 			return -1, groupId
 		}
@@ -160,7 +162,7 @@ func (this *SaleChanceService) Add(ctx context.Context) (int64, string) {
 
 // SaleChangeAdd 机会存储
 func SaleChangeAdd(tx *sql.Tx, args []interface{}) int64 {
-	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "custom_id", "tpl_id", "name", "summary", "classify", "expect_deal_time", "expect_deal_amount", "remark", "create_time", "create_person", "source"}
+	fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "custom_id", "tpl_id", "name", "summary", "classify", "expect_deal_time", "expect_deal_amount", "remark", "create_time", "create_person", "source", "connection_owner_id", "connection_business_id"}
 
 	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CHANCE, fields, args)
 	//
@@ -169,7 +171,7 @@ func SaleChangeAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 // Save 存库
-func (this *SaleChanceService) SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, transferArr []int64) (int64, int64) {
+func (this *SaleChanceService) SaveChange(ctx context.Context, argsChange, argsTask, argsTaskTeam []interface{}, transferArr []int64, ownerId, connectionBusinessId int64) (int64, int64) {
 	//存库
 	changeId, taskId := int64(-1), int64(-1)
 	cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
@@ -202,6 +204,10 @@ func (this *SaleChanceService) SaveChange(ctx context.Context, argsChange, argsT
 			this.EmployInfoId,
 		}
 		SalesFunnel := saveSalesFunnel(tx, argsSalesFunnel, this.BusinessType)
+		//人脉保存
+		if ownerId != 0 || connectionBusinessId != 0 {
+			SaveConnection(tx, this.PositionId, connectionBusinessId, ownerId, this.EntId, this.EntDeptId, this.EntUserId)
+		}
 		if changeId > 0 && taskId > 0 && ok1 && planId > 0 && SalesFunnel > 0 {
 			return true
 		}