official_website/app/validate/BaseValidate.php

51 lines
1.3 KiB
PHP
Raw Normal View History

2024-12-02 13:57:08 +08:00
<?php
namespace app\validate;
use app\lib\exception\Parameter;
use think\Exception;
use think\Validate;
class BaseValidate extends Validate
{
/**
* ['name'=>'aa','pid'=>1,'cc'=>1]
* @param $arrays
* @return array
* @throws Parameter
*/
public function getDataByRule($arrays){
$currentScene = $this->currentScene;
$scene = $this->scene;
if(!array_key_exists($currentScene, $scene)){
throw new Exception("效验scene值不存在");
}
$rules = $scene[$currentScene];
$newArray = [];
foreach ($rules as $value){
$newArray[$value] = $arrays[$value];
}
return $newArray;
}
protected function canBeEmpty($value, $rule='', $data='', $field=''){
return true;
}
public function isCommaString($value, $rule='', $data='', $field=''){
if(strpos($value, ',')){
$spec_values = explode(',', $value);
foreach($spec_values as $spec_value){
if(!is_numeric($spec_value) || $spec_value == 0){
return $field.'格式错误';
}
}
}elseif(!is_numeric($value) || $value == 0){
return $field.'格式错误';
}
return true;
}
}