设置
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
<?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\ConfigService;
|
||||||
|
|
||||||
|
class ConfigController extends BaseController
|
||||||
|
{
|
||||||
|
use CrudControllerTrait;
|
||||||
|
|
||||||
|
protected $service;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->service = new ConfigService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表页数据格式化
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\logic;
|
||||||
|
|
||||||
|
use app\common\traits\crud\CrudLogicTrait;
|
||||||
|
use app\common\model\Config;
|
||||||
|
|
||||||
|
class ConfigLogic
|
||||||
|
{
|
||||||
|
use CrudLogicTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定当前要操作的模型
|
||||||
|
*/
|
||||||
|
protected string $modelClass = Config::class;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model;
|
||||||
|
|
||||||
|
use support\Model;
|
||||||
|
|
||||||
|
class Config extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The connection name for the model.
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
protected $connection = 'mysql';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The table associated with the model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $table = 'config';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary key associated with the table.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the model should be timestamped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $timestamps = true;
|
||||||
|
|
||||||
|
|
||||||
|
protected $dateFormat = 'U';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $fillable = ['id', 'code', 'name', 'desc', 'value', 'sort', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不允许自动填充模型字段
|
||||||
|
*/
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\service;
|
||||||
|
|
||||||
|
use app\common\validate\ConfigValidate;
|
||||||
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
|
use app\common\model\Config;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
|
class ConfigService
|
||||||
|
{
|
||||||
|
|
||||||
|
use CrudServiceTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定当前要操作的模型
|
||||||
|
*/
|
||||||
|
protected string $modelClass = Config::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证器
|
||||||
|
*/
|
||||||
|
protected $validator = ConfigValidate::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取验证器
|
||||||
|
*/
|
||||||
|
public function getValidator()
|
||||||
|
{
|
||||||
|
return new $this->validator;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 构造 CrudUtil 查询配置
|
||||||
|
*/
|
||||||
|
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||||
|
{
|
||||||
|
$p = $request->all();
|
||||||
|
|
||||||
|
$config = [];
|
||||||
|
$config['model'] = $this->modelClass;
|
||||||
|
switch ($scene) {
|
||||||
|
case 'default':
|
||||||
|
$config['where']['status'] = 1;
|
||||||
|
$config['order']['sort'] = 'desc';
|
||||||
|
$config['order']['id'] = 'desc';
|
||||||
|
break;
|
||||||
|
case 'index':
|
||||||
|
$config['order']['sort'] = 'desc';
|
||||||
|
$config['order']['id'] = 'desc';
|
||||||
|
break;
|
||||||
|
case 'show':
|
||||||
|
$config['where']['id'] = $p['id'];
|
||||||
|
$config['where']['status'] = 1;
|
||||||
|
break;
|
||||||
|
case 'find':
|
||||||
|
$config['where']['code'] = $p['code'];
|
||||||
|
break;
|
||||||
|
case 'store':
|
||||||
|
break;
|
||||||
|
case 'update':
|
||||||
|
$config['where']['id'] = $p['id'];
|
||||||
|
break;
|
||||||
|
case 'destroy':
|
||||||
|
$config['where']['id'] = $p['id'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 查看单条 */
|
||||||
|
public function serviceFind(Request $request, string $scene = 'find')
|
||||||
|
{
|
||||||
|
$config = $this->buildQueryConfig($request, $scene);
|
||||||
|
$item = $this->logicShow($config);
|
||||||
|
return $this->postProcess(ucfirst($scene), $item);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -112,6 +112,12 @@ Route::group('/common', function () {
|
|||||||
Route::any('/list', [app\common\controller\BarrageController::class, 'index']);
|
Route::any('/list', [app\common\controller\BarrageController::class, 'index']);
|
||||||
Route::any('/store', [app\common\controller\BarrageController::class, 'store']);
|
Route::any('/store', [app\common\controller\BarrageController::class, 'store']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 设置
|
||||||
|
Route::group('/config', function () {
|
||||||
|
Route::any('/show', [app\common\controller\ConfigController::class, 'show']);
|
||||||
|
Route::any('/find', [app\common\controller\ConfigController::class, 'find']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -254,6 +260,15 @@ Route::group('/admin', function () {
|
|||||||
Route::any('/update', [app\admin\controller\BarrageController::class, 'update']);
|
Route::any('/update', [app\admin\controller\BarrageController::class, 'update']);
|
||||||
Route::any('/destroy', [app\admin\controller\BarrageController::class, 'destroy']);
|
Route::any('/destroy', [app\admin\controller\BarrageController::class, 'destroy']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 设置
|
||||||
|
Route::group('/config', function () {
|
||||||
|
Route::any('/list', [app\admin\controller\ConfigController::class, 'index']);
|
||||||
|
Route::any('/show', [app\admin\controller\ConfigController::class, 'show']);
|
||||||
|
Route::any('/store', [app\admin\controller\ConfigController::class, 'store']);
|
||||||
|
Route::any('/update', [app\admin\controller\ConfigController::class, 'update']);
|
||||||
|
Route::any('/destroy', [app\admin\controller\ConfigController::class, 'destroy']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user