updatesubscribeinfologic.go 2.4 KB

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