243 lines
7.1 KiB
PHP
243 lines
7.1 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Area;
|
|
use App\Models\AreaCode;
|
|
use Encore\Admin\Auth\Permission;
|
|
use Encore\Admin\Facades\Admin;
|
|
use Encore\Admin\Layout\Column;
|
|
use Encore\Admin\Layout\Content;
|
|
use Encore\Admin\Layout\Row;
|
|
use Encore\Admin\Widgets\InfoBox;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Modules\Mall\Models\Order;
|
|
use Modules\Mall\Models\OrderItem;
|
|
use Modules\User\Models\User;
|
|
use Modules\User\Models\UserStock;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public $content;
|
|
|
|
/**
|
|
* Notes : 数据看板
|
|
*
|
|
* @Date : 2021/3/10 5:12 下午
|
|
* @Author : < Jason.C >
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function index(Content $content)
|
|
{
|
|
$this->content = $content->title('数据看板')->description('Description...');
|
|
$admin = Admin::user();
|
|
if ($admin->id == 1) {
|
|
$this->getUserData();
|
|
$this->getAreaData();
|
|
$this->getScoreData();
|
|
} else {
|
|
$this->content->row($this->setDivider('您没有权限查看数据'));
|
|
}
|
|
|
|
return $this->content;
|
|
}
|
|
|
|
/**
|
|
* Notes: 获取用户数据
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date : 2021/11/17 11:24
|
|
*/
|
|
public function getUserData()
|
|
{
|
|
$this->content->row($this->setDivider('用户统计'));
|
|
|
|
$users = [
|
|
'all' => [
|
|
'name' => '用户总数',
|
|
'color' => 'blue',
|
|
'count' => User::count()
|
|
],
|
|
];
|
|
|
|
$this->content->row(function (Row $row) use ($users) {
|
|
foreach ($users as $user) {
|
|
$row->column(2, function (Column $column) use ($user) {
|
|
$column->append(new InfoBox(
|
|
$user['name'],
|
|
'users',
|
|
$user['color'],
|
|
'/admin/users',
|
|
$user['count'],
|
|
));
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
return $this->content;
|
|
}
|
|
|
|
/**
|
|
* Notes: 区域数据
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date: 2023/1/28 11:26
|
|
* @return mixed
|
|
*/
|
|
public function getAreaData()
|
|
{
|
|
$this->content->row($this->setDivider('提货码'));
|
|
$areas = [
|
|
'all' => [
|
|
'name' => '区域总数',
|
|
'color' => 'blue',
|
|
'link' => '/admin/areas',
|
|
'count' => Area::count()
|
|
],
|
|
'stock' => [
|
|
'name' => '提货码总数',
|
|
'color' => 'green',
|
|
'link' => '/admin/areas',
|
|
'count' => Area::sum('stock')
|
|
],
|
|
'release' => [
|
|
'name' => '提货码释放总数',
|
|
'color' => 'green',
|
|
'link' => '/admin/areas_codes',
|
|
'count' => AreaCode::count()
|
|
],
|
|
'get' => [
|
|
'name' => '提货码领取总数',
|
|
'color' => 'green',
|
|
'link' => '/admin/areas_codes',
|
|
'count' => AreaCode::whereNotNull('user_id')->count()
|
|
],
|
|
'use' => [
|
|
'name' => '提货码兑换总数',
|
|
'color' => 'green',
|
|
'link' => '/admin/areas_codes?status='.AreaCode::STATUS_USED,
|
|
'count' => AreaCode::whereNotNull('user_id')->where('status', AreaCode::STATUS_USED)->count()
|
|
],
|
|
'sign' => [
|
|
'name' => '提货码核销总数',
|
|
'color' => 'green',
|
|
'link' => '/admin/areas_codes?status='.AreaCode::STATUS_SIGN,
|
|
'count' => AreaCode::whereNotNull('user_id')->where('status', AreaCode::STATUS_SIGN)->count()
|
|
],
|
|
];
|
|
|
|
$this->content->row(function (Row $row) use ($areas) {
|
|
foreach ($areas as $area) {
|
|
$row->column(2, function (Column $column) use ($area) {
|
|
$column->append(new InfoBox(
|
|
$area['name'],
|
|
'goods',
|
|
$area['color'],
|
|
$area['link'],
|
|
$area['count'],
|
|
));
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
return $this->content;
|
|
}
|
|
|
|
/**
|
|
* Notes: 积分兑换信息
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date: 2023/1/29 8:50
|
|
* @return mixed
|
|
*/
|
|
public function getScoreData()
|
|
{
|
|
$this->content->row($this->setDivider('积分兑换订单'));
|
|
$lists = [
|
|
'all' => [
|
|
'name' => '兑换总数',
|
|
'color' => 'blue',
|
|
'link' => '',
|
|
'count' => Order::where('type', Order::TYPE_SCORE)->whereIn('state', [
|
|
Order::STATUS_INIT,
|
|
Order::STATUS_PAID,
|
|
Order::STATUS_DELIVERED,
|
|
Order::STATUS_SIGNED,
|
|
])->count()
|
|
],
|
|
'init' => [
|
|
'name' => '待支付',
|
|
'color' => 'green',
|
|
'link' => '',
|
|
'count' => Order::where('type', Order::TYPE_SCORE)->where('state', Order::STATUS_INIT)->count()
|
|
],
|
|
'paid' => [
|
|
'name' => '待发货',
|
|
'color' => 'green',
|
|
'link' => '',
|
|
'count' => Order::where('type', Order::TYPE_SCORE)->where('state', Order::STATUS_PAID)->count()
|
|
],
|
|
'delivered' => [
|
|
'name' => '待签收',
|
|
'color' => 'green',
|
|
'link' => '',
|
|
'count' => Order::where('type', Order::TYPE_SCORE)->where('state', Order::STATUS_DELIVERED)->count()
|
|
],
|
|
'sign' => [
|
|
'name' => '已签收',
|
|
'color' => 'green',
|
|
'link' => '',
|
|
'count' => Order::where('type', Order::TYPE_SCORE)->where('state', Order::STATUS_SIGNED)->count()
|
|
],
|
|
];
|
|
|
|
$this->content->row(function (Row $row) use ($lists) {
|
|
foreach ($lists as $list) {
|
|
$row->column(2, function (Column $column) use ($list) {
|
|
$column->append(new InfoBox(
|
|
$list['name'],
|
|
'goods',
|
|
$list['color'],
|
|
$list['link'],
|
|
$list['count'],
|
|
));
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
return $this->content;
|
|
}
|
|
|
|
|
|
/**
|
|
* Notes : 清理模型缓存
|
|
*
|
|
* @Date : 2021/6/8 10:51 上午
|
|
* @Author : < Jason.C >
|
|
* @return string
|
|
*/
|
|
public function cleanCache(): string
|
|
{
|
|
Artisan::call('modelCache:clear');
|
|
|
|
return '缓存清理成功';
|
|
}
|
|
|
|
public function setDivider($title)
|
|
{
|
|
return <<<HTML
|
|
<div style="height: 20px; border-bottom: 1px solid #eee; text-align: center;margin-top: 20px;margin-bottom: 20px;">
|
|
<span style="font-size: 18px; padding: 0 10px;">
|
|
{$title}
|
|
</span>
|
|
</div>
|
|
HTML;
|
|
}
|
|
|
|
}
|