126 lines
3.0 KiB
PHP
126 lines
3.0 KiB
PHP
<?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
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\validate\build;
|
||
|
||
|
||
use app\common\model\build\BuildPlan;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 施工汇报验证器
|
||
* Class BuildReportValidate
|
||
* @package app\adminapi\validate\build
|
||
*/
|
||
class BuildReportValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'plan_id' => 'require|checkPlan',
|
||
'person_detail' => 'require|checkDetail',
|
||
'file' => 'require|checkFile',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'plan_id.require' => '请选择施工计划',
|
||
'person_detail.require' => '请填写人工明细',
|
||
'file.require' => '请上传现场照片',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return BuildReportValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/22 16:08
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return BuildReportValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/22 16:08
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return BuildReportValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/22 16:08
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return BuildReportValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/22 16:08
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkPlan($value): bool|string
|
||
{
|
||
$data = BuildPlan::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '施工计划不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkFile($value): bool|string
|
||
{
|
||
$file = json_decode($value,true);
|
||
if(empty($file)){
|
||
return '附件必须是json数组';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkDetail($value): bool|string
|
||
{
|
||
$person_detail = json_decode($value,true);
|
||
if(empty($person_detail) || !is_array($person_detail)){
|
||
return '人工明细数据格式错误';
|
||
}
|
||
foreach($person_detail as $v) {
|
||
if(empty($v['person_id']) || empty($v['work_num'])){
|
||
return '人工明细缺少必要参数';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |