89 lines
2.2 KiB
PHP
89 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace app\admin\service;
|
||
|
||
use app\common\validate\CorpValidate;
|
||
use app\common\traits\crud\CrudServiceTrait;
|
||
use app\common\model\Corp;
|
||
|
||
class CorpService
|
||
{
|
||
use CrudServiceTrait;
|
||
|
||
/**
|
||
* 指定当前要操作的模型
|
||
*/
|
||
protected string $modelClass = Corp::class;
|
||
|
||
/**
|
||
* 验证器
|
||
*/
|
||
protected $validator = CorpValidate::class;
|
||
|
||
/**
|
||
* 获取验证器
|
||
*/
|
||
public function getValidator()
|
||
{
|
||
return new $this->validator;
|
||
}
|
||
|
||
|
||
/**
|
||
* 如果需要自定义,比如强制加一个 where['status']=1,
|
||
* 只要在这里重写:
|
||
*/
|
||
// protected function buildQueryConfig(Request $request): array
|
||
// {
|
||
// $config = [];
|
||
// $config['where']['id'] = 2;
|
||
// return $config;
|
||
// }
|
||
|
||
// /**
|
||
// * 复杂查询示例:
|
||
// * 只要在 URL 里添加 ?complex_query=1,
|
||
// * 并传入你需要的任何参数,
|
||
// * `serviceList()` 就会走到这里来:
|
||
// */
|
||
// protected function complexQuery(Request $request): array
|
||
// {
|
||
// // 假设前端传了 date_from、date_to
|
||
// $from = $request->get('date_from');
|
||
// $to = $request->get('date_to');
|
||
|
||
// // 交给 CrudUtil 执行一个自定义 query
|
||
// $pager = $this->logicComplex(function($q) use ($from, $to) {
|
||
// $q->where('status', 1);
|
||
|
||
// if ($from && $to) {
|
||
// $q->whereBetween('created_at', [$from, $to]);
|
||
// }
|
||
|
||
// // 再加个排序
|
||
// $q->orderBy('created_at','desc');
|
||
|
||
// // 用 paginate 而不是 listAll
|
||
// return $q->paginate(
|
||
// /* perPage */ (int)request()->get('limit',15),
|
||
// ['*'],
|
||
// 'page',
|
||
// (int)request()->get('page',1)
|
||
// );
|
||
// });
|
||
|
||
// // 把 Paginator 转成数组格式
|
||
// return [
|
||
// 'total' => $pager->total(),
|
||
// 'data' => $pager->items(),
|
||
// ];
|
||
// }
|
||
|
||
|
||
// protected function afterServiceList(array $res): array
|
||
// {
|
||
// // 对列表的 data 做处理
|
||
// $res['data'] = array_map(fn($i)=>[...], $res['data']);
|
||
// return $res;
|
||
// }
|
||
} |