修正评论,评论增加验证码验证判断

修正文章获取评论数问题
修正标签获取文章列表偶发的报错问题
文章详情增加评论数
文章列表页数据获取和详情页数据获取问题修正
This commit is contained in:
yumo 2024-02-19 00:20:38 +08:00
parent b02b2f39a8
commit b2cfc6d619
5 changed files with 25 additions and 14 deletions

View File

@ -2,4 +2,5 @@
- 完善euapi主题
- 完善获取分类,分类下的数量列表,现在只实现当前分类,没有包含下钻分类
- 完善用户发帖数量等字段
- doc文档上输出
- doc文档上输出
- 文章分类id和别名拆分,直接使用别名

View File

@ -85,6 +85,7 @@ class Document extends BaseModel
if (!$info) {
return [];
}
$info->comment = (new Comment())->where('document_id', $id)->count();
return $info->toArray();
}

View File

@ -142,7 +142,7 @@ class Ape extends TagLib
$display = $tag['display'] ?? 1;
$display = $display == 1 ? 1 : 0;
$parse = '<?php ';
$parse .= '$__FUN__ =' . "tpl_get_list(\"$orderBy\",$pageSize,\"$typeId\",\"$type\",\"$model\",\"$where\",$display);";
$parse .= '$__FUN__ =' . "tpl_get_list(\"$type\",\"$typeId\",\"$where\",\"$model\",\"$orderBy\",$pageSize,$display);";
$parse .= '$__LIST__ = $__FUN__["lists"];$pager = $__FUN__["model"]->render();';
$parse .= ' ?>';
$parse .= '{volist name="__LIST__" id="' . $void . '" key="i"}';

View File

@ -44,9 +44,7 @@ function get_document_category_list()
{
//缓存文章菜单
$documentCategory = cache(Data::DATA_DOCUMENT_CATEGORY_LIST);
$documentCategory = null;
if ($documentCategory === null) {
if (is_null($documentCategory)) {
$documentCategory = DocumentCategory::where('status', 1)->order('sort asc')->select()->toArray();
$documentList = Document::where('display', 1)
->where('status', 1)
@ -55,14 +53,17 @@ function get_document_category_list()
->column('count(*) as count', 'category_id');
//TODO 需要实现包含下级分类所有数据的逻辑 使用下面两个函数实现,暂未完成
///转换让id作为数组的键
foreach ($documentCategory as &$item) {
$tempList = [];
foreach ($documentCategory as $item) {
//根据栏目类型生成栏目url
$item['url'] = make_category_url($item);
$item['dc_count'] = $documentList[$item['id']] ?? 0;
$tempList[$item['id']] = $item;
}
$documentCategory = $tempList;
unset($item,$tempList,$documentList);
cache(Data::DATA_DOCUMENT_CATEGORY_LIST, $documentCategory);
}
return $documentCategory;
}
@ -390,7 +391,7 @@ function tpl_get_prenext($get, $cid = "",$type ="article")
* @throws DbException
* @throws ModelNotFoundException
*/
function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article', $where, int $display = 1)
function tpl_get_list($type, $cid, $where, string $table = 'article', string $orderBy = '', int $pageSize = 10, int $display = 1)
{
$documentListModel = (new Document())
->alias('a')
@ -460,7 +461,7 @@ function tpl_get_list($orderBy, int $pageSize, $cid, $type, $table = 'article',
//获取评论数 跟在文章后面
if (!empty($item)){
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
->where("id","in" ,array_column($documentListModel->toArray(),'id'))
->where("document_id","in" ,array_column($documentListModel->toArray(),'id'))
->group('id')
->select();
}
@ -497,7 +498,8 @@ function get_route_query()
*/
function make_category_url($item)
{
return url('/article/detail', ['id' => $item['alias'] ?: $item['id']])->build();
// return url('/article/lists', ['id' => $item['alias'] ?: $item['id']])->build();
return url('/article/lists', ['id' => $item['id']])->build();
}
/**
@ -595,7 +597,7 @@ function tpl_get_article_list($cid, $row, $orderby, $table = 'article', $type =
//获取评论数 跟在文章后面
if (!empty($item)){
$commentModel = (new Comment())->field('document_id as id,count(*) as comment')
->where("id","in" ,array_column($documentListModel->toArray(),'id'))
->where("document_id","in" ,array_column($documentListModel->toArray(),'id'))
->group('id')
->select();
}
@ -775,7 +777,7 @@ if (!function_exists('tpl_get_tags_list')) {
*/
function tpl_get_position($dc, $positionList = array())
{
array_push($positionList, $dc);
$positionList[] = $dc;
if ($dc['pid'] == 0) {
$htmlStr = '<a href="/">首页</a>';
$positionListCount = count($positionList);

View File

@ -77,8 +77,8 @@ class Article extends Base
//判断seo标题是否存在
$dc['meta_title'] = $dc['meta_title'] ?: $dc['title'];
//判断SEO 为空则取系统
$article['keywords'] = $dc['keywords'] ?: web_config('keywords');
$article['description'] = $dc['description'] ?: web_config('description');
$dc['keywords'] = $dc['keywords'] ?: web_config('keywords');
$dc['description'] = $dc['description'] ?: web_config('description');
//添加当前页面的位置信息
$dc['position'] = tpl_get_position($dc);
//输出文章分类
@ -138,6 +138,7 @@ class Article extends Base
}
$article['category_title'] = $dc['title'];
//判断SEO 为空则取系统
$article['meta_title'] = $article['title'];
$article['keywords'] = $article['keywords'] ?: web_config('keywords');
$article['description'] = $article['description'] ?: web_config('description');
//输出文章内容
@ -170,6 +171,7 @@ class Article extends Base
public function create_comment(Request $request)
{
$data = Util::postMore([
['captcha',''],
['document_id', ''],
['pid', ''],
['author', ''],
@ -192,6 +194,11 @@ class Article extends Base
$data['email'] = $this->userInfo['email']?:'';
$data['url'] = '';
}
//开始判断留言是否显示验证码,显示则需要判断验证码
if ($data['captcha'] != "" && !captcha_check($data['captcha'])){
// 验证码验证
$this->error('验证码不正确', null);
}
if ($data['document_id'] == "") $this->error("文章id不能为空");
if ($data['content'] == "") $this->error("内容能为空");
$data['status'] = web_config('comment_review') ? 0 : 1;