Selaa lähdekoodia

feat: 线索初始化

zhangxinlei1996 1 vuosi sitten
vanhempi
commit
d17447be4c
6 muutettua tiedostoa jossa 68 lisäystä ja 44 poistoa
  1. 2 2
      api/application.api
  2. 1 1
      api/etc/crmapplication.yaml
  3. 17 19
      api/etc/db.yaml
  4. 2 2
      api/internal/types/types.go
  5. 9 8
      entity/db.go
  6. 37 12
      service/sale_chance.go

+ 2 - 2
api/application.api

@@ -36,7 +36,7 @@ type (
 		ExpectedOrderTime int64    `json:"expectedOrderTime"` //最初预计落单段时间 时间戳
 		ExpectedMoney     int64    `json:"expectedOrderTime"` //最初预计落单金额
 		CustomName        string   `json:"customName"`        //客户全称
-		BusinessType      string   `json:"businessType"`      //业务类型
+		BusinessType      int64    `json:"businessType"`      //业务类型  1新客户需求 2老客户需求 3简易项目流程
 		Remarks           string   `json:"remarks"`           //备注
 		NextfollowUpTime  int64    `json:"nextfollowUpTime"`  //下次跟进时间戳
 		Types             int64    `json:"types"`             //处理方式 1自办;2转办
@@ -103,7 +103,7 @@ type (
 		CustomDetailIndustry int64    `json:"customDetailIndustry"` //客户细分行业
 		Province             string   `json:"province"`             //省份
 		City                 string   `json:"city"`                 //城市
-		District             string   `json:"district"`             //地区
+		District             string   `json:"district,optional"`    //地区
 		Address              string   `json:"address"`              //详细地址
 		CompanyPhone         string   `json:"companyPhone"`         //公司电话
 		NextfollowUpTime     int64    `json:"nextfollowUpTime"`     //下次跟进时间戳

+ 1 - 1
api/etc/crmapplication.yaml

@@ -14,7 +14,7 @@ UserCenterRpc:
 FileCenterRpc:
   Etcd:
     Hosts:
-    - 192.168.3.149:2379
+    - 127.0.0.1:2379
     Key: filecenter.rpc
 ossBucketName: jytest2022
 ossUrl: https://jytest2022.oss-cn-beijing.aliyuncs.com

+ 17 - 19
api/etc/db.yaml

@@ -28,25 +28,23 @@ mongo:
         dbName: qfw
         size: 5
         address: 192.168.3.206:27080
-    "bidding": {
-        "address": "192.168.3.206:27002",
-        "size": 5,
-        "dbName": "qfw_data",
-        "collection": "bidding",
-        "collection_change": "bidding_back",
-        "userName": "jyDevGroup",
-        "password": "jy@DevGroup"
-    }
-    "ent": {
-        "address": "192.168.3.206:27002",
-        "size": 5,
-        "dbName": "mixdata",
-        "replSet": "",
-        "collection": "qyxy",
-        "collection_change": "qyxy_change",
-        "userName": "jyDevGroup",
-        "password": "jy@DevGroup"
-    }
+    bidding:
+        address: 192.168.3.206:27002
+        size: 5
+        dbName: qfw_data
+        collection: bidding
+        collection_change: bidding_back
+        userName: jyDevGroup
+        password: jy@DevGroup
+    ent:
+        address: 192.168.3.206:27002
+        size: 5
+        dbName: mixdata
+        replSet: ""
+        collection: qyxy
+        collection_change: qyxy_change
+        userName: jyDevGroup
+        password: jy@DevGroup
 es:
     addr: http://192.168.3.241:9205
     size: 50

+ 2 - 2
api/internal/types/types.go

@@ -36,7 +36,7 @@ type SaleChanceReq struct {
 	ExpectedOrderTime int64    `json:"expectedOrderTime"` //最初预计落单段时间 时间戳
 	ExpectedMoney     int64    `json:"expectedOrderTime"` //最初预计落单金额
 	CustomName        string   `json:"customName"`        //客户全称
-	BusinessType      string   `json:"businessType"`      //业务类型
+	BusinessType      int64    `json:"businessType"`      //业务类型  1新客户需求 2老客户需求 3简易项目流程
 	Remarks           string   `json:"remarks"`           //备注
 	NextfollowUpTime  int64    `json:"nextfollowUpTime"`  //下次跟进时间戳
 	Types             int64    `json:"types"`             //处理方式 1自办;2转办
@@ -103,7 +103,7 @@ type CustomAddReq struct {
 	CustomDetailIndustry int64    `json:"customDetailIndustry"` //客户细分行业
 	Province             string   `json:"province"`             //省份
 	City                 string   `json:"city"`                 //城市
-	District             string   `json:"district"`             //地区
+	District             string   `json:"district,optional"`    //地区
 	Address              string   `json:"address"`              //详细地址
 	CompanyPhone         string   `json:"companyPhone"`         //公司电话
 	NextfollowUpTime     int64    `json:"nextfollowUpTime"`     //下次跟进时间戳

+ 9 - 8
entity/db.go

@@ -45,12 +45,13 @@ 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              = "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"
 )

+ 37 - 12
service/sale_chance.go

@@ -28,7 +28,7 @@ type SaleChanceService struct {
 	ExpectedOrderTime int64    //最初预计落单段时间 时间戳
 	ExpectedMoney     int64    //最初预计落单金额
 	CustomName        string   //客户全称
-	BusinessType      string   //业务类型
+	BusinessType      int64    //业务类型
 	Remarks           string   //备注
 	NextfollowUpTime  int64    //下次跟进时间戳
 	Types             int64    //处理方式 1自办;2转办
@@ -46,6 +46,8 @@ func (this *SaleChanceService) Add(ctx context.Context) int64 {
 	argsFollowRecord := []interface{}{}
 	//落单时间戳转时间
 	expect_deal_time := time.Unix(this.ExpectedOrderTime, 0).Format(date.Date_Full_Layout)
+	//下次跟进时间
+	nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
 
 	//判断处理方式
 	//转办
@@ -76,11 +78,11 @@ func (this *SaleChanceService) Add(ctx context.Context) int64 {
 		}
 	} else if this.Types == 1 {
 		//线索
-		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.ChanceName, this.Summary, expect_deal_time, this.ExpectedMoney, this.CustomId, this.BusinessType, this.Remarks, nowtime)
+		args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.CustomId, this.BusinessType, this.ChanceName, this.Summary, this.ChanceClassify, expect_deal_time, this.ExpectedMoney, this.Remarks, nowtime)
 		//任务
-		argsTask = append(argsTask, this.PositionId, this.EntId, this.EntUserId, this.ChanceName+"的跟进任务", 2, this.EmployInfoId, this.PositionId, 1, this.PositionId, nowtime, 1)
+		argsTask = append(argsTask, this.PositionId, this.EntId, this.EntUserId, this.ChanceName+"的跟进任务", 2, this.PositionId, 1, nowtime, 1, nextFollowTime)
 		//存库
-		if !SaveChange(ctx, args, argsTask, argsFollowRecord, this.PositionId, this.CreateName) {
+		if !SaveChange(ctx, args, argsTask, argsFollowRecord, this.PositionId, this.BusinessType, this.CreateName) {
 			return 0
 		}
 	}
@@ -91,24 +93,47 @@ func (this *SaleChanceService) Add(ctx context.Context) int64 {
 // 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"}
-	_, id := cm.BaseMysql.InsertBatchByTx(tx, entity.SALE_CHANCE, fields, args)
+	_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CHANCE, fields, args)
 	return id
 }
 
 // Save 存库
-func SaveChange(ctx context.Context, argsClue, argsTask, argsFollowRecord []interface{}, positionId int64, createName string) bool {
+func SaveChange(ctx context.Context, argsChange, argsTask, argsFollowRecord []interface{}, positionId, tplId int64, createName string) bool {
 	//存库
-	return cm.BaseMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
-		//插入线索
-		clueId := SaleChangeAdd(tx, argsClue)
+	return cm.CrmMysql.ExecTx("创建机会", func(tx *sql.Tx) bool {
+		//插入机会
+		changeId := SaleChangeAdd(tx, argsChange)
+		//传过来的argTask没有来源id,需要append
+		argsTask = append(argsTask, changeId)
 		//任务车存储
 		taskId := TaskAdd(tx, argsTask)
 		//操作台帐
-		ok := SaveLedger(ctx, positionId, clueId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", createName), createName)
-		if clueId > 0 && taskId > 0 && ok {
+		ok := SaveLedger(ctx, positionId, changeId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", createName), createName)
+		//任务执行计划
+		planId := TaskExecutePlanAdd(tx, tplId, taskId)
+		if changeId > 0 && taskId > 0 && ok && planId > 0 {
 			return true
 		}
-		log.Println("save change err: ", clueId, taskId, ok)
+		log.Println("save change err: ", changeId, taskId, ok, planId)
 		return false
 	})
 }
+
+// TaskExecutePlanAdd 任务执行计划存储
+func TaskExecutePlanAdd(tx *sql.Tx, tplId, taskId int64) int64 {
+	args := []interface{}{}
+	data := cm.CrmMysql.SelectBySqlByTx(tx, `SELECT b.name,c.name,c.id FROM task a 
+									INNER JOIN config_tpl_stage b ON (a.tpl_id=b.tpl_id and b.tpl_id=?)
+									INNER JOIN config_stage_matter c ON (c.stage_id=b.id) 
+									order by b.id,c.id `, tplId)
+	if data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			matterId := gconv.Int(v["id"])
+			args = append(args, taskId, matterId)
+		}
+		_, id := cm.CrmMysql.InsertBatchByTx(tx, entity.TASK_EXECUTE_PLAN, []string{"task_id", "matter_id"}, args)
+		return id
+	}
+
+	return 0
+}