Files
2026-06-11 12:15:29 +08:00

56 lines
1.3 KiB
PHP

<?php
namespace app\adminapi\validate\points;
use app\common\validate\BaseValidate;
use app\common\model\points\PointsProduct;
class PointsProductValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|checkProduct',
'name' => 'require|length:1,50',
'points' => 'require|integer|gt:0',
'amount' => 'require|float|gt:0',
];
protected $message = [
'id.require' => '商品id不能为空',
'name.require' => '商品名称不能为空',
'name.length' => '商品名称长度须在1-50位字符',
'points.require' => '积分数不能为空',
'points.integer' => '积分数须为整数',
'points.gt' => '积分数须大于0',
'amount.require' => '金额不能为空',
'amount.gt' => '金额须大于0',
];
public function sceneAdd()
{
return $this->remove('id', 'require|checkProduct');
}
public function sceneEdit()
{
}
public function sceneDetail()
{
return $this->only(['id']);
}
public function sceneDelete()
{
return $this->only(['id']);
}
public function checkProduct($value)
{
$product = PointsProduct::findOrEmpty($value);
if ($product->isEmpty()) {
return '积分商品不存在';
}
return true;
}
}