123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package service
- import (
- "context"
- "database/sql"
- "fmt"
- "log"
- "time"
- "app.yhyue.com/moapp/jybase/date"
- "app.yhyue.com/moapp/jybase/encrypt"
- "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
- cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
- "bp.jydev.jianyu360.cn/CRM/application/entity"
- "github.com/gogf/gf/v2/util/gconv"
- )
- //线索相关
- type SaleClueService struct {
- PositionId int64
- EntId int64
- EntUserId int64
- ClueName string
- CluesSource string
- Summary string
- EmployInfoId int64
- Types int64
- User []string
- FollowUpTime int64
- CreateName string
- }
- //Add 创建线索
- func (this *SaleClueService) Add(ctx context.Context) int64 {
- nowtime := time.Now().Format(date.Date_Full_Layout)
- log.Println(this.FollowUpTime, time.Unix(this.FollowUpTime, 0))
- nextFollowTime := time.Unix(this.FollowUpTime, 0).Format(date.Date_Full_Layout)
- args := []interface{}{}
- argsTask := []interface{}{}
- argsFollowRecord := []interface{}{}
- //判断处理方式
- //转办
- if this.Types == 2 {
- for _, v := range this.User {
- entuserid := encrypt.SE.Decode4Hex(v)
- i_entuserid := gconv.Int64(entuserid)
- resp, err := cm.UserCenterRpc.IdentityByEntUserId(ctx, &pb.IdentityReq{
- Id: i_entuserid,
- })
- if err != nil {
- log.Println("获取用户职位id信息出错", i_entuserid, "的信息出错", err)
- return 0
- } else if resp == nil {
- log.Println("entuser用户", i_entuserid, "没有找到职位信息")
- 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(ctx, args, argsTask, argsFollowRecord, positionid, createName) {
- return 0
- }
- }
- } else if this.Types == 1 {
- //线索
- args = append(args, this.PositionId, this.EntId, this.EntUserId, this.ClueName, this.CluesSource, this.Summary, this.EmployInfoId, 0, time.Now().Format(date.Date_Full_Layout))
- //任务
- argsTask = append(argsTask, this.PositionId, this.EntId, this.EntUserId, this.ClueName+"的跟进任务", 1, this.PositionId, 1, nowtime, 1, nextFollowTime)
- //存库
- if !Save(ctx, args, argsTask, argsFollowRecord, this.PositionId, this.CreateName) {
- return 0
- }
- }
- return 1
- }
- //SaleClueAdd 线索存储
- func SaleClueAdd(tx *sql.Tx, args []interface{}) int64 {
- fields := []string{"position_id", "ent_id", "ent_user_id", "name", "source", "summary", "employ_info_id", "is_close", "create_time"}
- _, id := cm.CrmMysql.InsertBatchByTx(tx, entity.SALE_CLUE, fields, args)
- return id
- }
- //TaskAdd 任务车存储
- func TaskAdd(tx *sql.Tx, args []interface{}) int64 {
- fields := []string{"position_id", "ent_id", "ent_user_id", "name", "source", "owner_id", "status", "create_time", "create_way", "next_follow_time", "source_id"}
- _, id := cm.CrmMysql.InsertBatchByTx(tx, entity.TASK, fields, args)
- return id
- }
- //FollowRecordAdd 跟进记录存储
- func FollowRecordAdd(tx *sql.Tx, args []interface{}) int64 {
- fields := []string{"position_id", "task_id"}
- _, id := cm.CrmMysql.InsertBatchByTx(tx, entity.FOLLOW_RECORD, fields, args)
- return id
- }
- //Save 存库
- func Save(ctx context.Context, argsClue, argsTask, argsFollowRecord []interface{}, positionId int64, createName string) bool {
- //存库
- return cm.CrmMysql.ExecTx("创建线索", func(tx *sql.Tx) bool {
- //插入线索
- clueId := SaleClueAdd(tx, argsClue)
- //传过来的argTask没有来源id,需要append
- argsTask = append(argsTask, clueId)
- //任务车存储
- taskId := TaskAdd(tx, argsTask)
- //操作台帐
- 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
- })
- }
|