116 lines
3.5 KiB
PHP
116 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\material;
|
||
|
||
|
||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||
use app\common\model\project\ProjectMaterialBudgetDetail;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 材料采购申请明细验证器
|
||
* Class MaterialPurchaseRequestDetailValidate
|
||
* @package app\adminapi\validate\material
|
||
*/
|
||
class MaterialPurchaseRequestDetailValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require|checkId',
|
||
'num' => 'require|integer|gt:0|checkNum',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'num.require' => '请填写申请采购数量',
|
||
'num.integer' => '申请采购数量值必须是整数',
|
||
'num.gt' => '申请采购数量之必须大于0',
|
||
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return MaterialPurchaseRequestDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/09 13:47
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id',true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return MaterialPurchaseRequestDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/09 13:47
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->only(['id','num']);
|
||
}
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return MaterialPurchaseRequestDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/09 13:47
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return MaterialPurchaseRequestDetailValidate
|
||
* @author likeadmin
|
||
* @date 2024/01/09 13:47
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkId($value): bool|string
|
||
{
|
||
$data = MaterialPurchaseRequestDetail::where('id',$value)->findOrEmpty();
|
||
if($data->isEmpty()){
|
||
return '数据不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkNum($value,$rule,$data){
|
||
//总预算数量 - 已申购数量 + 当前数据申购数量
|
||
$MaterialPurchaseRequestDetail = MaterialPurchaseRequestDetail::where('id',$data['id'])->findOrEmpty();
|
||
$project_material_budget_detail = ProjectMaterialBudgetDetail::where('id',$MaterialPurchaseRequestDetail['project_material_budget_detail_id'])->findOrEmpty();
|
||
//已经申购的数量
|
||
$PurchaseRequestNum = MaterialPurchaseRequestDetail::where('project_material_budget_detail_id',$MaterialPurchaseRequestDetail['project_material_budget_detail_id'])->sum('num');
|
||
if($value > ($project_material_budget_detail['num'] - $PurchaseRequestNum + $MaterialPurchaseRequestDetail['num'])){
|
||
return '申请采购数量不能大于剩余预算数量';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |