crud调整

This commit is contained in:
2025-07-21 15:09:06 +08:00
parent 228408149b
commit 45679bc5e4
15 changed files with 318 additions and 278 deletions
+14 -47
View File
@@ -2,9 +2,9 @@
namespace app\admin\service;
use app\common\validate\CorpValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\Corp;
use support\Request;
class CorpService
{
@@ -15,6 +15,19 @@ class CorpService
*/
protected string $modelClass = Corp::class;
/**
* 验证器
*/
protected $validator = CorpValidate::class;
/**
* 获取验证器
*/
public function getValidator()
{
return new $this->validator;
}
/**
* 如果需要自定义,比如强制加一个 where['status']=1,
@@ -27,33 +40,6 @@ class CorpService
// return $config;
// }
/**
* 如果需要自定义“哪些字段可筛选”或额外联表,
* 只需重写 buildQueryConfig:
*/
// protected function buildQueryConfig(Request $request): array
// {
// $config = parent::buildQueryConfig($request);
// // 强制只看 status=1 的记录
// $config['where']['status'] = 1;
// // 自动 eager load company relation
// $config['with'][] = 'company';
// return $config;
// }
/**
* 复杂查询,覆盖 complexQuery 方法
*/
// protected function complexQuery(array $params): array
// {
// return $this->logicComplex(function($q) use ($params) {
// // 自定义 join、where、select
// return $q->where('status', 1)
// ->orderBy('created_at','desc')
// ->paginate($params['limit'] ?? 15);
// })->toArray();
// }
// /**
// * 复杂查询示例:
// * 只要在 URL 里添加 ?complex_query=1,
@@ -100,23 +86,4 @@ class CorpService
// $res['data'] = array_map(fn($i)=>[...], $res['data']);
// return $res;
// }
// protected function afterServiceShow($item)
// {
// // 对详情对象处理
// $item['extra']=123;
// return $item;
// }
// afterServiceStore/Update/Destroy 同理
// protected function afterServiceList(mixed $result): array
// {
// if ($result['records']) {
// $result['records'] = array_map(fn($i) => [...$i], $result['records']);
// }
// return $result;
// }
}