🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 统计图,数据格式 http://tcourse.wmxuetang.com/index.php?r=xtback/statistics/statRegister&begin=1545667200000&end=1548259199999 ## JSON格式 ![](./img/2019-01-23_163944.png) ## 效果图 ![](./img/2019-01-23_165308.png) ## code ``` public function actionStatRegister() { $end = RequestUtils::getNormalRequest('end'); $begin = RequestUtils::getNormalRequest('begin'); $areaID = RequestUtils::getNormalRequest('areaID'); $begin = $begin ? $begin/1000 : strtotime('-1 month'); $end = $end ? $end/1000 : time(); $args = array( 'end' => new MongoDate($end+8*60*60), 'begin' => new MongoDate($begin+8*60*60), 'areaID' => $areaID, ); // 各个地区注册数据 $areaMap = array(); $areas = Area::model()->findAll('fdParentID=:pid',array(':pid'=>$areaID?:12675)); foreach ($areas as $area) { $areaMap[$area->id] = $area->fdName; } $eachArea = V2StatisticsService::factory()->statRegisterEachArea($args); $eachAreaData = array(); foreach ($eachArea as $area) { $aid = $area['areaID']; if (!$aid) { continue; } if (!isset($eachAreaData[$aid])) { $eachAreaData[$aid]['total'] = 0; $eachAreaData[$aid]['areaID'] = $aid; $eachAreaData[$aid]['areaName'] = isset($areaMap[$aid]) ? $areaMap[$aid] : '未知'; } $eachAreaData[$aid]['total'] += $area['total']; $eachAreaData[$aid]['data'][] = array( 'total' => $area['total'], 'userType' => $area['userType'], ); } if ($eachAreaData) { array_multisort(array_column($eachAreaData, 'total', 'areaID'), SORT_DESC, $eachAreaData); } // 各个用户类型注册数据 $eachUserTypeData = V2StatisticsService::factory()->statRegisterEachUserType($args); // 每天注册数据 $dates = DateTimeUtils::initializeTimestampArr($begin, $end); $maps = V2StatisticsService::factory()->statRegisterEachDay($args); $eachDayData = array(); foreach ($dates as $day) { if (isset($maps[$day])) { $eachDayData[] = $maps[$day]; } else { $eachDayData[] = array( 'total' => 0, 'day' => $day, 'data' => array() ); } } ResponseUtils::json(array( 'data' => array( 'eachDay' => $eachDayData, 'eachArea' => array_values($eachAreaData), 'eachUserType' => $eachUserTypeData ) )); } ```