get_api_wx_card_detail_logic.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package wxcard
  2. import (
  3. "context"
  4. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  5. "github.com/suyuan32/simple-admin-common/utils/pointy"
  6. "github.com/zeromicro/go-zero/core/errorx"
  7. "wechat-api/ent/wxcard"
  8. "wechat-api/internal/utils/dberrorhandler"
  9. "wechat-api/internal/svc"
  10. "wechat-api/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type GetApiWxCardDetailLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. func NewGetApiWxCardDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetApiWxCardDetailLogic {
  19. return &GetApiWxCardDetailLogic{
  20. Logger: logx.WithContext(ctx),
  21. ctx: ctx,
  22. svcCtx: svcCtx}
  23. }
  24. func (l *GetApiWxCardDetailLogic) GetApiWxCardDetail(req *types.IDReq) (*types.WxCardInfoResp, error) {
  25. if req.Id == 0 {
  26. return nil, errorx.NewDefaultError("参数错误")
  27. }
  28. data, err := l.svcCtx.DB.WxCard.Query().Where(wxcard.ID(req.Id)).Only(l.ctx)
  29. if err != nil {
  30. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  31. }
  32. var showChat, showAi bool
  33. if data.APIKey != "" && data.APIBase != "" {
  34. showChat = true
  35. }
  36. if data.AiInfo != "" {
  37. showAi = true
  38. }
  39. return &types.WxCardInfoResp{
  40. BaseDataInfo: types.BaseDataInfo{
  41. Code: 0,
  42. Msg: errormsg.Success,
  43. },
  44. Data: types.WxCardInfo{
  45. BaseIDInfo: types.BaseIDInfo{
  46. Id: &data.ID,
  47. CreatedAt: pointy.GetPointer(data.CreatedAt.UnixMilli()),
  48. UpdatedAt: pointy.GetPointer(data.UpdatedAt.UnixMilli()),
  49. },
  50. Name: &data.Name,
  51. Avatar: &data.Avatar,
  52. Logo: &data.Logo,
  53. Company: &data.Company,
  54. Address: &data.Address,
  55. Phone: &data.Phone,
  56. OfficialAccount: &data.OfficialAccount,
  57. WechatAccount: &data.WechatAccount,
  58. Email: &data.Email,
  59. Intro: &data.Intro,
  60. ShowChat: &showChat,
  61. ShowAi: &showAi,
  62. },
  63. }, nil
  64. }