示例#1
0
 public function deleteOne(Request $request)
 {
     $result = CollectArticle::where(['collect_id' => $request->get('collect_id'), 'article_id' => $request->get('article_id')])->delete();
     if ($result) {
         $this->succeed(true);
     } else {
         $this->setResult('collect_articles表删除记录失败!');
         $this->fail(true);
     }
 }
示例#2
0
文件: Collect.php 项目: Panfen/mango
 public function getcollectedArts($collectId)
 {
     $articles = array();
     $cas = CollectArticle::where('collect_id', $collectId)->get();
     foreach ($cas as $ca) {
         $article = Article::where('id', $ca->article_id)->first();
         array_push($articles, $article);
     }
     return $articles;
 }
示例#3
0
 public function collectArticle(Request $request)
 {
     $article_id = $request->get('article_id');
     $article = Article::findOrFail($article_id);
     $flag = true;
     //1.如果oldIds为空,表示之前没有收藏过该文章,直接添加
     //2.如果oldIds不为空,表示之前收藏过该文章,本次是修改,需要先删除原有记录
     //   2-1  ids 为空,表示不再收藏该文章
     //   2-2  ids 不为空,表示更换收藏夹
     if (empty($request->get('oldIds'))) {
         foreach ($request->get('ids') as $id) {
             $result = CollectArticle::create(array('collect_id' => $id, 'article_id' => $article_id, 'user_id' => \Auth::user()->id));
         }
         User::where('id', $article->user_id)->increment('score', 5);
         if (!$result) {
             $this->setResult("1");
             $flag = false;
         }
     } else {
         foreach ($request->get('oldIds') as $id) {
             $result = CollectArticle::where(['collect_id' => $id, 'article_id' => $article_id])->delete();
             if (!$result) {
                 $this->setResult("2");
                 $flag = false;
             }
         }
         if (!empty($request->get('ids'))) {
             foreach ($request->get('ids') as $id) {
                 $result = CollectArticle::create(array('collect_id' => $id, 'article_id' => $article_id));
                 if (!$result) {
                     $this->setResult("3");
                     $flag = false;
                 }
             }
         }
     }
     if ($flag) {
         $this->succeed(true);
     } else {
         $this->fail(true);
     }
 }
示例#4
0
文件: User.php 项目: Panfen/mango
 public function collectedArticle($id)
 {
     $results = array();
     $collects = Collect::where('user_id', \Auth::user()->id)->get();
     foreach ($collects as $collect) {
         $result = CollectArticle::where(['collect_id' => $collect->id, 'article_id' => $id])->first();
         if ($result) {
             array_push($results, $result);
         }
     }
     return $results;
 }
示例#5
0
文件: Article.php 项目: Panfen/mango
 public function countCollect($id)
 {
     return CollectArticle::where('article_id', $id)->count();
 }