cancel_by_ids_logic.go 1.1 KB

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