This commit is contained in:
2025-08-28 15:19:39 +08:00
parent 035450e762
commit df8a47c947
9 changed files with 293 additions and 1 deletions
@@ -0,0 +1,48 @@
<?php
namespace app\admin\controller;
use app\common\controller\BaseController;
use app\common\traits\crud\CrudControllerTrait;
use app\admin\service\SysAccountService;
class SysAccountController extends BaseController
{
use CrudControllerTrait;
protected $service;
public function __construct()
{
$this->service = new SysAccountService();
}
/**
* 列表页数据格式化
*
* @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']);
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']);
return $data;
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace app\admin\logic;
use app\common\traits\crud\CrudLogicTrait;
use app\common\model\SysAccount;
class SysAccountLogic
{
use CrudLogicTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysAccount::class;
}
+82
View File
@@ -0,0 +1,82 @@
<?php
namespace app\admin\service;
use app\admin\validate\SysAccountValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\SysAccount;
use support\Request;
class SysAccountService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = SysAccount::class;
/**
* 验证器
*/
protected $validator = SysAccountValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 构建查询条件
*/
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
{
$p = $request->all();
$config = [];
$config['model'] = $this->modelClass;
switch ($scene) {
case 'index':
// ====== ====== 排序 ====== ======
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
// ====== ====== 筛选 ====== ======
// 状态
if (isset($p['status']) && in_array($p['status'], [0,1])) {
$config['where']['status'] = $p['status'];
}
// 状态
if (isset($p['type']) && $p['type']) {
$config['where']['type'] = $p['type'];
}
// 关键字
if (isset($p['keyword']) && $p['keyword']) {
$k = '%' . $p['keyword'] . '%';
foreach (['account_name','account_number','bank_name','bank_branch','description'] as $col) {
$config['orWhere'][] = [$col, 'like', $k];
}
}
//$config['where']['status'] = 1;
break;
case 'show':
$config['where']['id'] = $p['id'];
//$config['where']['status'] = 1;
break;
case 'store':
break;
case 'update':
$config['where']['id'] = $p['id'];
break;
case 'destroy':
$config['where']['id'] = $p['id'];
break;
}
return $config;
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace app\admin\validate;
use think\Validate;
class SysAccountValidate extends Validate
{
// 规则
protected $rule = [
];
// 提示
protected $message = [
];
// 场景
protected $scene = [
'store' => [
],
'update' => [
]
];
}