feat: 新增软删除,留有记录保存
This commit is contained in:
parent
e5a09194ad
commit
956be17a4e
@ -22,16 +22,17 @@ func (BoothSlot) TableName() string {
|
|||||||
|
|
||||||
// Exhibition 展品展示表
|
// Exhibition 展品展示表
|
||||||
type Exhibition struct {
|
type Exhibition struct {
|
||||||
ID int64 `gorm:"primaryKey;column:id;autoIncrement"`
|
ID int64 `gorm:"primaryKey;column:id;autoIncrement"`
|
||||||
AssetID int64 `gorm:"column:asset_id;not null;uniqueIndex:uk_asset"`
|
AssetID int64 `gorm:"column:asset_id;not null;uniqueIndex:uk_asset"`
|
||||||
SlotID int64 `gorm:"column:slot_id;not null;index:idx_slot"`
|
SlotID int64 `gorm:"column:slot_id;not null;index:idx_slot"`
|
||||||
HostProfileID int64 `gorm:"column:host_profile_id;not null;index:idx_host"`
|
HostProfileID int64 `gorm:"column:host_profile_id;not null;index:idx_host"`
|
||||||
OccupierUID int64 `gorm:"column:occupier_uid;not null;index:idx_occupier"`
|
OccupierUID int64 `gorm:"column:occupier_uid;not null;index:idx_occupier"`
|
||||||
OccupierStarID int64 `gorm:"column:occupier_star_id;not null;index:idx_occupier"`
|
OccupierStarID int64 `gorm:"column:occupier_star_id;not null;index:idx_occupier"`
|
||||||
StartTime int64 `gorm:"column:start_time;not null"`
|
StartTime int64 `gorm:"column:start_time;not null"`
|
||||||
ExpireAt int64 `gorm:"column:expire_at;not null;index:idx_expire"`
|
ExpireAt int64 `gorm:"column:expire_at;not null;index:idx_expire"`
|
||||||
CreatedAt int64 `gorm:"column:created_at;not null"`
|
CreatedAt int64 `gorm:"column:created_at;not null"`
|
||||||
UpdatedAt int64 `gorm:"column:updated_at;not null"`
|
UpdatedAt int64 `gorm:"column:updated_at;not null"`
|
||||||
|
DeletedAt *int64 `gorm:"column:deleted_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 指定表名
|
// TableName 指定表名
|
||||||
|
|||||||
@ -118,9 +118,9 @@ func (r *rankingRepository) getHotRankingByDimension(starID int64, dimension str
|
|||||||
Where("exhibitions.expire_at > ?", now).
|
Where("exhibitions.expire_at > ?", now).
|
||||||
Where("fan_profiles.star_id = ?", starID)
|
Where("fan_profiles.star_id = ?", starID)
|
||||||
case "month":
|
case "month":
|
||||||
// 本月:本月内开始的展览,按点赞数排序
|
// 本月:本月内展览过的(未下架或本月内下架的)
|
||||||
db = db.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
db = db.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
||||||
Where("exhibitions.start_time >= ?", startOfMonth)
|
Where("exhibitions.expire_at >= ?", startOfMonth)
|
||||||
case "total":
|
case "total":
|
||||||
// 全部:直接使用 assets 表的 like_count,无需额外条件
|
// 全部:直接使用 assets 表的 like_count,无需额外条件
|
||||||
}
|
}
|
||||||
@ -141,9 +141,9 @@ func (r *rankingRepository) getHotRankingByDimension(starID int64, dimension str
|
|||||||
Where("exhibitions.expire_at > ?", now).
|
Where("exhibitions.expire_at > ?", now).
|
||||||
Where("host_fp.star_id = ?", starID)
|
Where("host_fp.star_id = ?", starID)
|
||||||
case "month":
|
case "month":
|
||||||
// 本月:本月内开始的展览
|
// 本月:本月内展览过的(未下架或本月内下架的)
|
||||||
countDB = countDB.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
countDB = countDB.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
||||||
Where("exhibitions.start_time >= ?", startOfMonth)
|
Where("exhibitions.expire_at >= ?", startOfMonth)
|
||||||
}
|
}
|
||||||
if err := countDB.Count(&total).Error; err != nil {
|
if err := countDB.Count(&total).Error; err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
@ -193,9 +193,9 @@ func (r *rankingRepository) GetMyBestRanking(userID, starID int64, dimension str
|
|||||||
Where("exhibitions.expire_at > ?", now).
|
Where("exhibitions.expire_at > ?", now).
|
||||||
Where("host_fp.star_id = ?", starID)
|
Where("host_fp.star_id = ?", starID)
|
||||||
case "month":
|
case "month":
|
||||||
// 本月:本月内开始的展览
|
// 本月:本月内展览过的(未下架或本月内下架的)
|
||||||
db = db.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
db = db.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
||||||
Where("exhibitions.start_time >= ?", startOfMonth)
|
Where("exhibitions.expire_at >= ?", startOfMonth)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户在该star下点赞数最高的藏品
|
// 获取用户在该star下点赞数最高的藏品
|
||||||
@ -236,9 +236,9 @@ func (r *rankingRepository) GetMyBestRanking(userID, starID int64, dimension str
|
|||||||
Where("exhibitions.expire_at > ?", now).
|
Where("exhibitions.expire_at > ?", now).
|
||||||
Where("host_fp.star_id = ?", starID)
|
Where("host_fp.star_id = ?", starID)
|
||||||
case "month":
|
case "month":
|
||||||
// 本月:本月内开始的展览
|
// 本月:本月内展览过的(未下架或本月内下架的)
|
||||||
rankingDB = rankingDB.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
rankingDB = rankingDB.Joins("INNER JOIN exhibitions ON exhibitions.asset_id = assets.id").
|
||||||
Where("exhibitions.start_time >= ?", startOfMonth)
|
Where("exhibitions.expire_at >= ?", startOfMonth)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := rankingDB.Count(&rank).Error; err != nil {
|
if err := rankingDB.Count(&rank).Error; err != nil {
|
||||||
|
|||||||
@ -136,10 +136,10 @@ func (r *galleryRepository) UnlockSlot(slotID int64) error {
|
|||||||
|
|
||||||
// ==================== 展品相关 ====================
|
// ==================== 展品相关 ====================
|
||||||
|
|
||||||
// GetExhibitionByAsset 根据资产ID获取展品展示记录
|
// GetExhibitionByAsset 根据资产ID获取展品展示记录(不含已删除)
|
||||||
func (r *galleryRepository) GetExhibitionByAsset(assetID int64) (*models.Exhibition, error) {
|
func (r *galleryRepository) GetExhibitionByAsset(assetID int64) (*models.Exhibition, error) {
|
||||||
var exhibition models.Exhibition
|
var exhibition models.Exhibition
|
||||||
err := r.db.Where("asset_id = ?", assetID).First(&exhibition).Error
|
err := r.db.Where("asset_id = ? AND deleted_at IS NULL", assetID).First(&exhibition).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, nil // 未找到记录,返回 nil(不是错误)
|
return nil, nil // 未找到记录,返回 nil(不是错误)
|
||||||
@ -149,10 +149,10 @@ func (r *galleryRepository) GetExhibitionByAsset(assetID int64) (*models.Exhibit
|
|||||||
return &exhibition, nil
|
return &exhibition, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExhibitionBySlot 根据展位ID获取展品展示记录
|
// GetExhibitionBySlot 根据展位ID获取展品展示记录(不含已删除)
|
||||||
func (r *galleryRepository) GetExhibitionBySlot(slotID int64) (*models.Exhibition, error) {
|
func (r *galleryRepository) GetExhibitionBySlot(slotID int64) (*models.Exhibition, error) {
|
||||||
var exhibition models.Exhibition
|
var exhibition models.Exhibition
|
||||||
err := r.db.Where("slot_id = ?", slotID).First(&exhibition).Error
|
err := r.db.Where("slot_id = ? AND deleted_at IS NULL", slotID).First(&exhibition).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, nil // 未找到记录,返回 nil(不是错误)
|
return nil, nil // 未找到记录,返回 nil(不是错误)
|
||||||
@ -162,10 +162,10 @@ func (r *galleryRepository) GetExhibitionBySlot(slotID int64) (*models.Exhibitio
|
|||||||
return &exhibition, nil
|
return &exhibition, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExhibitionsByUser 获取用户的所有展品展示记录
|
// GetExhibitionsByUser 获取用户的所有展品展示记录(不含已删除)
|
||||||
func (r *galleryRepository) GetExhibitionsByUser(userID, starID int64) ([]*models.Exhibition, error) {
|
func (r *galleryRepository) GetExhibitionsByUser(userID, starID int64) ([]*models.Exhibition, error) {
|
||||||
var exhibitions []*models.Exhibition
|
var exhibitions []*models.Exhibition
|
||||||
err := r.db.Where("occupier_uid = ? AND occupier_star_id = ?", userID, starID).
|
err := r.db.Where("occupier_uid = ? AND occupier_star_id = ? AND deleted_at IS NULL", userID, starID).
|
||||||
Find(&exhibitions).Error
|
Find(&exhibitions).Error
|
||||||
return exhibitions, err
|
return exhibitions, err
|
||||||
}
|
}
|
||||||
@ -178,20 +178,32 @@ func (r *galleryRepository) CreateExhibition(exhibition *models.Exhibition) erro
|
|||||||
return r.db.Create(exhibition).Error
|
return r.db.Create(exhibition).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteExhibition 删除展品展示记录(根据ID)
|
// DeleteExhibition 软删除展品展示记录(根据ID)
|
||||||
func (r *galleryRepository) DeleteExhibition(exhibitionID int64) error {
|
func (r *galleryRepository) DeleteExhibition(exhibitionID int64) error {
|
||||||
return r.db.Where("id = ?", exhibitionID).Delete(&models.Exhibition{}).Error
|
now := time.Now().UnixMilli()
|
||||||
|
return r.db.Model(&models.Exhibition{}).
|
||||||
|
Where("id = ?", exhibitionID).
|
||||||
|
Updates(map[string]interface{}{
|
||||||
|
"deleted_at": now,
|
||||||
|
"updated_at": now,
|
||||||
|
}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteExhibitionByAsset 删除展品展示记录(根据资产ID)
|
// DeleteExhibitionByAsset 软删除展品展示记录(根据资产ID)
|
||||||
func (r *galleryRepository) DeleteExhibitionByAsset(assetID int64) error {
|
func (r *galleryRepository) DeleteExhibitionByAsset(assetID int64) error {
|
||||||
return r.db.Where("asset_id = ?", assetID).Delete(&models.Exhibition{}).Error
|
now := time.Now().UnixMilli()
|
||||||
|
return r.db.Model(&models.Exhibition{}).
|
||||||
|
Where("asset_id = ?", assetID).
|
||||||
|
Updates(map[string]interface{}{
|
||||||
|
"deleted_at": now,
|
||||||
|
"updated_at": now,
|
||||||
|
}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetExpiredExhibitions 获取过期的展品展示记录
|
// GetExpiredExhibitions 获取过期的展品展示记录(不含已删除)
|
||||||
func (r *galleryRepository) GetExpiredExhibitions(beforeTime int64) ([]*models.Exhibition, error) {
|
func (r *galleryRepository) GetExpiredExhibitions(beforeTime int64) ([]*models.Exhibition, error) {
|
||||||
var exhibitions []*models.Exhibition
|
var exhibitions []*models.Exhibition
|
||||||
err := r.db.Where("expire_at <= ?", beforeTime).Find(&exhibitions).Error
|
err := r.db.Where("expire_at <= ? AND deleted_at IS NULL", beforeTime).Find(&exhibitions).Error
|
||||||
return exhibitions, err
|
return exhibitions, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -196,8 +196,8 @@ const handleAddClick = () => {
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
width: 40%;
|
width: 25%;
|
||||||
height: 40%;
|
height: 25%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@ -182,6 +182,9 @@ const handleCabinClick = (cabin) => {
|
|||||||
const handleTabChange = (newTab) => {
|
const handleTabChange = (newTab) => {
|
||||||
if (newTab === 0) {
|
if (newTab === 0) {
|
||||||
navExpanded.value = false
|
navExpanded.value = false
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/square/square'
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user