文档移除

dev
truthhun 1 year ago
parent 148aa79bae
commit 9801a930fe

@ -561,7 +561,7 @@ func (m *DBModel) initConfig() (err error) {
// 积分规则配置
{Category: ConfigCategoryScore, Name: ConfigScoreRegister, Label: "注册", Value: "10", Placeholder: "注册时获得的魔豆", InputType: "number", Sort: 10, Options: ""},
{Category: ConfigCategoryScore, Name: ConfigScoreSignIn, Label: "签到", Value: "1", Placeholder: "每日签到获得的魔豆", InputType: "number", Sort: 20, Options: ""},
{Category: ConfigCategoryScore, Name: ConfigScoreDeleteDocument, Label: "删除文档", Value: "-10", Placeholder: "删除上传文档可获得的魔豆,负数表示扣除", InputType: "number", Sort: 25, Options: ""},
{Category: ConfigCategoryScore, Name: ConfigScoreDeleteDocument, Label: "删除文档", Value: "1", Placeholder: "删除上传文档扣除的魔豆0表示不扣除", InputType: "number", Sort: 25, Options: ""},
{Category: ConfigCategoryScore, Name: ConfigScoreUploadDocument, Label: "上传文档", Value: "5", Placeholder: "上传一篇文档可获得的魔豆", InputType: "number", Sort: 30, Options: ""},
{Category: ConfigCategoryScore, Name: ConfigScoreUploadDocumentLimit, Label: "每日上传文档奖励次数", Value: "1", Placeholder: "每天最多可以获得多少次文档上传奖励0表示无奖励。", InputType: "number", Sort: 40, Options: ""},
{Category: ConfigCategoryScore, Name: ConfigScoreDocumentCollected, Label: "文档被收藏", Value: "1", Placeholder: "上传的文档被收藏后获得的魔豆", InputType: "number", Sort: 50, Options: ""},

@ -257,7 +257,7 @@ func (m *DBModel) DeleteDocument(ids []int64, deletedUserId int64, deepDelete ..
var (
docs []Document
docCates []DocumentCategory
docFields = []string{"id", "status", "user_id", "deleted_at", "deleted_user_id"}
docFields = []string{"id", "status", "user_id", "deleted_at", "deleted_user_id", "title"}
docCateFields = []string{"id", "document_id", "category_id"}
modelUser = &User{}
modelDocument = &Document{}
@ -274,6 +274,8 @@ func (m *DBModel) DeleteDocument(ids []int64, deletedUserId int64, deepDelete ..
docCateMap[docCate.DocumentId] = append(docCateMap[docCate.DocumentId], docCate.CategoryId)
}
cfgScore := m.GetConfigOfScore(ConfigScoreDeleteDocument)
sess := m.db.Begin()
defer func() {
if err != nil {
@ -283,6 +285,14 @@ func (m *DBModel) DeleteDocument(ids []int64, deletedUserId int64, deepDelete ..
}
}()
if len(deepDelete) > 0 && deepDelete[0] { // 彻底删除
err = sess.Model(&Attachment{}).Where("type = ? and type_id in (?)", AttachmentTypeDocument, ids).Update("type_id", 0).Error
if err != nil {
m.logger.Error("DeleteDocument", zap.Error(err))
return
}
}
for _, doc := range docs {
// 文档不是禁用状态,且未被逻辑删除,则需要减少用户、分类下的文档统计数量
// if doc.Status != DocumentStatusDisabled && doc.DeletedAt == nil {
@ -315,21 +325,45 @@ func (m *DBModel) DeleteDocument(ids []int64, deletedUserId int64, deepDelete ..
m.logger.Error("DeleteDocument", zap.Error(err))
return
}
} else { // 逻辑删除
err = sess.Model(&doc).Where("id = ?", doc.Id).Updates(map[string]interface{}{
"deleted_at": time.Now(),
"deleted_user_id": deletedUserId,
}).Error
continue
}
// 逻辑删除
err = sess.Model(&doc).Where("id = ?", doc.Id).Updates(map[string]interface{}{
"deleted_at": time.Now(),
"deleted_user_id": deletedUserId,
}).Error
if err != nil {
m.logger.Error("DeleteDocument", zap.Error(err))
return
}
// 扣除积分和添加动态
dynamic := &Dynamic{
UserId: doc.UserId,
Type: DynamicTypeDeleteDocument,
Content: fmt.Sprintf("删除了文档《%s》", doc.Title),
}
if cfgScore.DeleteDocument != 0 { // 小于0表示扣除积分
score := cfgScore.DeleteDocument
if score < 0 {
score = -score
}
dynamic.Content += fmt.Sprintf(",扣除了 %d 魔豆", score)
err = sess.Model(modelUser).Where("id = ?", doc.UserId).Update("credit_count", gorm.Expr("credit_count - ?", score)).Error
if err != nil {
m.logger.Error("DeleteDocument", zap.Error(err))
return
}
}
err = sess.Create(dynamic).Error
if err != nil {
m.logger.Error("DeleteDocument", zap.Error(err))
return
}
}
if len(deepDelete) > 0 && deepDelete[0] { // 彻底删除
err = sess.Model(&Attachment{}).Where("type = ? and type_id in (?)", AttachmentTypeDocument, ids).Update("type_id", 0).Error
if err != nil {
m.logger.Error("DeleteDocument", zap.Error(err))
return

@ -17,19 +17,20 @@ type Dynamic struct {
}
const (
DynamicTypeComment = 1 // 发表评论
DynamicTypeFavorite = 2 // 收藏文档
DynamicTypeUpload = 3 // 上传文档
DynamicTypeDownload = 4 // 下载文档
DynamicTypeLogin = 5 // 登录
DynamicTypeRegister = 6 // 注册
DynamicTypeAvatar = 7 // 更新了头像
DynamicTypePassword = 8 // 修改密码
DynamicTypeInfo = 9 // 修改个人信息
DynamicTypeVerify = 10 // 实名认证
DynamicTypeSign = 11 // 签到
DynamicTypeShare = 12 // 分享文档
DynamicTypeFollow = 13 // 关注用户
DynamicTypeComment = 1 // 发表评论
DynamicTypeFavorite = 2 // 收藏文档
DynamicTypeUpload = 3 // 上传文档
DynamicTypeDownload = 4 // 下载文档
DynamicTypeLogin = 5 // 登录
DynamicTypeRegister = 6 // 注册
DynamicTypeAvatar = 7 // 更新了头像
DynamicTypePassword = 8 // 修改密码
DynamicTypeInfo = 9 // 修改个人信息
DynamicTypeVerify = 10 // 实名认证
DynamicTypeSign = 11 // 签到
DynamicTypeShare = 12 // 分享文档
DynamicTypeFollow = 13 // 关注用户
DynamicTypeDeleteDocument = 14 // 删除文档
)
func (Dynamic) TableName() string {

@ -17,6 +17,7 @@
clearable
:placeholder="item.placeholder"
:step="1"
:min="0"
></el-input-number>
<el-input
v-else-if="item.input_type === 'textarea'"

@ -70,7 +70,11 @@
<el-button type="text" icon="el-icon-edit"></el-button>
</el-tooltip>
<el-tooltip content="删除文档" placement="top">
<el-button type="text" icon="el-icon-delete"></el-button>
<el-button
type="text"
icon="el-icon-delete"
@click="deleteDocument(scope.row)"
></el-button>
</el-tooltip>
</template>
</el-table-column>
@ -90,7 +94,7 @@
<script>
import { mapGetters } from 'vuex'
import { listDocument } from '~/api/document'
import { deleteDocument, listDocument } from '~/api/document'
import { formatBytes, formatDatetime, formatRelativeTime } from '~/utils/utils'
export default {
@ -163,6 +167,22 @@ export default {
query: { page },
})
},
deleteDocument(row) {
this.$confirm(`您确定要删除文档《${row.title}》吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(async () => {
const res = await deleteDocument({ id: row.id })
if (res.status === 200) {
this.$message({
type: 'success',
message: '删除成功!',
})
this.getDocuments()
}
})
},
},
}
</script>
@ -179,6 +199,7 @@ export default {
a {
line-height: 40px;
display: inline-block;
max-width: 100%;
}
}
}

@ -8,7 +8,7 @@
target="_blank"
:to="{
name: 'document-id',
params: { id: scope.row.id },
params: { id: scope.row.document_id },
}"
class="el-link el-link--default doc-title"
>

@ -364,6 +364,7 @@ export default {
} else {
console.log(res)
this.$message.error(res.data.message)
this.$router.replace('/404')
}
},
handleScroll() {

Loading…
Cancel
Save