acquirer_mkt_qr_get_logic.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package acquirer_mkt_qr
  2. import (
  3. "context"
  4. "encoding/json"
  5. "git.i2edu.net/i2/i2-bill-api/internal/utils"
  6. "git.i2edu.net/i2/i2-bill-api/model"
  7. "net/http"
  8. "strings"
  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 AcquirerMktQrGetLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewAcquirerMktQrGetLogic(ctx context.Context, svcCtx *svc.ServiceContext) AcquirerMktQrGetLogic {
  19. return AcquirerMktQrGetLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. }
  24. }
  25. func (l *AcquirerMktQrGetLogic) AcquirerMktQrGet(r *http.Request) (*types.Response, error) {
  26. // todo: add your logic here and delete this line
  27. userId := l.svcCtx.GetUserIdByJwt(l.ctx)
  28. erpId, err := model.GetAcquirePerm(userId, l.svcCtx.Transformer, l.svcCtx.DB)
  29. if err != nil {
  30. logx.Error(err.Error())
  31. return &types.Response{500, err.Error(), nil}, nil
  32. }
  33. if erpId == "" {
  34. return &types.Response{500, "请先申请成为兼职", nil}, nil
  35. }
  36. qr, err := model.GetAcquirerMktQr(userId, l.svcCtx.DB)
  37. if err != nil {
  38. logx.Error(err.Error())
  39. return &types.Response{500, err.Error(), nil}, nil
  40. }
  41. if qr.Id == 0 {
  42. return &types.Response{500, "请先编辑收单二维码信息", nil}, nil
  43. }
  44. qr.Qr = strings.TrimLeft(qr.Qr, "/")
  45. domain := strings.TrimRight(l.svcCtx.Config.Domain, "/")
  46. qr.Qr = domain + "/" + qr.Qr
  47. //渠道
  48. networkNodes, err := l.svcCtx.GetErpNetworkDetailTree()
  49. if err != nil {
  50. logx.Error(err.Error())
  51. return &types.Response{500, err.Error(), nil}, nil
  52. }
  53. var networkId, networkName string
  54. utils.TreePath(networkNodes, qr.QudaoId, &networkId, &networkName)
  55. qrByte, _ := json.Marshal(qr)
  56. var qrMap = make(map[string]interface{})
  57. json.Unmarshal(qrByte, &qrMap)
  58. qrMap["qudao_name"] = networkName
  59. qrMap["qudao_path"] = networkId
  60. //活动
  61. active, err := l.svcCtx.GetErpActivity()
  62. if err != nil {
  63. logx.Error(err.Error())
  64. return &types.Response{500, err.Error(), nil}, nil
  65. }
  66. qrMap["activity_name"] = utils.GetErpActiveName(qr.ActivityId, active)
  67. //校区
  68. schools, err := l.svcCtx.GetErpOrganSchool()
  69. if err != nil {
  70. logx.Error(err.Error())
  71. return &types.Response{500, err.Error(), nil}, nil
  72. }
  73. qrMap["school_name"] = utils.GetErpSchoolName(qr.SchoolId, schools)
  74. return &types.Response{200, "", qrMap}, nil
  75. }