feat: add community post categories and channels

This commit is contained in:
hajimi
2026-08-02 17:39:52 +08:00
parent 95f03af60e
commit b0b278d11f
18 changed files with 1132 additions and 12 deletions
@@ -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;
}
}