150 lines
3.9 KiB
PHP
150 lines
3.9 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\project;
|
||
|
||
use app\common\model\contract\SubcontractingContract;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\project\ProjectSubcontractSettlement;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 分包结算验证器
|
||
* Class ProjectSubcontractSettlementValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectSubcontractSettlementValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkData',
|
||
'project_id' => 'require|checkProject',
|
||
'contract_id' => 'require|checkContract',
|
||
'settlement_amount' => 'require|float|egt:0',
|
||
'settlement_date' => 'require|dateFormat:Y-m-d',
|
||
'annex' => 'checkAnnex',
|
||
'flow_id' => 'require|checkFlow',
|
||
'path' => 'require',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'project_id.require' => '请选择项目',
|
||
'contract_id.require' => '请选择合同',
|
||
'settlement_amount.require' => '请填写结算金额',
|
||
'settlement_amount.float' => '结算金额值必须是数字',
|
||
'settlement_amount.egt' => '结算金额值必须大于等于0',
|
||
'settlement_date.require' => '请选择结算日期',
|
||
'settlement_date.dateFormat' => '结算日期格式错误',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectSubcontractSettlementValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/29 13:59
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true)->remove('flow_id',true)->remove('path',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectSubcontractSettlementValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/29 13:59
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->remove('flow_id',true)->remove('path',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectSubcontractSettlementValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/29 13:59
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectSubcontractSettlementValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/29 13:59
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function sceneApprove()
|
||
{
|
||
return $this->only(['id','flow_id','path']);
|
||
}
|
||
|
||
public function checkData($value): bool|string
|
||
{
|
||
$data = ProjectSubcontractSettlement::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '数据不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkProject($value): bool|string
|
||
{
|
||
$data = Project::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '项目不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkContract($value,$rule,$data): bool|string
|
||
{
|
||
$contract = SubcontractingContract::where('id',$value)->findOrEmpty();
|
||
if($contract->isEmpty()){
|
||
return '合同不存在';
|
||
}
|
||
if($contract['project_id'] != $data['project_id']){
|
||
return '合同无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkAnnex($value): bool|string
|
||
{
|
||
if(!empty($value) && $value != ''){
|
||
if(!is_array($value)){
|
||
return '附件格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |