批量操作日志处理

This commit is contained in:
Anyon 2020-09-19 18:38:15 +08:00
parent 67ed38ffda
commit 6f956670f0
9 changed files with 59 additions and 19 deletions

View File

@ -14,8 +14,21 @@
// +----------------------------------------------------------------------
use think\admin\service\AdminService;
use think\admin\service\SystemService;
use think\helper\Str;
/*! 全局操作日志数据 */
$GLOBALS['oplogs'] = [];
/*! 操作日志批量写入日志 */
app()->event->listen('HttpEnd', function () {
if (is_array($GLOBALS['oplogs']) && count($GLOBALS['oplogs']) > 0) {
foreach (array_chunk($GLOBALS['oplogs'], 100) as $items) {
app()->db->name('SystemOplog')->insertAll($items);
}
}
});
/*! SQL 监听分析记录日志 */
app()->db->listen(function ($sqlstr) {
[$type,] = explode(' ', $sqlstr);
@ -24,18 +37,18 @@ app()->db->listen(function ($sqlstr) {
if (preg_match('/^INSERT\s+INTO\s+`(.*?)`\s+SET\s+(.*?)\s*$/i', $sqlstr, $matches)) {
if (stripos($matches[1] = Str::studly($matches[1]), 'SystemOplog') === false) {
$matches[2] = substr(str_replace(['`', '\''], '', $matches[2]), 0, 200);
return sysoplog("添加数据 {$matches[1]}", "添加数据:{$matches[2]}");
$GLOBALS['oplogs'][] = SystemService::instance()->getOplog("添加数据 {$matches[1]}", "添加数据:{$matches[2]}");
}
} elseif (preg_match('/^UPDATE\s+`(.*?)`\s+SET\s+(.*?)\s+WHERE\s+(.*?)\s*$/i', $sqlstr, $matches)) {
if (stripos($matches[1] = Str::studly($matches[1]), 'SystemOplog') === false) {
$matches[3] = substr(str_replace(['`', '\''], '', $matches[3]), 0, 200);
$matches[2] = substr(str_replace(['`', '\''], '', $matches[2]), 0, 200);
return sysoplog("更新数据 {$matches[1]} {$matches[3]} ", "更新内容{$matches[2]}");
$GLOBALS['oplogs'][] = SystemService::instance()->getOplog("更新数据 {$matches[1]} {$matches[3]} ", "更新内容 {$matches[2]}");
}
} elseif (preg_match('/^DELETE\s*FROM\s*`(.*?)`\s*WHERE\s*(.*?)\s*$/i', $sqlstr, $matches)) {
if (stripos($matches[1] = Str::studly($matches[1]), 'SystemOplog') === false) {
$matches[2] = str_replace(['`', '\''], '', $matches[2]);
return sysoplog("删除数据 {$matches[1]}", "删除条件{$matches[2]}");
$GLOBALS['oplogs'][] = SystemService::instance()->getOplog("删除数据 {$matches[1]}", "删除条件 {$matches[2]}");
}
}
}

View File

@ -79,7 +79,7 @@ class TruckService extends Service
*/
public function query($code, $number)
{
return $this->_getInterface()->doRequest('https://open.cuci.cc/user/api.auth.express/query', [
return $this->_getInterface()->doRequest('api.auth.express/query', [
'type' => 'free', 'express' => $code, 'number' => $number,
]);
}
@ -91,7 +91,7 @@ class TruckService extends Service
*/
public function company()
{
return $this->_getInterface()->doRequest('https://open.cuci.cc/user/api.auth.express/getCompany');
return $this->_getInterface()->doRequest('api.auth.express/getCompany');
}
/**
@ -101,7 +101,8 @@ class TruckService extends Service
private function _getInterface(): InterfaceService
{
$service = InterfaceService::instance();
// 测试的账号及密钥,随时可能会变更,请联系客服获取自己的账号和密钥
// 测试的账号及密钥随时可能会变更,请联系客服更新
$service->getway('https://open.cuci.cc/user/');
$service->setAuth("6998081316132228", "193fc1d9a2aac78475bc8dbeb9a5feb1");
return $service;
}

View File

@ -216,16 +216,18 @@ return array(
'app\\data\\controller\\ShopGoods' => $baseDir . '/app/data/controller/ShopGoods.php',
'app\\data\\controller\\ShopGoodsCate' => $baseDir . '/app/data/controller/ShopGoodsCate.php',
'app\\data\\controller\\ShopGoodsMark' => $baseDir . '/app/data/controller/ShopGoodsMark.php',
'app\\data\\controller\\ShopGoodsStock' => $baseDir . '/app/data/controller/ShopGoodsStock.php',
'app\\data\\controller\\ShopOrder' => $baseDir . '/app/data/controller/ShopOrder.php',
'app\\data\\controller\\ShopOrderSend' => $baseDir . '/app/data/controller/ShopOrderSend.php',
'app\\data\\controller\\ShopOrderService' => $baseDir . '/app/data/controller/ShopOrderService.php',
'app\\data\\controller\\ShopTruckCompany' => $baseDir . '/app/data/controller/ShopTruckCompany.php',
'app\\data\\controller\\ShopTruckTemplate' => $baseDir . '/app/data/controller/ShopTruckTemplate.php',
'app\\data\\controller\\api\\Auth' => $baseDir . '/app/data/controller/api/Auth.php',
'app\\data\\controller\\api\\Data' => $baseDir . '/app/data/controller/api/Data.php',
'app\\data\\controller\\api\\Goods' => $baseDir . '/app/data/controller/api/Goods.php',
'app\\data\\controller\\api\\Login' => $baseDir . '/app/data/controller/api/Login.php',
'app\\data\\controller\\api\\News' => $baseDir . '/app/data/controller/api/News.php',
'app\\data\\controller\\api\\Notify' => $baseDir . '/app/data/controller/api/Notify.php',
'app\\data\\controller\\api\\Wechat' => $baseDir . '/app/data/controller/api/Wechat.php',
'app\\data\\controller\\api\\Wxapp' => $baseDir . '/app/data/controller/api/Wxapp.php',
'app\\data\\controller\\api\\auth\\Address' => $baseDir . '/app/data/controller/api/auth/Address.php',
'app\\data\\controller\\api\\auth\\Center' => $baseDir . '/app/data/controller/api/auth/Center.php',

View File

@ -353,16 +353,18 @@ class ComposerStaticInit7ad2dfd941224dedfd9e69a3187017d8
'app\\data\\controller\\ShopGoods' => __DIR__ . '/../..' . '/app/data/controller/ShopGoods.php',
'app\\data\\controller\\ShopGoodsCate' => __DIR__ . '/../..' . '/app/data/controller/ShopGoodsCate.php',
'app\\data\\controller\\ShopGoodsMark' => __DIR__ . '/../..' . '/app/data/controller/ShopGoodsMark.php',
'app\\data\\controller\\ShopGoodsStock' => __DIR__ . '/../..' . '/app/data/controller/ShopGoodsStock.php',
'app\\data\\controller\\ShopOrder' => __DIR__ . '/../..' . '/app/data/controller/ShopOrder.php',
'app\\data\\controller\\ShopOrderSend' => __DIR__ . '/../..' . '/app/data/controller/ShopOrderSend.php',
'app\\data\\controller\\ShopOrderService' => __DIR__ . '/../..' . '/app/data/controller/ShopOrderService.php',
'app\\data\\controller\\ShopTruckCompany' => __DIR__ . '/../..' . '/app/data/controller/ShopTruckCompany.php',
'app\\data\\controller\\ShopTruckTemplate' => __DIR__ . '/../..' . '/app/data/controller/ShopTruckTemplate.php',
'app\\data\\controller\\api\\Auth' => __DIR__ . '/../..' . '/app/data/controller/api/Auth.php',
'app\\data\\controller\\api\\Data' => __DIR__ . '/../..' . '/app/data/controller/api/Data.php',
'app\\data\\controller\\api\\Goods' => __DIR__ . '/../..' . '/app/data/controller/api/Goods.php',
'app\\data\\controller\\api\\Login' => __DIR__ . '/../..' . '/app/data/controller/api/Login.php',
'app\\data\\controller\\api\\News' => __DIR__ . '/../..' . '/app/data/controller/api/News.php',
'app\\data\\controller\\api\\Notify' => __DIR__ . '/../..' . '/app/data/controller/api/Notify.php',
'app\\data\\controller\\api\\Wechat' => __DIR__ . '/../..' . '/app/data/controller/api/Wechat.php',
'app\\data\\controller\\api\\Wxapp' => __DIR__ . '/../..' . '/app/data/controller/api/Wxapp.php',
'app\\data\\controller\\api\\auth\\Address' => __DIR__ . '/../..' . '/app/data/controller/api/auth/Address.php',
'app\\data\\controller\\api\\auth\\Center' => __DIR__ . '/../..' . '/app/data/controller/api/auth/Center.php',

View File

@ -958,17 +958,17 @@
},
{
"name": "zoujingli/think-library",
"version": "v6.0.8",
"version_normalized": "6.0.8.0",
"version": "v6.0.9",
"version_normalized": "6.0.9.0",
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "686db8b3131f4cec0f5f5927338baba4580d65c5"
"reference": "6fa904cad8bde5b2d04750d17323fe715a0c2b4d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/686db8b3131f4cec0f5f5927338baba4580d65c5",
"reference": "686db8b3131f4cec0f5f5927338baba4580d65c5",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/6fa904cad8bde5b2d04750d17323fe715a0c2b4d",
"reference": "6fa904cad8bde5b2d04750d17323fe715a0c2b4d",
"shasum": "",
"mirrors": [
{
@ -985,7 +985,7 @@
"ext-mbstring": "*",
"topthink/framework": "^6.0"
},
"time": "2020-09-14T08:48:48+00:00",
"time": "2020-09-19T10:23:24+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-09-14 16:57:43
// This file is automatically generated at:2020-09-19 18:29:10
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',

View File

@ -41,7 +41,7 @@ class Library extends Service
/**
* 扩展库版本号
*/
const VERSION = '6.0.8';
const VERSION = '6.0.9';
/**
* 启动服务

View File

@ -116,6 +116,17 @@ class InterfaceService extends Service
return $this;
}
/**
* 设置接口网关地址
* @param string $getway
* @return $this
*/
public function getway(string $getway)
{
$this->baseurl = $getway;
return $this;
}
/**
* 获取请求数据
* @param boolean $check 验证数据

View File

@ -176,19 +176,30 @@ class SystemService extends Service
}
/**
* 写入系统日志
* 写入系统日志内容
* @param string $action
* @param string $content
* @return integer
*/
public function setOplog($action, $content)
{
return $this->app->db->name('SystemOplog')->insert([
return $this->app->db->name('SystemOplog')->insert($this->getOplog($action, $content));
}
/**
* 获取系统日志内容
* @param string $action
* @param string $content
* @return array
*/
public function getOplog($action, $content)
{
return [
'node' => NodeService::instance()->getCurrent(),
'action' => $action, 'content' => $content,
'geoip' => $this->app->request->ip() ?: '127.0.0.1',
'username' => AdminService::instance()->getUserName() ?: '-',
]);
];
}
/**