updatesubscribeinfologic.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. IC "jyBXSubscribe/rpc/init"
  6. "jyBXSubscribe/rpc/internal/svc"
  7. "jyBXSubscribe/rpc/model/service"
  8. "jyBXSubscribe/rpc/type/bxsubscribe"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type UpdateSubScribeInfoLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewUpdateSubScribeInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateSubScribeInfoLogic {
  17. return &UpdateSubScribeInfoLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // 修改订阅信息接口
  24. func (l *UpdateSubScribeInfoLogic) UpdateSubScribeInfo(in *bxsubscribe.UpdateSubScribeInfoReq) (*bxsubscribe.StatusResp, error) {
  25. // todo: add your logic here and delete this line
  26. resp := &bxsubscribe.StatusResp{}
  27. subService := &service.SubseribeService{
  28. UserId: in.UserId,
  29. }
  30. if in.Area != nil {
  31. //格式转换 地区
  32. areaMap := map[string]interface{}{}
  33. for k, v := range in.Area {
  34. areaMap[k] = v.City
  35. }
  36. subService.Area = areaMap
  37. }
  38. //关键词转换
  39. if in.Items != nil {
  40. items := []map[string]interface{}{}
  41. item := map[string]interface{}{}
  42. for _, v := range in.Items {
  43. item["s_item"] = v.SItem
  44. item["updatetime"] = v.UpdateTime
  45. akey := []map[string]interface{}{}
  46. for _, vv := range v.AKey {
  47. akey = append(akey, map[string]interface{}{
  48. "key": vv.Key,
  49. "matchway": vv.Matchway,
  50. "appendkey": vv.AppendKey,
  51. "notkey": vv.Notkey,
  52. })
  53. }
  54. item["a_key"] = akey
  55. items = append(items)
  56. }
  57. subService.Items = items
  58. }
  59. //
  60. if in.Apppush != "" {
  61. subService.Apppush = in.Apppush
  62. }
  63. if in.Buyerclass != nil {
  64. subService.Buyerclass = in.Buyerclass
  65. }
  66. if in.Infotype != nil {
  67. subService.Infotype = in.Infotype
  68. }
  69. if in.Mail != "" {
  70. subService.Mail = in.Mail
  71. }
  72. if in.Mailpush != "" {
  73. subService.Mailpush = in.Mailpush
  74. }
  75. if in.Matchway != "" {
  76. subService.Matchway = in.Matchway
  77. }
  78. if in.Ratemode != "" {
  79. subService.Ratemode = in.Ratemode
  80. }
  81. if in.Projectmatch != "" {
  82. subService.Projectmatch = in.Projectmatch
  83. }
  84. if in.Otherbuyerclass != "" {
  85. subService.Otherbuyerclass = in.Otherbuyerclass
  86. }
  87. subService.Mgo = IC.Mgo
  88. status, err := subService.Update()
  89. if err != nil || status == 0 {
  90. l.Error(fmt.Sprintf("%+v", in), err.Error())
  91. resp.ErrorMsg = err.Error()
  92. resp.ErrorCode = -1
  93. } else {
  94. resp.Status = status
  95. }
  96. return resp, nil
  97. }