fix: 解决访问没有埋点的问题
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
Reference in New Issue
Block a user