Merge branch 'master' of https://gitee.com/jaguarjack/catchAdmin
This commit is contained in:
commit
d97b5f62ee
@ -61,6 +61,8 @@ class Category extends BaseModel
|
|||||||
'deleted_at',
|
'deleted_at',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
protected $updateChildrenFields = ['status'];
|
||||||
|
|
||||||
const LIST_TYPE = 1; // 列表
|
const LIST_TYPE = 1; // 列表
|
||||||
const PAGE_TYPE = 2; // 单页
|
const PAGE_TYPE = 2; // 单页
|
||||||
const COVER_TYPE = 3; // 封面
|
const COVER_TYPE = 3; // 封面
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
namespace catchAdmin\cms\model\events;
|
namespace catchAdmin\cms\model\events;
|
||||||
|
|
||||||
|
use catcher\exceptions\CatchException;
|
||||||
use catcher\exceptions\FailedException;
|
use catcher\exceptions\FailedException;
|
||||||
use catcher\Utils;
|
use catcher\Utils;
|
||||||
|
|
||||||
@ -24,10 +25,15 @@ trait CategoryEvent
|
|||||||
* @time 2021年03月03日
|
* @time 2021年03月03日
|
||||||
* @param \think\Model $category
|
* @param \think\Model $category
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public static function onBeforeInsert(\think\Model $category): void
|
public static function onBeforeInsert(\think\Model $category): void
|
||||||
{
|
{
|
||||||
|
if (self::where('name', $category->getData('name'))->find()) {
|
||||||
|
throw new FailedException('分类名称重复,请重新填写');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,10 +42,21 @@ trait CategoryEvent
|
|||||||
* @time 2021年03月03日
|
* @time 2021年03月03日
|
||||||
* @param \think\Model $category
|
* @param \think\Model $category
|
||||||
* @return mixed|void
|
* @return mixed|void
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public static function onBeforeUpdate(\think\Model $category)
|
public static function onBeforeUpdate(\think\Model $category)
|
||||||
{
|
{
|
||||||
|
$data = $category->getData();
|
||||||
|
|
||||||
|
if (isset($data['name'])) {
|
||||||
|
$where = $category->getWhere();
|
||||||
|
|
||||||
|
if (self::where('name', $category->getData('name'))->where('id', '<>', $where['id'])->find()) {
|
||||||
|
throw new FailedException('分类名称重复,请重新填写');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -184,7 +184,7 @@ trait BaseOptionsTrait
|
|||||||
if (!empty($this->updateChildrenFields)) {
|
if (!empty($this->updateChildrenFields)) {
|
||||||
if (is_array($this->updateChildrenFields)) {
|
if (is_array($this->updateChildrenFields)) {
|
||||||
foreach ($data as $field => $value) {
|
foreach ($data as $field => $value) {
|
||||||
if (in_array($field, $this->updateChildrenFields)) {
|
if (! in_array($field, $this->updateChildrenFields)) {
|
||||||
unset($data[$field]);
|
unset($data[$field]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user