168 lines
4.2 KiB
PHP
168 lines
4.2 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\custom;
|
||
|
||
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\validate\BaseValidate;
|
||
|
||
|
||
/**
|
||
* Custom验证器
|
||
* Class CustomValidate
|
||
* @package app\adminapi\validate\custom
|
||
*/
|
||
class CustomValidate extends BaseValidate
|
||
{
|
||
|
||
/**
|
||
* 设置校验规则
|
||
* @var string[]
|
||
*/
|
||
protected $rule = [
|
||
'id' => 'require',
|
||
'org_id' => 'require|checkOrg',
|
||
'dept_id' => 'require|checkDept',
|
||
'name' => 'require|unique:'.Custom::class,
|
||
'custom_type' => 'require|checkType',
|
||
'phone' => 'require',
|
||
'credit_rating' => 'require|checkRat',
|
||
'master_name' => 'require',
|
||
'master_phone' => 'mobile',
|
||
'master_email' => 'email',
|
||
'other_contacts' => 'checkContacts'
|
||
];
|
||
|
||
|
||
protected $message = [
|
||
'id.require' => '缺少必要参数',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_id.require' => '请选择部门',
|
||
'name.require' => '请填写客户名称',
|
||
'name.unique' => '客户名称已存在',
|
||
'custom_type.require' => '请选择客户属性',
|
||
'phone.require' => '请填写客户电话',
|
||
'credit_rating.require' => '请选择信用度',
|
||
'master_name.require' => '请填写主要负责人姓名',
|
||
'master_phone.mobile' => '主要负责人手机号格式错误',
|
||
'master_email.email' => '主要负责人邮箱格式错误',
|
||
];
|
||
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return CustomValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/11 22:10
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', true);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return CustomValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/11 22:10
|
||
*/
|
||
public function sceneEdit()
|
||
{}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return CustomValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/11 22:10
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return CustomValidate
|
||
* @author likeadmin
|
||
* @date 2023/11/11 22:10
|
||
*/
|
||
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 checkType($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value','custom_type')->column('value');
|
||
if(!in_array($value,$dictData)){
|
||
return '客户属性无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkRat($value): bool|string
|
||
{
|
||
$dictData = DictData::where('type_value','credit_rating')->column('value');
|
||
if(!in_array($value,$dictData)){
|
||
return '信用度无效';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkContacts($value): bool|string
|
||
{
|
||
if(empty($value) || !is_array($value)){
|
||
return '其他联系人数据格式错误';
|
||
}
|
||
foreach($value as $v){
|
||
if(empty($v['name'])){
|
||
return '请填写联系人姓名';
|
||
}
|
||
if(isset($v['annex']) && $v['annex'] != ''){
|
||
if(!is_array($v['annex'])){
|
||
return '联系人附件格式错误';
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |