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