90 lines
2.5 KiB
PHP
90 lines
2.5 KiB
PHP
<?php
|
|
namespace app\common\controller;
|
|
|
|
use app\common\controller\BaseController;
|
|
use app\common\service\OssService;
|
|
use app\common\traits\crud\CrudControllerTrait;
|
|
use app\common\service\ConfigService;
|
|
use support\Request;
|
|
|
|
class ConfigController extends BaseController
|
|
{
|
|
use CrudControllerTrait;
|
|
|
|
protected $service;
|
|
|
|
protected $noNeedLogin = ['find'];
|
|
|
|
protected $noNeedHeaderData = ['find'];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->service = new ConfigService();
|
|
}
|
|
|
|
/**
|
|
* 获取详情
|
|
*
|
|
* @param Request $request 请求对象
|
|
* @param int|string $id 资源 ID
|
|
* @return mixed 返回资源详情数据
|
|
*/
|
|
public function find(Request $request)
|
|
{
|
|
try {
|
|
$raw = $this->service->serviceFind($request);
|
|
$data = $this->transformData($raw, method_exists($this, 'showFormat')
|
|
? [$this, 'showFormat']
|
|
: null);
|
|
return $this->success($data);
|
|
} catch (\Throwable $e) {
|
|
return $this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function indexFormat($data)
|
|
{
|
|
if (!empty($data['value'])){
|
|
$value = explode(',', $data['value']);
|
|
$ossservice = new OssService();
|
|
foreach ($value as $k => $v){
|
|
$value[$k] = $ossservice->generatePrivateUrl($v);
|
|
}
|
|
$data['value_pull'] = implode(',', $value);
|
|
}
|
|
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']);
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 列表页数据格式化
|
|
*
|
|
* @param array $data
|
|
* @return array
|
|
*/
|
|
protected function showFormat($data)
|
|
{
|
|
if (!empty($data['value'])){
|
|
$value = explode(',', $data['value']);
|
|
$ossservice = new OssService();
|
|
foreach ($value as $k => $v){
|
|
$value[$k] = $ossservice->generatePrivateUrl($v);
|
|
}
|
|
$data['value_pull'] = implode(',', $value);
|
|
}
|
|
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']);
|
|
return $data;
|
|
}
|
|
} |