cancel_by_ids_logic.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package add_friend
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/errorx"
  5. "time"
  6. "wechat-api/ent/addwechatfriendlog"
  7. "wechat-api/internal/svc"
  8. "wechat-api/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type CancelByIdsLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewCancelByIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CancelByIdsLogic {
  17. return &CancelByIdsLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx}
  21. }
  22. func (l *CancelByIdsLogic) CancelByIds(req *types.CancelByIdsReq) (resp *types.BaseMsgResp, err error) {
  23. if req.Ids == nil {
  24. return nil, errorx.NewInvalidArgumentError("参数ids不能为空")
  25. }
  26. if len(req.Ids) == 0 {
  27. return nil, errorx.NewInvalidArgumentError("参数ids不能为空")
  28. }
  29. var isCanAdd []int
  30. isCanAdd = append(isCanAdd, 0, 1)
  31. err = l.svcCtx.DB.AddWechatFriendLog.Update().
  32. SetIsCanAdd(5). // 假设要将IsCanAdd字段设置为5
  33. SetUpdatedAt(time.Now().Unix()). // 设置修改时间
  34. Where(addwechatfriendlog.IDIn(req.Ids...), addwechatfriendlog.IsCanAddIn(isCanAdd...)).
  35. Exec(l.ctx)
  36. if err != nil {
  37. return nil, errorx.NewInvalidArgumentError("取消失败")
  38. }
  39. return &types.BaseMsgResp{
  40. Code: 0,
  41. Msg: "取消成功",
  42. }, nil
  43. }