<?php
<364666827@qq.com>,开发者QQ群:50304283
namespace app\system\model;
use think\Model;
class SystemHook extends Model
{
protected $createTime = 'ctime';
protected $updateTime = 'mtime';
protected $autoWriteTimestamp = true;
/**
* 钩子入库
* @param array $data 入库数据
* @author 橘子俊 <364666827@qq.com>
* @return bool
*/
public function storage($data = [])
{
if (empty($data)) {
$data = request()->post();
}
if (self::where('name', $data['name'])->find()) {
return true;
}
$validate = new \app\system\validate\Hook;;
if($validate->check($data) !== true) {
$this->error = $validate->getError();
return false;
}
if (isset($data['id']) && !empty($data['id'])) {
$res = $this->update($data);
} else {
$res = $this->create($data);
}
if (!$res) {
$this->error = '保存失败!';
return false;
}
return $res;
}
/**
* 删除钩子
* @param string $source 来源名称
* @author 橘子俊 <364666827@qq.com>
* @return bool
*/
public static function delHook($source = '')
{
if (empty($source)) {
return false;
}
if (self::where('source', $source)->delete() === false) {
return false;
}
return true;
}
}