2025-11-24 16:34:56 +08:00
|
|
|
<?php
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
|
|
|
|
|
use app\common\controller\BaseController;
|
|
|
|
|
use app\common\model\PostCategory;
|
|
|
|
|
use app\common\model\PostMedia;
|
|
|
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
|
|
|
use app\common\service\PostService;
|
|
|
|
|
|
|
|
|
|
class PostController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
use CrudControllerTrait;
|
|
|
|
|
|
|
|
|
|
protected $service;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->service = new PostService();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表页数据格式化
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function indexFormat($data)
|
|
|
|
|
{
|
|
|
|
|
if (isset($data['created_at']))
|
|
|
|
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
|
|
|
|
if (isset($data['updated_at']))
|
|
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
|
|
|
|
if (isset($data['id']))
|
|
|
|
|
$data['media'] = PostMedia::where('post_id', $data['id'])->get();
|
|
|
|
|
if (isset($data['category_id']))
|
|
|
|
|
$data['category_name'] = PostCategory::where('id', $data['category_id'])->value('name')??'';
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 列表页数据格式化
|
|
|
|
|
*
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function showFormat($data)
|
|
|
|
|
{
|
|
|
|
|
if (isset($data['created_at']))
|
|
|
|
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
|
|
|
|
if (isset($data['updated_at']))
|
|
|
|
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
|
|
|
|
if (isset($data['id']))
|
|
|
|
|
$data['media'] = PostMedia::where('post_id', $data['id'])->get();
|
2025-12-02 10:46:57 +08:00
|
|
|
if (isset($data['category_id']))
|
|
|
|
|
$data['category_name'] = PostCategory::where('id', $data['category_id'])->value('name')??'';
|
2025-11-24 16:34:56 +08:00
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
}
|