Files
bsh_info/app/common/service/NoticeService.php
T
2025-12-23 17:01:44 +08:00

72 lines
1.8 KiB
PHP

<?php
namespace app\common\service;
use app\common\validate\NoticeValidate;
use app\common\traits\crud\CrudServiceTrait;
use app\common\model\Notice;
use support\Request;
class NoticeService
{
use CrudServiceTrait;
/**
* 指定当前要操作的模型
*/
protected string $modelClass = Notice::class;
/**
* 验证器
*/
protected $validator = NoticeValidate::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['where']['status'] = 1;
if (isset($p['status']) && !empty($p['status'])) {
$config['where']['status'] = $p['status'];
}
$config['order']['sort'] = 'desc';
$config['order']['id'] = 'desc';
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;
}
}