Browse Source

增加统计

黄宗昌 2 years ago
parent
commit
1f1efe539e

+ 5 - 5
app/Admin/Controllers/HomeController.php

xqd
@@ -32,25 +32,25 @@ class HomeController extends Controller
                 });
                 $row->column(2, function (Column $column) {
                     $column->row(function (Row $row) {
-                        $row->column(12, new Examples\TotalUsers());
+                        $row->column(12, new Examples\TotalProduct());
                     });
                 });
                 // 举报
                 $row->column(10, function (Column $column) {
-                    $column->row(new Examples\NewUsers());
+                    $column->row(new Examples\NewReport());
                 });
                 $row->column(2, function (Column $column) {
                     $column->row(function (Row $row) {
-                        $row->column(12, new Examples\TotalUsers());
+                        $row->column(12, new Examples\TotalReport());
                     });
                 });
                 // 消息
                 $row->column(10, function (Column $column) {
-                    $column->row(new Examples\NewUsers());
+                    $column->row(new Examples\NewMsg());
                 });
                 $row->column(2, function (Column $column) {
                     $column->row(function (Row $row) {
-                        $row->column(12, new Examples\TotalUsers());
+                        $row->column(12, new Examples\TotalMsg());
                     });
                 });
             });

+ 155 - 0
app/Admin/Metrics/Examples/NewMsg.php

