Merge branch 'develop'
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?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']);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user