101 lines
2.3 KiB
PHP
101 lines
2.3 KiB
PHP
<?php
|
|
|
|
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
|
|
{
|
|
protected $rule = [
|
|
'id' => 'require|checkPost',
|
|
'status' => 'require|in:0,1,2',
|
|
'is_top' => 'require|in:0,1',
|
|
'is_hot' => 'require|in:0,1',
|
|
'is_recommend' => 'require|in:0,1',
|
|
'sort' => 'require|integer|egt:0|elt:1000000',
|
|
'is_topic' => 'require|in:0,1',
|
|
'category_id' => 'require|integer|egt:0|checkCategory',
|
|
'content' => 'require|max:16000',
|
|
];
|
|
|
|
protected $message = [
|
|
'id.require' => '帖子id不能为空',
|
|
'status.require' => '状态不能为空',
|
|
'content.require' => '帖子内容不能为空',
|
|
'content.max' => '帖子内容不能超过16000个字符',
|
|
];
|
|
|
|
public function sceneDetail()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function sceneDelete()
|
|
{
|
|
return $this->only(['id']);
|
|
}
|
|
|
|
public function sceneStatus()
|
|
{
|
|
return $this->only(['id', 'status']);
|
|
}
|
|
|
|
public function sceneEditContent()
|
|
{
|
|
return $this->only(['id', 'content']);
|
|
}
|
|
|
|
public function sceneTop()
|
|
{
|
|
return $this->only(['id', 'is_top']);
|
|
}
|
|
|
|
public function sceneHot()
|
|
{
|
|
return $this->only(['id', 'is_hot']);
|
|
}
|
|
|
|
public function sceneRecommend()
|
|
{
|
|
return $this->only(['id', 'is_recommend']);
|
|
}
|
|
|
|
public function sceneSort()
|
|
{
|
|
return $this->only(['id', 'sort']);
|
|
}
|
|
|
|
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);
|
|
if ($post->isEmpty()) {
|
|
return '帖子不存在';
|
|
}
|
|
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;
|
|
}
|
|
}
|