feat(1.0.2):修复专栏问题;修复多端登录问题;

developing
张帅 2 weeks ago
parent 4f00b1bd82
commit 2543c93ecf

@ -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

@ -0,0 +1,11 @@
package crypto
import "testing"
func TestPasswordEncode(t *testing.T) {
}
func TestPasswordDecode(t *testing.T) {
}

@ -0,0 +1,13 @@
package crypto
import "testing"
func TestPhoneEncode(t *testing.T) {
ser := NewPhoneEncryptionService()
v, _ := ser.Encrypt("17782351006")
t.Log(v)
}
func TestPhoneDecode(t *testing.T) {
}

@ -17,37 +17,28 @@ func NewService(repo purchase.Repository) *Service {
} }
} }
// HasPermission 检查用户是否有权限访问内容 // CreatePurchase 创建购买记录
func (s *Service) HasPermission(userId, contentId uint64, contentType purchase.ContentType, price float64) (bool, error) { func (s *Service) CreatePurchase(userId, contentId uint64, contentType purchase.ContentType, price float64) error {
// 如果内容是免费的直接返回true p := &purchase.Purchase{}
if price == 0 { var err error
return true, nil
}
// 检查用户是否购买了内容 if contentType == purchase.ContentTypeColumn {
purchase, err := s.repo.FindByUserIdAndContent(userId, contentId, contentType) p, err = s.repo.FindColumnWithId(userId, contentId)
if err != nil {
return false, err } else {
} p, err = s.repo.FindArticleWithId(userId, contentId)
if purchase == nil {
return false, nil
}
return purchase.IsValid(), nil
} }
// CreatePurchase 创建购买记录
func (s *Service) CreatePurchase(userId, contentId uint64, contentType purchase.ContentType, price float64) error {
// 检查是否已购买 // 检查是否已购买
exist, err := s.repo.FindByUserIdAndContent(userId, contentId, contentType)
if err != nil { if err != nil {
return err return err
} }
if exist != nil { if p != nil {
return errors.New("已经购买过该内容") return errors.New("已经购买过该内容")
} }
// 创建购买记录 // 创建购买记录
purchase := purchase.NewPurchase(userId, contentId, contentType, price, 0) newP := purchase.NewPurchase(userId, contentId, contentType, price, 0)
return s.repo.Save(purchase) return s.repo.Save(newP)
} }

