engineering/app/adminapi/validate/contract/ContractValidate.php
2024-01-22 11:42:04 +08:00

263 lines
7.3 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\contract;
use app\common\model\auth\Admin;
use app\common\model\bid\BidBuyBiddingDocument;
use app\common\model\custom\Custom;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\dict\DictData;
use app\common\model\finance\FinanceReturnedMoney;
use app\common\model\project\Project;
use app\common\validate\BaseValidate;
/**
* 项目合同验证器
* Class ContractValidate
* @package app\adminapi\validate\contract
*/
class ContractValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'custom_id' => 'require|checkCustom',
'buy_bidding_document_id' => 'require|checkBuyBiddingDocument',
'contract_name' => 'require',
'contract_type' => 'require|checkContractType',
'contract_pricing_method' => 'require|checkContractPricingMethod',
'party_a' => 'require',
'party_a_mobile' => 'mobile',
'party_b' => 'require',
'party_b_mobile' => 'mobile',
'amount' => 'require|float|gt:0',
'business_director' => 'require|checkBusinessDirector',
'contract_status' => 'require|checkContractStatus',
'expire' => 'require|dateFormat:Y-m-d',
'contract_date' => 'require|dateFormat:Y-m-d',
'annex' => 'checkAnnex',
'returned_money' => 'require|checkReturnedMoney'
];
/**
* 参数描述
* @var string[]
*/
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'custom_id.require' => '请选择客户',
'buy_bidding_document_id.require' => '请选择标书编号',
'contract_name.require' => '请填写合同名称',
'contract_type.require' => '请选择合同类型',
'contract_pricing_method.require' => '请选择合同计价方式',
'party_a.require' => '请填写甲方名称',
'party_a_mobile.mobile' => '甲方手机号码格式错误',
'party_b.require' => '请填写乙方名称',
'party_b_mobile.mobile' => '乙方手机号码格式错误',
'amount.require' => '请填写合同金额',
'amount.float' => '合同金额值必须是数字',
'amount.gt' => '写合同金额值必须大于0',
'business_director.require' => '请选择业务负责人',
'contract_status.require' => '请选择合同状态',
'expire.require' => '请选择合同有效期',
'expire.dateFormat' => '合同有效期数据格式错误',
'contract_date.require' => '请选择签约日期',
'contract_date.dateFormat' => '签约日期数据格式错误',
'returned_money.require' => '回款计划信息不能为空',
];
/**
* @notes 添加场景
* @return ContractValidate
* @author likeadmin
* @date 2023/12/02 17:19
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return ContractValidate
* @author likeadmin
* @date 2023/12/02 17:19
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return ContractValidate
* @author likeadmin
* @date 2023/12/02 17:19
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ContractValidate
* @author likeadmin
* @date 2023/12/02 17:19
*/
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 checkCustom($value): bool|string
{
$custom = Custom::where('id',$value)->findOrEmpty();
if($custom->isEmpty()){
return '客户信息不存在';
}
return true;
}
public function checkBuyBiddingDocument($value,$rule,$data): bool|string
{
$buy_bidding_document = BidBuyBiddingDocument::where('id',$value)->findOrEmpty();
if($buy_bidding_document->isEmpty()){
return '标书信息不存在';
}
$project = Project::where('id',$buy_bidding_document['project_id'])->findOrEmpty();
if($data['custom_id'] != $project['custom_id']){
return '标书信息无效';
}
return true;
}
public function checkContractType($value): bool|string
{
$dict = DictData::where('type_value','contract_type')->column('value');
if(!in_array($value,$dict)){
return '合同类型无效';
}
return true;
}
public function checkContractPricingMethod($value): bool|string
{
$dict = DictData::where('type_value','contract_pricing_method')->column('value');
if(!in_array($value,$dict)){
return '合同计价方式无效';
}
return true;
}
public function checkContractStatus($value): bool|string
{
$dict = DictData::where('type_value','contract_status')->column('value');
if(!in_array($value,$dict)){
return '合同状态无效';
}
return true;
}
public function checkBusinessDirector($value): bool|string
{
$user = Admin::where('id',$value)->findOrEmpty();
if($user->isEmpty()){
return '业务负责人信息不存在';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
if(!is_array($value)){
return '附件格式错误';
}
}
return true;
}
public function checkReturnedMoney($value): bool|string
{
$detail = $value;//json_decode($value,true);
if(empty($detail) || !is_array($detail)){
return '回款计划数据格式错误';
}
foreach($detail as $v) {
if(isset($v['id']) && $v['id'] != ''){
$info = FinanceReturnedMoney::where('id',$v['id'])->findOrEmpty();
if($info->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['return_date'])){
return '请选择计划回款日期';
}
if(empty($v['amount'])){
return '金额不能为空';
}else{
if(!is_numeric($v['amount']) || $v['amount'] <= 0){
return '金额必须是大于0的数字';
}
}
}
return true;
}
}