engineering/app/adminapi/validate/marketing/MarketingBusinessOpportunityValidate.php
2024-04-11 17:36:55 +08:00

230 lines
6.5 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\marketing;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dict\DictData;
use app\common\model\marketing\MarketingBusinessOpportunity;
use app\common\model\marketing\MarketingCustom;
use app\common\validate\BaseValidate;
/**
* 市场经营--投标管理--业务机会验证器
* Class MarketingBusinessOpportunityValidate
* @package app\adminapi\validate\marketing
*/
class MarketingBusinessOpportunityValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'project_name' => 'require',
'bid_date' => 'require|dateFormat:Y-m-d',
'construct_company' => 'require|checkConstructCompany',
'management_company' => 'require',
'business_nature' => 'checkBusinessNature',
'industry_nature' => 'checkIndustryNature',
'info_sources' => 'checkInfoSources',
'fund_sources' => 'checkFundSources',
'const_area' => 'checkConstArea',
'total_investment' => 'float|egt:0',
'jianan_investment' => 'float|egt:0',
'head' => 'checkHead',
'dept' => 'checkDept',
'leader' => 'checkLeader',
'annex' => 'checkAnnex',
'flow_id' => 'require|checkFlow',
'path' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_name' => '项目名称',
'project_code' => '项目编号',
'bid_date' => '预计招标日期',
'construct_company' => '建设单位',
'management_company' => '建设管理单位',
'business_nature' => '业务性质',
'industry_nature' => '行业性质',
'info_sources' => '消息来源',
'fund_sources' => '资金来源',
'const_area' => '建设区域',
'project_address' => '项目地点',
'total_investment' => '工程总投资',
'jianan_investment' => '建安投资额',
'project_overview' => '工程概况',
'remark' => '备注',
'head' => '负责人',
'dept' => '负责部门',
'leader' => '分管领导',
'contacts' => '联系人信息',
'flow_id' => '审批流id',
'path' => '路径',
];
/**
* @notes 添加场景
* @return MarketingBusinessOpportunityValidate
* @author likeadmin
* @date 2024/04/11 14:27
*/
public function sceneAdd()
{
return $this->remove('id', true)->remove('flow_id', true)->remove('path', true);
}
/**
* @notes 编辑场景
* @return MarketingBusinessOpportunityValidate
* @author likeadmin
* @date 2024/04/11 14:27
*/
public function sceneEdit()
{
return $this->remove('flow_id', true)->remove('path', true);
}
/**
* @notes 删除场景
* @return MarketingBusinessOpportunityValidate
* @author likeadmin
* @date 2024/04/11 14:27
*/
public function sceneDelete()
{
return $this->only(['id'])->remove('id', 'checkData');
}
/**
* @notes 详情场景
* @return MarketingBusinessOpportunityValidate
* @author likeadmin
* @date 2024/04/11 14:27
*/
public function sceneDetail()
{
return $this->only(['id']);
}
/**
* @notes 审批场景
* @return MarketingBusinessOpportunityValidate
* @author likeadmin
* @date 2024/04/11 14:27
*/
public function sceneApprove()
{
return $this->only(['id', 'flow_id', 'path']);
}
public function checkData($value): bool|string
{
$data = MarketingBusinessOpportunity::where('id', $value)->findOrEmpty();
return $data->isEmpty() ? '数据不存在' : true;
}
public function checkConstructCompany($value): bool|string
{
$data = MarketingCustom::where('id', $value)->findOrEmpty();
return $data->isEmpty() ? '建设单位数据不存在' : true;
}
public function checkBusinessNature($value): bool|string
{
if (empty($value)) return true;
$dict = DictData::where('type_value', 'cost_consultation_business_nature')->column('value');
if (!in_array($value, $dict)) {
return '业务性质数据值无效';
}
return true;
}
public function checkIndustryNature($value): bool|string
{
if (empty($value)) return true;
$dict = DictData::where('type_value', 'cost_consultation_industry_nature')->column('value');
if (!in_array($value, $dict)) {
return '行业性质数据值无效';
}
return true;
}
public function checkInfoSources($value): bool|string
{
if (empty($value)) return true;
$dict = DictData::where('type_value', 'info_sources')->column('value');
if (!in_array($value, $dict)) {
return '消息来源数据值无效';
}
return true;
}
public function checkFundSources($value): bool|string
{
if (empty($value)) return true;
$dict = DictData::where('type_value', 'cost_consultation_fund_sources')->column('value');
if (!in_array($value, $dict)) {
return '资金来源数据值无效';
}
return true;
}
public function checkConstArea($value): bool|string
{
if (empty($value)) return true;
$dict = DictData::where('type_value', 'cost_consultation_const_area')->column('value');
if (!in_array($value, $dict)) {
return '建设区域数据值无效';
}
return true;
}
public function checkHead($value): bool|string
{
if (empty($value)) return true;
$data = Admin::where('id', $value)->findOrEmpty();
return $data->isEmpty() ? '负责人数据不存在' : true;
}
public function checkDept($value): bool|string
{
if (empty($value)) return true;
$data = Dept::where('id', $value)->findOrEmpty();
return $data->isEmpty() ? '负责部门数据不存在' : true;
}
public function checkLeader($value): bool|string
{
if (empty($value)) return true;
$data = Admin::where('id', $value)->findOrEmpty();
return $data->isEmpty() ? '分管领导数据不存在' : true;
}
}