engineering/app/adminapi/validate/supplier/SupplierContactsValidate.php
2024-01-21 09:43:44 +08:00

147 lines
3.6 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\supplier;
use app\common\model\dict\DictData;
use app\common\model\supplier\Supplier;
use app\common\validate\BaseValidate;
/**
* SupplierContacts验证器
* Class SupplierContactsValidate
* @package app\adminapi\validate\supplier
*/
class SupplierContactsValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'supplier_id' => 'require|checkSupplier',
'name' => 'require',
'sex' => 'in:0,1',
'birthday' => 'dateFormat:Y-m-d',
'contacts_type' => 'checkContactsType',
'contacts_cate' => 'checkContactsCate',
'id_type' => 'checkIdType',
'annex' => 'checkAnnex'
];
protected $message = [
'id.require' => '缺少必要参数',
'supplier_id.require' => '请选择供应商',
'name.require' => '请填写姓名',
'sex.in' => '性别值无效',
'birthday.dateFormat' => '出生日期数据格式错误',
];
/**
* @notes 添加场景
* @return SupplierContactsValidate
* @author likeadmin
* @date 2023/12/26 13:47
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return SupplierContactsValidate
* @author likeadmin
* @date 2023/12/26 13:47
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return SupplierContactsValidate
* @author likeadmin
* @date 2023/12/26 13:47
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SupplierContactsValidate
* @author likeadmin
* @date 2023/12/26 13:47
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkSupplier($value): bool|string
{
$supplier = Supplier::where('id',$value)->findOrEmpty();
if($supplier->isEmpty()){
return '供应商信息不存在';
}
return true;
}
public function checkContactsType($value): bool|string
{
$dict = DictData::where('type_value','contacts_type')->column('value');
if(!in_array($value,$dict)){
return '联系人分类无效';
}
return true;
}
public function checkContactsCate($value): bool|string
{
$dict = DictData::where('type_value','contacts_cate')->column('value');
if(!in_array($value,$dict)){
return '联系人类型无效';
}
return true;
}
public function checkIdType($value): bool|string
{
$dict = DictData::where('type_value','id_type')->column('value');
if(!in_array($value,$dict)){
return '证件类型无效';
}
return true;
}
public function checkAnnex($value): bool|string
{
if(!empty($value) && $value != ''){
if(!is_array($value)){
return '附件格式错误';
}
}
return true;
}
}