77 lines
2.2 KiB
PHP
77 lines
2.2 KiB
PHP
<?php
|
|
namespace app\admin\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\service\OssService;
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
use app\common\service\PostCategoryService;
|
|
use support\Request;
|
|
|
|
class PostCategoryController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new PostCategoryService();
|
|
}
|
|
|
|
public function preset(Request $request)
|
|
{
|
|
try {
|
|
$raw = $this->service->serviceListAll($request);
|
|
$data = [];
|
|
foreach ($raw as $item) {
|
|
unset($item['created_at']);
|
|
unset($item['updated_at']);
|
|
$data[] = $this->indexFormat($item);
|
|
}
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 分类树
|
|
* @param Request $request
|
|
* @return \support\Response
|
|
*/
|
|
public function tree(Request $request)
|
|
{
|
|
try {
|
|
$params = $request->all();
|
|
$result = $this->service->getList($params);
|
|
return $this->success($result, '获取分类列表');
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @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']);
|
|
$ossservice = new OssService();
|
|
if (!empty($data['icon_active'])){
|
|
$data['icon_active_pull'] = $ossservice->generatePrivateUrl($data['icon_active']);
|
|
}
|
|
if (!empty($data['icon_inactive'])){
|
|
$data['icon_inactive_pull'] = $ossservice->generatePrivateUrl($data['icon_inactive']);
|
|
}
|
|
if (!empty($data['icon_preset'])){
|
|
$data['icon_preset_pull'] = $ossservice->generatePrivateUrl($data['icon_preset']);
|
|
}
|
|
return $data;
|
|
}
|
|
} |