xqd
@@ -0,0 +1,155 @@
+<?php
+
+namespace App\Admin\Metrics\Examples;
+
+use App\Models\Msg;
+use Dcat\Admin\Widgets\Metrics\Line;
+use Illuminate\Http\Request;
+
+class NewMsg extends Line
+{
+    /**
+     * 初始化卡片内容
+     *
+     * @return void
+     */
+    protected function init()
+    {
+        parent::init();
+
+        $this->title(admin_trans('admin-home.New_Msg'));
+        $this->dropdown([
+            '7' => admin_trans('admin-home.Last_7_days'),
+            '30' => admin_trans('admin-home.Last_month'),
+//            '180' => admin_trans('admin-home.Last_half_year'),
+//            '365' => admin_trans('admin-home.Last_year'),
+        ]);
+    }
+
+    /**
+     * 处理请求
+     *
+     * @param Request $request
+     *
+     * @return mixed|void
+     */
+    public function handle(Request $request)
+    {
+        $generator = function ($len, $min = 10, $max = 300) {
+            for ($i = 0; $i <= $len; $i++) {
+                yield mt_rand($min, $max);
+            }
+        };
+
+        switch ($request->get('option')) {
+            case '365':
+                $user = $this->new_user("365");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '30':
+                $user = $this->new_user("30");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '180':
+                $user = $this->new_user("180");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '7':
+            default:
+            $user = $this->new_user("7");
+            // 卡片内容
+            $this->withContent($user['num']);
+            // 图表数据
+            $this->withChart($user['num_arr']);
+            break;
+        }
+    }
+
+    /**
+     *  新用户 一年
+     *   write by wanglas
+     */
+    public function new_user($kind){
+
+        if ($kind=='365'){
+            $t_last = date('Y-m-d H:i:s',strtotime('-1 year'));
+            $t_time = 86400*12;
+            $count = 31;
+        }elseif ($kind=='180'){
+            $t_last = date('Y-m-d H:i:s',strtotime('-180 day'));
+            $t_time = 86400*6;
+            $count = 31;
+        }elseif ($kind=='30'){
+            $t_last = date('Y-m-d',strtotime('-30 day'));
+            $t_time = 86400;
+            $count = 30;
+        }elseif ($kind=='7'){
+            $t_last = date('Y-m-d',strtotime('-7 day'));
+            $t_time = 86400;
+            $count = 8;
+        }
+        //统计会员总数
+        $t_now = date('Y-m-d');
+        $num = Msg::query()->whereBetween('created_at',array($t_last,$t_now))->count();
+        //计算会员增长数量
+        for ($i=1 ; $i < $count; $i++) {
+            $today=strtotime(date('Ymd'));
+            $start_time = date('Y-m-d',$today-$t_time*$i);
+            $end_time  = date('Y-m-d',$today-$t_time*($i-1));
+            $inc_num = Msg::query()->whereBetween('created_at',[$start_time,$end_time])->count();
+            //$arr_t[]=$now;
+            $arr_n[]=$inc_num;
+        }
+        //逆序输出数组
+        //$arr_t=array_reverse($arr_t);  //时间
+        $arr_n=array_reverse($arr_n);  //数量
+        return array('num'=>$num,'num_arr'=>$arr_n);
+    }
+
+    /**
+     * 设置图表数据.
+     *
+     * @param array $data
+     *
+     * @return $this
+     */
+    public function withChart(array $data)
+    {
+        return $this->chart([
+            'series' => [
+                [
+                    'name' => $this->title,
+                    'data' => $data,
+                ],
+            ],
+        ]);
+    }
+
+    /**
+     * 设置卡片内容.
+     *
+     * @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
+        );
+    }
+}

+ 155 - 0
app/Admin/Metrics/Examples/NewProduct.php

xqd
@@ -0,0 +1,155 @@
+<?php
+
+namespace App\Admin\Metrics\Examples;
+
+use App\Models\Product;
+use Dcat\Admin\Widgets\Metrics\Line;
+use Illuminate\Http\Request;
+
+class NewProduct extends Line
+{
+    /**
+     * 初始化卡片内容
+     *
+     * @return void
+     */
+    protected function init()
+    {
+        parent::init();
+
+        $this->title(admin_trans('admin-home.New_Product'));
+        $this->dropdown([
+            '7' => admin_trans('admin-home.Last_7_days'),
+            '30' => admin_trans('admin-home.Last_month'),
+//            '180' => admin_trans('admin-home.Last_half_year'),
+//            '365' => admin_trans('admin-home.Last_year'),
+        ]);
+    }
+
+    /**
+     * 处理请求
+     *
+     * @param Request $request
+     *
+     * @return mixed|void
+     */
+    public function handle(Request $request)
+    {
+        $generator = function ($len, $min = 10, $max = 300) {
+            for ($i = 0; $i <= $len; $i++) {
+                yield mt_rand($min, $max);
+            }
+        };
+
+        switch ($request->get('option')) {
+            case '365':
+                $user = $this->new_user("365");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '30':
+                $user = $this->new_user("30");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '180':
+                $user = $this->new_user("180");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '7':
+            default:
+            $user = $this->new_user("7");
+            // 卡片内容
+            $this->withContent($user['num']);
+            // 图表数据
+            $this->withChart($user['num_arr']);
+            break;
+        }
+    }
+
+    /**
+     *  新用户 一年
+     *   write by wanglas
+     */
+    public function new_user($kind){
+
+        if ($kind=='365'){
+            $t_last = date('Y-m-d H:i:s',strtotime('-1 year'));
+            $t_time = 86400*12;
+            $count = 31;
+        }elseif ($kind=='180'){
+            $t_last = date('Y-m-d H:i:s',strtotime('-180 day'));
+            $t_time = 86400*6;
+            $count = 31;
+        }elseif ($kind=='30'){
+            $t_last = date('Y-m-d',strtotime('-30 day'));
+            $t_time = 86400;
+            $count = 30;
+        }elseif ($kind=='7'){
+            $t_last = date('Y-m-d',strtotime('-7 day'));
+            $t_time = 86400;
+            $count = 8;
+        }
+        //统计会员总数
+        $t_now = date('Y-m-d');
+        $num = Product::query()->whereBetween('created_at',array($t_last,$t_now))->count();
+        //计算会员增长数量
+        for ($i=1 ; $i < $count; $i++) {
+            $today=strtotime(date('Ymd'));
+            $start_time = date('Y-m-d',$today-$t_time*$i);
+            $end_time  = date('Y-m-d',$today-$t_time*($i-1));
+            $inc_num = Product::query()->whereBetween('created_at',[$start_time,$end_time])->count();
+            //$arr_t[]=$now;
+            $arr_n[]=$inc_num;
+        }
+        //逆序输出数组
+        //$arr_t=array_reverse($arr_t);  //时间
+        $arr_n=array_reverse($arr_n);  //数量
+        return array('num'=>$num,'num_arr'=>$arr_n);
+    }
+
+    /**
+     * 设置图表数据.
+     *
+     * @param array $data
+     *
+     * @return $this
+     */
+    public function withChart(array $data)
+    {
+        return $this->chart([
+            'series' => [
+                [
+                    'name' => $this->title,
+                    'data' => $data,
+                ],
+            ],
+        ]);
+    }
+
+    /**
+     * 设置卡片内容.
+     *
+     * @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
+        );
+    }
+}

+ 155 - 0
app/Admin/Metrics/Examples/NewReport.php

xqd
@@ -0,0 +1,155 @@
+<?php
+
+namespace App\Admin\Metrics\Examples;
+
+use App\Models\ReportLog;
+use Dcat\Admin\Widgets\Metrics\Line;
+use Illuminate\Http\Request;
+
+class NewReport extends Line
+{
+    /**
+     * 初始化卡片内容
+     *
+     * @return void
+     */
+    protected function init()
+    {
+        parent::init();
+
+        $this->title(admin_trans('admin-home.New_Report'));
+        $this->dropdown([
+            '7' => admin_trans('admin-home.Last_7_days'),
+            '30' => admin_trans('admin-home.Last_month'),
+//            '180' => admin_trans('admin-home.Last_half_year'),
+//            '365' => admin_trans('admin-home.Last_year'),
+        ]);
+    }
+
+    /**
+     * 处理请求
+     *
+     * @param Request $request
+     *
+     * @return mixed|void
+     */
+    public function handle(Request $request)
+    {
+        $generator = function ($len, $min = 10, $max = 300) {
+            for ($i = 0; $i <= $len; $i++) {
+                yield mt_rand($min, $max);
+            }
+        };
+
+        switch ($request->get('option')) {
+            case '365':
+                $user = $this->new_user("365");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '30':
+                $user = $this->new_user("30");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '180':
+                $user = $this->new_user("180");
+                // 卡片内容
+                $this->withContent($user['num']);
+                // 图表数据
+                $this->withChart($user['num_arr']);
+                break;
+            case '7':
+            default:
+            $user = $this->new_user("7");
+            // 卡片内容
+            $this->withContent($user['num']);
+            // 图表数据
+            $this->withChart($user['num_arr']);
+            break;
+        }
+    }
+
+    /**
+     *  新用户 一年
+     *   write by wanglas
+     */
+    public function new_user($kind){
+
+        if ($kind=='365'){
+            $t_last = date('Y-m-d H:i:s',strtotime('-1 year'));
+            $t_time = 86400*12;
+            $count = 31;
+        }elseif ($kind=='180'){
+            $t_last = date('Y-m-d H:i:s',strtotime('-180 day'));
+            $t_time = 86400*6;
+            $count = 31;
+        }elseif ($kind=='30'){
+            $t_last = date('Y-m-d',strtotime('-30 day'));
+            $t_time = 86400;
+            $count = 30;
+        }elseif ($kind=='7'){
+            $t_last = date('Y-m-d',strtotime('-7 day'));
+            $t_time = 86400;
+            $count = 8;
+        }
+        //统计会员总数
+        $t_now = date('Y-m-d');
+        $num = ReportLog::query()->whereBetween('created_at',array($t_last,$t_now))->count();
+        //计算会员增长数量
+        for ($i=1 ; $i < $count; $i++) {
+            $today=strtotime(date('Ymd'));
+            $start_time = date('Y-m-d',$today-$t_time*$i);
+            $end_time  = date('Y-m-d',$today-$t_time*($i-1));
+            $inc_num = ReportLog::query()->whereBetween('created_at',[$start_time,$end_time])->count();
+            //$arr_t[]=$now;
+            $arr_n[]=$inc_num;
+        }
+        //逆序输出数组
+        //$arr_t=array_reverse($arr_t);  //时间
+        $arr_n=array_reverse($arr_n);  //数量
+        return array('num'=>$num,'num_arr'=>$arr_n);
+    }
+
+    /**
+     * 设置图表数据.
+     *
+     * @param array $data
+     *
+     * @return $this
+     */
+    public function withChart(array $data)
+    {
+        return $this->chart([
+            'series' => [
+                [
+                    'name' => $this->title,
+                    'data' => $data,
+                ],
+            ],
+        ]);
+    }
+
+    /**
+     * 设置卡片内容.
+     *
+     * @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
+        );
+    }
+}

+ 107 - 0
app/Admin/Metrics/Examples/TotalMsg.php

xqd
@@ -0,0 +1,107 @@
+<?php
+
+namespace App\Admin\Metrics\Examples;
+
+use App\Models\Game;
+use App\Models\Msg;
+use App\Models\Team;
+use Dcat\Admin\Widgets\Metrics\Card;
+use Illuminate\Contracts\Support\Renderable;
+use Illuminate\Http\Request;
+
+class TotalMsg extends Card
+{
+    /**
+     * 卡片底部内容.
+     *
+     * @var string|Renderable|\Closure
+     */
+    protected $footer;
+
+    /**
+     * 初始化卡片.
+     */
+    protected function init()
+    {
+        parent::init();
+        $this->title(trans('admin-home.Total_Msg'));
+    }
+
+    /**
+     * 处理请求.
+     *
+     * @param Request $request
+     *
+     * @return void
+     */
+    public function handle(Request $request)
+    {
+        $total_team = Msg::query()->count();
+        $this->content($total_team);
+    }
+
+    /**
+     * @param int $percent
+     *
+     * @return $this
+     */
+    public function up($percent)
+    {
+        return $this->footer(
+            "<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase"
+        );
+    }
+
+    /**
+     * @param int $percent
+     *
+     * @return $this
+     */
+    public function down($percent)
+    {
+        return $this->footer(
+            "<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease"
+        );
+    }
+
+    /**
+     * 设置卡片底部内容.
+     *
+     * @param string|Renderable|\Closure $footer
+     *
+     * @return $this
+     */
+    public function footer($footer)
+    {
+        $this->footer = $footer;
+
+        return $this;
+    }
+
+    /**
+     * 渲染卡片内容.
+     *
+     * @return string
+     */
+    public function renderContent()
+    {
+        $content = parent::renderContent();
+
+        return <<<HTML
+<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px;cursor: pointer" onclick="location.href='/admin/user'">
+    <h2 class="ml-1 font-lg-1" style="font-size: 48px!important;">{$content}</h2>
+</div>
+
+HTML;
+    }
+
+    /**
+     * 渲染卡片底部内容.
+     *
+     * @return string
+     */
+    public function renderFooter()
+    {
+        return $this->toString($this->footer);
+    }
+}

