94 lines
2.8 KiB
PHP
Executable File
94 lines
2.8 KiB
PHP
Executable File
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
|
// +----------------------------------------------------------------------
|
|
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
|
// | 开源版本可自由商用,可去除界面版权logo
|
|
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
|
// | github下载:https://github.com/likeshop-github/likeadmin
|
|
// | 访问官网:https://www.likeadmin.cn
|
|
// | likeadmin团队 版权所有 拥有最终解释权
|
|
// +----------------------------------------------------------------------
|
|
// | author: likeadminTeam
|
|
// +----------------------------------------------------------------------
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\validate\tcm;
|
|
|
|
use app\common\model\tcm\Diagnosis;
|
|
use app\common\model\tcm\DiagnosisTodo;
|
|
use app\common\validate\BaseValidate;
|
|
|
|
/**
|
|
* 诊单待办事项验证
|
|
* Class DiagnosisTodoValidate
|
|
* @package app\adminapi\validate\tcm
|
|
*/
|
|
class DiagnosisTodoValidate extends BaseValidate
|
|
{
|
|
protected $rule = [
|
|
'id' => 'require|number',
|
|
'diagnosis_id' => 'require|number|gt:0|checkDiagnosis',
|
|
'content' => 'require|length:1,500',
|
|
'remind_time' => 'require|number|checkRemindFuture',
|
|
];
|
|
|
|
protected $message = [
|
|
'id.require' => '参数缺失',
|
|
'diagnosis_id.require' => '诊单 id 不能为空',
|
|
'diagnosis_id.gt' => '诊单 id 非法',
|
|
'content.require' => '请输入提醒内容',
|
|
'content.length' => '提醒内容长度需在 1-500 字',
|
|
'remind_time.require' => '请选择提醒时间',
|
|
'remind_time.number' => '提醒时间格式错误',
|
|
];
|
|
|
|
public function sceneAdd()
|
|
{
|
|
return $this->only(['diagnosis_id', 'content', 'remind_time']);
|
|
}
|
|
|
|
public function sceneCancel()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function sceneDetail()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function sceneList()
|
|
{
|
|
return $this->only(['diagnosis_id'])
|
|
->append('diagnosis_id', 'require|number|gt:0');
|
|
}
|
|
|
|
/**
|
|
* 诊单存在校验
|
|
*/
|
|
protected function checkDiagnosis($value): bool|string
|
|
{
|
|
$diagnosis = Diagnosis::findOrEmpty((int) $value);
|
|
if ($diagnosis->isEmpty()) {
|
|
return '诊单不存在';
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 提醒时间必须在当前时间之后(至少 30 秒),避免立刻就过期
|
|
*/
|
|
protected function checkRemindFuture($value): bool|string
|
|
{
|
|
$ts = (int) $value;
|
|
if ($ts <= time() + 30) {
|
|
return '提醒时间必须晚于当前时间';
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|