check($params, [], $scene)) { $this->error($validate->getError()); } } else { // 添加自定义验证场景,字段为当前提交的所有字段 $validate->scene('custom', array_keys($params)); if (!$validate->check($params, [], 'custom')) { $this->error($validate->getError()); } } return true; } /** * 过滤前端发来的短时间内的重复的请求 * * @return void */ public function repeatFilter($flag = null, $expire = 5) { $key = ''; $ip = request()->ip(); if (!$flag) { $flag = request()->baseUrl(); } $key = 'shopro:' . $flag . ':' . $ip; if (redis_cache('?' . $key)) { error_stop('请稍后再试'); } // 缓存 5 秒 redis_cache($key, time(), $expire); } /** * 监听数据库 sql * * @return void */ public function dbListen() { \think\Db::listen(function ($sql, $time) { echo $sql . ' [' . $time . 's]' . "
"; }); } }