Some checks failed
Build docker and publish / build (20.15.1) (push) Has been cancelled
refactor: 重构用户模型和密码验证逻辑 feat(epay): 添加支付类型支持 docs: 添加安装和配置指南文档 fix: 修复优惠券过期检查逻辑 perf: 优化设备解绑缓存清理流程 test: 添加密码验证测试用例 chore: 更新依赖版本
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
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/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
|
|
}
|
|
resp.List = list
|
|
return
|
|
}
|