瀏覽代碼

feat: 新增操作台账

zhangxinlei1996 1 年之前
父節點
當前提交
3a4c8574dd

+ 10 - 0
api/application.api

@@ -20,6 +20,7 @@ type (
 		Types        int64    `json:"types"`                 //处理方式 1自办;2转办
 		User         []string `json:"user,optional"`         //企业用户id
 		EmployInfoId int64    `json:"employInfoId"`          //资讯收录id
+		CreateName   string   `json:"createName"`            //创建人
 	}
 
 	SaleChanceReq {
@@ -42,6 +43,7 @@ type (
 		User              []string `json:"user"`              //企业用户id
 		EmployInfoId      int64    `json:"employInfoId"`      //资讯收录id
 		CustomId          int64    `json:"customId"`          //客户id
+		CreateName        string   `json:"createName"`        //创建人
 	}
 
 	EmployOperateReq {
@@ -114,6 +116,14 @@ type (
 	}
 
 	FileUploadReq {
+		AppId      string `header:"appId,default=10000"`
+		BaseUserId int64  `header:"newUserId"`
+		PositionId int64  `header:"positionId,optional"`
+		EntUserId  int64  `header:"entUserId,optional"`
+		EntId      int64  `header:"entId,optional"`
+		BusinessId int64  `form:"businessId"` //业务id
+		Types      int64  `form:"type"`       //类型;1:跟进记录-线下 2:跟进记录-线上 3:跟进记录-备忘 4:销售机会-项目文档 5:客户-客户档案
+		FileType   string `form:"fileType"`   //文件类型,产品介绍、项目方案、立项报告、报价文件、招标文件、投标文件、中标通知书、合同、发票、其他文件
 	}
 )
 

+ 3 - 0
api/common/initconfig.go

@@ -13,6 +13,7 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/usercenter"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/config"
 	"bp.jydev.jianyu360.cn/CRM/application/entity"
+	"bp.jydev.jianyu360.cn/CRM/baseCenter/rpc/basecenter"
 	"github.com/zeromicro/go-zero/core/conf"
 	"github.com/zeromicro/go-zero/core/logx"
 	"github.com/zeromicro/go-zero/zrpc"
@@ -37,6 +38,7 @@ var (
 	Mgo           mongodb.MongodbSim
 	UserCenterRpc usercenter.UserCenter
 	FileCenterRpc filecenter.FileCenter
+	BaseCenterRpc basecenter.BaseCenter
 )
 
 func init() {
@@ -139,4 +141,5 @@ func init() {
 	}
 	UserCenterRpc = usercenter.NewUserCenter(zrpc.MustNewClient(C.UserCenterRpc))
 	FileCenterRpc = filecenter.NewFileCenter(zrpc.MustNewClient(C.FileCenterRpc))
+	BaseCenterRpc = basecenter.NewBaseCenter(zrpc.MustNewClient(C.BaseCenterRpc))
 }

+ 5 - 0
api/etc/crmapplication.yaml

@@ -18,3 +18,8 @@ FileCenterRpc:
     Key: filecenter.rpc
 ossBucketName: jytest2022
 ossUrl: https://jytest2022.oss-cn-beijing.aliyuncs.com
+BaseCenterRpc:
+  Etcd:
+    Hosts:
+    - 127.0.0.1:2379
+    Key: basecenter.rpc

+ 1 - 0
api/internal/config/config.go

@@ -16,6 +16,7 @@ type Config struct {
 	FileCenterRpc zrpc.RpcClientConf
 	OssBucketName string
 	OssUrl        string
+	BaseCenterRpc zrpc.RpcClientConf
 }
 
 type Db struct {

+ 1 - 0
api/internal/logic/clueaddlogic.go

@@ -38,6 +38,7 @@ func (l *ClueAddLogic) ClueAdd(req *types.ClueAddReq) (resp *types.Reply, err er
 		Types:        req.Types,
 		User:         req.User,
 		FollowUpTime: req.FollowUpTime,
+		CreateName:   req.CreateName,
 	}
 	status := clue.Add(l.ctx)
 

+ 17 - 1
api/internal/logic/fileuploadlogic.go

@@ -12,6 +12,7 @@ import (
 	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/svc"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
+	"bp.jydev.jianyu360.cn/CRM/application/service"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -34,9 +35,9 @@ func NewFileUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http
 func (l *FileUploadLogic) FileUpload(req *types.FileUploadReq) (resp *types.Reply, err error) {
 	resp = &types.Reply{}
 	file, header, _ := l.r.FormFile("file")
+	status := 1
 	defer file.Close()
 	bt, _ := ioutil.ReadAll(file)
-	fmt.Println(cm.C.OssBucketName, cm.C.OssUrl, header.Filename)
 	up, err := cm.FileCenterRpc.Upload(l.ctx, &fpb.UploadReq{
 		File:          bt,
 		OssBucketName: cm.C.OssBucketName,
@@ -46,6 +47,7 @@ func (l *FileUploadLogic) FileUpload(req *types.FileUploadReq) (resp *types.Repl
 	if up == nil || up.Url == "" {
 		resp.Error_code = -1
 		resp.Error_msg = "上传失败"
+		resp.Data = map[string]interface{}{"status": -1}
 		return
 	}
 	key := up.Key
@@ -69,6 +71,19 @@ func (l *FileUploadLogic) FileUpload(req *types.FileUploadReq) (resp *types.Repl
 	if len(fileTypeTmp) > 0 && len(fileTypeTmp) == 2 {
 		ftype = strings.Split(header.Filename, ".")[1]
 	}
+
+	fl := &service.File{
+		Name:       header.Filename, //附件名称
+		Suffix:     ftype,           //文件后缀
+		FileType:   req.FileType,    //文件类型,产品介绍、项目方案、立项报告、报价文件、招标文件、投标文件、中标通知书、合同、发票、其他文件
+		Size:       fileSize,        //文件大小
+		Oss:        up.Url,          //oss地址
+		BusinessId: req.BusinessId,  //业务id
+		Types:      req.Types,       //类型;1:跟进记录-线下 2:跟进记录-线上 3:跟进记录-备忘 4:销售机会-项目文档 5:客户-客户档案
+	}
+	if !fl.Add() {
+		status = -1
+	}
 	data = map[string]interface{}{
 		"filename": header.Filename,
 		"ftype":    ftype,
@@ -76,6 +91,7 @@ func (l *FileUploadLogic) FileUpload(req *types.FileUploadReq) (resp *types.Repl
 		"size":     fileSize,
 		"ossurl":   cm.C.OssUrl,
 		"url":      up.Url,
+		"status":   status,
 	}
 
 	resp.Data = data

+ 1 - 0
api/internal/logic/salechanceaddlogic.go

@@ -46,6 +46,7 @@ func (l *SaleChanceAddLogic) SaleChanceAdd(req *types.SaleChanceReq) (resp *type
 		User:              req.User,              //企业用户id
 		EmployInfoId:      req.EmployInfoId,      //资讯收录id
 		CustomId:          req.CustomId,          //客户id
+		CreateName:        req.CreateName,
 	}
 	status := chance.Add(l.ctx)
 

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

@@ -20,6 +20,7 @@ type ClueAddReq struct {
 	Types        int64    `json:"types"`                 //处理方式 1自办;2转办
 	User         []string `json:"user,optional"`         //企业用户id
 	EmployInfoId int64    `json:"employInfoId"`          //资讯收录id
+	CreateName   string   `json:"createName"`            //创建人
 }
 
 type SaleChanceReq struct {
@@ -42,6 +43,7 @@ type SaleChanceReq struct {
 	User              []string `json:"user"`              //企业用户id
 	EmployInfoId      int64    `json:"employInfoId"`      //资讯收录id
 	CustomId          int64    `json:"customId"`          //客户id
+	CreateName        string   `json:"createName"`        //创建人
 }
 
 type EmployOperateReq struct {
@@ -114,4 +116,12 @@ type CustomAddReq struct {
 }
 
 type FileUploadReq struct {
+	AppId      string `header:"appId,default=10000"`
+	BaseUserId int64  `header:"newUserId"`
+	PositionId int64  `header:"positionId,optional"`
+	EntUserId  int64  `header:"entUserId,optional"`
+	EntId      int64  `header:"entId,optional"`
+	BusinessId int64  `form:"businessId"` //业务id
+	Types      int64  `form:"type"`       //类型;1:跟进记录-线下 2:跟进记录-线上 3:跟进记录-备忘 4:销售机会-项目文档 5:客户-客户档案
+	FileType   string `form:"fileType"`   //文件类型,产品介绍、项目方案、立项报告、报价文件、招标文件、投标文件、中标通知书、合同、发票、其他文件
 }

+ 3 - 2
go.mod

@@ -3,12 +3,13 @@ module bp.jydev.jianyu360.cn/CRM/application
 go 1.19
 
 require (
-	app.yhyue.com/moapp/jybase v0.0.0-20230828030111-c6369d0d5cfd
+	app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40
 	app.yhyue.com/moapp/jypkg v0.0.0-20230825092743-3bfc415bb5bb
 	bp.jydev.jianyu360.cn/BaseService/fileCenter v0.0.0-20230831080320-b872b8b3d8b4
 	bp.jydev.jianyu360.cn/BaseService/gateway v1.3.4
 	bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.14-0.20230821092053-934ffe439a9d
-	github.com/RoaringBitmap/roaring v1.4.0
+	bp.jydev.jianyu360.cn/CRM/baseCenter v0.0.0-20230904054652-d86e21ec57f3
+	github.com/RoaringBitmap/roaring v1.5.0
 	github.com/gogf/gf/v2 v2.0.6
 	github.com/zeromicro/go-zero v1.5.5
 	go.mongodb.org/mongo-driver v1.12.1

+ 7 - 4
go.sum

@@ -9,8 +9,8 @@ app.yhyue.com/moapp/jybase v0.0.0-20220420032112-668025915ee4/go.mod h1:qNRA0sHu
 app.yhyue.com/moapp/jybase v0.0.0-20220421060131-a1001013ba46/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 app.yhyue.com/moapp/jybase v0.0.0-20220427020729-974c1a148186/go.mod h1:qNRA0sHuYqcLoYoP8irpaWnW9YsXixe6obBIkwaXpD0=
 app.yhyue.com/moapp/jybase v0.0.0-20230117032034-ad7c00ffe11a/go.mod h1:zB47XTeJvpcbtBRYgkQuxOICWNexiZfbUO+7aUf6mNs=
-app.yhyue.com/moapp/jybase v0.0.0-20230828030111-c6369d0d5cfd h1:7FgWW5hm1BakK75upA8WpaekiXtUY6mVvUQfSYkEf/k=
-app.yhyue.com/moapp/jybase v0.0.0-20230828030111-c6369d0d5cfd/go.mod h1:D40Ae0rQilH8Hc5o2Vtt04Tjh/DNEFpcS3/WkJMPJb8=
+app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40 h1:/FcBvpf/KW8g6GBfTkypVW1pGbNs+iNhDrUGUi+KNjc=
+app.yhyue.com/moapp/jybase v0.0.0-20230901064756-2fc66b18db40/go.mod h1:Hv9U/7oHRucqH315Tr1+d03NCvS9mOKPfk8pwwlOIwQ=
 app.yhyue.com/moapp/jypkg v0.0.0-20230825092743-3bfc415bb5bb h1:J9CQ60meKlABYqeOB6zdZXJtBHAsJqnHeWhd/OOCUtU=
 app.yhyue.com/moapp/jypkg v0.0.0-20230825092743-3bfc415bb5bb/go.mod h1:VaHDi3twSg4G84k2+UFOe7ZCw5EqUZVAkW2N2dHeMbU=
 app.yhyue.com/moapp/message v0.0.0-20221223100203-6402e389d9ae h1:6rDDaz6yxvE8viTSzEBwKYOFWq14TMfuBivSazUZMz4=
@@ -34,6 +34,8 @@ bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220418072311-2062bed1e700/
 bp.jydev.jianyu360.cn/BaseService/userCenter v0.0.0-20220421015128-4a36f3eac5c5/go.mod h1:GT0QC4aaKDuXxAvaU4G02XjCc31TU1ctqBGqxQYOfC4=
 bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.14-0.20230821092053-934ffe439a9d h1:7Mkr/6fGB2OZ56VZDI1FwfAAd6h6XediO2oRhztywYs=
 bp.jydev.jianyu360.cn/BaseService/userCenter v1.2.14-0.20230821092053-934ffe439a9d/go.mod h1:03M9BWIGHy7BbGxLvjt8V9zZzEZDWhN6BuHVfVcDFbQ=
+bp.jydev.jianyu360.cn/CRM/baseCenter v0.0.0-20230904054652-d86e21ec57f3 h1:6py1No+pUGaHcPNZ1IUYIg9RIsEJOcKFCuxwDDAzKL8=
+bp.jydev.jianyu360.cn/CRM/baseCenter v0.0.0-20230904054652-d86e21ec57f3/go.mod h1:piwHJz2xm8etjtQpSGAfSbWR/zY46Ck8NSiwWQk11/Q=
 cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
 cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw=
@@ -94,8 +96,8 @@ github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb0
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
 github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
 github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
-github.com/RoaringBitmap/roaring v1.4.0 h1:ehaTAeD4CPajbVpGC8lthQcAgitoitkuClGj/Bn669s=
-github.com/RoaringBitmap/roaring v1.4.0/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE=
+github.com/RoaringBitmap/roaring v1.5.0 h1:V0VCSiHjroItEYCM3guC8T83ehi5QMt3oM9EefTTOms=
+github.com/RoaringBitmap/roaring v1.5.0/go.mod h1:plvDsJQpxOC5bw8LRteu/MLWHsHez/3y6cubLI4/1yE=
 github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
 github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs=
 github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
@@ -817,6 +819,7 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe
 github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
 github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeIUDq/j97IG+FhNqkowIyEcD88LrW6fyU3K3WqY=
+github.com/yl2chen/cidranger v1.0.2/go.mod h1:9U1yz7WPYDwf0vpNWFaeRh0bjwz5RVgRy/9UEQfHl0g=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA=
 github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
 github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

+ 35 - 9
service/custom.go

@@ -3,6 +3,7 @@ package service
 import (
 	"context"
 	"database/sql"
+	"fmt"
 	"log"
 	"time"
 
@@ -11,6 +12,7 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
 	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/entity"
+	baseC "bp.jydev.jianyu360.cn/CRM/baseCenter/rpc/pb"
 	"github.com/gogf/gf/v2/util/gconv"
 )
 
@@ -69,7 +71,7 @@ func (this *CustomService) Add(ctx context.Context) int64 {
 			//任务
 			//argsTask = append(argsTask, positionid, this.EntId, this.EntUserId, this.ClueName+"的跟进任务", this.CluesSource, this.EmployInfoId, positionid, 1, this.PositionId, nowtime, 1)
 
-			if !SaveCustom(args, argsTask, this.EmployInfoId, this.EmployCustomId, positionid) {
+			if !SaveCustom(ctx, args, argsTask, this.EmployInfoId, this.EmployCustomId, positionid, this.CreateName) {
 				return 0
 			}
 		}
@@ -79,7 +81,7 @@ func (this *CustomService) Add(ctx context.Context) int64 {
 		//任务
 		argsTask = append(argsTask, this.PositionId, this.EntId, this.EntUserId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, nextFollowTime)
 		//存库
-		if !SaveCustom(args, argsTask, this.EmployInfoId, this.EmployCustomId, this.PositionId) {
+		if !SaveCustom(ctx, args, argsTask, this.EmployInfoId, this.EmployCustomId, this.PositionId, this.CreateName) {
 			return 0
 		}
 	}
@@ -95,7 +97,7 @@ func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 //EmployCustomUpdate 是否创建客户修改
-func CustomUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionid int64) bool {
+func CustomUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionId int64) bool {
 	tablename := ""
 	id := int64(0)
 	if employ_custom_id > 0 {
@@ -108,24 +110,48 @@ func CustomUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionid int64
 	if tablename == "" || id == 0 {
 		return true
 	}
-	return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionid}, map[string]interface{}{"is_create_custom": 1})
+	return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionId}, map[string]interface{}{"is_create_custom": 1})
 }
 
-func SaveCustom(argsCustom, argsTask []interface{}, employ_info_id, employ_custom_id, positionid int64) bool {
+func SaveCustom(ctx context.Context, argsCustom, argsTask []interface{}, employ_info_id, employ_custom_id, positionId int64, createPerson string) bool {
 	//存库
 	return cm.CrmMysql.ExecTx("创建客户", func(tx *sql.Tx) bool {
-		//插入线索
+		//插入客户
 		customId := SaleCustomAdd(tx, argsCustom)
 		//传过来的argTask没有来源id,需要append
 		argsTask = append(argsTask, customId)
 		//任务车存储
 		taskId := TaskAdd(tx, argsTask)
-		ok := CustomUpdate(tx, employ_info_id, employ_custom_id, positionid)
-		//插入线索
-		if customId > 0 && taskId > 0 && ok {
+		ok := CustomUpdate(tx, employ_info_id, employ_custom_id, positionId)
+		//插入台账
+		ok2 := SaveLedger(ctx, positionId, customId, taskId, "创建客户", fmt.Sprintf("%s创建了客户", createPerson), createPerson)
+		if customId > 0 && taskId > 0 && ok && ok2 {
 			return true
 		}
 		log.Println("SaveCustom err:", customId, taskId, ok)
 		return false
 	})
 }
+
+//SaveLedger 操作台帐相关
+func SaveLedger(ctx context.Context, positionId, businessId, taskId int64, types, content, createPerson string) bool {
+	//操作台账
+	resp, err := cm.BaseCenterRpc.LedgerAdd(ctx, &baseC.LedgerAddReq{
+		PositionId:   positionId,
+		BusinessId:   businessId, //业务id
+		TaskId:       taskId,     //任务id
+		Types:        types,      //类型
+		Content:      content,    //内容
+		CreateWay:    1,          //创建方式 1:人 2:系统
+		CreatePerson: createPerson,
+	})
+	if err != nil {
+		log.Println("save ledger err:", err)
+		return false
+	}
+	if resp == nil {
+		log.Println("save ledger resp is nil")
+		return false
+	}
+	return resp.State
+}

+ 48 - 0
service/file.go

@@ -0,0 +1,48 @@
+package service
+
+import (
+	"database/sql"
+	"time"
+
+	"app.yhyue.com/moapp/jybase/date"
+	cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+//文件相关
+
+type File struct {
+	Name       string //附件名称
+	Suffix     string //文件后缀
+	FileType   string //文件类型,产品介绍、项目方案、立项报告、报价文件、招标文件、投标文件、中标通知书、合同、发票、其他文件
+	Size       string //文件大小
+	Oss        string //oss地址
+	BusinessId int64  //业务id
+	Types      int64  //类型;1:跟进记录-线下 2:跟进记录-线上 3:跟进记录-备忘 4:销售机会-项目文档 5:客户-客户档案
+}
+
+//Add 文件上传
+func (this *File) Add() bool {
+	//存库
+	return cm.CrmMysql.ExecTx("上传文件", func(tx *sql.Tx) bool {
+		attachmentId := cm.CrmMysql.InsertByTx(tx, "attachment", map[string]interface{}{
+			"name":        this.Name,
+			"suffix":      this.Suffix,
+			"type":        this.FileType,
+			"size":        this.Size,
+			"oss":         this.Oss,
+			"create_time": time.Now().Format(date.Date_Full_Layout),
+		})
+		pointId := cm.CrmMysql.InsertByTx(tx, "anchor_point", map[string]interface{}{
+			"attachment_id": attachmentId,
+			"business_id":   this.BusinessId,
+			"type":          this.Types,
+		})
+		if attachmentId > 0 && pointId > 0 {
+			return true
+		}
+
+		logx.Info("file add err:", attachmentId, pointId)
+		return false
+	})
+}

+ 8 - 3
service/sale_chance.go

@@ -3,6 +3,7 @@ package service
 import (
 	"context"
 	"database/sql"
+	"fmt"
 	"log"
 	"time"
 
@@ -34,6 +35,7 @@ type SaleChanceService struct {
 	User              []string //企业用户id
 	EmployInfoId      int64    //资讯收录id
 	CustomId          int64    //客户id
+	CreateName        string
 }
 
 // Add 创建机会
@@ -78,7 +80,7 @@ func (this *SaleChanceService) Add(ctx context.Context) int64 {
 		//任务
 		argsTask = append(argsTask, this.PositionId, this.EntId, this.EntUserId, this.ChanceName+"的跟进任务", 2, this.EmployInfoId, this.PositionId, 1, this.PositionId, nowtime, 1)
 		//存库
-		if !SaveChange(args, argsTask, argsFollowRecord) {
+		if !SaveChange(ctx, args, argsTask, argsFollowRecord, this.PositionId, this.CreateName) {
 			return 0
 		}
 	}
@@ -94,16 +96,19 @@ func SaleChangeAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 // Save 存库
-func SaveChange(argsClue, argsTask, argsFollowRecord []interface{}) bool {
+func SaveChange(ctx context.Context, argsClue, argsTask, argsFollowRecord []interface{}, positionId int64, createName string) bool {
 	//存库
 	return cm.BaseMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
 		//插入线索
 		clueId := SaleChangeAdd(tx, argsClue)
 		//任务车存储
 		taskId := TaskAdd(tx, argsTask)
-		if clueId > 0 && taskId > 0 {
+		//操作台帐
+		ok := SaveLedger(ctx, positionId, clueId, taskId, "创建销售机会", fmt.Sprintf("%s创建了销售机会", createName), createName)
+		if clueId > 0 && taskId > 0 && ok {
 			return true
 		}
+		log.Println("save change err: ", clueId, taskId, ok)
 		return false
 	})
 }

+ 10 - 5
service/sale_clue.go

@@ -3,6 +3,7 @@ package service
 import (
 	"context"
 	"database/sql"
+	"fmt"
 	"log"
 	"time"
 
@@ -26,6 +27,7 @@ type SaleClueService struct {
 	Types        int64
 	User         []string
 	FollowUpTime int64
+	CreateName   string
 }
 
 //Add 创建线索
@@ -53,12 +55,13 @@ func (this *SaleClueService) Add(ctx context.Context) int64 {
 				return 0
 			}
 			positionid := resp.PositionId
+			createName := resp.EntUserName
 			//线索
 			args = append(args, positionid, this.EntId, i_entuserid, this.ClueName, this.CluesSource, this.Summary, this.EmployInfoId, 0, nowtime)
 			//任务
 			argsTask = append(argsTask, positionid, this.EntId, this.EntUserId, this.ClueName+"的跟进任务", this.CluesSource, positionid, 1, nowtime, 1, nextFollowTime)
 
-			if !Save(args, argsTask, argsFollowRecord) {
+			if !Save(ctx, args, argsTask, argsFollowRecord, positionid, createName) {
 				return 0
 			}
 		}
@@ -68,7 +71,7 @@ func (this *SaleClueService) Add(ctx context.Context) int64 {
 		//任务
 		argsTask = append(argsTask, this.PositionId, this.EntId, this.EntUserId, this.ClueName+"的跟进任务", 1, this.PositionId, 1, nowtime, 1, nextFollowTime)
 		//存库
-		if !Save(args, argsTask, argsFollowRecord) {
+		if !Save(ctx, args, argsTask, argsFollowRecord, this.PositionId, this.CreateName) {
 			return 0
 		}
 	}
@@ -98,7 +101,7 @@ func FollowRecordAdd(tx *sql.Tx, args []interface{}) int64 {
 }
 
 //Save 存库
-func Save(argsClue, argsTask, argsFollowRecord []interface{}) bool {
+func Save(ctx context.Context, argsClue, argsTask, argsFollowRecord []interface{}, positionId int64, createName string) bool {
 	//存库
 	return cm.CrmMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
 		//插入线索
@@ -107,10 +110,12 @@ func Save(argsClue, argsTask, argsFollowRecord []interface{}) bool {
 		argsTask = append(argsTask, clueId)
 		//任务车存储
 		taskId := TaskAdd(tx, argsTask)
-		//插入线索
-		if clueId > 0 && taskId > 0 {
+		//操作台帐
+		ok := SaveLedger(ctx, positionId, clueId, taskId, "创建销售线索", fmt.Sprintf("%s创建了销售线索", createName), createName)
+		if clueId > 0 && taskId > 0 && ok {
 			return true
 		}
+		log.Println("save clue err: ", clueId, taskId, ok)
 		return false
 	})
 }