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

181 lines
4.7 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\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\dict\DictData;
use app\common\validate\BaseValidate;
/**
* Supplier验证器
* Class SupplierValidate
* @package app\adminapi\validate\supplier
*/
class SupplierValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'create_user_id' => 'require|checkCreateUser',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'supplier_name' => 'require',
'supplier_photos' => 'checkAnnex',
'supplier_group' => 'checkSupplierGroup',
'supplier_category' => 'checkSupplierCategory',
'supplier_grade' => 'checkSupplierGrade',
'contacts_sex' => 'in:0,1',
'birthday' => 'dateFormat:Y-m-d',
'annex' => 'checkAnnex',
'init_invoice_amount' => 'float|egt:0',
'credit_limit' => 'float|egt:0',
];
protected $message = [
'id.require' => '缺少必要参数',
'create_user_id.require' => '请选择建档人',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'supplier_name.require' => '请填写供应商名称',
'contacts_sex.in' => '联系人性别无效',
'birthday.dateFormat' => '出生日期数据格式错误',
'init_invoice_amount.float' => '期初未开票金额值必须是数字',
'init_invoice_amount.egt' => '期初未开票金额值必须大于等于0',
'credit_limit.float' => '授信额度值必须是数字',
'credit_limit.egt' => '授信额度值必须大于等于0',
];
/**
* @notes 添加场景
* @return SupplierValidate
* @author likeadmin
* @date 2023/12/26 10:56
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return SupplierValidate
* @author likeadmin
* @date 2023/12/26 10:56
*/
public function sceneEdit()
{}
/**
* @notes 删除场景
* @return SupplierValidate
* @author likeadmin
* @date 2023/12/26 10:56
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return SupplierValidate
* @author likeadmin
* @date 2023/12/26 10:56
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkCreateUser($value): bool|string
{
$user = Admin::where('id',$value)->findOrEmpty();
if($user->isEmpty()){
return '建档人信息不存在';
}
return true;
}
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 checkSupplierGroup($value): bool|string
{
$dict = DictData::where('type_value','supplier_group')->column('value');
if(!in_array($value,$dict)){
return '供应商分组无效';
}
return true;
}
public function checkSupplierCategory($value): bool|string
{
$dict = DictData::where('type_value','supplier_category')->column('value');
if(!in_array($value,$dict)){
return '供应商分类无效';
}
return true;
}
public function checkSupplierGrade($value): bool|string
{
$dict = DictData::where('type_value','supplier_grade')->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;
}
}