示例#1
0
 public function show($id)
 {
     $userId = \Auth::user()->id;
     $article = Article::findOrFail($id);
     if ($userId != $article->user_id) {
         //作者本人访问不增加文章浏览量
         Article::where('id', $id)->increment('view');
         //博主访客+1
         $r = FlowTrace::where(['user_id' => $article->user_id, 'time' => substr(Carbon::now(), 0, 10)])->first();
         if ($r) {
             $r->increment('daycount');
         } else {
             FlowTrace::create(array('user_id' => $article->user_id, 'time' => substr(Carbon::now(), 0, 10), 'daycount' => 1));
         }
         //博主积分+1
         User::where('id', $article->user_id)->increment('score');
     }
     $tags = Tag::where(['user_id' => \Auth::user()->id, 'article_id' => $id])->get();
     $followAuthor = FollowAuthor::where(['my_id' => \Auth::user()->id, 'user_id' => $article->user_id])->first();
     $recommend = false;
     $record = RecommendArticle::where(['user_id' => \Auth::user()->id, 'article_id' => $id])->first();
     if ($record) {
         $recommend = true;
     }
     $collects = Collect::where('user_id', $userId)->get();
     $collected = \Auth::user()->collectedArticle($article->id);
     // if(is_null($article)){
     // 	abort(404);
     // }
     return view('member.articles.show', compact('userId', 'article', 'tags', 'followAuthor', 'recommend', 'collects', 'collected'));
 }
示例#2
0
 public function getActiveStat(Request $request)
 {
     $data = array();
     for ($i = 6; $i >= 0; $i--) {
         $date = substr(Carbon::now()->subDay($i), 0, 10);
         $flowTrace = FlowTrace::where(['user_id' => $request->get('id'), 'time' => $date])->pluck('daycount') ?: 0;
         array_push($data, $flowTrace);
     }
     if (count($data) > 0) {
         $this->setResult($data);
         $this->succeed(true);
     } else {
         $this->setResult('获取数据失败');
         $this->fail(true);
     }
 }
示例#3
0
文件: User.php 项目: Panfen/mango
 public function AllVisitors($userId)
 {
     return FlowTrace::where('user_id', $userId)->sum('daycount') ?: 0;
 }