From e105bef4601c57f9a20a6174793bd23116cc7e2e Mon Sep 17 00:00:00 2001 From: JaguarJack <82664165@qq.com> Date: Mon, 24 May 2021 21:08:01 +0800 Subject: [PATCH] update cms category event --- catch/cms/model/events/CategoryEvent.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/catch/cms/model/events/CategoryEvent.php b/catch/cms/model/events/CategoryEvent.php index dd4e591..0bd931b 100644 --- a/catch/cms/model/events/CategoryEvent.php +++ b/catch/cms/model/events/CategoryEvent.php @@ -13,6 +13,7 @@ namespace catchAdmin\cms\model\events; +use catcher\exceptions\CatchException; use catcher\exceptions\FailedException; use catcher\Utils; @@ -24,10 +25,15 @@ trait CategoryEvent * @time 2021年03月03日 * @param \think\Model $category * @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 { - + if (self::where('name', $category->getData('name'))->find()) { + throw new FailedException('分类名称重复,请重新填写'); + } } /** @@ -36,10 +42,17 @@ trait CategoryEvent * @time 2021年03月03日 * @param \think\Model $category * @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) { - + $where = $category->getWhere(); + + if (self::where('name', $category->getData('name'))->where('id', '<>', $where['id'])->find()) { + throw new FailedException('分类名称重复,请重新填写'); + } } /**