acquirer_mkt_qr_update_logic.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package acquirer_mkt_qr
  2. import (
  3. "context"
  4. "encoding/json"
  5. "git.i2edu.net/i2/i2-bill-api/internal/logic/user"
  6. "git.i2edu.net/i2/i2-bill-api/model"
  7. "io/ioutil"
  8. "net/http"
  9. "time"
  10. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  11. "git.i2edu.net/i2/i2-bill-api/internal/types"
  12. "git.i2edu.net/i2/go-zero/core/logx"
  13. )
  14. type AcquirerMktQrUpdateLogic struct {
  15. logx.Logger
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. }
  19. func NewAcquirerMktQrUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerMktQrUpdateLogic {
  20. return AcquirerMktQrUpdateLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *AcquirerMktQrUpdateLogic) AcquirerMktQrUpdate(r *http.Request) (*types.Response, error) {
  27. // todo: add your logic here and delete this line
  28. userId := l.svcCtx.GetUserIdByJwt(l.ctx)
  29. body, err := ioutil.ReadAll(r.Body)
  30. if err != nil {
  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. return &types.Response{500, err.Error(), nil}, nil
  37. }
  38. erpId, err := user.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
  39. if err != nil {
  40. return &types.Response{500, err.Error(), nil}, nil
  41. }
  42. if erpId == "" {
  43. return &types.Response{500, "请先申请兼职", nil}, nil
  44. }
  45. sql := `
  46. select
  47. qr.qudao_id,activity_id,school_id
  48. from
  49. i2bill_acquirer_mkt_qr qr
  50. inner join
  51. i2bill_mkt_part_time_user part
  52. on
  53. qr.user_id = part_user.id
  54. where
  55. part.mk_id = ? and qr.del_flag = 0 and part.del_flag = 0`
  56. acquirers, err := l.svcCtx.DB.SQL(sql, erpId).Query().List()
  57. if err != nil {
  58. return &types.Response{500, err.Error(), nil}, nil
  59. }
  60. if len(acquirers) == 0 {
  61. return &types.Response{500, "请选择渠道", nil}, nil
  62. }
  63. if bean.Id != 0 {
  64. bean.QudaoId, _ = acquirers[0]["qudao_id"].(int64)
  65. bean.ActivityId, _ = acquirers[0]["activity_id"].(int64)
  66. bean.SchoolId, _ = acquirers[0]["school_id"].(int64)
  67. }
  68. bean.QudaoId, _ = acquirers[0]["qudao_id"].(int64)
  69. bean.ActivityId, _ = acquirers[0]["activity_id"].(int64)
  70. bean.SchoolId, _ = acquirers[0]["school_id"].(int64)
  71. bean.UserId = userId
  72. bean.CreateTime = time.Now()
  73. bean.LastUpdateTime = bean.CreateTime
  74. bean.CreateBy = bean.UserId
  75. bean.LastUpdateBy = bean.CreateBy
  76. bean.DelFlag = 0
  77. bean.Qr = "test.jpg"
  78. //生成二维码
  79. _, err = l.svcCtx.DB.Insert(bean)
  80. if err != nil {
  81. return &types.Response{500, err.Error(), nil}, nil
  82. }
  83. return &types.Response{200, "", nil}, nil
  84. }