168 lines
4.8 KiB
PHP
168 lines
4.8 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\contract\Contract;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dept\Orgs;
|
||
use app\common\model\dict\DictData;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* 合同洽商验证器
|
||
* Class ContractNegotiationValidate
|
||
* @package app\adminapi\validate\contract
|
||
*/
|
||
class ContractNegotiationValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'org_id' => 'require|checkOrg',
|
||
'dept_id' => 'require|checkDept',
|
||
'contract_id' => 'require|checkContract',
|
||
'negotiation_name' => 'require',
|
||
'negotiation_amount' => 'require|float|gt:0',
|
||
'negotiation_type' => 'require|checkNegotiationType',
|
||
'labor_costs' => 'float|egt:0',
|
||
'material_costs' => 'float|egt:0',
|
||
'warranty_amount' => 'float|egt:0',
|
||
'warranty_expire_date' => 'dateFormat:Y-m-d',
|
||
'negotiation_quotation' => 'checkAnnex',
|
||
'negotiation_basis' => 'checkAnnex',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_id.require' => '请选择部门',
|
||
'contract_id.require' => '请选择项目合同',
|
||
'negotiation_name.require' => '请填写洽商单名称',
|
||
'negotiation_amount.require' => '请填写洽商金额',
|
||
'negotiation_amount.float' => '洽商金额值必须是数字',
|
||
'negotiation_amount.gt' => '洽商金额值必须大于0',
|
||
'negotiation_type.require' => '请选择洽商类别',
|
||
'labor_costs.float' => '成本金额(人工)值必须是数字',
|
||
'labor_costs.egt' => '成本金额(人工)值必须大于等于0',
|
||
'material_costs.float' => '成本金额(材料)值必须是数字',
|
||
'material_costs.egt' => '成本金额(材料)值必须大于等于0',
|
||
'warranty_amount.float' => '洽商质保金额值必须是数字',
|
||
'warranty_amount.egt' => '洽商质保金额值必须大于等于0',
|
||
'warranty_expire_date.dateFormat' => '洽商质保到期时间数据格式错误',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return ContractNegotiationValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/04 21:26
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return ContractNegotiationValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/04 21:26
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return ContractNegotiationValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/04 21:26
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return ContractNegotiationValidate
|
||
* @author likeadmin
|
||
* @date 2023/12/04 21:26
|
||
*/
|
||
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 checkContract($value): bool|string
|
||
{
|
||
$contract = Contract::where('id',$value)->findOrEmpty();
|
||
if($contract->isEmpty()){
|
||
return '项目合同信息不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkNegotiationType($value): bool|string
|
||
{
|
||
$dict = DictData::where('type_value','negotiation_type')->column('value');
|
||
if(!in_array($value,$dict)){
|
||
return '洽商类别无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkAnnex($value): bool|string
|
||
{
|
||
if(!empty($value) && $value != ''){
|
||
$annex =$value;// json_decode($value,true);
|
||
if(empty($annex) || !is_array($annex)){
|
||
return '附件数据格式错误';
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |