65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\validate\community;
|
|
|
|
use app\common\model\community\CommunityCategory;
|
|
use app\common\validate\BaseValidate;
|
|
|
|
class CommunityCategoryValidate extends BaseValidate
|
|
{
|
|
protected $rule = [
|
|
'id' => 'require|checkCategory',
|
|
'name' => 'require|length:1,50|checkNameUnique',
|
|
'icon' => 'max:500',
|
|
'sort' => 'integer|egt:0',
|
|
'status' => 'in:0,1',
|
|
];
|
|
|
|
protected $message = [
|
|
'id.require' => '分类id不能为空',
|
|
'name.require' => '分类名称不能为空',
|
|
'name.length' => '分类名称长度须在1-50位字符',
|
|
'icon.max' => '分类图标地址不能超过500个字符',
|
|
'sort.integer' => '排序值必须为整数',
|
|
'sort.egt' => '排序值不能小于0',
|
|
'status.in' => '分类状态值错误',
|
|
];
|
|
|
|
public function sceneAdd()
|
|
{
|
|
return $this->remove('id', 'require|checkCategory');
|
|
}
|
|
|
|
public function sceneEdit()
|
|
{
|
|
}
|
|
|
|
public function sceneDetail()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function sceneDelete()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function checkCategory($value)
|
|
{
|
|
$category = CommunityCategory::findOrEmpty($value);
|
|
if ($category->isEmpty()) {
|
|
return '分类不存在';
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function checkNameUnique($value, $rule, $data)
|
|
{
|
|
$query = CommunityCategory::where('name', trim((string) $value));
|
|
if (!empty($data['id'])) {
|
|
$query->where('id', '<>', (int) $data['id']);
|
|
}
|
|
return $query->count() > 0 ? '分类名称已存在' : true;
|
|
}
|
|
}
|