hi-server/internal/logic/public/subscribe/querySubscribeListLogic.go
shanshanzhong 26c9ff2f0f
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 8m31s
x
2026-03-28 22:57:19 -07:00

74 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package subscribe
import (
"context"
"encoding/json"
"github.com/perfect-panel/server/internal/model/subscribe"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
// "github.com/perfect-panel/server/pkg/apiversion"
// "github.com/perfect-panel/server/pkg/constant"
"github.com/perfect-panel/server/pkg/logger"
"github.com/perfect-panel/server/pkg/tool"
"github.com/perfect-panel/server/pkg/xerr"
"github.com/pkg/errors"
)
type QuerySubscribeListLogic struct {
logger.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// Get subscribe list
func NewQuerySubscribeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QuerySubscribeListLogic {
return &QuerySubscribeListLogic{
Logger: logger.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *QuerySubscribeListLogic) QuerySubscribeList(req *types.QuerySubscribeListRequest) (resp *types.QuerySubscribeListResponse, err error) {
total, data, err := l.svcCtx.SubscribeModel.FilterList(l.ctx, &subscribe.FilterParams{
Page: 1,
Size: 9999,
Language: req.Language,
Sell: true,
DefaultLanguage: true,
})
if err != nil {
l.Errorw("[QuerySubscribeListLogic] Database Error", logger.Field("error", err.Error()))
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "QuerySubscribeList error: %v", err.Error())
}
resp = &types.QuerySubscribeListResponse{
Total: total,
}
list := make([]types.Subscribe, len(data))
for i, item := range data {
var sub types.Subscribe
tool.DeepCopy(&sub, item)
if item.Discount != "" {
var discount []types.SubscribeDiscount
_ = json.Unmarshal([]byte(item.Discount), &discount)
sub.Discount = discount
list[i] = sub
}
list[i] = sub
}
// 老版本(无 api-header去掉排序最后一个套餐
// rawVersion, _ := l.ctx.Value(constant.CtxKeyAPIHeaderRaw).(string)
// useLatest := apiversion.UseLatest(rawVersion, apiversion.DefaultThreshold)
// if !useLatest && len(list) > 0 {
// list = list[:len(list)-1]
// }
resp.List = list
resp.Total = int64(len(list))
return
}