add 数据之眼大屏-首页平台用户数据和店铺统计接口

This commit is contained in:
chenbo 2023-12-05 18:55:01 +08:00
parent 0efcdfc7d2
commit f4296c0949
2 changed files with 98 additions and 2 deletions

View File

@ -0,0 +1,88 @@
<?php
namespace app\controller\api\dataview;
use app\common\repositories\BaseRepository;
use app\common\repositories\user\UserRepository;
use app\common\repositories\user\UserVisitRepository;
use crmeb\basic\BaseController;
use think\App;
use think\facade\Cache;
use think\facade\Db;
use think\exception\ValidateException;
class User extends BaseController
{
public function __construct(App $app, BaseRepository $repository)
{
parent::__construct($app);
$this->repository = $repository;
$this->areaCode = $this->request->param('areaCode', '');
$this->streetCode = $this->request->param('streetCode', '');
if ($this->areaCode == '' && $this->streetCode == '') {
throw new ValidateException('请选择地区');
}
}
public function userMerchantCount(UserRepository $repository, UserVisitRepository $visitRepository)
{
// 近5日 平台用户量统计
$userCountlist = [];
$merchatCountList = [];
// 4天前
$startBeforeDay5 = strtotime(date('Y-m-d', strtotime('-4 days')));
$endBeforeDay5 = $startBeforeDay5+ 86399;
$userCountlist[] = $this->getTimeRangeUserCount([$startBeforeDay5, $endBeforeDay5]);
// 3天前
$startBeforeDay4 = strtotime(date('Y-m-d', strtotime('-3 days')));
$endBeforeDay4 = $startBeforeDay4 + 86399;
$userCountlist[] = $this->getTimeRangeUserCount([$startBeforeDay4, $endBeforeDay4]);
// 2天前
$startBeforeDay3 = strtotime(date('Y-m-d', strtotime('-2 days')));
$endBeforeDay3 = $startBeforeDay3 + 86399;
$userCountlist[] = $this->getTimeRangeUserCount([$startBeforeDay3, $endBeforeDay3]);
// 1天前
$startBeforeDay2= strtotime(date('Y-m-d', strtotime('-1 days')));
$endBeforeDay2 = $startBeforeDay2+ 86399;
$userCountlist[] = $this->getTimeRangeUserCount([$startBeforeDay2, $endBeforeDay2]);
// 今天
$startCurrDay1 = strtotime(date('Y-m-d', time()));
$endCurrDay1 = $startCurrDay1+ 86399;
$userCountlist[] = $this->getTimeRangeUserCount([$startCurrDay1, $endCurrDay1]);
// 地方店铺数量统计
// 该地区下所有乡镇
$geoStreetList = Db::name('geo_street')->where('area_code',$this->areaCode)->select()->toArray();
// 遍历统计每个乡镇的店铺数
foreach ($geoStreetList as $street) {
$temp['street_name'] = $street['street_name'];
$temp['merchant_count'] = Db::name('merchant')->where('street_id', $street['street_code'])->count();
$merchatCountList[] = $temp;
unset($temp);
}
return app('json')->success(compact('userCountlist', 'merchatCountList'));
}
public function getTimeRangeUserCount($timeRange=[])
{
// 新增
$newUserCount = Db::name('user')
->whereTime('create_time', 'between', $timeRange)
->count();
// 访问
$viewUserCount = Db::name('user')
->whereTime('last_time', 'between', $timeRange)
->count();
// 累计
$totalUserCount = Db::name('user')->whereTime('create_time', '<', $timeRange[1])->count();
return compact('newUserCount', 'viewUserCount', 'totalUserCount');
}
}

View File

@ -716,18 +716,26 @@ Route::group('api/', function () {
// dataview接口
Route::group('dataview', function () {
// Route::post('cancel/:id', '/cancelGroupOrder');
/**---------------------物流溯源监控大屏api-------------------- start **/
Route::get('curr_order_info', 'Order/currOrderInfo');
Route::get('order_ranking', 'Order/orderRanking');
Route::get('delivered_product_ranking', 'Order/deliveredProductRanking');
Route::get('town_map_count', 'Order/townMapCount');
Route::get('date_range_order_count', 'Order/dateRangeOrderCount');
Route::get('vehicle_list', 'Logistics/vehicleList');
Route::get('latest_logistics', 'Logistics/latestLogistics');
Route::get('logistics_count', 'Logistics/logisticsCount');
Route::get('logistics_map_count', 'Logistics/logisticsMapCount');
/**---------------------物流溯源监控大屏api---------------------- end **/
/**---------------------数据之眼可视化大屏api------------------- start */
Route::get('user_merchat_count', 'User/userMerchantCount');
/**---------------------数据之眼可视化大屏api-------------------- end */
})->prefix('api.dataview.');