lihai-oa/app/project/validate/ProjectCheck.php

53 lines
1.8 KiB
PHP
Raw Normal View History

2023-10-24 15:17:16 +08:00
<?php
namespace app\project\validate;
use think\Validate;
2023-10-31 10:12:16 +08:00
use think\facade\Db;
2023-10-24 15:17:16 +08:00
class ProjectCheck extends Validate
{
protected $rule = [
2023-10-31 10:12:16 +08:00
'name' => 'require|unique:project',
'start_time' => 'require',
'end_time' => 'require',
'director_uid' => 'require',
'content' => 'require',
'code' => 'alphaNum|length:5,10|unique:project',
'id' => 'require|checkProject'
2023-10-24 15:17:16 +08:00
];
protected $message = [
'name.require' => '项目名称不能为空',
2023-10-31 10:12:16 +08:00
'name.unique' => '项目已存在',
'start_time.require' => '项目开始时间不能为空',
'end_time.require' => '项目结束时间不能为空',
'director_uid.require' => '项目负责人不能为空',
'content.require' => '项目简介不能为空',
2023-10-24 15:17:16 +08:00
'code.alphaNum' => '项目代码只能为5至10为字母和数字',
'code.length' => '项目代码只能为5至10为字母和数字',
'code.unique' => '同样的项目代码已经存在',
'id.require' => '缺少更新条件',
];
protected $scene = [
2023-10-31 10:12:16 +08:00
'add' => ['name','start_time','end_time','director_uid','content','code'],
'edit' => ['id', 'name','start_time','end_time','director_uid','content','code']
2023-10-24 15:17:16 +08:00
];
2023-10-31 10:12:16 +08:00
public function checkProject($id, $rule, $data)
{
$project = Db::name('project')->where([
'id' => $id
])->findOrEmpty();
if (empty($project)) {
return '项目不存在';
}
$oProject = Db::name('project')->where([
'name' => $data['name']
])->findOrEmpty();
if (!empty($oProject) && ($oProject['id'] != $id)) {
return '项目已存在';
}
return true;
}
2023-10-24 15:17:16 +08:00
}