|
|
@ -2,6 +2,7 @@ package article
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"cls/internal/domain/article"
|
|
|
|
"cls/internal/domain/article"
|
|
|
|
|
|
|
|
"cls/internal/domain/column"
|
|
|
|
"cls/internal/domain/free_trial"
|
|
|
|
"cls/internal/domain/free_trial"
|
|
|
|
"cls/internal/domain/purchase"
|
|
|
|
"cls/internal/domain/purchase"
|
|
|
|
domainUser "cls/internal/domain/user"
|
|
|
|
domainUser "cls/internal/domain/user"
|
|
|
@ -17,6 +18,7 @@ import (
|
|
|
|
type ArticleService struct {
|
|
|
|
type ArticleService struct {
|
|
|
|
repo article.ArticleRepository
|
|
|
|
repo article.ArticleRepository
|
|
|
|
userRepo domainUser.UserRepository
|
|
|
|
userRepo domainUser.UserRepository
|
|
|
|
|
|
|
|
columnRepo column.ColumnRepository
|
|
|
|
purchaseRepo purchase.Repository
|
|
|
|
purchaseRepo purchase.Repository
|
|
|
|
userAggregateRepo domainUser.UserAggregateRepository
|
|
|
|
userAggregateRepo domainUser.UserAggregateRepository
|
|
|
|
FreeRepo free_trial.FreeTrialRepository
|
|
|
|
FreeRepo free_trial.FreeTrialRepository
|
|
|
@ -26,11 +28,13 @@ type ArticleService struct {
|
|
|
|
func NewArticleService(repo article.ArticleRepository,
|
|
|
|
func NewArticleService(repo article.ArticleRepository,
|
|
|
|
userRepo domainUser.UserRepository,
|
|
|
|
userRepo domainUser.UserRepository,
|
|
|
|
purchaseRepo purchase.Repository,
|
|
|
|
purchaseRepo purchase.Repository,
|
|
|
|
|
|
|
|
columnRepo column.ColumnRepository,
|
|
|
|
userAggregateRepo domainUser.UserAggregateRepository,
|
|
|
|
userAggregateRepo domainUser.UserAggregateRepository,
|
|
|
|
FreeRepo free_trial.FreeTrialRepository,
|
|
|
|
FreeRepo free_trial.FreeTrialRepository,
|
|
|
|
log logger.New) *ArticleService {
|
|
|
|
log logger.New) *ArticleService {
|
|
|
|
return &ArticleService{repo,
|
|
|
|
return &ArticleService{repo,
|
|
|
|
userRepo,
|
|
|
|
userRepo,
|
|
|
|
|
|
|
|
columnRepo,
|
|
|
|
purchaseRepo,
|
|
|
|
purchaseRepo,
|
|
|
|
userAggregateRepo,
|
|
|
|
userAggregateRepo,
|
|
|
|
FreeRepo,
|
|
|
|
FreeRepo,
|
|
|
@ -61,10 +65,28 @@ var class_type_reverse = map[string]uint64{
|
|
|
|
"金牌纪要库": 20087,
|
|
|
|
"金牌纪要库": 20087,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var column_class = map[uint64]uint64{
|
|
|
|
|
|
|
|
81201: 20015,
|
|
|
|
|
|
|
|
81202: 20014,
|
|
|
|
|
|
|
|
81204: 20021,
|
|
|
|
|
|
|
|
81205: 20013,
|
|
|
|
|
|
|
|
81206: 20022,
|
|
|
|
|
|
|
|
81208: 20023,
|
|
|
|
|
|
|
|
81209: 20025,
|
|
|
|
|
|
|
|
81210: 20026,
|
|
|
|
|
|
|
|
81232: 20087,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a *ArticleService) Find(ePhone string, page *page.Page, searchParams map[string]string) error {
|
|
|
|
func (a *ArticleService) Find(ePhone string, page *page.Page, searchParams map[string]string) error {
|
|
|
|
conds := make([]builder.Cond, 0)
|
|
|
|
conds := make([]builder.Cond, 0)
|
|
|
|
class := searchParams["search_like_class"]
|
|
|
|
columnInfo := &column.Column{}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
class := searchParams["search_eq_class"]
|
|
|
|
if class != "" {
|
|
|
|
if class != "" {
|
|
|
|
|
|
|
|
columnInfo, err = a.columnRepo.FindByName(class)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
a.log.Error(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
classCode := class_type_reverse[class]
|
|
|
|
classCode := class_type_reverse[class]
|
|
|
|
if classCode != 0 {
|
|
|
|
if classCode != 0 {
|
|
|
|
conds = append(conds, builder.Eq{"type": classCode})
|
|
|
|
conds = append(conds, builder.Eq{"type": classCode})
|
|
|
@ -73,7 +95,7 @@ func (a *ArticleService) Find(ePhone string, page *page.Page, searchParams map[s
|
|
|
|
conds = append(conds, builder.And(builder.Gt{"ctime": time.Now().AddDate(0, 0, -2).Unix()}).And(builder.Eq{"is_free": 0}))
|
|
|
|
conds = append(conds, builder.And(builder.Gt{"ctime": time.Now().AddDate(0, 0, -2).Unix()}).And(builder.Eq{"is_free": 0}))
|
|
|
|
articles := make([]*article.LianV1Article, 0)
|
|
|
|
articles := make([]*article.LianV1Article, 0)
|
|
|
|
page.Content = &articles
|
|
|
|
page.Content = &articles
|
|
|
|
err := a.repo.Find(page, conds)
|
|
|
|
err = a.repo.Find(page, conds)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
a.log.Error(err)
|
|
|
|
a.log.Error(err)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -85,11 +107,17 @@ func (a *ArticleService) Find(ePhone string, page *page.Page, searchParams map[s
|
|
|
|
a.log.Error(err)
|
|
|
|
a.log.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if user != nil {
|
|
|
|
if user != nil {
|
|
|
|
columnData, err := a.purchaseRepo.FindColumnsByUserId(user.Id)
|
|
|
|
var columnData []*purchase.Purchase
|
|
|
|
|
|
|
|
if columnInfo != nil && columnInfo.ID > 0 {
|
|
|
|
|
|
|
|
columnData, err = a.purchaseRepo.FindColumnById(user.Id, columnInfo.ID)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
columnData, err = a.purchaseRepo.FindColumnsByUserId(user.Id)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
columnMap := make(map[uint64]struct{})
|
|
|
|
columnMap := make(map[uint64]struct{})
|
|
|
|
if len(columnData) != 0 {
|
|
|
|
if len(columnData) != 0 {
|
|
|
|
for _, v := range columnData {
|
|
|
|
for _, v := range columnData {
|
|
|
|
columnMap[v.ContentId] = struct{}{}
|
|
|
|
columnMap[column_class[v.ContentId]] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -211,7 +239,7 @@ func (a *ArticleService) FindUnLock(ePhone string, page *page.Page, searchParams
|
|
|
|
|
|
|
|
|
|
|
|
func (a *ArticleService) FindFree(page *page.Page, searchParams map[string]string) error {
|
|
|
|
func (a *ArticleService) FindFree(page *page.Page, searchParams map[string]string) error {
|
|
|
|
conds := make([]builder.Cond, 0)
|
|
|
|
conds := make([]builder.Cond, 0)
|
|
|
|
class := searchParams["search_like_class"]
|
|
|
|
class := searchParams["search_eq_class"]
|
|
|
|
if class != "" {
|
|
|
|
if class != "" {
|
|
|
|
classCode := class_type_reverse[class]
|
|
|
|
classCode := class_type_reverse[class]
|
|
|
|
if classCode != 0 {
|
|
|
|
if classCode != 0 {
|
|
|
@ -260,7 +288,7 @@ func (a *ArticleService) Detail(userPhone string, id uint64) (*ArticleDto, error
|
|
|
|
return nil, errors.New("未找到用户")
|
|
|
|
return nil, errors.New("未找到用户")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
p, err := a.purchaseRepo.FindByUserIdAndContent(user.Id, id, purchase.ContentTypeArticle)
|
|
|
|
p, err := a.purchaseRepo.FindArticleWithId(user.Id, id)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
a.log.Error(err)
|
|
|
|
a.log.Error(err)
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|