package logic import ( "encoding/json" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" "context" "fusenapi/server/orders/internal/svc" "fusenapi/server/orders/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type GetOrderInvoiceLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewGetOrderInvoiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderInvoiceLogic { return &GetOrderInvoiceLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *GetOrderInvoiceLogic) GetOrderInvoice(req *types.GetOrderInvoiceReq, userinfo *auth.UserInfo) (resp *basic.Response) { if userinfo.GetIdType() != auth.IDTYPE_User { return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first") } //获取用户信息 userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn) user, err := userModel.FindOne(l.ctx, userinfo.UserId) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info") } if user.Id == 0 { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user not found") } if req.Sn == "" { return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "param sn is required") } //查询订单信息 orderModel := gmodel.NewFsOrderModel(l.svcCtx.MysqlConn) orderInfo, err := orderModel.FindOneBySn(l.ctx, userinfo.UserId, req.Sn) if err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get order info") } if orderInfo.Id == 0 { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "order is not exists") } //地址数据 var address gmodel.FsAddress if err = json.Unmarshal([]byte(*orderInfo.AddressInfo), &address); err != nil { logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse address info") } if user.LastName != nil && user.FirstName != nil { } return resp.SetStatus(basic.CodeOK) }