MCPcopy Index your code
hub / github.com/TruthHun/DocHub / RemoveToRecycle

Method RemoveToRecycle

models/RecycleModel.go:134–234  ·  view source on GitHub ↗

将文档移入回收站(软删除) @param uid 操作人,即将文档移入回收站的人 @param self 是否是用户自己操作 @param ids 文档id,即需要删除的文档id @return errs 错误

(uid interface{}, self bool, ids ...interface{})

Source from the content-addressed store, hash-verified

132//@param ids 文档id,即需要删除的文档id
133//@return errs 错误
134func (this *DocumentRecycle) RemoveToRecycle(uid interface{}, self bool, ids ...interface{}) (err error) {
135 //软删除
136 //1、将文档状态标记为-1
137 //2、将文档id录入到回收站
138 //3、用户文档数量减少
139 //4、整站文档数量减少
140 //5、分类下的文档减少
141 //不需要删除用户的收藏记录
142 //不需要删除文档的评分记录
143
144 var docInfo []DocumentInfo
145 sys, _ := NewSys().Get()
146
147 if len(ids) == 0 {
148 return
149 }
150
151 o := orm.NewOrm()
152
153 o.QueryTable(GetTableDocumentInfo()).Filter("Id__in", ids...).Filter("Status__in", DocStatusNormal, DocStatusConverting).All(&docInfo)
154
155 if len(docInfo) == 0 {
156 return
157 }
158
159 o.Begin()
160 defer func() {
161 if err == nil {
162 o.Commit()
163 } else {
164 o.Rollback()
165 }
166 }()
167
168 sqlSys := fmt.Sprintf("update %v set `CntDoc`=`CntDoc`-? where Id=1", GetTableSys())
169 _, err = o.Raw(sqlSys, len(docInfo)).Exec()
170 if err != nil {
171 return
172 }
173
174 sqlUser := fmt.Sprintf("update %v set `Document`=`Document`-? ,`Coin`=`Coin`-? where Id=?", GetTableUserInfo())
175 sqlCate := fmt.Sprintf("update %v set `Cnt`=`Cnt`-? where `Id` in(?,?,?)", GetTableCategory())
176 doc := NewDocument()
177 now := int(time.Now().Unix())
178 for _, info := range docInfo {
179 _, err = o.Raw(sqlCate, 1, info.ChanelId, info.Pid, info.Cid).Exec()
180 if err != nil {
181 return
182 }
183
184 _, err = o.Raw(sqlUser, 1, sys.Reward, info.Uid).Exec() //用户个人的文档数量和金币减少
185 if err != nil {
186 return
187 }
188
189 log := CoinLog{
190 Uid: info.Uid,
191 Coin: -sys.Reward,

Callers 4

ActionMethod · 0.95
DeepDelMethod · 0.95
DocDelMethod · 0.80
SetIllegalMethod · 0.80

Calls 13

GetDocumentMethod · 0.95
DeleteIndexMethod · 0.95
NewSysFunction · 0.85
GetTableDocumentInfoFunction · 0.85
GetTableSysFunction · 0.85
GetTableUserInfoFunction · 0.85
GetTableCategoryFunction · 0.85
NewDocumentFunction · 0.85
UpdateByIdsFunction · 0.85
NewElasticSearchClientFunction · 0.85
AllMethod · 0.80
InsertMethod · 0.80

Tested by

no test coverage detected