diff --git a/market/controllers/api/sylive/Statistics.php b/market/controllers/api/sylive/Statistics.php index 360e0166..c7522144 100644 --- a/market/controllers/api/sylive/Statistics.php +++ b/market/controllers/api/sylive/Statistics.php @@ -1117,31 +1117,55 @@ class Statistics extends BaseController $this->return_response_list($date); } - public function stacked_order_get() + /** + * Notes:获取观看数-订单数区域折线图数据 + * Created on: 2022/11/23 10:54 + * Created by: dengbw + */ + public function stacked_watchOrder_get() { $activityId = intval($this->input_param('activityId')); $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); - $times = []; + $times = $legendData = $yAxisSeries = $xAxisData = []; if ($re) { + $type = 0; $timeStart = $re['timeStart']; $timeEnd = $re['timeEnd']; - if ($timeStart != '0000-00-00 00:00:00' && $timeEnd != '0000-00-00 00:00:00') { - $start_Time = strtotime('2022-11-26 10:00:00'); - $end_Time = strtotime('2022-11-26 17:30:00'); + if ($timeStart != '0000-00-00 00:00:00' && (date('Y-m-d H:i:s') > $timeStart)) { + $start_Time = strtotime($timeStart); + $end_Time = strtotime($timeEnd); + $legend_data = [['name' => date('Y-m-d', $start_Time) . '的观看数', 'value' => 'watch'], + ['name' => date('Y-m-d', $start_Time) . '的订单数', 'value' => 'order']]; $add_time = '+1 hour'; $diff = abs($start_Time - $end_Time); // 获取时间差 $hour = ceil($diff / 3600); // 获取相差小时数 $hour <= 6 && $add_time = '+30 minute';//转分钟显示 - while ($start_Time <= $end_Time) { + $ii = 0; + while ($start_Time < $end_Time) { $start = date('Y-m-d H:i:s', $start_Time); - $name_start = date('d H:i', $start_Time); + $ii > 0 && $start = date('Y-m-d H:i:s', $start_Time + 60); + $name_start = date('H:i', $start_Time); $start_Time = strtotime($add_time, $start_Time); - $name_end = date('H:i', $start_Time); - $times[] = ['name' => $name_start . '-' . $name_end, 'start' => $start, 'end' => date('Y-m-d H:i:s', $start_Time)]; + $name = $name_start . '-' . date('H:i', $start_Time); + $end = date('Y-m-d H:i:s', $start_Time + 59); + $times[] = ['name' => $name, 'start' => $start, 'end' => $end]; + $xAxisData[] = $name; + $ii++; + } + foreach ($legend_data as $v) { + $legendData[] = $v['name']; + $counts = []; + foreach ($times as $v2) { + $start = strtotime($v2['start']); + $end = strtotime($v2['end']); + $counts[] = $this->mdSyliveActivityKpidata->count(['kpi' => $v['value'], 'type' => $type + , 'createTime >=' => $start, 'createTime <=' => $end, 'activityId' => $activityId]); + } + $yAxisSeries[] = ['name' => $v['name'], 'type' => 'line', 'data' => $counts]; } } } - $date['times'] = $times; + $date = ['legendData' => $legendData, 'xAxisData' => $xAxisData, 'yAxisSeries' => $yAxisSeries]; $this->return_response_list($date); }