get_pay_recharge_by_id_logic.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package pay_recharge
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-core/rpc/types/core"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "wechat-api/internal/utils/dberrorhandler"
  8. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  9. "github.com/suyuan32/simple-admin-common/utils/pointy"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetPayRechargeByIdLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewGetPayRechargeByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPayRechargeByIdLogic {
  18. return &GetPayRechargeByIdLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. func (l *GetPayRechargeByIdLogic) GetPayRechargeById(req *types.IDReq) (*types.PayRechargeInfoResp, error) {
  25. data, err := l.svcCtx.DB.PayRecharge.Get(l.ctx, req.Id)
  26. if err != nil {
  27. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  28. }
  29. departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: data.OrganizationID})
  30. if err != nil {
  31. return nil, err
  32. }
  33. bUserInfo := types.UserInfo{}
  34. if data.UserID != "" {
  35. userInfo, _ := l.svcCtx.CoreRpc.GetUserById(l.ctx, &core.UUIDReq{Id: data.UserID})
  36. if userInfo != nil {
  37. bUserInfo.Id = userInfo.Id
  38. bUserInfo.Username = userInfo.Username
  39. bUserInfo.Nickname = userInfo.Nickname
  40. bUserInfo.Avatar = userInfo.Avatar
  41. }
  42. }
  43. return &types.PayRechargeInfoResp{
  44. BaseDataInfo: types.BaseDataInfo{
  45. Code: 0,
  46. Msg: errormsg.Success,
  47. },
  48. Data: types.PayRechargeInfo{
  49. BaseIDInfo: types.BaseIDInfo{
  50. Id: &data.ID,
  51. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  52. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  53. },
  54. UserId: &data.UserID,
  55. UserInfo: bUserInfo,
  56. Number: &data.Number,
  57. Status: &data.Status,
  58. Money: &data.Money,
  59. OutTradeNo: &data.OutTradeNo,
  60. OrganizationId: &data.OrganizationID,
  61. OrganizationName: departmentInfo.Name,
  62. },
  63. }, nil
  64. }