代码拉取完成,页面将自动刷新
同步操作将从 进击的皇虫/DocHub 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package HomeControllers
import (
"fmt"
"github.com/TruthHun/DocHub/helper"
"github.com/TruthHun/DocHub/models"
"github.com/astaxie/beego/orm"
)
type CollectController struct {
BaseController
}
//收藏文档
func (this *CollectController) Get() {
if this.IsLogin == 0 {
this.ResponseJson(false, "您当前未登录,请先登录")
}
cid, _ := this.GetInt("Cid")
did, _ := this.GetInt("Did")
if cid == 0 || did == 0 {
this.ResponseJson(false, "收藏失败:参数不正确")
}
collect := models.Collect{Did: did, Cid: cid}
rows, err := orm.NewOrm().Insert(&collect)
if err != nil {
helper.Logger.Error("SQL执行失败:%v", err.Error())
}
if err != nil || rows == 0 {
this.ResponseJson(false, "收藏失败:您已收藏过该文档")
}
//文档被收藏的数量+1
models.Regulate(models.GetTableDocumentInfo(), "Ccnt", 1, fmt.Sprintf("`Id`=%v", did))
//收藏夹的文档+1
models.Regulate(models.GetTableCollectFolder(), "Cnt", 1, fmt.Sprintf("`Id`=%v", cid))
this.ResponseJson(true, "恭喜您,文档收藏成功。")
}
//收藏夹列表
func (this *CollectController) FolderList() {
uid, _ := this.GetInt("uid")
if uid < 1 {
uid = this.IsLogin
}
if uid == 0 {
this.ResponseJson(false, "获取收藏夹失败:请先登录")
}
lists, rows, err := models.GetList(models.GetTableCollectFolder(), 1, 100, orm.NewCondition().And("Uid", uid), "-Id")
if err != nil {
helper.Logger.Error(err.Error())
}
if rows > 0 && err == nil {
this.ResponseJson(true, "收藏夹获取获取成功", lists)
}
this.ResponseJson(false, "暂时没有收藏夹,请先在会员中心创建收藏夹")
}
//取消收藏文档
func (this *CollectController) CollectCancel() {
if this.IsLogin == 0 {
this.ResponseJson(false, "您当前未登录,请先登录")
}
cid, _ := this.GetInt("Cid")
did, _ := this.GetInt("Did")
if cid == 0 || did == 0 {
this.ResponseJson(false, "收藏失败:参数不正确")
}
if err := models.NewCollect().Cancel(did, cid, this.IsLogin); err != nil {
helper.Logger.Error(err.Error())
this.ResponseJson(false, "移除收藏文档失败,可能您为收藏该文档")
}
//文档被收藏的数量-1
models.Regulate(models.GetTableDocumentInfo(), "Ccnt", -1, "`Id`=?", did)
//收藏夹的文档-1
models.Regulate(models.GetTableCollectFolder(), "Cnt", -1, "`Id`=?", cid)
this.ResponseJson(true, "恭喜您,删除收藏文档成功")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。