|
@@ -11,15 +11,15 @@ namespace app\index\controller;
|
|
|
|
|
|
// 引入框架内置类
|
|
// 引入框架内置类
|
|
use think\facade\View;
|
|
use think\facade\View;
|
|
|
|
+use think\exception\HttpException;
|
|
|
|
|
|
use app\common\model\Category as CategoryModel;
|
|
use app\common\model\Category as CategoryModel;
|
|
use app\common\model\Article as ArticleModel;
|
|
use app\common\model\Article as ArticleModel;
|
|
use app\common\model\ArticleTags as ArticleTagsModel;
|
|
use app\common\model\ArticleTags as ArticleTagsModel;
|
|
-use think\exception\HttpException;
|
|
|
|
|
|
+use app\common\model\ArticleDolikeLog;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 文章管理
|
|
* 文章管理
|
|
-
|
|
|
|
*/
|
|
*/
|
|
class Article extends Base
|
|
class Article extends Base
|
|
{
|
|
{
|
|
@@ -40,7 +40,8 @@ class Article extends Base
|
|
'limit' => $list->listRows(),
|
|
'limit' => $list->listRows(),
|
|
'page' => $list->currentPage(),
|
|
'page' => $list->currentPage(),
|
|
'lastPage' => $list->lastPage(),
|
|
'lastPage' => $list->lastPage(),
|
|
- 'pagelist' => $list->render()
|
|
|
|
|
|
+ 'pagelist' => $list->render(),
|
|
|
|
+ 'cid' => $params['cid']
|
|
]);
|
|
]);
|
|
|
|
|
|
return View::fetch();
|
|
return View::fetch();
|
|
@@ -63,10 +64,6 @@ class Article extends Base
|
|
|
|
|
|
$prev_next = ArticleModel::getNextPrev($id, $data->cid);
|
|
$prev_next = ArticleModel::getNextPrev($id, $data->cid);
|
|
|
|
|
|
- View::assign('cid', $data->cid);
|
|
|
|
- View::assign('data', $data);
|
|
|
|
- View::assign('prev_next', $prev_next);
|
|
|
|
-
|
|
|
|
if ($data->content_type==1) {
|
|
if ($data->content_type==1) {
|
|
$parsedownExtension = new \ParsedownExtension();
|
|
$parsedownExtension = new \ParsedownExtension();
|
|
// $parsedownExtension->setTocEnabled(true);
|
|
// $parsedownExtension->setTocEnabled(true);
|
|
@@ -75,6 +72,10 @@ class Article extends Base
|
|
$data->content = $res['content'];
|
|
$data->content = $res['content'];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ View::assign('cid', $data->cid);
|
|
|
|
+ View::assign('data', $data);
|
|
|
|
+ View::assign('prev_next', $prev_next);
|
|
|
|
+
|
|
return View::fetch();
|
|
return View::fetch();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -83,14 +84,28 @@ class Article extends Base
|
|
*/
|
|
*/
|
|
public function dolike()
|
|
public function dolike()
|
|
{
|
|
{
|
|
- $id = input('post.id');
|
|
|
|
|
|
+ $id = $this->request->post('id');
|
|
|
|
+
|
|
|
|
+ $ip = $this->request->ip();
|
|
|
|
+
|
|
|
|
+ $log = ArticleDolikeLog::where('aid', $id)->where('ip', $ip)->find();
|
|
|
|
+
|
|
|
|
+ if ($log) {
|
|
|
|
+ return ['code' => 1, 'msg'=>'多谢喜欢, 已经点过赞了'];
|
|
|
|
+ }
|
|
|
|
|
|
$res = ArticleModel::where('id', $id)->inc('likes')->update();
|
|
$res = ArticleModel::where('id', $id)->inc('likes')->update();
|
|
|
|
|
|
|
|
+ // 记录 dolike 日志
|
|
|
|
+ @ArticleDolikeLog::create([
|
|
|
|
+ 'aid' => $id,
|
|
|
|
+ 'ip' => $this->request->ip()
|
|
|
|
+ ]);
|
|
|
|
+
|
|
if ($res===false) {
|
|
if ($res===false) {
|
|
- return ['code' => 2];
|
|
|
|
|
|
+ return ['code' => 2, 'msg'=>'未知错误'];
|
|
} else {
|
|
} else {
|
|
- return ['code' => 0, 'msg'=>'未知错误'];
|
|
|
|
|
|
+ return ['code' => 0];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -139,7 +154,7 @@ class Article extends Base
|
|
*/
|
|
*/
|
|
public function time()
|
|
public function time()
|
|
{
|
|
{
|
|
- $list =ArticleModel::field('id,cid,title,titlepic,username,summary,hits,sorts,status,create_time')->with(['category'])->order('update_time desc')->paginate();
|
|
|
|
|
|
+ $list =ArticleModel::field('id,cid,title,titlepic,username,summary,hits,sort,status,create_time')->with(['category'])->order('update_time desc')->paginate();
|
|
|
|
|
|
View::assign('list', $list);
|
|
View::assign('list', $list);
|
|
|
|
|