Files
fdesk/app/admin/controller/SysDictController.php
T

95 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\model\SysDictItem;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysDictService;
use support\Request;
class SysDictController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysDictService();
}
/**
* 列表页数据格式化
*
* @param array $data
* @return array
*/
protected function indexFormat($data)
{
if (isset($data['sysDictItem']))
$data['sysDictItem'] = SysDictItem::where('dict_id',$data['id'])->get();
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']);
2025-09-02 15:42:30 +08:00
if (isset($data['category_id'])){
$data['category'] = SysDictItem::where('id',$data['category_id'])->value('item_label');
} else {
$data['category'] = '';
}
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']);
$data['sysDictItem'] = SysDictItem::where('dict_id',$data['id'])->get();
return $data;
}
2025-09-01 17:08:02 +08:00
public function listScopeFormat($data)
{
$rdata = [];
foreach ($data as $item) {
$rdata[$item['dict_code']] = $item['sysDictItem'];
}
return $rdata;
}
public function listScope(Request $request)
{
try {
$raw = $this->service->serviceListAllScope($request);
$data = $this->transformData($raw, method_exists($this, 'listScopeFormat')
? [$this, 'listScopeFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
2025-09-02 14:47:21 +08:00
public function group(Request $request)
{
try {
$raw = $this->service->group($request);
$data = $this->transformData($raw, method_exists($this, 'groupFormat')
? [$this, 'groupFormat']
: null);
return $this->success($data);
} catch (\Throwable $e) {
return $this->error($e->getMessage());
}
}
}