<?php
/**
* @author 龙虾 <15108148@qq.com>
* @version 2.0 2020-08-31
* @copyright 睿谷信息 <www.rgxx.com>
*/
namespace app\admin\model;
use think\Model;

class Hooks extends Model
{
	// 检查钩子命名
	public static function checkHook($hooks)
	{
		$hooks_a = explode(',',$hooks);
		$local_hooks = self::column('name');
		if(array_intersect($local_hooks,$hooks_a)){
			return false;
		}
		return true;
	}


	// 添加钩子
	public static function addhooks($hooks,$addon_name)
	{
		$data = [];
		$hooks_a = explode(',',$hooks);
        foreach ($hooks_a as $v) {
            $data[] = [
                'name'        => $v,
                'addon_name'  => $addon_name,
                'create_time' => time(),
                'update_time' => time(),
            ];
        }
        if (!self::insertAll($data)) {
            return false;
        }
        return true;
	}

	// 删除钩子
	public static function deletehooks($addon_name)
    {
        if (false === self::where('addon_name', $addon_name)->delete()) {
            return false;
        } else {
        	return true;
        }
    }
}