@ -63,21 +63,6 @@ func (u *UserService) SetPassword(phone, pwd string) error {
return err return err
} }
// GetUserInfo 获取用户信息
func (u *UserService) GetUserInfo(username string) (*UserDto, error) {
existUser, err := u.repo.FindByUsername(username)
if err != nil {
return nil, err
}
return &UserDto{
Uid: existUser.Id,
Username: existUser.Username,
Phone: existUser.Phone,
Status: existUser.Status,
}, nil
}
func (u *UserService) GetUserGiftCount(ePhone string) (int, error) { func (u *UserService) GetUserGiftCount(ePhone string) (int, error) {
c, err := u.repo.GetUserGiftCount(ePhone) c, err := u.repo.GetUserGiftCount(ePhone)
if err != nil { if err != nil {
@ -109,6 +94,7 @@ func (u *UserService) GetUserProfileByePhone(ePhone string) (*UserDto, error) {
return nil, err return nil, err
} }
if user == nil { if user == nil {
u.log.Error("未找到用户")
return nil, errors.New("未找到用户") return nil, errors.New("未找到用户")
} }
p, err := u.phoneEncryption.StringPhone(user.Phone) p, err := u.phoneEncryption.StringPhone(user.Phone)

@ -4,16 +4,10 @@ package purchase
type Repository interface { type Repository interface {
// Save 保存购买记录 // Save 保存购买记录
Save(purchase *Purchase) error Save(purchase *Purchase) error
// FindByUserIdAndContent 根据用户ID和内容ID查找购买记录 FindArticleWithId(uid uint64, contentId uint64) (*Purchase, error)
FindByUserIdAndContent(userId, contentId uint64, contentType ContentType) (*Purchase, error)
// FindByUserId 查找用户的所有购买记录
FindByUserId(userId uint64) ([]*Purchase, error)
FindColumnById(uid uint64, ids ...uint64) ([]*Purchase, error) FindColumnById(uid uint64, ids ...uint64) ([]*Purchase, error)
FindArticleById(uid uint64, ids ...uint64) ([]*Purchase, error) FindArticleById(uid uint64, ids ...uint64) ([]*Purchase, error)
FindArticlesByUserId(userId uint64) ([]*Purchase, error) FindArticlesByUserId(userId uint64) ([]*Purchase, error)
FindColumnsByUserId(userId uint64) ([]*Purchase, error) FindColumnsByUserId(userId uint64) ([]*Purchase, error)
// FindByContent 查找内容的所有购买记录
FindByContent(contentId uint64, contentType ContentType) ([]*Purchase, error)
FindColumnWithId(uid uint64, contentId uint64) (*Purchase, error) FindColumnWithId(uid uint64, contentId uint64) (*Purchase, error)
} }

@ -4,6 +4,7 @@ import (
"cls/internal/domain/purchase" "cls/internal/domain/purchase"
"cls/pkg/logger" "cls/pkg/logger"
"cls/pkg/xorm_engine" "cls/pkg/xorm_engine"
"time"
"xorm.io/builder" "xorm.io/builder"
) )
@ -30,31 +31,6 @@ func (r *PurchaseRepositoryORM) Save(purchase *purchase.Purchase) error {
return err return err
} }
func (r *PurchaseRepositoryORM) FindByUserIdAndContent(userId, contentId uint64, contentType purchase.ContentType) (*purchase.Purchase, error) {
purchase := &purchase.Purchase{}
exist, err := r.engine.Where("user_id = ? AND content_id = ? AND content_type = ?",
userId, contentId, contentType).Get(purchase)
if err != nil {
return nil, err
}
if !exist {
return nil, nil
}
return purchase, nil
}
func (r *PurchaseRepositoryORM) FindByUserId(userId uint64) ([]*purchase.Purchase, error) {
purchases := make([]*purchase.Purchase, 0)
err := r.engine.Where("user_id = ?", userId).Find(&purchases)
return purchases, err
}
func (r *PurchaseRepositoryORM) FindByContent(contentId uint64, contentType purchase.ContentType) ([]*purchase.Purchase, error) {
purchases := make([]*purchase.Purchase, 0)
err := r.engine.Where("content_id = ? AND content_type = ?", contentId, contentType).Find(&purchases)
return purchases, err
}
func (r *PurchaseRepositoryORM) FindArticlesByUserId(userId uint64) ([]*purchase.Purchase, error) { func (r *PurchaseRepositoryORM) FindArticlesByUserId(userId uint64) ([]*purchase.Purchase, error) {
purchases := make([]*purchase.Purchase, 0) purchases := make([]*purchase.Purchase, 0)
err := r.engine.Where(builder.Eq{"user_id": userId}.And(builder.Eq{"content_type": purchase.ContentTypeArticle})).Find(&purchases) err := r.engine.Where(builder.Eq{"user_id": userId}.And(builder.Eq{"content_type": purchase.ContentTypeArticle})).Find(&purchases)
@ -63,7 +39,9 @@ func (r *PurchaseRepositoryORM) FindArticlesByUserId(userId uint64) ([]*purchase
func (r *PurchaseRepositoryORM) FindColumnsByUserId(userId uint64) ([]*purchase.Purchase, error) { func (r *PurchaseRepositoryORM) FindColumnsByUserId(userId uint64) ([]*purchase.Purchase, error) {
purchases := make([]*purchase.Purchase, 0) purchases := make([]*purchase.Purchase, 0)
err := r.engine.Where(builder.Eq{"user_id": userId}.And(builder.Eq{"content_type": purchase.ContentTypeColumn})).Find(&purchases) err := r.engine.Where(builder.Eq{"user_id": userId}.
And(builder.Eq{"content_type": purchase.ContentTypeColumn})).
And(builder.Gte{"expired_at": time.Now()}).Find(&purchases)
return purchases, err return purchases, err
} }
@ -75,13 +53,25 @@ func (r *PurchaseRepositoryORM) FindArticleById(uid uint64, ids ...uint64) ([]*p
func (r *PurchaseRepositoryORM) FindColumnById(uid uint64, ids ...uint64) ([]*purchase.Purchase, error) { func (r *PurchaseRepositoryORM) FindColumnById(uid uint64, ids ...uint64) ([]*purchase.Purchase, error) {
purchases := make([]*purchase.Purchase, 0) purchases := make([]*purchase.Purchase, 0)
err := r.engine.Where(builder.Eq{"user_id": uid}.And(builder.In("content_id", ids)).And(builder.Eq{"content_type": purchase.ContentTypeColumn})).Find(&purchases) err := r.engine.Where(builder.Eq{"user_id": uid}.And(builder.In("content_id", ids)).
And(builder.Eq{"content_type": purchase.ContentTypeColumn})).
And(builder.Gte{"expired_at": time.Now()}).Find(&purchases)
return purchases, err return purchases, err
} }
func (r *PurchaseRepositoryORM) FindColumnWithId(uid uint64, contentId uint64) (*purchase.Purchase, error) { func (r *PurchaseRepositoryORM) FindColumnWithId(uid uint64, contentId uint64) (*purchase.Purchase, error) {
data := &purchase.Purchase{} data := &purchase.Purchase{}
_, err := r.engine.Where("user_id = ? AND content_id = ? AND content_type = ?", uid, contentId, purchase.ContentTypeColumn).Get(data) _, err := r.engine.Where("user_id = ? AND content_id = ? AND content_type = ?", uid, contentId, purchase.ContentTypeColumn).
And(builder.Gte{"expired_at": time.Now()}).Get(data)
if err != nil {
return nil, err
}
return data, nil
}
func (r *PurchaseRepositoryORM) FindArticleWithId(uid uint64, contentId uint64) (*purchase.Purchase, error) {
data := &purchase.Purchase{}
_, err := r.engine.Where("user_id = ? AND content_id = ? AND content_type = ?", uid, contentId, purchase.ContentTypeArticle).Get(data)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -49,7 +49,7 @@ func (a *ArticleHandler) findAll(c *gin.Context) {
} }
err = a.service.Find(ePhone, p, map[string]string{ err = a.service.Find(ePhone, p, map[string]string{
"search_like_class": c.Query("search_like_class")}) "search_eq_class": c.Query("search_eq_class")})
if err != nil { if err != nil {
c.AbortWithStatus(http.StatusInternalServerError) c.AbortWithStatus(http.StatusInternalServerError)
} else { } else {
@ -91,7 +91,7 @@ func (a *ArticleHandler) free(c *gin.Context) {
return return
} }
err = a.service.FindFree(p, map[string]string{ err = a.service.FindFree(p, map[string]string{
"search_like_class": c.Query("search_like_class")}) "search_eq_class": c.Query("search_eq_class")})
if err != nil { if err != nil {
c.AbortWithStatus(http.StatusInternalServerError) c.AbortWithStatus(http.StatusInternalServerError)
} else { } else {

@ -8,6 +8,7 @@ import { GoCaptchaModule } from 'go-captcha-angular';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import {AuthInterceptor} from "./core/interceptors/auth.interceptor"; import {AuthInterceptor} from "./core/interceptors/auth.interceptor";
import {CheckInterceptor} from "./core/interceptors/check.interceptor";
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -28,6 +29,11 @@ import {AuthInterceptor} from "./core/interceptors/auth.interceptor";
useClass: AuthInterceptor, useClass: AuthInterceptor,
multi: true, multi: true,
}, },
{
provide: HTTP_INTERCEPTORS,
useClass: CheckInterceptor,
multi: true,
},
], ],
bootstrap: [AppComponent], bootstrap: [AppComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]

@ -49,7 +49,11 @@ export class ArticleContentComponent implements OnInit {
} }
getData() { getData() {
if(this.className != "") {
this.searchParams['search_eq_class'] = this.className;
} else {
this.searchParams['search_eq_class'] = ""
}
switch (this.currentSelect){ switch (this.currentSelect){
case "new": case "new":
return this.getNewData() return this.getNewData()
@ -78,6 +82,8 @@ export class ArticleContentComponent implements OnInit {
this.searchParams['page'] = this.searchParams['page']+1; this.searchParams['page'] = this.searchParams['page']+1;
this.hasMore = res.items.length === this.searchParams['size']; this.hasMore = res.items.length === this.searchParams['size'];
this.cdr.detectChanges(); this.cdr.detectChanges();
} else {
this.hasMore = false;
} }
} }
}) })
@ -85,9 +91,6 @@ export class ArticleContentComponent implements OnInit {
getUnLockData() { getUnLockData() {
this.getUsername() this.getUsername()
if(this.username!= ""){ if(this.username!= ""){
if(this.className != "") {
this.searchParams['search_eq_class'] = this.className
}
this.homeService.unlockList(this.searchParams).pipe(takeUntil(this.destroy$)).subscribe(res=>{ this.homeService.unlockList(this.searchParams).pipe(takeUntil(this.destroy$)).subscribe(res=>{
if(res.items) { if(res.items) {
if(res.items.length > 0) { if(res.items.length > 0) {
@ -95,6 +98,8 @@ export class ArticleContentComponent implements OnInit {
this.searchParams['page'] = this.searchParams['page']+1; this.searchParams['page'] = this.searchParams['page']+1;
this.hasMore = res.items.length === this.searchParams['size']; this.hasMore = res.items.length === this.searchParams['size'];
this.cdr.detectChanges(); this.cdr.detectChanges();
} else {
this.hasMore = false;
} }
} }
}) })
@ -109,6 +114,8 @@ export class ArticleContentComponent implements OnInit {
this.searchParams['page'] = this.searchParams['page']+1; this.searchParams['page'] = this.searchParams['page']+1;
this.hasMore = res.items.length === this.searchParams['size']; this.hasMore = res.items.length === this.searchParams['size'];
this.cdr.detectChanges(); this.cdr.detectChanges();
} else {
this.hasMore = false;
} }
} }
}) })

Loading…
Cancel
Save