token['root_org']]; $condition[] = ['publish', '=', 1]; $condition[] = ['delete_time', '=', 0]; empty($label) ?: $condition[] = ['label', '=', $label]; empty($type) ?: $condition[] = ['type', '=', $type]; empty($keyword) ?: $condition[] = ['title', 'like', '%' . $keyword . '%']; // 获取数据 $data = ArticleModel::where($condition)->withAttr('content', function ($value, $data) { $value = htmlspecialchars_decode($value); $value = preg_replace('/\s/', '', $value); $value = str_replace(" ", "", $value); $value = strip_tags($value); $text = mb_substr($value, 0, 40, "utf-8"); return $text; })->field('id,title,content,cover_img,cover_share_img')->page($page, $limit)->order('uploadtime desc')->select()->toArray(); $count = ArticleModel::where($condition)->count(); return json(['code' => 0, 'data' => $data, 'count' => $count, 'msg' => '获取成功']); } /** * 类型获取 */ public function type() { $type = VideoType::field('id,name')->where(['pid' => 0, 'type' => 'article', 'root_id' => request()->token['root_org']])->select()->toArray(); $label = VideoType::field('id,pid,name')->where([['pid', '>', 0], ['type', '=', 'article'], ['root_id', '=', request()->token['root_org']]])->select()->toArray(); foreach ($type as &$val) { $val['sonLabel'] = []; foreach ($label as $typeVal) { if ($val['id'] == $typeVal['pid']) { $val['sonLabel'][] = $typeVal; } } } return json(['code' => 0, 'data' => $type, 'msg' => '获取成功']); } /** * 获取视频详情 */ public function info($article_id) { $article = ArticleModel::field('id,title,content,cover_img,hot,cover_share_img')->where(['id' => $article_id, 'publish' => 1, 'delete_time' => 0])->find(); if (empty($article)) { $article = [ 'title' => '该文章不存在', 'content' => '您访问的内容不存在', 'cover_img' => '', 'hot' => 0 ]; return json(['code' => 0, 'msg' => '获取成功', 'data' => $article]); } $token = request()->token; if (!$token['isEmployee']) { ArticleModel::where('id', '=', $article_id)->inc('hot')->update(); ArticleModel::where('id', $article_id)->inc('view_times')->update(); } // 添加足迹 if (!empty($token['uid']) && !$token['isEmployee']) { event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $article)); } return json(['code' => 0, 'msg' => '获取成功', 'data' => $article]); } }