feat: add community post categories and channels
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace app\adminapi\validate\community;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\community\CommunityCategory;
|
||||
use app\common\model\community\CommunityPost;
|
||||
|
||||
class CommunityPostValidate extends BaseValidate
|
||||
@@ -13,6 +14,8 @@ class CommunityPostValidate extends BaseValidate
|
||||
'is_top' => 'require|in:0,1',
|
||||
'is_hot' => 'require|in:0,1',
|
||||
'is_recommend' => 'require|in:0,1',
|
||||
'is_topic' => 'require|in:0,1',
|
||||
'category_id' => 'require|integer|egt:0|checkCategory',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
@@ -50,6 +53,16 @@ class CommunityPostValidate extends BaseValidate
|
||||
return $this->only(['id', 'is_recommend']);
|
||||
}
|
||||
|
||||
public function sceneTopic()
|
||||
{
|
||||
return $this->only(['id', 'is_topic']);
|
||||
}
|
||||
|
||||
public function sceneCategory()
|
||||
{
|
||||
return $this->only(['id', 'category_id']);
|
||||
}
|
||||
|
||||
public function checkPost($value)
|
||||
{
|
||||
$post = CommunityPost::findOrEmpty($value);
|
||||
@@ -58,4 +71,16 @@ class CommunityPostValidate extends BaseValidate
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkCategory($value)
|
||||
{
|
||||
if ((int) $value === 0) {
|
||||
return true;
|
||||
}
|
||||
$category = CommunityCategory::where('id', $value)->where('status', 1)->findOrEmpty();
|
||||
if ($category->isEmpty()) {
|
||||
return '帖子分类不存在或已禁用';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user