engineering/app/adminapi/validate/material/MaterialValidate.php
2024-01-21 09:43:44 +08:00

146 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\material;
use app\common\model\material\MaterialClassify;
use app\common\validate\BaseValidate;
/**
* 自购材料验证器
* Class MaterialValidate
* @package app\adminapi\validate\material
*/
class MaterialValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'first_level' => 'require|checkFirstLevel',
'second_level' => 'checkSecondLevel',
'three_level' => 'checkThreeLevel',
'code' => 'require',
'name' => 'require',
'specs' => 'require',
'unit' => 'require',
'inventory' => 'integer|egt:0',
'sales_price' => 'float|egt:0',
'cost_price' => 'float|egt:0',
'annex' => 'checkAnnex'
];
protected $message = [
'id.require' => '缺少必要参数',
'first_level.require' => '请选择材料大类',
'code.require' => '请填写材料编码',
'name.require' => '请填写材料名称',
'specs.require' => '请填写规格型号',
'unit.require' => '请填写单位',
'inventory.integer' => '安全库存量值必须是整数',
'inventory.egt' => '安全库存量值必须大于等于0',
'sales_price.float' => '销售指导价值必须是数字',
'sales_price.egt' => '销售指导价值必须大于等于0',
'cost_price.float' => '预算成本价值必须是数字',
'cost_price.egt' => '预算成本价值必须大于等于0',
];
/**
* @notes 添加场景
* @return MaterialValidate
* @author likeadmin
* @date 2024/01/04 10:59
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return MaterialValidate
* @author likeadmin
* @date 2024/01/04 10:59
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return MaterialValidate
* @author likeadmin
* @date 2024/01/04 10:59
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return MaterialValidate
* @author likeadmin
* @date 2024/01/04 10:59
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkFirstLevel($value): bool|string
{
$classify = MaterialClassify::where('id',$value)->where('pid',0)->findOrEmpty();
if($classify->isEmpty()){
return '材料大类不存在';
}
return true;
}
public function checkSecondLevel($value,$rule,$data): bool|string
{
$classify = MaterialClassify::where('id',$value)->where('pid',$data['first_level'])->findOrEmpty();
if($classify->isEmpty()){
return '材料中类不存在';
}
return true;
}
public function checkThreeLevel($value,$rule,$data): bool|string
{
$classify = MaterialClassify::where('id',$value)->where('pid',$data['second_level'])->findOrEmpty();
if($classify->isEmpty()){
return '材料小类不存在';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
if(!is_array($value)){
return '附件格式错误';
}
}
return true;
}
}