|
@@ -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
|
|
|
+}
|