648 lines
19 KiB
PHP
648 lines
19 KiB
PHP
<?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\logic\statistic\TradeStatisticLogic;
|
||
use app\admin\logic\WorkbenchLogic;
|
||
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);
|
||
}
|
||
|
||
//首页订单
|
||
public function order()
|
||
{
|
||
$data = [
|
||
"yAxis" => [
|
||
"maxnum" => 35,
|
||
"maxprice" => "111374.41"
|
||
],
|
||
"legend" => [
|
||
"订单金额",
|
||
"订单数"
|
||
],
|
||
"xAxis" => [
|
||
"2024-05-06",
|
||
"2024-05-07",
|
||
"2024-05-08",
|
||
"2024-05-09",
|
||
"2024-05-10",
|
||
"2024-05-11",
|
||
"2024-05-12",
|
||
"2024-05-13",
|
||
"2024-05-14",
|
||
"2024-05-15",
|
||
"2024-05-16",
|
||
"2024-05-17",
|
||
"2024-05-18",
|
||
"2024-05-19",
|
||
"2024-05-20",
|
||
"2024-05-21",
|
||
"2024-05-22",
|
||
"2024-05-23",
|
||
"2024-05-24",
|
||
"2024-05-25",
|
||
"2024-05-26",
|
||
"2024-05-27",
|
||
"2024-05-28",
|
||
"2024-05-29",
|
||
"2024-05-30",
|
||
"2024-05-31",
|
||
"2024-06-01",
|
||
"2024-06-02",
|
||
"2024-06-03",
|
||
"2024-06-04"
|
||
],
|
||
"series" => [
|
||
[
|
||
"name" => "订单金额",
|
||
"type" => "bar",
|
||
"itemStyle" => [
|
||
"normal" => [
|
||
"color" => [
|
||
"x" => 0,
|
||
"y" => 0,
|
||
"x2" => 0,
|
||
"y2" => 1,
|
||
"colorStops" => [
|
||
[
|
||
"offset" => 0,
|
||
"color" => "#69cdff"
|
||
],
|
||
[
|
||
"offset" => 0.5,
|
||
"color" => "#3eb3f7"
|
||
],
|
||
[
|
||
"offset" => 1,
|
||
"color" => "#1495eb"
|
||
]
|
||
]
|
||
]
|
||
]
|
||
],
|
||
"data" => [
|
||
171.29,
|
||
167.46,
|
||
1455.65,
|
||
45.47,
|
||
542.69,
|
||
216.58,
|
||
228.82,
|
||
34.24,
|
||
8249.85,
|
||
664.23,
|
||
8586.24,
|
||
10.19,
|
||
90.19,
|
||
105.4,
|
||
62.59,
|
||
1051.34,
|
||
160.84,
|
||
2437.68,
|
||
111374.41,
|
||
12161.05,
|
||
189,
|
||
4831.65,
|
||
1276.31,
|
||
582.4,
|
||
906.02,
|
||
597,
|
||
0.08,
|
||
771.16,
|
||
10262.64,
|
||
278.67
|
||
]
|
||
],
|
||
[
|
||
"name" => "订单数",
|
||
"type" => "line",
|
||
"itemStyle" => [
|
||
"normal" => [
|
||
"color" => [
|
||
"x" => 0,
|
||
"y" => 0,
|
||
"x2" => 0,
|
||
"y2" => 1,
|
||
"colorStops" => [
|
||
[
|
||
"offset" => 0,
|
||
"color" => "#6fdeab"
|
||
],
|
||
[
|
||
"offset" => 0.5,
|
||
"color" => "#44d693"
|
||
],
|
||
[
|
||
"offset" => 1,
|
||
"color" => "#2cc981"
|
||
]
|
||
]
|
||
]
|
||
]
|
||
],
|
||
"data" => [
|
||
5,
|
||
8,
|
||
15,
|
||
6,
|
||
13,
|
||
5,
|
||
3,
|
||
4,
|
||
7,
|
||
14,
|
||
12,
|
||
6,
|
||
2,
|
||
2,
|
||
6,
|
||
8,
|
||
19,
|
||
18,
|
||
13,
|
||
30,
|
||
2,
|
||
35,
|
||
12,
|
||
5,
|
||
20,
|
||
2,
|
||
2,
|
||
7,
|
||
13,
|
||
6
|
||
],
|
||
"yAxisIndex" => 1
|
||
]
|
||
],
|
||
"pre_cycle" => [
|
||
"count" => [
|
||
"data" => 170
|
||
],
|
||
"price" => [
|
||
"data" => "1333354.63"
|
||
]
|
||
],
|
||
"cycle" => [
|
||
"count" => [
|
||
"data" => 268,
|
||
"percent" => 57.65,
|
||
"is_plus" => 1
|
||
],
|
||
"price" => [
|
||
"data" => "157451.54",
|
||
"percent" => 88.19,
|
||
"is_plus" => -1
|
||
]
|
||
]
|
||
];
|
||
return $this->data($data);
|
||
}
|
||
//-------------------------------商品统计---------------------------------------//
|
||
|
||
/**
|
||
* 商品概况
|
||
*/
|
||
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 = [];
|
||
$today = new DateTime();
|
||
$thirtyDaysAgo = new DateTime($today->format('Y-m-d'));
|
||
$thirtyDaysAgo->modify('-30 days');
|
||
|
||
for ($i = 0; $i < 31; $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);
|
||
}
|
||
|
||
/**
|
||
* 获取商品排名数据
|
||
*/
|
||
public function get_product_ranking()
|
||
{
|
||
$data = [
|
||
[
|
||
"product_id" => 1661,
|
||
"visit" => "1331",
|
||
"user" => 119,
|
||
"cart" => "26",
|
||
"orders" => "22",
|
||
"pay" => "11",
|
||
"price" => "690.02",
|
||
"cost" => "0.00",
|
||
"profit" => "1.00",
|
||
"collect" => "4",
|
||
"changes" => "0.06",
|
||
"repeats" => "0.28",
|
||
"store_name" => "瞌睡兔 美式复古圆领卫衣外套女春秋款小个子宽松百搭休闲上衣",
|
||
"image" => "https://multi-store.crmeb.net/uploads/attach/2024/02/19/2f3f938d720fc4212216ab855808bf85.jpg",
|
||
"product_price" => "100.00",
|
||
"stock" => 16777213,
|
||
"is_show" => 1
|
||
],
|
||
];
|
||
return $this->data($data);
|
||
}
|
||
|
||
//-------------------------------用户统计---------------------------------------//
|
||
|
||
/**
|
||
* 获取用户概况
|
||
*/
|
||
public function get_user_basic()
|
||
{
|
||
$data = [
|
||
"people" => [
|
||
"num" => 1086,
|
||
"last_num" => 20904,
|
||
"percent" => "-94.80"
|
||
],
|
||
"browse" => [
|
||
"num" => 11296,
|
||
"last_num" => 363632,
|
||
"percent" => "-96.89"
|
||
],
|
||
"newUser" => [
|
||
"num" => 391,
|
||
"last_num" => 21790,
|
||
"percent" => "-98.20"
|
||
],
|
||
"payPeople" => [
|
||
"num" => 84,
|
||
"last_num" => 1314,
|
||
"percent" => "-93.60"
|
||
],
|
||
"payPercent" => [
|
||
"num" => "7.73",
|
||
"last_num" => "6.28",
|
||
"percent" => "23.08"
|
||
],
|
||
"payUser" => [
|
||
"num" => 27,
|
||
"last_num" => 431,
|
||
"percent" => "-93.73"
|
||
],
|
||
"rechargePeople" => [
|
||
"num" => 13,
|
||
"last_num" => 121,
|
||
"percent" => "-89.25"
|
||
],
|
||
"payPrice" => [
|
||
"num" => 2042.04,
|
||
"last_num" => 10352.37,
|
||
"percent" => "-80.27"
|
||
],
|
||
"cumulativeUser" => [
|
||
"num" => 22852,
|
||
"last_num" => 21790,
|
||
"percent" => "4.87"
|
||
],
|
||
"cumulativePayUser" => [
|
||
"num" => 552,
|
||
"last_num" => 521,
|
||
"percent" => "5.95"
|
||
],
|
||
"cumulativeRechargePeople" => [
|
||
"num" => 134,
|
||
"last_num" => 121,
|
||
"percent" => "10.74"
|
||
],
|
||
"cumulativePayPeople" => [
|
||
"num" => 1380,
|
||
"last_num" => 1314,
|
||
"percent" => "5.02"
|
||
]
|
||
];
|
||
return $this->data($data);
|
||
}
|
||
|
||
/**
|
||
* 获取用户趋势
|
||
*/
|
||
public function get_user_trend()
|
||
{
|
||
$data = [
|
||
"xAxis" => [
|
||
"2024-05-06",
|
||
"2024-05-07",
|
||
"2024-05-08",
|
||
"2024-05-09",
|
||
"2024-05-10",
|
||
"2024-05-11",
|
||
"2024-05-12",
|
||
"2024-05-13",
|
||
"2024-05-14",
|
||
"2024-05-15",
|
||
"2024-05-16",
|
||
"2024-05-17",
|
||
"2024-05-18",
|
||
"2024-05-19",
|
||
"2024-05-20",
|
||
"2024-05-21",
|
||
"2024-05-22",
|
||
"2024-05-23",
|
||
"2024-05-24",
|
||
"2024-05-25",
|
||
"2024-05-26",
|
||
"2024-05-27",
|
||
"2024-05-28",
|
||
"2024-05-29",
|
||
"2024-05-30",
|
||
"2024-05-31",
|
||
"2024-06-01",
|
||
"2024-06-02",
|
||
"2024-06-03",
|
||
"2024-06-04"
|
||
],
|
||
"series" => [
|
||
[
|
||
"name" => "新增用户数",
|
||
"value" => [
|
||
13,
|
||
15,
|
||
11,
|
||
20,
|
||
9,
|
||
8,
|
||
1,
|
||
6,
|
||
15,
|
||
20,
|
||
9,
|
||
13,
|
||
5,
|
||
2,
|
||
17,
|
||
19,
|
||
8,
|
||
12,
|
||
12,
|
||
22,
|
||
9,
|
||
32,
|
||
17,
|
||
16,
|
||
14,
|
||
17,
|
||
10,
|
||
5,
|
||
20,
|
||
7
|
||
]
|
||
],
|
||
[
|
||
"name" => "访客数",
|
||
"value" => [
|
||
44,
|
||
69,
|
||
59,
|
||
82,
|
||
58,
|
||
37,
|
||
27,
|
||
44,
|
||
43,
|
||
57,
|
||
54,
|
||
49,
|
||
24,
|
||
17,
|
||
42,
|
||
68,
|
||
55,
|
||
72,
|
||
52,
|
||
130,
|
||
45,
|
||
213,
|
||
108,
|
||
97,
|
||
84,
|
||
78,
|
||
54,
|
||
45,
|
||
94,
|
||
52
|
||
]
|
||
],
|
||
[
|
||
"name" => "成交用户数",
|
||
"value" => [
|
||
3,
|
||
4,
|
||
5,
|
||
5,
|
||
3,
|
||
3,
|
||
1,
|
||
3,
|
||
4,
|
||
7,
|
||
9,
|
||
5,
|
||
1,
|
||
1,
|
||
4,
|
||
4,
|
||
7,
|
||
6,
|
||
7,
|
||
8,
|
||
2,
|
||
14,
|
||
5,
|
||
5,
|
||
8,
|
||
3,
|
||
1,
|
||
4,
|
||
8,
|
||
4
|
||
]
|
||
],
|
||
[
|
||
"name" => "充值用户",
|
||
"value" => [
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
2,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
2,
|
||
1,
|
||
1,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
1,
|
||
2,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
0,
|
||
0,
|
||
1,
|
||
1
|
||
]
|
||
],
|
||
[
|
||
"name" => "新增付费用户数",
|
||
"value" => [
|
||
0,
|
||
3,
|
||
2,
|
||
1,
|
||
0,
|
||
0,
|
||
0,
|
||
0,
|
||
1,
|
||
4,
|
||
4,
|
||
1,
|
||
1,
|
||
1,
|
||
0,
|
||
0,
|
||
0,
|
||
3,
|
||
3,
|
||
1,
|
||
0,
|
||
3,
|
||
2,
|
||
0,
|
||
1,
|
||
3,
|
||
1,
|
||
2,
|
||
3,
|
||
0
|
||
]
|
||
]
|
||
]
|
||
];
|
||
return $this->data($data);
|
||
}
|
||
//-------------------------------交易统计---------------------------------------//
|
||
//当日订单金额
|
||
public function top_trade()
|
||
{
|
||
$logic=(new TradeStatisticLogic());
|
||
$leftToday = $logic->getTopLeftTrade(['create_time' => 'today']);
|
||
$leftyestoday = $logic->getTopLeftTrade(['create_time' => 'yestoday']);
|
||
$rightOne = $logic->getTopRightOneTrade();
|
||
$rightTwo = $logic->getTopRightTwoTrade();
|
||
$right = ['today' => $rightOne, 'month' => $rightTwo];
|
||
$totalleft = [$leftToday, $leftyestoday];
|
||
$left = [];
|
||
foreach ($totalleft as $k => $v) {
|
||
$left['name'] = "当日订单金额";
|
||
$left['x'] = $v['curve']['x'];
|
||
$left['series'][$k]['money'] = round($v['total_money'], 2);
|
||
$left['series'][$k]['value'] = array_values($v['curve']['y']);
|
||
}
|
||
|
||
$data['left'] = $left;
|
||
$data['right'] = $right;
|
||
return $this->data($data);
|
||
}
|
||
|
||
//交易趋势
|
||
public function bottom_trade()
|
||
{
|
||
$data=(new TradeStatisticLogic())->getBottomTrade(['data'=>'2024/05/21-2024/06/19']);
|
||
return $this->data($data);
|
||
}
|
||
}
|