66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
namespace App\System\Mapper;
|
|
|
|
use App\System\Model\SettingCrontab;
|
|
use Hyperf\Database\Model\Builder;
|
|
use Builder\Abstracts\AbstractMapper;
|
|
use Builder\Annotation\Transaction;
|
|
|
|
class SettingCrontabMapper extends AbstractMapper
|
|
{
|
|
/**
|
|
* @var SettingCrontab
|
|
*/
|
|
public $model;
|
|
|
|
public function assignModel()
|
|
{
|
|
$this->model = SettingCrontab::class;
|
|
}
|
|
|
|
/**
|
|
* @param array $ids
|
|
* @return bool
|
|
* @throws \Exception
|
|
*/
|
|
#[Transaction]
|
|
public function delete(array $ids): bool
|
|
{
|
|
foreach ($ids as $id) {
|
|
$model = $this->model::find($id);
|
|
if ($model) {
|
|
$model->logs()->delete();
|
|
$model->delete();
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 搜索处理器
|
|
* @param Builder $query
|
|
* @param array $params
|
|
* @return Builder
|
|
*/
|
|
public function handleSearch(Builder $query, array $params): Builder
|
|
{
|
|
if (isset($params['name'])) {
|
|
$query->where('name', 'like', '%'.$params['name'].'%');
|
|
}
|
|
if (isset($params['status'])) {
|
|
$query->where('status', $params['status']);
|
|
}
|
|
if (isset($params['type'])) {
|
|
$query->where('type', $params['type']);
|
|
}
|
|
if (isset($params['created_at']) && is_array($params['created_at']) && count($params['created_at']) == 2) {
|
|
$query->whereBetween(
|
|
'created_at',
|
|
[ $params['created_at'][0] . ' 00:00:00', $params['created_at'][1] . ' 23:59:59' ]
|
|
);
|
|
}
|
|
return $query;
|
|
}
|
|
} |