acquirer_mkt_qr_update_logic.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package acquirer_mkt_qr
  2. import (
  3. "context"
  4. "encoding/json"
  5. "git.i2edu.net/i2/i2-bill-api/model"
  6. "io/ioutil"
  7. "net/http"
  8. "time"
  9. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  10. "git.i2edu.net/i2/i2-bill-api/internal/types"
  11. "git.i2edu.net/i2/go-zero/core/logx"
  12. )
  13. type AcquirerMktQrUpdateLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewAcquirerMktQrUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerMktQrUpdateLogic {
  19. return AcquirerMktQrUpdateLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *AcquirerMktQrUpdateLogic) AcquirerMktQrUpdate(r *http.Request) (*types.Response, error) {
  26. // todo: add your logic here and delete this line
  27. userId := l.svcCtx.GetUserIdByJwt(l.ctx)
  28. body, err := ioutil.ReadAll(r.Body)
  29. if err != nil {
  30. logx.Error(err.Error())
  31. return &types.Response{500, err.Error(), nil}, nil
  32. }
  33. bean := new(model.I2billAcquirerMktQrXorm)
  34. err = json.Unmarshal(body, bean)
  35. if err != nil {
  36. logx.Error(err.Error())
  37. return &types.Response{500, err.Error(), nil}, nil
  38. }
  39. userInfo, err := model.GetI2bilUserInfo(userId, l.svcCtx.DB)
  40. if err != nil {
  41. logx.Error(err.Error())
  42. return &types.Response{500, err.Error(), nil}, nil
  43. }
  44. //mk
  45. if userInfo.ErpId != "" {
  46. erpId, err := model.GetErpUser("", userInfo.ErpId, l.svcCtx.Transformer)
  47. if err != nil {
  48. logx.Error(err.Error())
  49. return &types.Response{500, err.Error(), nil}, nil
  50. }
  51. if erpId == "" {
  52. return &types.Response{500, "未找到mk用户", nil}, nil
  53. }
  54. } else {
  55. //兼职
  56. partUser, err := model.GetPartTimeXormByUserId(userId, l.svcCtx.DB)
  57. if err != nil {
  58. logx.Error(err.Error())
  59. return &types.Response{500, err.Error(), nil}, nil
  60. }
  61. if partUser.Id == 0 {
  62. return &types.Response{500, "请先申请成为兼职", nil}, nil
  63. }
  64. bean.QudaoId = 1058
  65. bean.ActivityId = 0
  66. }
  67. acquirersQr := new(model.I2billAcquirerMktQrXorm)
  68. _, err = l.svcCtx.DB.Where("user_id = ? and del_flag = 0", userId).Get(acquirersQr)
  69. if err != nil {
  70. logx.Error(err.Error())
  71. return &types.Response{500, err.Error(), nil}, nil
  72. }
  73. if acquirersQr.Id != 0 {
  74. bean.LastUpdateTime = time.Now()
  75. bean.LastUpdateBy = userId
  76. _, err = l.svcCtx.DB.ID(acquirersQr.Id).AllCols().Update(bean)
  77. if err != nil {
  78. logx.Error(err.Error())
  79. return &types.Response{500, err.Error(), nil}, nil
  80. }
  81. return &types.Response{200, "", nil}, nil
  82. }
  83. bean.LastUpdateBy = userId
  84. bean.LastUpdateTime = time.Now()
  85. bean.CreateBy = userId
  86. bean.CreateTime = bean.LastUpdateTime
  87. bean.DelFlag = 0
  88. //生成二维码
  89. bean.Qr = "test.jpg"
  90. _, err = l.svcCtx.DB.Insert(bean)
  91. if err != nil {
  92. return &types.Response{500, err.Error(), nil}, nil
  93. }
  94. return &types.Response{200, "", nil}, nil
  95. }