class
OrderPlace
extends
BaseValidate
{
protected
$rule
= [
'products'
=>
'checkProducts'
];
protected
$singleRule
= [
'product_id'
=>
'require|isPositiveInteger'
,
'count'
=>
'require|isPositiveInteger'
,
];
protected
function
checkProducts(
$values
)
{
...
foreach
(
$values
as
$value
)
{
$this
->checkProduct(
$value
);
}
return
true;
}
protected
function
checkProduct(
$value
)
{
$validate
=
new
BaseValidate(
$this
->singleRule);
$result
=
$validate
->check(
$value
);
if
(!
$result
){
throw
new
ParameterException([
'msg'
=>
'商品列表参数错误'
,
]);
}
}
}