272 lines
7.4 KiB
PHP
272 lines
7.4 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\contract;
|
||
|
||
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dept\Orgs;
|
||
use app\common\model\dict\DictData;
|
||
use app\common\model\material\MaterialPurchaseRequestDetail;
|
||
use app\common\model\project\Project;
|
||
use app\common\model\supplier\Supplier;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 采购合同验证器
|
||
* Class ProcurementContractValidate
|
||
* @package app\adminapi\validate\contract
|
||
*/
|
||
class ProcurementContractValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'org_id' => 'require|checkOrg',
|
||
'dept_id' => 'require|checkDept',
|
||
'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'
|
||
];
|
||
|
||
|
||
/**
|
||
* 参数描述
|
||
* @var string[]
|
||
*/
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_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);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ProcurementContractValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/04 22:08
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ProcurementContractValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/04 22:08
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ProcurementContractValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/04 22:08
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
public function checkOrg($value): bool|string
|
||
{
|
||
$org = Orgs::where('id',$value)->findOrEmpty();
|
||
if($org->isEmpty()){
|
||
return '组织不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkDept($value,$rule,$data): bool|string
|
||
{
|
||
$dept = Dept::where('id',$value)->findOrEmpty();
|
||
if($dept->isEmpty()){
|
||
return '部门不存在';
|
||
}
|
||
if($dept['org_id'] != $data['org_id']){
|
||
return '部门无效';
|
||
}
|
||
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
|
||
{
|
||
$project = Project::where('id',$value)->findOrEmpty();
|
||
if($project->isEmpty()){
|
||
return '项目信息不存在';
|
||
}
|
||
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
|
||
{
|
||
$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 checkAnnex($value): bool|string
|
||
{
|
||
if(!empty($value) && $value != ''){
|
||
$annex = json_decode($value,true);
|
||
if(empty($annex) || !is_array($annex)){
|
||
return '附件格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkProcurementContractDetail($value): bool|string
|
||
{
|
||
$detail = json_decode($value,true);
|
||
if(empty($detail) || !is_array($detail)){
|
||
return '采购合同明细数据格式错误';
|
||
}
|
||
foreach($detail as $v) {
|
||
if(empty($v['material_purchase_request_detail_id'])){
|
||
return '请选择采购申请明细信息';
|
||
}else{
|
||
$material_purchase_request_detail = MaterialPurchaseRequestDetail::where('id',$v['material_purchase_request_detail_id'])->findOrEmpty();
|
||
if($material_purchase_request_detail->isEmpty()){
|
||
return '采购申请明细信息不存在';
|
||
}
|
||
}
|
||
if(empty($v['num'])){
|
||
return '数量不能为空';
|
||
}else{
|
||
if(!is_numeric($v['num']) || $v['num'] <= 0){
|
||
return '数量必须是大于0的数字';
|
||
}
|
||
}
|
||
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;
|
||
}
|
||
|
||
public function checkPaymentPlan($value): bool|string
|
||
{
|
||
$detail = json_decode($value,true);
|
||
if(empty($detail) || !is_array($detail)){
|
||
return '付款计划据格式错误';
|
||
}
|
||
foreach($detail as $v) {
|
||
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;
|
||
}
|
||
} |