1
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\apis\controller;
|
||||
|
||||
use app\apis\model\CommentModel;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use app\apis\model\ArticleModel;
|
||||
@@ -47,11 +48,12 @@ class ArticleController extends BaseController
|
||||
if ($item['cover']) {
|
||||
$item['cover_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($item['cover']);
|
||||
}
|
||||
$item['comment'] = CommentModel::where(['article_id' => $item['id'], ['created_at', '<=', time()]])->get();
|
||||
foreach ($item['comment'] as &$comment) {
|
||||
|
||||
if ($comment['avatar']) {
|
||||
$comment['avatar_full'] = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($comment['avatar']);
|
||||
}
|
||||
$comment['created_at'] = date('Y-m-d H:i:s', $comment['created_at']);
|
||||
}
|
||||
unset($comment);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace app\apis\model;
|
||||
|
||||
use app\console\model\AdminsModel;
|
||||
use app\console\model\CommentModel;
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
@@ -53,4 +55,14 @@ class ArticleModel extends Model
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
|
||||
public function comment()
|
||||
{
|
||||
return $this->hasMany(CommentModel::class, 'article_id', 'id');
|
||||
}
|
||||
|
||||
public function creater()
|
||||
{
|
||||
return $this->belongsTo(AdminsModel::class, 'user_id','id');
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,7 @@ class ArticleService extends BaseService
|
||||
'fields' => ['id', 'locale', 'title', 'subtitle', 'cover', 'content', 'user_id', 'is_top', 'sort', 'status', 'publish_time', 'created_at', 'updated_at'],
|
||||
'relations' => [
|
||||
'creater' => ['id', 'nickname',],
|
||||
'comment' => ['id', 'article_id', 'content', 'avatar', 'name',],
|
||||
// 'translation' => ['model_id', 'name'],
|
||||
// 'brand.translation' => ['brand_id', 'name']
|
||||
// 'comment' => ['id', 'article_id', 'content', 'avatar', 'name',],
|
||||
],
|
||||
'sorts' => [
|
||||
['field' => 'is_top', 'direction' => 'desc'],
|
||||
@@ -54,6 +52,7 @@ class ArticleService extends BaseService
|
||||
],
|
||||
'fields' => ['id', 'locale', 'title', 'subtitle', 'cover', 'content', 'user_id', 'is_top', 'sort', 'status', 'publish_time', 'created_at', 'updated_at'],
|
||||
'relations' => [
|
||||
'creater' => ['id', 'nickname',],
|
||||
'comment' => ['id', 'article_id', 'content', 'avatar', 'name',],
|
||||
// 'translation' => ['model_id', 'name']
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user