updatesubscribeinfologic.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package logic
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. . "jyBXSubscribe/entity"
  7. IC "jyBXSubscribe/rpc/init"
  8. "jyBXSubscribe/rpc/internal/svc"
  9. "jyBXSubscribe/rpc/model/service"
  10. "jyBXSubscribe/rpc/type/bxsubscribe"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type UpdateSubScribeInfoLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewUpdateSubScribeInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSubScribeInfoLogic {
  19. return &UpdateSubScribeInfoLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. // 修改订阅信息接口
  26. func (l *UpdateSubScribeInfoLogic) UpdateSubScribeInfo(inc *bxsubscribe.UpdateSubScribeInfoReq) (*bxsubscribe.StatusResp, error) {
  27. // todo: add your logic here and delete this line
  28. resp := &bxsubscribe.StatusResp{}
  29. in := &SubscribeUpdate{}
  30. err := json.Unmarshal(inc.SubSet, &in)
  31. if err != nil {
  32. return resp, nil
  33. }
  34. subService := &service.SubseribeService{
  35. UserId: inc.UserId,
  36. Mgo: IC.Mgo,
  37. SubscribeUpdate: in,
  38. PositionId: inc.PositionId,
  39. BaseUserId: inc.BaseUserId,
  40. MgoLog: IC.MgoLog,
  41. }
  42. status, err := subService.Update()
  43. if err != nil || status == 0 {
  44. l.Error(fmt.Sprintf("%+v", in), err.Error())
  45. resp.ErrorMsg = err.Error()
  46. resp.ErrorCode = -1
  47. } else {
  48. resp.Status = status
  49. }
  50. return resp, nil
  51. }