update
This commit is contained in:
parent
55d4fe7d21
commit
66eaf507fe
@ -12,254 +12,258 @@
|
|||||||
// | author: likeadminTeam
|
// | author: likeadminTeam
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace app\adminapi\validate\contract;
|
namespace app\adminapi\validate\contract;
|
||||||
|
|
||||||
|
|
||||||
use app\common\model\contract\ProcurementContract;
|
use app\common\model\contract\ProcurementContract;
|
||||||
use app\common\model\contract\ProcurementContractDetail;
|
use app\common\model\contract\ProcurementContractDetail;
|
||||||
use app\common\model\dict\DictData;
|
use app\common\model\dict\DictData;
|
||||||
use app\common\model\finance\FinancePaymentPlan;
|
use app\common\model\finance\FinancePaymentPlan;
|
||||||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||||||
use app\common\model\project\Project;
|
use app\common\model\project\Project;
|
||||||
use app\common\model\supplier\Supplier;
|
use app\common\model\supplier\Supplier;
|
||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 采购合同验证器
|
* 采购合同验证器
|
||||||
* Class ProcurementContractValidate
|
* Class ProcurementContractValidate
|
||||||
* @package app\adminapi\validate\contract
|
* @package app\adminapi\validate\contract
|
||||||
*/
|
*/
|
||||||
class ProcurementContractValidate extends BaseValidate
|
class ProcurementContractValidate extends BaseValidate
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置校验规则
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $rule = [
|
|
||||||
'id' => 'require|checkData',
|
|
||||||
'supplier_id' => 'require|checkSupplier',
|
|
||||||
'project_id' => 'require|checkProject',
|
|
||||||
'contract_name' => 'require',
|
|
||||||
'contract_type' => 'require|checkContractType',
|
|
||||||
'signing_date' => 'require|dateFormat:Y-m-d',
|
|
||||||
'pay_type' => 'require|checkPayType',
|
|
||||||
'account_period' => 'require|checkAccountPeriod',
|
|
||||||
'retention_money_rate' => 'require|float|egt:0',
|
|
||||||
'annex' => 'checkAnnex',
|
|
||||||
'procurement_contract_detail' => 'require|checkProcurementContractDetail',
|
|
||||||
'payment_plan' => 'require|checkPaymentPlan',
|
|
||||||
'flow_id' => 'require|checkFlow',
|
|
||||||
'path' => 'require',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 参数描述
|
|
||||||
* @var string[]
|
|
||||||
*/
|
|
||||||
protected $message = [
|
|
||||||
'id.require' => '缺少必要参数',
|
|
||||||
'supplier_id.require' => '请选择供应商',
|
|
||||||
'project_id.require' => '请选择项目',
|
|
||||||
'contract_name.require' => '请填写合同名称',
|
|
||||||
'contract_type.require' => '请选择合同类型',
|
|
||||||
'signing_date.require' => '请选择签约日期',
|
|
||||||
'signing_date.dateFormat' => '签约日期数据格式错误',
|
|
||||||
'pay_type.require' => '请选择付款方式',
|
|
||||||
'account_period.require' => '请选择账期',
|
|
||||||
'retention_money_rate.require' => '请填写质保金比例',
|
|
||||||
'retention_money_rate.float' => '质保金比例值必须是数字',
|
|
||||||
'retention_money_rate.egt' => '质保金比例值必须大于等于0',
|
|
||||||
'procurement_contract_detail.require' => '采购合同明细不能为空',
|
|
||||||
'payment_plan.require' => '付款计划不能为空'
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 添加场景
|
|
||||||
* @return ProcurementContractValidate
|
|
||||||
* @author likeadmin
|
|
||||||
* @date 2023/12/04 22:08
|
|
||||||
*/
|
|
||||||
public function sceneAdd()
|
|
||||||
{
|
|
||||||
return $this->remove('id', true)->remove('flow_id',true)->remove('path',true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 编辑场景
|
|
||||||
* @return ProcurementContractValidate
|
|
||||||
* @author likeadmin
|
|
||||||
* @date 2023/12/04 22:08
|
|
||||||
*/
|
|
||||||
public function sceneEdit()
|
|
||||||
{
|
|
||||||
return $this->remove('flow_id',true)->remove('path',true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 删除场景
|
|
||||||
* @return ProcurementContractValidate
|
|
||||||
* @author likeadmin
|
|
||||||
* @date 2023/12/04 22:08
|
|
||||||
*/
|
|
||||||
public function sceneDelete()
|
|
||||||
{
|
|
||||||
return $this->only(['id'])->remove('id','checkData');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 详情场景
|
|
||||||
* @return ProcurementContractValidate
|
|
||||||
* @author likeadmin
|
|
||||||
* @date 2023/12/04 22:08
|
|
||||||
*/
|
|
||||||
public function sceneDetail()
|
|
||||||
{
|
|
||||||
return $this->only(['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function sceneApprove()
|
|
||||||
{
|
{
|
||||||
return $this->only(['id','flow_id','path']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkData($value): bool|string
|
/**
|
||||||
{
|
* 设置校验规则
|
||||||
$data = ProcurementContract::where('id',$value)->findOrEmpty();
|
* @var string[]
|
||||||
if($data->isEmpty()){
|
*/
|
||||||
return '数据不存在';
|
protected $rule = [
|
||||||
|
'id' => 'require|checkData',
|
||||||
|
'supplier_id' => 'require|checkSupplier',
|
||||||
|
'project_id' => 'require|checkProject',
|
||||||
|
'contract_name' => 'require',
|
||||||
|
'contract_type' => 'require|checkContractType',
|
||||||
|
'signing_date' => 'require|dateFormat:Y-m-d',
|
||||||
|
'pay_type' => 'require|checkPayType',
|
||||||
|
'account_period' => 'require|checkAccountPeriod',
|
||||||
|
'retention_money_rate' => 'require|float|egt:0',
|
||||||
|
'annex' => 'checkAnnex',
|
||||||
|
'procurement_contract_detail' => 'require|checkProcurementContractDetail',
|
||||||
|
'payment_plan' => 'require|checkPaymentPlan',
|
||||||
|
'flow_id' => 'require|checkFlow',
|
||||||
|
'path' => 'require',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数描述
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $message = [
|
||||||
|
'id.require' => '缺少必要参数',
|
||||||
|
'supplier_id.require' => '请选择供应商',
|
||||||
|
'project_id.require' => '请选择项目',
|
||||||
|
'contract_name.require' => '请填写合同名称',
|
||||||
|
'contract_type.require' => '请选择合同类型',
|
||||||
|
'signing_date.require' => '请选择签约日期',
|
||||||
|
'signing_date.dateFormat' => '签约日期数据格式错误',
|
||||||
|
'pay_type.require' => '请选择付款方式',
|
||||||
|
'account_period.require' => '请选择账期',
|
||||||
|
'retention_money_rate.require' => '请填写质保金比例',
|
||||||
|
'retention_money_rate.float' => '质保金比例值必须是数字',
|
||||||
|
'retention_money_rate.egt' => '质保金比例值必须大于等于0',
|
||||||
|
'procurement_contract_detail.require' => '采购合同明细不能为空',
|
||||||
|
'payment_plan.require' => '付款计划不能为空'
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加场景
|
||||||
|
* @return ProcurementContractValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/12/04 22:08
|
||||||
|
*/
|
||||||
|
public function sceneAdd()
|
||||||
|
{
|
||||||
|
return $this->remove('id', true)->remove('flow_id', true)->remove('path', true);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkSupplier($value): bool|string
|
|
||||||
{
|
|
||||||
$supplier = Supplier::where('id',$value)->findOrEmpty();
|
|
||||||
if($supplier->isEmpty()){
|
|
||||||
return '供应商信息不存在';
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkProject($value): bool|string
|
/**
|
||||||
{
|
* @notes 编辑场景
|
||||||
$project = Project::where('id',$value)->findOrEmpty();
|
* @return ProcurementContractValidate
|
||||||
if($project->isEmpty()){
|
* @author likeadmin
|
||||||
return '项目信息不存在';
|
* @date 2023/12/04 22:08
|
||||||
|
*/
|
||||||
|
public function sceneEdit()
|
||||||
|
{
|
||||||
|
return $this->remove('flow_id', true)->remove('path', true);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkContractType($value): bool|string
|
|
||||||
{
|
|
||||||
$dict = DictData::where('type_value','procurement_contract_type')->column('value');
|
|
||||||
if(!in_array($value,$dict)){
|
|
||||||
return '合同类型无效';
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkPayType($value): bool|string
|
/**
|
||||||
{
|
* @notes 删除场景
|
||||||
$dict = DictData::where('type_value','pay_type')->column('value');
|
* @return ProcurementContractValidate
|
||||||
if(!in_array($value,$dict)){
|
* @author likeadmin
|
||||||
return '付款方式无效';
|
* @date 2023/12/04 22:08
|
||||||
|
*/
|
||||||
|
public function sceneDelete()
|
||||||
|
{
|
||||||
|
return $this->only(['id'])->remove('id', 'checkData');
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkAccountPeriod($value): bool|string
|
|
||||||
{
|
|
||||||
$dict = DictData::where('type_value','account_period')->column('value');
|
|
||||||
if(!in_array($value,$dict)){
|
|
||||||
return '账期无效';
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkProcurementContractDetail($value): bool|string
|
/**
|
||||||
{
|
* @notes 详情场景
|
||||||
if(!empty($value) && !is_array($value)){
|
* @return ProcurementContractValidate
|
||||||
return '采购合同明细数据格式错误';
|
* @author likeadmin
|
||||||
|
* @date 2023/12/04 22:08
|
||||||
|
*/
|
||||||
|
public function sceneDetail()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
foreach($value as $v) {
|
|
||||||
if(isset($v['id']) && $v['id'] != ''){
|
public function sceneApprove()
|
||||||
$data_detail = ProcurementContractDetail::where('id',$v['id'])->findOrEmpty();
|
{
|
||||||
if($data_detail->isEmpty()){
|
return $this->only(['id', 'flow_id', 'path']);
|
||||||
return '采购合同明细信息不存在';
|
}
|
||||||
}
|
|
||||||
}
|
public function checkData($value): bool|string
|
||||||
if(empty($v['material_purchase_request_detail_id'])){
|
{
|
||||||
return '请选择采购申请明细信息';
|
$data = ProcurementContract::where('id', $value)->findOrEmpty();
|
||||||
}else{
|
if ($data->isEmpty()) {
|
||||||
$material_purchase_request_detail = MaterialPurchaseRequestDetail::where('id',$v['material_purchase_request_detail_id'])->findOrEmpty();
|
return '数据不存在';
|
||||||
if($material_purchase_request_detail->isEmpty()){
|
}
|
||||||
return '采购申请明细信息不存在';
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(empty($v['num'])){
|
public function checkSupplier($value): bool|string
|
||||||
return '数量不能为空';
|
{
|
||||||
}else{
|
$supplier = Supplier::where('id', $value)->findOrEmpty();
|
||||||
if(!is_numeric($v['num']) || $v['num'] <= 0){
|
if ($supplier->isEmpty()) {
|
||||||
return '数量必须是大于0的数字';
|
return '供应商信息不存在';
|
||||||
}
|
}
|
||||||
}
|
return true;
|
||||||
if(empty($v['price'])){
|
}
|
||||||
return '含税单价不能为空';
|
|
||||||
}else{
|
public function checkProject($value): bool|string
|
||||||
if(!is_numeric($v['price']) || $v['price'] <= 0){
|
{
|
||||||
return '含税单价必须是大于0的数字';
|
$project = Project::where('id', $value)->findOrEmpty();
|
||||||
}
|
if ($project->isEmpty()) {
|
||||||
}
|
return '项目信息不存在';
|
||||||
if(empty($v['tax_rate'])){
|
}
|
||||||
return '请选择税率';
|
return true;
|
||||||
}else{
|
}
|
||||||
$dict = DictData::where('type_value','tax_rate')->column('value');
|
|
||||||
if(!in_array($v['tax_rate'],$dict)){
|
public function checkContractType($value): bool|string
|
||||||
return '税率无效';
|
{
|
||||||
|
$dict = DictData::where('type_value', 'procurement_contract_type')->column('value');
|
||||||
|
if (!in_array($value, $dict)) {
|
||||||
|
return '合同类型无效';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPayType($value): bool|string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value', 'pay_type')->column('value');
|
||||||
|
if (!in_array($value, $dict)) {
|
||||||
|
return '付款方式无效';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkAccountPeriod($value): bool|string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value', 'account_period')->column('value');
|
||||||
|
if (!in_array($value, $dict)) {
|
||||||
|
return '账期无效';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkProcurementContractDetail($value): bool|string
|
||||||
|
{
|
||||||
|
if (!empty($value) && !is_array($value)) {
|
||||||
|
return '采购合同明细数据格式错误';
|
||||||
|
}
|
||||||
|
foreach ($value as $v) {
|
||||||
|
$material_purchase_request_detail = MaterialPurchaseRequestDetail::where('id', $v['material_purchase_request_detail_id'])->findOrEmpty();
|
||||||
|
if (isset($v['id']) && $v['id'] != '') {
|
||||||
|
$data_detail = ProcurementContractDetail::where('id', $v['id'])->findOrEmpty();
|
||||||
|
if ($data_detail->isEmpty()) {
|
||||||
|
return '采购合同明细信息不存在';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($v['material_purchase_request_detail_id'])) {
|
||||||
|
return '请选择采购申请明细信息';
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ($material_purchase_request_detail->isEmpty()) {
|
||||||
|
return '采购申请明细信息不存在';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($v['num'])) {
|
||||||
|
return '数量不能为空';
|
||||||
|
} else {
|
||||||
|
if (!is_numeric($v['num']) || $v['num'] <= 0) {
|
||||||
|
return '数量必须是大于0的数字';
|
||||||
|
}
|
||||||
|
if ($v['num'] > $material_purchase_request_detail['num']) {
|
||||||
|
return '数量不能大于申请数量';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($v['price'])) {
|
||||||
|
return '含税单价不能为空';
|
||||||
|
} else {
|
||||||
|
if (!is_numeric($v['price']) || $v['price'] <= 0) {
|
||||||
|
return '含税单价必须是大于0的数字';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($v['tax_rate'])) {
|
||||||
|
return '请选择税率';
|
||||||
|
} else {
|
||||||
|
$dict = DictData::where('type_value', 'tax_rate')->column('value');
|
||||||
|
if (!in_array($v['tax_rate'], $dict)) {
|
||||||
|
return '税率无效';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function checkPaymentPlan($value): bool|string
|
public function checkPaymentPlan($value): bool|string
|
||||||
{
|
{
|
||||||
if(!empty($value) && !is_array($value)){
|
if (!empty($value) && !is_array($value)) {
|
||||||
return '付款计划据格式错误';
|
return '付款计划据格式错误';
|
||||||
|
}
|
||||||
|
foreach ($value as $v) {
|
||||||
|
if (isset($v['id']) && $v['id'] != '') {
|
||||||
|
$data_detail = FinancePaymentPlan::where('id', $v['id'])->findOrEmpty();
|
||||||
|
if ($data_detail->isEmpty()) {
|
||||||
|
return '付款计划信息不存在';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($v['period'])) {
|
||||||
|
return '请选择期次';
|
||||||
|
} else {
|
||||||
|
$dict = DictData::where('type_value', 'pay_period')->column('value');
|
||||||
|
if (!in_array($v['period'], $dict)) {
|
||||||
|
return '期次无效';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($v['pay_date'])) {
|
||||||
|
return '请选择计划付款日期';
|
||||||
|
}
|
||||||
|
if (empty($v['amount'])) {
|
||||||
|
return '金额不能为空';
|
||||||
|
} else {
|
||||||
|
if (!is_numeric($v['amount']) || $v['amount'] <= 0) {
|
||||||
|
return '金额必须是大于0的数字';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
foreach($value as $v) {
|
|
||||||
if(isset($v['id']) && $v['id'] != ''){
|
|
||||||
$data_detail = FinancePaymentPlan::where('id',$v['id'])->findOrEmpty();
|
|
||||||
if($data_detail->isEmpty()){
|
|
||||||
return '付款计划信息不存在';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(empty($v['period'])){
|
|
||||||
return '请选择期次';
|
|
||||||
}else{
|
|
||||||
$dict = DictData::where('type_value','pay_period')->column('value');
|
|
||||||
if(!in_array($v['period'],$dict)){
|
|
||||||
return '期次无效';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(empty($v['pay_date'])){
|
|
||||||
return '请选择计划付款日期';
|
|
||||||
}
|
|
||||||
if(empty($v['amount'])){
|
|
||||||
return '金额不能为空';
|
|
||||||
}else{
|
|
||||||
if(!is_numeric($v['amount']) || $v['amount'] <= 0){
|
|
||||||
return '金额必须是大于0的数字';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user