getData('name'))->find()) { throw new FailedException('分类名称重复,请重新填写'); } } /** * 更新前 * * @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) { $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('分类名称重复,请重新填写'); } } } /** * 删除前 * * @time 2021年03月03日 * @param $category * @return void */ public static function onBeforeDelete($category) { if ($category->hasNextLevel()) { throw new FailedException('存在下级栏目, 无法删除'); } } }