+ 108 - 0
app/Admin/Metrics/Examples/TotalProduct.php

xqd
@@ -0,0 +1,108 @@
+<?php
+
+namespace App\Admin\Metrics\Examples;
+
+use App\Models\Game;
+use App\Models\Product;
+use App\Models\Team;
+use App\Models\User;
+use Dcat\Admin\Widgets\Metrics\Card;
+use Illuminate\Contracts\Support\Renderable;
+use Illuminate\Http\Request;
+
+class TotalProduct extends Card
+{
+    /**
+     * 卡片底部内容.
+     *
+     * @var string|Renderable|\Closure
+     */
+    protected $footer;
+
+    /**
+     * 初始化卡片.
+     */
+    protected function init()
+    {
+        parent::init();
+        $this->title(trans('admin-home.Total_Product'));
+    }
+
+    /**
+     * 处理请求.
+     *
+     * @param Request $request
+     *
+     * @return void
+     */
+    public function handle(Request $request)
+    {
+        $total_team = Product::query()->count();
+        $this->content($total_team);
+    }
+
+    /**
+     * @param int $percent
+     *
+     * @return $this
+     */
+    public function up($percent)
+    {
+        return $this->footer(
+            "<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase"
+        );
+    }
+
+    /**
+     * @param int $percent
+     *
+     * @return $this
+     */
+    public function down($percent)
+    {
+        return $this->footer(
+            "<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease"
+        );
+    }
+
+    /**
+     * 设置卡片底部内容.
+     *
+     * @param string|Renderable|\Closure $footer
+     *
+     * @return $this
+     */
+    public function footer($footer)
+    {
+        $this->footer = $footer;
+
+        return $this;
+    }
+
+    /**
+     * 渲染卡片内容.
+     *
+     * @return string
+     */
+    public function renderContent()
+    {
+        $content = parent::renderContent();
+
+        return <<<HTML
+<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px;cursor: pointer" onclick="location.href='/admin/user'">
+    <h2 class="ml-1 font-lg-1" style="font-size: 48px!important;">{$content}</h2>
+</div>
+
+HTML;
+    }
+
+    /**
+     * 渲染卡片底部内容.
+     *
+     * @return string
+     */
+    public function renderFooter()
+    {
+        return $this->toString($this->footer);
+    }
+}

