fix: 解决访问没有埋点的问题

This commit is contained in:
2025-11-10 17:28:52 +08:00
parent e440631275
commit 57dea2ca87
38 changed files with 4172 additions and 1624 deletions

View File

@@ -30,25 +30,26 @@ class StatShop extends BaseModel
*/
public function addShopStat($data)
{
log_write('店铺按天新统计数据开始添加', 'debug');
$site_id = $data['site_id'] ?? 1;
log_write('店铺按天新统计数据开始添加site_id'.$site_id, 'debug');
try{
$carbon = Carbon::now();
$dir = __UPLOAD__.'/stat/stat_shop/';
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
return $this->error(sprintf('Directory "%s" was not created', $dir));
}
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_'.$carbon->second.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_shop',$data['site_id']);
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_'.$carbon->second.'_s'.$site_id.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_shop', $site_id);
$stat_extend->handleData($data);//写入文件
//增加当天时统计
$this->addShopHourStat($data, $carbon);
}catch (\Exception $e){
log_write('店铺按天新统计数据添加失败:' . $e->getMessage(), 'error');
log_write('店铺按天新统计数据添加失败site_id'.$site_id . ',错误信息' . $e->getMessage(), 'error');
return $this->error('店铺按天新统计数据添加失败');
}
log_write('店铺按天新统计数据已添加', 'debug');
log_write('店铺按天新统计数据已添加site_id'.$site_id, 'debug');
return $this->success();
}
@@ -100,6 +101,7 @@ class StatShop extends BaseModel
Log::write(time().'stat_shop_'.json_encode($data_array));
$system_stat = new \app\model\system\Stat();
foreach ($data_array as $json_k => $json_v){
$json_v = $this->removeExtraFields($json_v);
$system_stat->addStatShopModel($json_v);
}
log_write('店铺按天统计数据处理成功', 'debug');
@@ -118,18 +120,19 @@ class StatShop extends BaseModel
*/
public function addShopHourStat($data, $carbon)
{
log_write('店铺按小时新统计数据开始添加', 'debug');
$site_id = $data['site_id'] ?? 1;
log_write('店铺按小时新统计数据开始添加site_id'.$site_id, 'debug');
try{
$dir = __UPLOAD__.'/stat/stat_shop_hour/';
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
return $this->error(sprintf('Directory "%s" was not created', $dir));
}
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_'.$carbon->hour.'_'.$carbon->second.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_shop_hour',$data['site_id']);
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_'.$carbon->hour.'_'.$carbon->second.'_s'.$site_id.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_shop_hour', $site_id);
$stat_extend->handleData($data);//写入文件
log_write('店铺按小时新统计数据已添加', 'debug');
log_write('店铺按小时新统计数据已添加site_id'.$site_id, 'debug');
}catch (\Exception $e){
log_write('店铺按小时新统计数据添加失败:' . $e->getMessage(), 'error');
log_write('店铺按小时新统计数据添加失败site_id'.$site_id . ',错误信息' . $e->getMessage(), 'error');
return $this->error('店铺按小时新统计数据添加失败');
}
return $this->success();
@@ -178,6 +181,7 @@ class StatShop extends BaseModel
Log::write(time().'stat_shop_hour_'.json_encode($data_array));
$system_stat = new \app\model\system\Stat();
foreach ($json_array as $json_k => $json_v){
$json_v = $this->removeExtraFields($json_v);
$system_stat->addStatShopHourModel($json_v);
}
log_write('系统计划任务执行店铺按小时统计完成');
@@ -186,6 +190,19 @@ class StatShop extends BaseModel
}
}
/**
* 将不需要的字段从json_v中移除并返回处理后的数组
* @param array $json_v 原始json数组
* @return array 处理后的json数组
*/
public function removeExtraFields($json_v)
{
try {
// 从json_v中移除多余字段
unset($json_v['store_id']); // 移除store_id字段
} catch (\Exception $e) {}
return $json_v;
}
public function scanFile($path) {
$result = [];

View File

@@ -31,25 +31,35 @@ class StatStore extends BaseModel
*/
public function addStoreStat($data)
{
$dir = __UPLOAD__.'/stat/stat_store/';
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
return $this->error(sprintf('Directory "%s" was not created', $dir));
}
$carbon = Carbon::now();
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_'.$carbon->second.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_store');
$stat_extend->handleData($data);//写入文件
$site_id = $data['site_id'] ?? 1;
log_write('门店按天新统计数据开始添加site_id'.$site_id, 'debug');
try {
$dir = __UPLOAD__.'/stat/stat_store/';
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
return $this->error(sprintf('Directory "%s" was not created', $dir));
}
$carbon = Carbon::now();
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_s'.$site_id.'_'.$carbon->second.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_store', $site_id);
$stat_extend->handleData($data);//写入文件
//增加当天时统计
$this->addStoreHourStat($data, $carbon);
//增加当天时统计
$this->addStoreHourStat($data, $carbon);
//增加店铺统计
$stat_shop = [];
foreach ($data as $k => $value) {
if($k != 'site_id' && $k != 'store_id') $stat_shop[ 'cashier_' . $k ] = $value;
//增加店铺统计
$stat_shop = [];
foreach ($data as $k => $value) {
if($k != 'site_id' && $k != 'store_id') $stat_shop[ 'cashier_' . $k ] = $value;
}
$stat_shop_model = new StatShop();
$stat_shop_model->addShopStat($stat_shop);
} catch (\Exception $e) {
log_write('门店按天新统计数据添加失败site_id'.$site_id . ',错误信息:' . $e->getMessage(), 'error');
return $this->error('门店按天新统计数据添加失败');
}
$stat_shop_model = new StatShop();
$stat_shop_model->addShopStat($stat_shop);
log_write('门店按天新统计数据已添加site_id'.$site_id, 'debug');
return $this->success();
}
@@ -59,11 +69,18 @@ class StatStore extends BaseModel
*/
public function cronStatStore()
{
log_write('门店按天统计数据开始处理', 'debug');
$path = __UPLOAD__.'/stat/stat_store';
if(!is_dir($path)) return;
if(!is_dir($path)) {
log_write('门店按天统计数据处理失败:目录不存在:'.$path, 'error');
return;
}
$result = $this->scanFile($path);
if(empty($result)) return;
if(empty($result)) {
log_write('门店按天统计数据处理失败:目录下无文件:'.$path, 'error');
return;
}
try {
$json_array = [];
@@ -95,8 +112,9 @@ class StatStore extends BaseModel
foreach ($json_array as $json_k => $json_v){
$store_stat->addStatStoreModel($json_v);
}
log_write('门店按天统计数据处理成功', 'debug');
} catch (\Exception $e) {
log_write('门店按天统计数据处理失败:'.$e->getMessage(), 'error');
}
}
@@ -108,13 +126,22 @@ class StatStore extends BaseModel
*/
public function addStoreHourStat($data, $carbon)
{
$dir = __UPLOAD__.'/stat/stat_store_hour/';
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
return $this->error(sprintf('Directory "%s" was not created', $dir));
$site_id = $data['site_id'] ?? 1;
log_write('门店按小时新统计数据开始添加site_id'.$site_id, 'debug'); //增加site_id
try {
$dir = __UPLOAD__.'/stat/stat_store_hour/';
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
return $this->error(sprintf('Directory "%s" was not created', $dir));
}
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_s'.$site_id.'_'.$carbon->hour.'_'.$carbon->second.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_store_hour', $site_id);
$stat_extend->handleData($data);//写入文件
log_write('门店按小时新统计数据已添加site_id'.$site_id, 'debug'); //增加site_id
} catch (\Exception $e) {
log_write('门店按小时新统计数据添加失败site_id'.$site_id . ',错误信息:' . $e->getMessage(), 'error'); //增加site_id
return $this->error('门店按小时新统计数据添加失败');
}
$filename = $dir.$carbon->year.'_'.$carbon->month.'_'.$carbon->day.'_'.$carbon->hour.'_'.$carbon->second.'_'.unique_random().'.json';
$stat_extend = new Stat($filename, 'stat_store_hour');
$stat_extend->handleData($data);//写入文件
return $this->success();
}
@@ -123,11 +150,18 @@ class StatStore extends BaseModel
*/
public function cronStatStoreHour()
{
log_write('门店按小时统计数据开始处理', 'debug');
$path = __UPLOAD__.'/stat/stat_store_hour';
if(!is_dir($path)) return;
if(!is_dir($path)) {
log_write('门店按小时统计数据处理失败:目录不存在:'.$path, 'error');
return;
}
$result = $this->scanFile($path);
if(empty($result)) return;
if(empty($result)) {
log_write('门店按小时统计数据处理失败:目录下无文件:'.$path, 'error');
return;
}
try {
$json_array = [];
@@ -154,13 +188,14 @@ class StatStore extends BaseModel
$data_array[$k] = $json_v;
}
}
Log::write(time().'stat_store_hour'.json_encode($data_array));
Log::write(time().'stat_store_hour_'.json_encode($data_array));
$store_stat = new \app\model\store\Stat();
foreach ($json_array as $json_k => $json_v){
$store_stat->addStatStoreHourModel($json_v);
}
log_write('门店按小时统计数据处理成功', 'debug');
} catch (\Exception $e) {
log_write('门店按小时统计数据处理失败:'.$e->getMessage(), 'error');
}
}