コード例 #1
0
 public function newFavorite($document_id)
 {
     $this->requireLogin();
     //将文章添加到收藏夹
     $addon = new FavoriteAddon();
     $model = $addon->getFavoriteModel();
     $result = $model->addFavorite($this->getUid(), $document_id);
     if (!$result) {
         $this->errorCode = 2201;
         $this->error = "收藏失败:" . $model->getError();
         return false;
     }
     //增加文章收藏数
     $document = D('Home/Document')->detail($document_id);
     $model_name = D('Admin/Model')->getNameById($document['model_id']);
     if ($model_name == 'weibo') {
         D('Home/Weibo', 'Logic')->where(array('id' => $document['id']))->save(array('bookmark' => $document['bookmark'] + 1));
     }
     //返回收藏编号
     $this->apiSuccess("收藏成功", null, array('favorite_id' => $result));
 }
コード例 #2
0
ファイル: UserController.class.php プロジェクト: yaomoo/bbs
 public function deleteFavorite($favorite_id)
 {
     $this->requireLogin();
     //确认指定的收藏是自己的
     $addon = new FavoriteAddon();
     $model = $addon->getFavoriteModel();
     $favorite = $model->getFavoriteById($favorite_id);
     if (!$favorite) {
         $this->apiError(1702, "该编号的收藏不存在,无法删除");
     }
     if ($favorite['uid'] != $this->getUid()) {
         $this->apiError(1701, '权限不足');
     }
     //删除数据库中的数据库
     $model->deleteFavoriteById($favorite_id);
     //减小收藏数
     $document = D('Home/Document')->detail($favorite['document_id']);
     $model_name = D('Admin/Model')->getNameById($document['model_id']);
     if ($model_name == 'weibo') {
         D('Home/Weibo', 'Logic')->where(array('id' => $document['id']))->save(array('bookmark' => $document['bookmark'] - 1));
     }
     // 返回成功结果
     $this->apiSuccess("删除成功");
 }