132 lines
3.5 KiB
PHP
132 lines
3.5 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\financial;
|
||
|
||
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\financial\FinancialBudgetDoc;
|
||
use app\common\model\financial\FinancialBudgetDocDetail;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 财务管理--项目预算书--预算明细验证器
|
||
* Class FinancialBudgetDocDetailValidate
|
||
* @package app\adminapi\validate\financial
|
||
*/
|
||
class FinancialBudgetDocDetailValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkData',
|
||
'budget_doc_id' => 'require|checkBudgetDoc',
|
||
'dept_id' => 'require|checkDept',
|
||
'type' => 'require|checkType',
|
||
'amount' => 'require|float|gt:0',
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'budget_doc_id' => '预算书id',
|
||
'dept_id' => '部门',
|
||
'type' => '预算分成方式',
|
||
'amount' => '预算分成金额',
|
||
'remark' => '备注',
|
||
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return FinancialBudgetDocDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/26 13:54
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->only(['budget_doc_id', 'dept_id', 'type', 'amount', 'remark']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return FinancialBudgetDocDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/26 13:54
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->only(['id', 'budget_doc_id', 'dept_id', 'type', 'amount', 'remark']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return FinancialBudgetDocDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/26 13:54
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkData');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return FinancialBudgetDocDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/03/26 13:54
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkData($value): bool|string
|
||
{
|
||
$data = FinancialBudgetDocDetail::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '数据不存在' : true;
|
||
}
|
||
|
||
public function checkBudgetDoc($value): bool|string
|
||
{
|
||
$data = FinancialBudgetDoc::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '项目预算书信息不存在' : true;
|
||
}
|
||
|
||
public function checkDept($value): bool|string
|
||
{
|
||
$data = Dept::where('id', $value)->findOrEmpty();
|
||
return $data->isEmpty() ? '部门信息不存在' : true;
|
||
}
|
||
|
||
public function checkType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value', 'budget_share_method')->column('value');
|
||
return !in_array($value, $dict) ? '预算分成方式数据值无效' : true;
|
||
}
|
||
|
||
} |