+ 107 - 0
app/Admin/Metrics/Examples/TotalReport.php

xqd
@@ -0,0 +1,107 @@
+<?php
+
+namespace App\Admin\Metrics\Examples;
+
+use App\Models\Game;
+use App\Models\ReportLog;
+use App\Models\Team;
+use Dcat\Admin\Widgets\Metrics\Card;
+use Illuminate\Contracts\Support\Renderable;
+use Illuminate\Http\Request;
+
+class TotalReport extends Card
+{
+    /**
+     * 卡片底部内容.
+     *
+     * @var string|Renderable|\Closure
+     */
+    protected $footer;
+
+    /**
+     * 初始化卡片.
+     */
+    protected function init()
+    {
+        parent::init();
+        $this->title(trans('admin-home.Total_Report'));
+    }
+
+    /**
+     * 处理请求.
+     *
+     * @param Request $request
+     *
+     * @return void
+     */
+    public function handle(Request $request)
+    {
+        $total_team = ReportLog::query()->count();
+        $this->content($total_team);
+    }
+
+    /**
+     * @param int $percent
+     *
+     * @return $this
+     */
+    public function up($percent)
+    {
+        return $this->footer(
+            "<i class=\"feather icon-trending-up text-success\"></i> {$percent}% Increase"
+        );
+    }
+
+    /**
+     * @param int $percent
+     *
+     * @return $this
+     */
+    public function down($percent)
+    {
+        return $this->footer(
+            "<i class=\"feather icon-trending-down text-danger\"></i> {$percent}% Decrease"
+        );
+    }
+
+    /**
+     * 设置卡片底部内容.
+     *
+     * @param string|Renderable|\Closure $footer
+     *
+     * @return $this
+     */
+    public function footer($footer)
+    {
+        $this->footer = $footer;
+
+        return $this;
+    }
+
+    /**
+     * 渲染卡片内容.
+     *
+     * @return string
+     */
+    public function renderContent()
+    {
+        $content = parent::renderContent();
+
+        return <<<HTML
+<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px;cursor: pointer" onclick="location.href='/admin/user'">
+    <h2 class="ml-1 font-lg-1" style="font-size: 48px!important;">{$content}</h2>
+</div>
+
+HTML;
+    }
+
+    /**
+     * 渲染卡片底部内容.
+     *
+     * @return string
+     */
+    public function renderFooter()
+    {
+        return $this->toString($this->footer);
+    }
+}

+ 8 - 1
resources/lang/ko/admin-home.php

xqd
@@ -14,5 +14,12 @@ return [
 
     'whole'   => '모두',
 
-    'New_Product' => '신제품'
+    'New_Product' => '신제품',
+    'Total_Product' => '제품 총수',
+
+    'New_Report' => '신규 신고',
+    'Total_Report' => '적발 건수',
+
+    'New_Msg' => '새 소식',
+    'Total_Msg' => '메시지 수',
 ];

+ 6 - 1
resources/lang/zh/admin-home.php

xqd
@@ -22,5 +22,10 @@ return [
     'whole'   => '全部',
     'New_Lock' => '新增设备',
     'Total_Lock' => '设备总数',
-    'New_Product' => '新产品'
+    'New_Product' => '新产品',
+    'Total_Product' => '产品总数',
+    'New_Report' => '新举报',
+    'Total_Report' => '举报总数',
+    'New_Msg' => '新消息',
+    'Total_Msg' => '消息总数',
 ];