Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
service
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
aimeiyue
service
Commits
278ad0f9
Commit
278ad0f9
authored
Sep 23, 2024
by
lizhilin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新
parent
4d3cf722
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
585 additions
and
48 deletions
+585
-48
app/Admin/Controllers/HomeController.php
+36
-11
app/Admin/Metrics/Examples/OrderAjaxBar.php
+112
-0
app/Admin/Metrics/Examples/OrderBar.php
+118
-0
app/Admin/Metrics/Examples/OrderPickCount.php
+38
-15
app/Admin/Metrics/Examples/OrderWaitCount.php
+38
-15
app/Http/Controllers/Api/GoodController.php
+4
-2
app/Http/Controllers/Api/OrderController.php
+0
-1
app/Http/Controllers/Api/UserController.php
+2
-2
app/Models/OrderInfo.php
+53
-2
app/Store/Metrics/Examples/StoreOrderChats.php
+184
-0
No files found.
app/Admin/Controllers/HomeController.php
View file @
278ad0f9
...
@@ -8,33 +8,58 @@
...
@@ -8,33 +8,58 @@
use
Dcat\Admin\Layout\Column
;
use
Dcat\Admin\Layout\Column
;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Layout\Content
;
use
Dcat\Admin\Layout\Row
;
use
Dcat\Admin\Layout\Row
;
use
Dcat\Admin\Widgets\Card
;
use
Dcat\Admin\Widgets\Dropdown
;
use
Dcat\Admin\Widgets\Box
;
class
HomeController
extends
Controller
class
HomeController
extends
Controller
{
{
public
function
index
(
Content
$content
)
public
function
index
(
Content
$content
)
{
{
//-----
// 构建下拉菜单,当点击菜单时发起请求获取数据重新渲染图表
$menu
=
[
'7'
=>
'最近7天'
,
'30'
=>
'最近30天'
,
'365'
=>
'最近一年'
,
];
$dropdown
=
Dropdown
::
make
(
$menu
)
->
button
(
current
(
$menu
))
->
click
()
->
map
(
function
(
$v
,
$k
)
{
// 此处设置的 data-xxx 属性会作为post数据发送到后端api
return
"<a class='switch-bar' data-option='
{
$k
}
'>
{
$v
}
</a>"
;
});
// 传递自定义参数
$id
=
1
;
$username
=
'jack'
;
$bar
=
Examples\OrderAjaxBar
::
make
(
$id
,
$username
)
->
fetching
(
'$("#my-box").loading()'
)
// 设置loading效果
->
fetched
(
'$("#my-box").loading(false)'
)
// 移除loading效果
->
click
(
'.switch-bar'
);
// 设置图表点击菜单则重新发起请求,且被点击的目标元素上的 data-xxx 属性会被作为post数据发送到后端API
$box
=
Box
::
make
(
'销售额趋势'
,
$bar
)
->
id
(
'my-box'
)
// 设置盒子的ID
->
tool
(
$dropdown
);
// 设置下拉菜单按钮
//------
return
$content
return
$content
->
header
(
'Dashboard'
)
->
header
(
'Dashboard'
)
->
description
(
'Description...'
)
->
description
(
'Description...'
)
->
body
(
function
(
Row
$row
)
{
->
body
(
function
(
Row
$row
)
use
(
$box
)
{
$row
->
column
(
12
,
function
(
Column
$column
)
{
$row
->
column
(
12
,
function
(
Column
$column
)
use
(
$box
)
{
$column
->
row
(
function
(
Row
$row
)
{
$column
->
row
(
function
(
Row
$row
)
use
(
$box
)
{
$row
->
column
(
6
,
new
Examples\OrderWaitCount
());
$row
->
column
(
6
,
new
Examples\OrderWaitCount
());
$row
->
column
(
6
,
new
Examples\OrderPickCount
());
$row
->
column
(
6
,
new
Examples\OrderPickCount
());
//$row->column(12, new Examples\StoreOrderChats());
//$row->column(12, new Examples\StoreOrderChats());
$row
->
column
(
12
,
new
Examples\Sessions
());
//$row->column(12, Card::make('订单信息', Examples\MyBar::make()));
$row
->
column
(
12
,
Card
::
make
(
'订单信息'
,
$box
));
$row
->
column
(
12
,
new
Examples\Product
());
$row
->
column
(
12
,
new
Examples\Product
());
});
});
});
});
// $row->column(12, function (Column $column) {
// $column->row(function (Row $row) {
// //$row->column(12, new Examples\Product());
// });
// // $column->row(new Examples\Sessions());
// // $column->row(new Examples\ProductOrders());
// });
// $row->column(12,'欢迎登录');
// $row->column(12,'欢迎登录');
});
});
}
}
...
...
app/Admin/Metrics/Examples/OrderAjaxBar.php
0 → 100644
View file @
278ad0f9
<?php
namespace
App\Admin\Metrics\Examples
;
use
App\Models\OrderInfo
;
use
Illuminate\Http\Request
;
class
OrderAjaxBar
extends
OrderBar
{
protected
$id
;
protected
$username
;
// 这里的参数一定要设置默认值
public
function
__construct
(
$id
=
null
,
$username
=
null
)
{
parent
::
__construct
();
$this
->
id
=
$id
;
$this
->
username
=
$username
;
}
/**
* 处理请求
* 如果你的图表类中包含此方法,则可以通过此方法处理前端通过ajax提交的获取图表数据的请求
*
* @param Request $request
* @return mixed|void
*/
public
function
handle
(
Request
$request
)
{
// 获取 parameters 方法设置的自定义参数
$id
=
$request
->
get
(
'id'
);
$username
=
$request
->
get
(
'username'
);
switch
((
int
)
$request
->
get
(
'option'
))
{
case
365
:
$monthArr
=
$amounts
=
[];
for
(
$i
=
11
;
$i
>=
0
;
$i
--
)
{
$month
=
date
(
'Y-m'
,
strtotime
(
'-'
.
$i
.
' month'
));
array_push
(
$monthArr
,
$month
);
$orderAmount
=
OrderInfo
::
getMonthAmount
(
$month
);
array_push
(
$amounts
,
$orderAmount
);
}
// 你的数据查询逻辑
$data
=
[
[
'data'
=>
$amounts
//[44, 55, 41, 64, 22, 43, 21]
]
];
$categories
=
$monthArr
;
//[2001, 2002, 2003, 2004, 2005, 2006, 2007];
break
;
case
30
:
$dayArr
=
$amounts
=
[];
for
(
$i
=
30
;
$i
>=
0
;
$i
--
)
{
$day
=
date
(
"Y-m-d"
,
strtotime
(
"-"
.
$i
.
" day"
));
array_push
(
$dayArr
,
$day
);
$orderAmount
=
OrderInfo
::
getDayAmount
(
$day
);
array_push
(
$amounts
,
$orderAmount
);
}
// 你的数据查询逻辑
$data
=
[
[
'data'
=>
$amounts
//[44, 55, 41, 64, 22, 43, 21]
]
];
$categories
=
$dayArr
;
break
;
case
7
:
default
:
$dayArr
=
$amounts
=
[];
for
(
$i
=
7
;
$i
>=
0
;
$i
--
)
{
$day
=
date
(
"Y-m-d"
,
strtotime
(
"-"
.
$i
.
" day"
));
array_push
(
$dayArr
,
$day
);
$orderAmount
=
mt_rand
(
100
,
200
);
//OrderInfo::getDayAmount($day);
array_push
(
$amounts
,
$orderAmount
);
}
// 你的数据查询逻辑
$data
=
[
[
'data'
=>
$amounts
]
];
$categories
=
$dayArr
;
//[2001, 2002, 2003, 2004, 2005, 2006, 2007];
break
;
}
$this
->
withData
(
$data
);
$this
->
withCategories
(
$categories
);
}
/**
* 这里返回需要异步传递到 handler 方法的参数
*
* @return array
*/
public
function
parameters
()
:
array
{
return
[
'id'
=>
$this
->
id
,
'username'
=>
$this
->
username
,
];
}
/**
* 这里覆写父类的方法,不再查询数据
*/
protected
function
buildData
()
{}
}
app/Admin/Metrics/Examples/OrderBar.php
0 → 100644
View file @
278ad0f9
<?php
namespace
App\Admin\Metrics\Examples
;
use
Dcat\Admin\Admin
;
use
Dcat\Admin\Widgets\ApexCharts\Chart
;
class
OrderBar
extends
Chart
{
public
function
__construct
(
$containerSelector
=
null
,
$options
=
[])
{
parent
::
__construct
(
$containerSelector
,
$options
);
$this
->
setUpOptions
();
}
/**
* 初始化图表配置
*/
protected
function
setUpOptions
()
{
$color
=
Admin
::
color
();
$colors
=
[
$color
->
primary
(),
$color
->
primaryDarker
()];
$this
->
options
([
'colors'
=>
$colors
,
'chart'
=>
[
'type'
=>
'bar'
,
'height'
=>
430
,
'barWidth'
=>
'1'
],
'plotOptions'
=>
[
'bar'
=>
[
'horizontal'
=>
false
,
'width'
=>
'1%'
,
'dataLabels'
=>
[
'position'
=>
'top'
,
],
]
],
'dataLabels'
=>
[
'enabled'
=>
true
,
'offsetX'
=>
-
6
,
'style'
=>
[
'fontSize'
=>
'12px'
,
'colors'
=>
[
'#fff'
]
]
],
'stroke'
=>
[
'show'
=>
true
,
'width'
=>
1
,
'colors'
=>
[
'#fff'
]
],
'xaxis'
=>
[
'categories'
=>
[],
],
]);
}
/**
* 处理图表数据
*/
protected
function
buildData
()
{
// 执行你的数据查询逻辑
$data
=
[
[
'data'
=>
[
44
,
55
,
41
,
64
,
22
,
43
,
21
]
]
];
$categories
=
[
2001
,
2002
,
2003
,
2004
,
2005
,
2006
,
2007
];
$this
->
withData
(
$data
);
$this
->
withCategories
(
$categories
);
}
/**
* 设置图表数据
*
* @param array $data
*
* @return $this
*/
public
function
withData
(
array
$data
)
{
//$data[0] = array_merge($data[0], ['itemStyle' => ['barWidth' => '1%']]);
// echo "<pre>";
// print_r($data);
// die;
return
$this
->
option
(
'series'
,
$data
);
}
/**
* 设置图表类别.
*
* @param array $data
*
* @return $this
*/
public
function
withCategories
(
array
$data
)
{
return
$this
->
option
(
'xaxis.categories'
,
$data
);
}
/**
* 渲染图表
*
* @return string
*/
public
function
render
()
{
$this
->
buildData
();
return
parent
::
render
();
}
}
app/Admin/Metrics/Examples/OrderPickCount.php
View file @
278ad0f9
...
@@ -27,17 +27,22 @@ protected function init()
...
@@ -27,17 +27,22 @@ protected function init()
parent
::
init
();
parent
::
init
();
$this
->
title
(
'已取货总数'
);
$this
->
title
(
'已取货总数'
);
$this
->
dropdown
([
'1'
=>
'今天'
,
'7'
=>
'最近7天'
,
'30'
=>
'最近30天'
,
'365'
=>
'最近一年'
,
]);
#日期选择开始
#日期选择开始
$id
=
$this
->
id
();
//
$id = $this->id();
$this
->
datepicker
(
$id
)
//
$this->datepicker($id)
->
click
(
"#
{
$id
}
.datepicker .btn-primary"
)
//
->click("#{$id} .datepicker .btn-primary")
->
addVariables
([
//
->addVariables([
'datepicker'
=>
[
//
'datepicker' => [
'start'
=>
''
,
//date('Y-m-d', strtotime('-7 days')),
//
'start' => '', //date('Y-m-d', strtotime('-7 days')),
'end'
=>
''
,
//date('Y-m-d', time()),
//
'end' => '', //date('Y-m-d', time()),
]
//
]
]);
//
]);
}
}
/**
/**
...
@@ -50,19 +55,37 @@ protected function init()
...
@@ -50,19 +55,37 @@ protected function init()
public
function
handle
(
Request
$request
)
public
function
handle
(
Request
$request
)
{
{
//dd($request->input());
//dd($request->input());
$started
=
$request
->
get
(
'started'
)
??
''
;
//
$started = $request->get('started') ?? '';
$ended
=
$request
->
get
(
'ended'
)
??
''
;
//
$ended = $request->get('ended') ?? '';
switch
(
$request
->
get
(
'option'
))
{
switch
(
$request
->
get
(
'option'
))
{
case
'365'
:
case
'365'
:
$data
=
OrderInfo
::
getNumDayData
(
365
,
[
3
,
4
]);
// 卡片内容
$this
->
withContent
(
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
case
'30'
:
case
'30'
:
$data
=
OrderInfo
::
getNumDayData
(
30
,
[
3
,
4
]);
// 卡片内容
$this
->
withContent
(
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
case
'7'
:
case
'7'
:
$data
=
OrderInfo
::
getNumDayData
(
7
,
[
3
,
4
]);
// 卡片内容
$this
->
withContent
(
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
default
:
default
:
$
count
=
OrderInfo
::
getNumDayData
(
$started
,
$ended
,
[
3
,
4
]);
$
data
=
OrderInfo
::
getNumDayData
(
7
,
[
3
,
4
]);
// 卡片内容
// 卡片内容
$this
->
withContent
(
$
count
);
$this
->
withContent
(
$
data
[
'total'
]
);
// 图表数据
// 图表数据
//
$this->withChart($data['list']);
$this
->
withChart
(
$data
[
'list'
]);
}
}
}
}
...
...
app/Admin/Metrics/Examples/OrderWaitCount.php
View file @
278ad0f9
...
@@ -26,17 +26,22 @@ protected function init()
...
@@ -26,17 +26,22 @@ protected function init()
parent
::
init
();
parent
::
init
();
$this
->
title
(
'待取货总数'
);
$this
->
title
(
'待取货总数'
);
$this
->
dropdown
([
'1'
=>
'今天'
,
'7'
=>
'最近7天'
,
'30'
=>
'最近30天'
,
'365'
=>
'最近一年'
,
]);
#日期选择开始
#日期选择开始
$id
=
$this
->
id
();
//
$id = $this->id();
$this
->
datepicker
(
$id
)
//
$this->datepicker($id)
->
click
(
"#
{
$id
}
.datepicker .btn-primary"
)
//
->click("#{$id} .datepicker .btn-primary")
->
addVariables
([
//
->addVariables([
'datepicker'
=>
[
//
'datepicker' => [
'start'
=>
''
,
//date('Y-m-d', strtotime('-7 days')),
//
'start' => '', //date('Y-m-d', strtotime('-7 days')),
'end'
=>
''
,
//date('Y-m-d', time()),
//
'end' => '', //date('Y-m-d', time()),
]
//
]
]);
//
]);
}
}
/**
/**
...
@@ -49,19 +54,37 @@ protected function init()
...
@@ -49,19 +54,37 @@ protected function init()
public
function
handle
(
Request
$request
)
public
function
handle
(
Request
$request
)
{
{
//dd($request->input());
//dd($request->input());
$started
=
$request
->
get
(
'started'
)
??
''
;
//
$started = $request->get('started') ?? '';
$ended
=
$request
->
get
(
'ended'
)
??
''
;
//
$ended = $request->get('ended') ?? '';
switch
(
$request
->
get
(
'option'
))
{
switch
(
$request
->
get
(
'option'
))
{
case
'365'
:
case
'365'
:
$data
=
OrderInfo
::
getNumDayData
(
365
,
[
2
]);
// 卡片内容
$this
->
withContent
(
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
case
'30'
:
case
'30'
:
$data
=
OrderInfo
::
getNumDayData
(
30
,
[
2
]);
// 卡片内容
$this
->
withContent
(
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
case
'7'
:
case
'7'
:
$data
=
OrderInfo
::
getNumDayData
(
7
,
[
2
]);
// 卡片内容
$this
->
withContent
(
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
default
:
default
:
$
count
=
OrderInfo
::
getNumDayData
(
$started
,
$ended
,
[
2
]);
$
data
=
OrderInfo
::
getNumDayData
(
1
,
[
2
]);
// 卡片内容
// 卡片内容
$this
->
withContent
(
$
count
);
$this
->
withContent
(
$
data
[
'total'
]
);
// 图表数据
// 图表数据
//
$this->withChart($data['list']);
$this
->
withChart
(
$data
[
'list'
]);
}
}
}
}
...
...
app/Http/Controllers/Api/GoodController.php
View file @
278ad0f9
...
@@ -217,8 +217,10 @@ public function getDetail(Request $request)
...
@@ -217,8 +217,10 @@ public function getDetail(Request $request)
$userObj
=
optional
(
Auth
::
user
());
$userObj
=
optional
(
Auth
::
user
());
if
(
$userObj
)
{
if
(
$userObj
)
{
$mer_id
=
$userObj
->
merchant_id
;
$mer_id
=
$userObj
->
merchant_id
;
$merchantObj
=
Merchant
::
find
(
$mer_id
);
if
(
$mer_id
)
{
$kf_phone
=
$merchantObj
->
phone
;
$merchantObj
=
Merchant
::
find
(
$mer_id
);
$kf_phone
=
$merchantObj
->
phone
;
}
//收藏
//收藏
$is_collect
=
UserCollect
::
where
([
'goods_id'
=>
$goods_id
,
'uid'
=>
$userObj
->
id
])
->
wherenull
(
'deleted_at'
)
->
count
();
$is_collect
=
UserCollect
::
where
([
'goods_id'
=>
$goods_id
,
'uid'
=>
$userObj
->
id
])
->
wherenull
(
'deleted_at'
)
->
count
();
}
}
...
...
app/Http/Controllers/Api/OrderController.php
View file @
278ad0f9
...
@@ -277,7 +277,6 @@ public function pay(Request $request)
...
@@ -277,7 +277,6 @@ public function pay(Request $request)
$order_id
=
$request
->
order_id
??
0
;
$order_id
=
$request
->
order_id
??
0
;
$openid
=
$request
->
user
()
->
openid
;
$openid
=
$request
->
user
()
->
openid
;
DB
::
beginTransaction
();
DB
::
beginTransaction
();
try
{
try
{
$res
=
''
;
$res
=
''
;
...
...
app/Http/Controllers/Api/UserController.php
View file @
278ad0f9
...
@@ -172,7 +172,7 @@ public function info(Request $request)
...
@@ -172,7 +172,7 @@ public function info(Request $request)
return
$this
->
JsonResponse
([
return
$this
->
JsonResponse
([
'user_id'
=>
$user
->
id
,
'user_id'
=>
$user
->
id
,
'nickname'
=>
$user
->
name
,
'nickname'
=>
$user
->
name
,
'avatar'
=>
$user
->
avatar
?
env
(
'IMAGE_URL'
)
.
$user
->
avatar
:
'
'
,
'avatar'
=>
$user
->
avatar
?
env
(
'IMAGE_URL'
)
.
$user
->
avatar
:
env
(
'IMAGE_URL'
)
.
'/wximg/my.png
'
,
'phone'
=>
$user
->
phone
,
'phone'
=>
$user
->
phone
,
'phone_sec'
=>
$user
->
phone
?
substr
(
$user
->
phone
,
0
,
3
)
.
"****"
.
substr
(
$user
->
phone
,
7
)
:
''
,
'phone_sec'
=>
$user
->
phone
?
substr
(
$user
->
phone
,
0
,
3
)
.
"****"
.
substr
(
$user
->
phone
,
7
)
:
''
,
//'status' => $user->status,
//'status' => $user->status,
...
@@ -441,7 +441,7 @@ public function getMyFriend(Request $request)
...
@@ -441,7 +441,7 @@ public function getMyFriend(Request $request)
$data
[
'list'
][]
=
[
$data
[
'list'
][]
=
[
'name'
=>
$item
->
name
,
'name'
=>
$item
->
name
,
'divide_price'
=>
(
float
)
$divide_price
,
'divide_price'
=>
(
float
)
$divide_price
,
'avatar'
=>
(
$item
->
avatar
?
env
(
'IMAGE_URL'
)
.
$item
->
avatar
:
'
'
),
'avatar'
=>
(
$item
->
avatar
?
env
(
'IMAGE_URL'
)
.
$item
->
avatar
:
env
(
'IMAGE_URL'
)
.
'/wximg/my.png
'
),
'addtime'
=>
date
(
'Y-m-d H:i:s'
,
strtotime
(
$item
->
created_at
))
'addtime'
=>
date
(
'Y-m-d H:i:s'
,
strtotime
(
$item
->
created_at
))
];
];
}
}
...
...
app/Models/OrderInfo.php
View file @
278ad0f9
...
@@ -36,13 +36,13 @@ public function merchant()
...
@@ -36,13 +36,13 @@ public function merchant()
}
}
/**
/**
* 获取
指定天数
订单量
* 获取
日期
订单量
* started 开始时间
* started 开始时间
* ended 截至时间
* ended 截至时间
* status 订单状态
* status 订单状态
* merchant_id 商户ID
* merchant_id 商户ID
*/
*/
public
static
function
getNumDayData
(
$started
=
''
,
$ended
=
''
,
$status
=
[],
$merchant_id
=
0
)
public
static
function
getNumDayData
2
(
$started
=
''
,
$ended
=
''
,
$status
=
[],
$merchant_id
=
0
)
{
{
$where
=
[];
$where
=
[];
$sqlObj
=
new
self
();
$sqlObj
=
new
self
();
...
@@ -61,8 +61,59 @@ public static function getNumDayData($started = '', $ended = '', $status = [], $
...
@@ -61,8 +61,59 @@ public static function getNumDayData($started = '', $ended = '', $status = [], $
return
$count
;
return
$count
;
}
}
//指定天数
public
static
function
getNumDayData
(
$dayNum
,
$status
=
[])
{
$days
=
[
date
(
'Y-m-d'
)];
for
(
$i
=
1
;
$i
<
$dayNum
;
$i
++
)
{
$days
[]
=
date
(
"Y-m-d"
,
strtotime
(
"-
$i
day"
));
}
$days
=
array_reverse
(
$days
);
$data
=
[
'total'
=>
0
,
'list'
=>
[]
];
$where
=
[];
$sqlObj
=
new
self
();
if
(
$status
)
{
$sqlObj
=
$sqlObj
->
whereIn
(
'order_status'
,
$status
);
}
foreach
(
$days
as
$day
)
{
$startTime
=
$day
.
' 00:00:00'
;
$endTime
=
$day
.
' 23:59:59'
;
$count
=
$sqlObj
->
whereBetween
(
'created_at'
,
[
$startTime
,
$endTime
])
->
where
(
$where
)
->
count
();
$data
[
'list'
][
$day
]
=
$count
;
$data
[
'total'
]
+=
$count
;
}
return
$data
;
}
//统计获取默天的销售额
public
static
function
getDayAmount
(
$dayDate
)
{
$startTime
=
$dayDate
.
' 00:00:00'
;
$endTime
=
$dayDate
.
' 23:59:59'
;
$sqlObj
=
new
self
();
$amount
=
$sqlObj
->
whereBetween
(
'created_at'
,
[
$startTime
,
$endTime
])
->
whereNull
(
'deleted_at'
)
->
sum
(
'order_amount'
);
return
$amount
;
}
//统计获取月销售额 2023-09
public
static
function
getMonthAmount
(
$monthDate
)
{
$mdate
=
$monthDate
.
"-01"
;
$firstDayOfMonth
=
date
(
'Y-m-01'
,
strtotime
(
date
(
$mdate
)));
$lastDayOfMonth
=
date
(
'Y-m-t'
,
strtotime
(
date
(
$mdate
)));
$startTime
=
$firstDayOfMonth
.
' 00:00:00'
;
$endTime
=
$lastDayOfMonth
.
' 23:59:59'
;
$sqlObj
=
new
self
();
$amount
=
$sqlObj
->
whereBetween
(
'created_at'
,
[
$startTime
,
$endTime
])
->
whereNull
(
'deleted_at'
)
->
sum
(
'order_amount'
);
return
$amount
;
}
//获取最近一年的订单量
//获取最近一年的订单量
public
static
function
getYearData
()
public
static
function
getYearData
()
{
{
...
...
app/Store/Metrics/Examples/StoreOrderChats.php
0 → 100644
View file @
278ad0f9
<?php
namespace
App\Store\Metrics\Examples
;
use
App\Models\StoreOrder
;
use
Dcat\Admin\Widgets\Metrics\Line
;
use
Illuminate\Http\Request
;
class
StoreOrderChats
extends
Line
{
/**
* 初始化卡片内容
*
* @return void
*/
protected
function
init
()
{
parent
::
init
();
$this
->
title
(
'已完成订单'
);
$this
->
dropdown
([
'7'
=>
'最近7天'
,
'30'
=>
'最近30天'
,
'365'
=>
'最近一年'
,
]);
$this
->
height
(
600
);
$this
->
chartHeight
(
500
);
$this
->
chartOptions
=
[
'colors'
=>
[
'#FF69B4'
],
'chart'
=>
[
'type'
=>
'area'
,
'dropShadow'
=>
[
'enabled'
=>
true
,
'color'
=>
'#000'
,
'top'
=>
18
,
'left'
=>
7
,
'blur'
=>
10
,
'opacity'
=>
0.2
],
'toolbar'
=>
[
'show'
=>
false
],
'zoom'
=>
[
//关闭缩放
'enabled'
=>
false
]
],
'stroke'
=>
[
'show'
=>
true
,
'width'
=>
1
,
'colors'
=>
[
'#77B6EA'
],
'curve'
=>
'smooth'
],
// 'fill' => [
// 'type' => 'gradient',
// 'gradient'=>[
// 'opacityFrom' => 0.6,
// 'opacityTo'=> 0.8
// ]
// ],
'grid'
=>
[
'borderColor'
=>
'#e7e7e7'
,
'row'
=>
[
'opacity'
=>
0.5
],
],
//圆点大小
'markers'
=>
[
'size'
=>
0
],
'dataLabels'
=>
[
'enabled'
=>
false
,
'offsetX'
=>
0
,
'style'
=>
[
'fontSize'
=>
'12px'
,
'colors'
=>
[
'#FFFFFF'
]
]
],
'plotOptions'
=>
[
'line'
=>
[
'horizontal'
=>
true
,
'dataLabels'
=>
[
'position'
=>
'top'
,
],
]
],
'xaxis'
=>
[
'categories'
=>
[],
],
];
}
/**
* 处理请求
*
* @param Request $request
*
* @return mixed|void
*/
public
function
handle
(
Request
$request
)
{
switch
(
$request
->
get
(
'option'
))
{
case
'365'
:
$data
=
StoreOrder
::
getYearOrder
();
// 卡片内容
$this
->
withContent
(
'总量: '
.
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
case
'30'
:
$data
=
StoreOrder
::
getNumDayOrder
(
30
);
// 卡片内容
$this
->
withContent
(
'总量: '
.
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
break
;
case
'7'
:
default
:
$data
=
StoreOrder
::
getNumDayOrder
(
7
);
// 卡片内容
$this
->
withContent
(
'总量: '
.
$data
[
'total'
]);
// 图表数据
$this
->
withChart
(
$data
[
'list'
]);
}
}
/**
* 设置图表数据.
*
* @param array $data
*
* @return $this
*/
public
function
withChart
(
array
$data
)
{
$days
=
[];
$order_data
=
[
];
foreach
(
$data
as
$k
=>
$v
){
$days
[]
=
$k
;
$order_data
[]
=
$v
;
}
return
$this
->
chart
([
'series'
=>
[
[
'name'
=>
'完成订单'
,
'data'
=>
$order_data
],
],
'xaxis'
=>
[
'categories'
=>
$days
],
]);
}
/**
* 设置卡片内容.
*
* @param string $content
*
* @return $this
*/
public
function
withContent
(
$content
)
{
return
$this
->
content
(
<<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-lg-1">{$content}</h2>
<span class="mb-0 mr-1 text-80">{$this->title}</span>
</div>
HTML
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment