lihaiMiddleOffice/app/admin/controller/WorkbenchController.php

145 lines
4.9 KiB
PHP
Raw Permalink Normal View History

2025-02-26 10:13:24 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https=>//gitee.com/likeshop_gitee/likeadmin
// | github下载https=>//github.com/likeshop-github/likeadmin
// | 访问官网https=>//www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author=> likeadminTeam
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\lists\statistics\StoreProductLists;
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupLists;
use app\admin\lists\store_order_cart_info\StoreOrderCartInfoGroupMonthLists;
use app\admin\logic\statistic\ProductStatisticLogic;
use app\admin\logic\statistic\TradeStatisticLogic;
use app\admin\logic\statistic\UserStatisticLogic;
use app\admin\logic\statistic\WarehouseLogic;
use app\admin\logic\WorkbenchLogic;
use app\store\logic\WorkbenchLogic as LogicWorkbenchLogic;
use DateInterval;
use DateTime;
/**
* 工作台
* Class WorkbenchCotroller
* @package app\admin\controller
*/
class WorkbenchController extends BaseAdminController
{
/**
* @notes 工作台
* @author 乔峰
* @date 2021/12/29 17=>01
*/
public function index()
{
$result = WorkbenchLogic::index();
return $this->data($result);
}
/**
* @notes 工作台
* @author 乔峰
* @date 2021/12/29 17=>01
*/
public function store_index_new()
{
$params['store_id'] = $this->request->adminInfo['store_id'];
$result = WorkbenchLogic::index($params);
return $this->data($result);
}
//-------------------------------商品统计---------------------------------------//
/**
* 商品概况
*/
public function get_basic()
{
$startTime = $this->request->get('start_time'); //开始时间
$endTime = $this->request->get('end_time'); //结束时间
if (empty($startTime)) { //如果没有传开始时间则默认获取最近7天的数据
$startTime = strtotime(date('Y-m-d'));
$endTime = $startTime + 86400;
}
$where = [
['create_time', 'between', [$startTime, $endTime]]
];
$data = WorkbenchLogic::get_basic($where);
return $this->data($data);
}
/**
* 商品趋势
*/
public function get_trend()
{
$dates = [];
$date = $this->request->get('date', '');
$days = 31;
if ($date) {
$arr = explode('-', $date);
if ($arr[0] == $arr[1]) {
$date = new DateTime($arr[0]);
$dates[] = $date->format("Y-m-d");
} else {
$datetime_start = new DateTime($arr[0]);
$datetime_end = new DateTime($arr[1]);
$days = $datetime_start->diff($datetime_end)->days;
for ($i = 0; $i <= $days; $i++) {
$date = new DateTime($datetime_start->format('Y-m-d'));
$date->modify('+' . $i . ' days');
$dates[] = $date->format('Y-m-d');
}
}
} else {
$today = new DateTime();
$thirtyDaysAgo = new DateTime($today->format('Y-m-d'));
$thirtyDaysAgo->modify('-30 days');
for ($i = 0; $i < $days; $i++) {
$date = new DateTime($thirtyDaysAgo->format('Y-m-d'));
$date->modify('+' . $i . ' days');
$dates[] = $date->format('Y-m-d');
}
}
$data = [
"xAxis" => $dates,
"series" => [
[
"name" => "商品浏览量",
"data" => WorkbenchLogic::store_visit_count($dates),
"type" => "line",
"smooth" => "true",
"yAxisIndex" => 1
],
[
"name" => "商品访客量",
"data" => WorkbenchLogic::store_visit_user($dates),
"type" => "line",
"smooth" => "true",
"yAxisIndex" => 1
],
[
"name" => "支付金额",
"data" => WorkbenchLogic::payPrice($dates),
"type" => "bar"
],
[
"name" => "退款金额",
"data" => WorkbenchLogic::refundPrice($dates),
"type" => "bar"
]
]
];
return $this->data($data);
}
}