350 lines
10 KiB
PHP
350 lines
10 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->getUserStockData();
|
|
// $this->getUserStockOrderData();
|
|
} 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: 2022/9/1 13:35
|
|
* @return mixed
|
|
*/
|
|
public function getUserStockData()
|
|
{
|
|
$this->content->row($this->setDivider('会员水库存数'));
|
|
|
|
$all = UserStock::query()->sum('stock');
|
|
$holds = UserStock::query()->sum('hold');
|
|
$sy = bcsub($all, $holds);
|
|
|
|
$users = [
|
|
'all' => [
|
|
'name' => '总数',
|
|
'color' => 'blue',
|
|
'count' => UserStock::query()->sum('stock')
|
|
],
|
|
'stock' => [
|
|
'name' => '已提货数',
|
|
'color' => 'green',
|
|
'count' => UserStock::query()->sum('hold')
|
|
],
|
|
'sy' => [
|
|
'name' => '待提货数',
|
|
'color' => 'green',
|
|
'count' => $sy
|
|
],
|
|
];
|
|
|
|
$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'],
|
|
'goods',
|
|
$user['color'],
|
|
'/admin/stocks',
|
|
$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;
|
|
}
|
|
|
|
public function getUserFreeData()
|
|
{
|
|
$this->content->row($this->setDivider('会员水库存数'));
|
|
|
|
$all = UserStock::query()->sum('stock');
|
|
$holds = UserStock::query()->sum('hold');
|
|
$sy = bcsub($all, $holds);
|
|
|
|
$users = [
|
|
'all' => [
|
|
'name' => '总数',
|
|
'color' => 'blue',
|
|
'count' => UserStock::query()->sum('stock')
|
|
],
|
|
'stock' => [
|
|
'name' => '已提货数',
|
|
'color' => 'green',
|
|
'count' => UserStock::query()->sum('hold')
|
|
],
|
|
'sy' => [
|
|
'name' => '待提货数',
|
|
'color' => 'green',
|
|
'count' => $sy
|
|
],
|
|
];
|
|
|
|
$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'],
|
|
'goods',
|
|
$user['color'],
|
|
'/admin/stocks',
|
|
$user['count'],
|
|
));
|
|
|
|
});
|
|
}
|
|
});
|
|
|
|
return $this->content;
|
|
}
|
|
|
|
/**
|
|
* Notes: 提货订单数量
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date: 2022/9/1 13:51
|
|
*/
|
|
public function getUserStockOrderData()
|
|
{
|
|
$this->content->row($this->setDivider('会员提货订单'));
|
|
|
|
|
|
$deliver = OrderItem::query()
|
|
->whereHas('order', function ($q) {
|
|
$q->paid();
|
|
})->sum('qty');
|
|
|
|
$deliverd = OrderItem::query()
|
|
->whereHas('order', function ($q) {
|
|
$q->whereIn('state', [
|
|
Order::STATUS_SIGNED,
|
|
Order::STATUS_DELIVERED,
|
|
]);
|
|
})->sum('qty');
|
|
|
|
$users = [
|
|
'all' => [
|
|
'name' => '订单总数',
|
|
'color' => 'blue',
|
|
'count' => Order::query()->where('type', Order::TYPE_SAMPLE)->count()
|
|
],
|
|
'deliver' => [
|
|
'name' => '待发货',
|
|
'color' => 'green',
|
|
'count' => Order::query()
|
|
->where('type', Order::TYPE_SAMPLE)
|
|
->paid()
|
|
->count()
|
|
],
|
|
'deliverd' => [
|
|
'name' => '已发货',
|
|
'color' => 'green',
|
|
'count' => Order::query()
|
|
->where('type', Order::TYPE_SAMPLE)
|
|
->whereIn('state', [
|
|
Order::STATUS_DELIVERED,
|
|
])
|
|
->count(),
|
|
],
|
|
'signed' => [
|
|
'name' => '已签收',
|
|
'color' => 'green',
|
|
'count' => Order::query()
|
|
->where('type', Order::TYPE_SAMPLE)
|
|
->whereIn('state', [
|
|
Order::STATUS_SIGNED,
|
|
])
|
|
->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'],
|
|
'goods',
|
|
$user['color'],
|
|
'/admin/stocks',
|
|
$user['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;
|
|
}
|
|
|
|
}
|