acquirer_mkt_qr_get_logic.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. erpUser, err := model.GetAcquirePermInfo(userId, l.svcCtx.Transformer, l.svcCtx.DB, l.ctx)
  29. if err != nil {
  30. logx.Error(err.Error())
  31. return &types.Response{500, err.Error(), nil}, nil
  32. }
  33. if erpUser == nil || erpUser.UserId == "" {
  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{200, "请先编辑收单二维码信息", nil}, nil
  43. }
  44. if erpUser.Role != qr.Role {
  45. return &types.Response{200, "请先重新编辑收单二维码信息", nil}, nil
  46. }
  47. qr.Qr = strings.TrimLeft(qr.Qr, "/")
  48. domain := strings.TrimRight(l.svcCtx.Config.AliYunOss.FileUrl, "/")
  49. qr.Qr = domain + "/" + qr.Qr
  50. //渠道
  51. networkNodes, err := l.svcCtx.GetErpNetworkDetailTree(l.ctx)
  52. if err != nil {
  53. logx.Error(err.Error())
  54. return &types.Response{500, err.Error(), nil}, nil
  55. }
  56. var networkId, networkName string
  57. utils.TreePath(networkNodes, qr.NetworkDetailId, &networkId, &networkName)
  58. qrByte, _ := json.Marshal(qr)
  59. var qrMap = make(map[string]interface{})
  60. json.Unmarshal(qrByte, &qrMap)
  61. qrMap["qudao_name"] = networkName
  62. qrMap["qudao_path"] = networkId
  63. //活动
  64. active, err := l.svcCtx.GetErpActivity(l.ctx)
  65. if err != nil {
  66. logx.Error(err.Error())
  67. return &types.Response{500, err.Error(), nil}, nil
  68. }
  69. qrMap["activity_name"] = utils.GetErpActiveName(qr.ActivityId, active)
  70. //校区
  71. schools, err := l.svcCtx.GetErpOrganSchool(l.ctx)
  72. if err != nil {
  73. logx.Error(err.Error())
  74. return &types.Response{500, err.Error(), nil}, nil
  75. }
  76. qrMap["school_name"] = utils.GetErpSchoolName(qr.SchoolId, schools)
  77. return &types.Response{200, "", qrMap}, nil
  78. }