Files
anmo/server/app/adminapi/validate/crontab/CrontabValidate.php
2025-08-19 14:16:51 +08:00

137 lines
3.7 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | likeshop100%开源免费商用商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | 商业版本务必购买商业授权,以免引起法律纠纷
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshopTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\crontab;
use app\common\validate\BaseValidate;
use Cron\CronExpression;
/**
* 定时任务验证器
* Class CrontabValidate
* @package app\adminapi\validate\crontab
*/
class CrontabValidate extends BaseValidate
{
protected $rule = [
'name' => 'require',
'type' => 'require|in:1',
'command' => 'require',
'status' => 'require|in:1,2,3',
'expression' => 'require|checkExpression',
'id' => 'require',
'operate' => 'require'
];
protected $message = [
'name.require' => '请输入定时任务名称',
'type.require' => '请选择类型',
'type.in' => '类型值错误',
'command.require' => '请输入命令',
'status.require' => '请选择状态',
'status.in' => '状态值错误',
'expression.require' => '请输入运行规则',
'id.require' => '参数缺失',
'operate.require' => '请选择操作',
];
/**
* @notes 添加定时任务场景
* @return CrontabValidate
* @author Tab
* @date 2021/8/17 11:18
*/
public function sceneAdd()
{
return $this->remove('id', 'require')->remove('operate', 'require');
}
/**
* @notes 查看定时任务详情场景
* @return CrontabValidate
* @author Tab
* @date 2021/8/17 11:55
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 编辑定时任务
* @return CrontabValidate
* @author Tab
* @date 2021/9/15 15:53
*/
public function sceneEdit()
{
return $this->remove('operate', 'require');
}
/**
* @notes 删除定时任务场景
* @return CrontabValidate
* @author Tab
* @date 2021/8/17 14:09
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes
* @return CrontabValidate
* @author Tab
* @date 2021/8/17 15:06
*/
public function sceneOperate()
{
return $this->only(['id', 'operate']);
}
/**
* @notes 获取规则执行时间场景
* @return CrontabValidate
* @author Tab
* @date 2021/8/17 15:36
*/
public function sceneExpression()
{
return $this->only(['expression']);
}
/**
* @notes 校验运行规则
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author Tab
* @date 2021/8/17 11:42
*/
public function checkExpression($value, $rule, $data)
{
if(CronExpression::isValidExpression($value) === false) {
return '定时任务运行规则错误';
}
return true;
}
}