plat_followup_comment.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package plat
  2. import (
  3. "context"
  4. "dashoo.cn/opms_libary/myerrors"
  5. "database/sql"
  6. "fmt"
  7. "github.com/gogf/gf/frame/g"
  8. "github.com/gogf/gf/util/gconv"
  9. "strings"
  10. "dashoo.cn/micro/app/dao/plat"
  11. model "dashoo.cn/micro/app/model/plat"
  12. "dashoo.cn/micro/app/service"
  13. )
  14. type followupCommentService struct {
  15. *service.ContextService
  16. Dao *plat.PlatFollowupCommentDao
  17. FollowupDao *plat.PlatFollowupDao
  18. }
  19. func NewFollowupCommentService(ctx context.Context) (svc *followupCommentService, err error) {
  20. svc = new(followupCommentService)
  21. if svc.ContextService, err = svc.Init(ctx); err != nil {
  22. return nil, err
  23. }
  24. svc.Dao = plat.NewPlatFollowupCommentDao(svc.Tenant)
  25. svc.FollowupDao = plat.NewPlatFollowupDao(svc.Tenant)
  26. return svc, nil
  27. }
  28. // 跟进记录留言信息列表
  29. func (s *followupCommentService) GetList(req *model.SearchPlatFollowupCommentReq) (total int, followupCommentList []*model.PlatFollowupComment, err error) {
  30. followupCommentModel := s.Dao.M
  31. if req.FollowId != "" {
  32. followupCommentModel = followupCommentModel.Where("follow_id", req.FollowId)
  33. }
  34. if req.Pid != "" {
  35. followupCommentModel = followupCommentModel.Where("pid", req.Pid)
  36. }
  37. total, err = followupCommentModel.Count()
  38. if err != nil {
  39. g.Log().Error(err)
  40. err = myerrors.DbError("获取总行数失败。")
  41. return
  42. }
  43. err = followupCommentModel.Order("created_time DESC").Scan(&followupCommentList)
  44. return
  45. }
  46. // 添加信息
  47. func (s *followupCommentService) Create(req *model.AddPlatFollowupCommentReq) (err error) {
  48. followup, err := s.FollowupDao.WherePri(req.FollowId).One()
  49. if err != nil {
  50. return err
  51. }
  52. platFollowupComment := new(model.PlatFollowupComment)
  53. if err = gconv.Struct(req, platFollowupComment); err != nil {
  54. return
  55. }
  56. // 填充创建信息
  57. service.SetCreatedInfo(platFollowupComment, s.GetCxtUserId(), s.GetCxtUserName())
  58. // 填充更新信息
  59. //service.SetUpdatedInfo(platFollowupComment, s.GetCxtUserId(), s.GetCxtUserName())
  60. _, err = s.Dao.Insert(platFollowupComment)
  61. if err != nil {
  62. return
  63. }
  64. // 从配置中获取消息提醒设置 销售总监、销售助理
  65. configs, err := g.DB(s.Tenant).Model("sys_config").Where("config_key IN ('SalesDirector','SalesAssociate')").FindAll()
  66. if err != nil && err != sql.ErrNoRows {
  67. g.Log().Error(err)
  68. return
  69. }
  70. var recvUserIds []string
  71. for _, config := range configs {
  72. recvUserIds = append(recvUserIds, strings.Split(config["config_value"].String(), ",")...)
  73. }
  74. recvUserIds = append(recvUserIds, gconv.String(followup.CreatedBy))
  75. msg := g.MapStrStr{
  76. "msgTitle": "跟进记录评论提醒",
  77. "msgContent": fmt.Sprintf("%v %v 评论:%v", followup.TargetName, platFollowupComment.CreatedName, platFollowupComment.Content),
  78. "msgType": "20",
  79. "recvUserIds": strings.Join(recvUserIds, ","),
  80. "msgStatus": "10",
  81. "sendType": "30",
  82. }
  83. if err := service.CreateSystemMessage(msg); err != nil {
  84. g.Log().Error("消息提醒异常:", err)
  85. }
  86. return
  87. }