| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package plat
- import (
- "context"
- "dashoo.cn/opms_libary/myerrors"
- "database/sql"
- "fmt"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/util/gconv"
- "dashoo.cn/micro/app/dao/plat"
- model "dashoo.cn/micro/app/model/plat"
- "dashoo.cn/micro/app/service"
- )
- type followupCommentService struct {
- *service.ContextService
- Dao *plat.PlatFollowupCommentDao
- FollowupDao *plat.PlatFollowupDao
- }
- func NewFollowupCommentService(ctx context.Context) (svc *followupCommentService, err error) {
- svc = new(followupCommentService)
- if svc.ContextService, err = svc.Init(ctx); err != nil {
- return nil, err
- }
- svc.Dao = plat.NewPlatFollowupCommentDao(svc.Tenant)
- svc.FollowupDao = plat.NewPlatFollowupDao(svc.Tenant)
- return svc, nil
- }
- // 跟进记录留言信息列表
- func (s *followupCommentService) GetList(req *model.SearchPlatFollowupCommentReq) (total int, followupCommentList []*model.PlatFollowupComment, err error) {
- followupCommentModel := s.Dao.M
- if req.FollowId != "" {
- followupCommentModel = followupCommentModel.Where("follow_id", req.FollowId)
- }
- if req.Pid != "" {
- followupCommentModel = followupCommentModel.Where("pid", req.Pid)
- }
- total, err = followupCommentModel.Count()
- if err != nil {
- g.Log().Error(err)
- err = myerrors.DbError("获取总行数失败。")
- return
- }
- err = followupCommentModel.Order("created_time DESC").Scan(&followupCommentList)
- return
- }
- // 添加信息
- func (s *followupCommentService) Create(req *model.AddPlatFollowupCommentReq) (err error) {
- followup, err := s.FollowupDao.WherePri(req.FollowId).One()
- if err != nil {
- return err
- }
- platFollowupComment := new(model.PlatFollowupComment)
- if err = gconv.Struct(req, platFollowupComment); err != nil {
- return
- }
- // 填充创建信息
- service.SetCreatedInfo(platFollowupComment, s.GetCxtUserId(), s.GetCxtUserName())
- // 填充更新信息
- //service.SetUpdatedInfo(platFollowupComment, s.GetCxtUserId(), s.GetCxtUserName())
- _, err = s.Dao.Insert(platFollowupComment)
- if err != nil {
- return
- }
- // 从配置中获取消息提醒设置
- config, err := g.DB(s.Tenant).Model("sys_config").Where("config_key = 'SalesAssociate'").One()
- if err != nil && err != sql.ErrNoRows {
- g.Log().Error(err)
- return
- }
- // 销售助理用户Id
- salesAssociate := config["config_value"].String()
- recvUserIds := salesAssociate + "," + gconv.String(followup.CreatedBy)
- msg := g.MapStrStr{
- "msgTitle": "跟进记录评论提醒",
- "msgContent": fmt.Sprintf("<p>%v %v 评论:%v</p>", followup.TargetName, platFollowupComment.CreatedName, platFollowupComment.Content),
- "msgType": "20",
- "recvUserIds": recvUserIds,
- "msgStatus": "10",
- "sendType": "10",
- }
- if err := service.CreateSystemMessage(msg); err != nil {
- g.Log().Error("消息提醒异常:", err)
- }
- return
- }
|