* @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function addHooks($hooks = [], $plugin_name = '') { if (!empty($hooks) && is_array($hooks)) { $data = []; foreach ($hooks as $name => $description) { if (is_numeric($name)) { $name = $description; $description = ''; } if (self::where('name', $name)->find()) { continue; } $data[] = [ 'name' => $name, 'plugin' => $plugin_name, 'description' => $description, 'create_time' => request()->time(), 'update_time' => request()->time(), ]; } if (!empty($data) && false === self::insertAll($data)) { return false; } } return true; } /** * 删除钩子 * @param string $plugin_name 钩子名称 * @author 蔡伟明 <314013107@qq.com> * @return bool * @throws \think\Exception * @throws \think\exception\PDOException */ public static function deleteHooks($plugin_name = '') { if (!empty($plugin_name)) { if (false === self::where('plugin', $plugin_name)->delete()) { return false; } } return true; } }