136 lines
3.6 KiB
PHP
136 lines
3.6 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\dict\DictData;
|
||
use app\common\model\material\Material;
|
||
use app\common\model\project\ProjectMaterialBudget;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 材料预算明细验证器
|
||
* Class ProjectMaterialBudgetDetailValidate
|
||
* @package app\adminapi\validate\project
|
||
*/
|
||
class ProjectMaterialBudgetDetailValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'material_budget_id' => 'require|checkMaterialBudget',
|
||
'material_id' => 'require|checkMaterial',
|
||
'budget_type' => 'require|checkBudgetType',
|
||
'price' => 'require|float|egt:0',
|
||
'num' => 'require|integer|gt:0',
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'material_budget_id.require' => '请选择材料预算',
|
||
'material_id.require' => '请选择材料',
|
||
'budget_type.require' => '请选择类型',
|
||
'price.require' => '请填写单价',
|
||
'price.float' => '单价值必须是数字',
|
||
'price.egt' => '单价值必须大于等于0',
|
||
'num.require' => '请填写数量',
|
||
'num.integer' => '数量值必须时整数',
|
||
'num.gt' => '数量值必须大于0',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ProjectMaterialBudgetDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 21:52
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProjectMaterialBudgetDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 21:52
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProjectMaterialBudgetDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 21:52
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProjectMaterialBudgetDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/08 21:52
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkMaterialBudget($value): bool|string
|
||
{
|
||
$material_budget = ProjectMaterialBudget::where('id',$value)->findOrEmpty();
|
||
if($material_budget->isEmpty()){
|
||
return '材料预算信息不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkMaterial($value): bool|string
|
||
{
|
||
$material = Material::where('id',$value)->findOrEmpty();
|
||
if($material->isEmpty()){
|
||
return '材料信息不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkBudgetType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value','budget_type')->column('value');
|
||
if(!in_array($value,$dict)){
|
||
return '类型值无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |