custom.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package service
  2. import (
  3. "context"
  4. "database/sql"
  5. "log"
  6. "time"
  7. "app.yhyue.com/moapp/jybase/date"
  8. "app.yhyue.com/moapp/jybase/encrypt"
  9. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  10. cm "bp.jydev.jianyu360.cn/CRM/application/api/common"
  11. "bp.jydev.jianyu360.cn/CRM/application/entity"
  12. "github.com/gogf/gf/v2/util/gconv"
  13. )
  14. //客户相关
  15. type CustomService struct {
  16. BaseUserId int64
  17. PositionId int64
  18. EntUserId int64
  19. EntId int64
  20. CustomType int64 //客户类型
  21. Summary string //概要信息
  22. CustomAllName string //客户全称
  23. CustomAbbreviation string //客户简称
  24. CustomLevel int64 //客户级别
  25. CustomIndustry int64 //客户行业
  26. CustomDetailIndustry int64 //客户细分行业
  27. Province string //省份
  28. City string //城市
  29. District string //地区
  30. Address string //详细地址
  31. CompanyPhone string //公司电话
  32. NextfollowUpTime int64 //下次跟进时间戳
  33. Types int64 //处理方式 1自办;2转办
  34. User []string //转办用户
  35. EmployCustomId int64 //客户收录id
  36. EmployInfoId int64 //资讯收录id
  37. Remarks string //备注
  38. CreateName string //创建人
  39. }
  40. //Add 创建客户
  41. func (this *CustomService) Add(ctx context.Context) int64 {
  42. nowtime := time.Now().Format(date.Date_Full_Layout)
  43. nextFollowTime := time.Unix(this.NextfollowUpTime, 0).Format(date.Date_Full_Layout)
  44. args := []interface{}{}
  45. argsTask := []interface{}{}
  46. //判断处理方式
  47. //转办
  48. if this.Types == 2 {
  49. for _, v := range this.User {
  50. entuserid := encrypt.SE.Decode4Hex(v)
  51. i_entuserid := gconv.Int64(entuserid)
  52. resp, err := cm.UserCenterRpc.IdentityByEntUserId(ctx, &pb.IdentityReq{
  53. Id: i_entuserid,
  54. })
  55. if err != nil {
  56. log.Println("获取用户职位id信息出错", i_entuserid, "的信息出错", err)
  57. return 0
  58. } else if resp == nil {
  59. log.Println("entuser用户", i_entuserid, "没有找到职位信息")
  60. return 0
  61. }
  62. positionid := resp.PositionId
  63. //线索
  64. //args = append(args, positionid, this.EntId, i_entuserid, this.EmployInfoId, this.EmployCustomId, this.Types, this.CustomAllName, this.CustomAbbreviation, this.Summary, this.CustomLevel, this.CustomIndustry, this.CustomDetailIndustry, this.Province, this.City, this.District, this.Address, this.CompanyPhone, this.Remarks, nowtime)
  65. //任务
  66. //argsTask = append(argsTask, positionid, this.EntId, this.EntUserId, this.ClueName+"的跟进任务", this.CluesSource, this.EmployInfoId, positionid, 1, this.PositionId, nowtime, 1)
  67. if !SaveCustom(args, argsTask, this.EmployInfoId, this.EmployCustomId, positionid) {
  68. return 0
  69. }
  70. }
  71. } else if this.Types == 1 {
  72. //客户
  73. args = append(args, this.PositionId, this.EntId, this.EntUserId, this.EmployInfoId, this.EmployCustomId, this.CustomType, this.CustomAllName, this.CustomAbbreviation, this.Summary, this.CustomLevel, this.CustomIndustry, this.CustomDetailIndustry, this.Province, this.City, this.District, this.Address, this.CompanyPhone, this.Remarks, this.CreateName, nowtime)
  74. //任务
  75. argsTask = append(argsTask, this.PositionId, this.EntId, this.EntUserId, this.CustomAllName+"的跟进任务", 3, this.PositionId, 1, nowtime, 1, nextFollowTime)
  76. //存库
  77. if !SaveCustom(args, argsTask, this.EmployInfoId, this.EmployCustomId, this.PositionId) {
  78. return 0
  79. }
  80. }
  81. return 1
  82. }
  83. //
  84. func SaleCustomAdd(tx *sql.Tx, args []interface{}) int64 {
  85. fields := []string{"position_id", "ent_id", "ent_user_id", "employ_info_id", "employ_custom_id", "type", "full_name", "sort_name", "summary", "level", "industry", "subdivision_industry", "province", "city", "county", "address", "phone", "remark", "create_person", "create_time"}
  86. _, id := cm.CrmMysql.InsertBatchByTx(tx, entity.CUSTOM, fields, args)
  87. return id
  88. }
  89. //EmployCustomUpdate 是否创建客户修改
  90. func CustomUpdate(tx *sql.Tx, employ_info_id, employ_custom_id, positionid int64) bool {
  91. tablename := ""
  92. id := int64(0)
  93. if employ_custom_id > 0 {
  94. tablename = entity.EMPLOY_CUSTOM
  95. id = employ_custom_id
  96. } else if employ_info_id > 0 {
  97. tablename = entity.EMPLOY_INFO
  98. id = employ_info_id
  99. }
  100. if tablename == "" || id == 0 {
  101. return true
  102. }
  103. return cm.CrmMysql.UpdateByTx(tx, tablename, map[string]interface{}{"id": id, "position_id": positionid}, map[string]interface{}{"is_create_custom": 1})
  104. }
  105. func SaveCustom(argsCustom, argsTask []interface{}, employ_info_id, employ_custom_id, positionid int64) bool {
  106. //存库
  107. return cm.CrmMysql.ExecTx("创建客户", func(tx *sql.Tx) bool {
  108. //插入线索
  109. customId := SaleCustomAdd(tx, argsCustom)
  110. //传过来的argTask没有来源id,需要append
  111. argsTask = append(argsTask, customId)
  112. //任务车存储
  113. taskId := TaskAdd(tx, argsTask)
  114. ok := CustomUpdate(tx, employ_info_id, employ_custom_id, positionid)
  115. //插入线索
  116. if customId > 0 && taskId > 0 && ok {
  117. return true
  118. }
  119. log.Println("SaveCustom err:", customId, taskId, ok)
  120. return false
  121. })
  122. }