plat_followup_comment.go 2.7 KB

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