ソースを参照

[智价云] 报表统计看板接口

tangyuanwang 2 ヶ月 前
コミット
43d1379e63

+ 383 - 0
app/Http/Controllers/Manager/Statistics/OverviewPanel.php

@@ -0,0 +1,383 @@
+<?php
+
+namespace App\Http\Controllers\manager\Statistics;
+
+use App\Http\Controllers\Controller;
+use App\Http\Requests\Manager\Statistics\OverviewPanel as request;
+use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
+use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
+use Illuminate\Support\Facades\DB;
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+use PhpOffice\PhpSpreadsheet\Style\Alignment;
+
+/**
+ * 报表统计-概览面板
+ * @author 唐远望
+ * @version   1.0
+ * @date      2025-12-26
+ * 
+ */
+class OverviewPanel extends Controller
+{
+
+    /**
+     * 禁止挂网链接数统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function getViolationLinkCount(request $request, ViolationProductModel $violationProductModel)
+    {
+        $request->scene('getViolationLinkCount')->validate();
+        $limit = request('limit', config('page_num', 10));
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $violationProductModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /**
+     * 禁止挂网链接数统计-导出
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function Violation_export(request $request, ViolationProductModel $violationProductModel)
+    {
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $violationProductModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->get()->toarray();
+        //执行下载
+        $this->Violation_export_download($result);
+    }
+
+
+    /**
+     * 禁止挂网链接数统计-导出下载
+     * @author 唐远望
+     * @version 1.0
+     * @date 2025-06-17
+     */
+    public function Violation_export_download($data)
+    {
+        // 创建一个新的 Spreadsheet 对象
+        $spreadsheet = new Spreadsheet();
+        $sheet = $spreadsheet->getActiveSheet();
+
+        //合并单元格
+        $sheet->mergeCells('A1:B1');
+        $sheet->setCellValue('A1', '禁止挂网链接数统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
+        // 获取合并后的单元格样式对象
+        $style = $sheet->getStyle('A1');
+        // 设置水平居中和垂直居中
+        $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
+        // 然后设置行高以适应两行文本
+        $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
+        // 设置表头
+        $sheet->setCellValue('A2', '公司名称');
+        $sheet->setCellValue('B2', '链接挂网数量');
+
+        // 填充数据
+        $row = 3; // 从第3行开始
+        foreach ($data as $item) {
+            $sheet->setCellValue('A' . $row, $item['company_name']);
+            $sheet->setCellValue('B' . $row, $item['count']);
+            $row++;
+        }
+        // 生成 Excel 文件
+        $writer = new Xlsx($spreadsheet);
+
+        // 直接输出到浏览器(下载)
+        $filename = '禁止挂网链接数统计数据' . date('YmdHis') . '.xlsx';
+        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        header('Content-Disposition: attachment;filename="' . $filename . '"');
+        header('Cache-Control: max-age=0');
+        $writer->save('php://output');
+        exit;
+    }
+
+    /**
+     * 禁止挂网公司月度统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
+    {
+        $request->scene('get_violation_company_count')->validate();
+        $limit = request('limit', config('page_num', 10));
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $violationProductModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /**
+     * 禁止挂网公司月度统计-导出
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function violation_company_export(request $request, ViolationProductModel $violationProductModel)
+    {
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $violationProductModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->get()->toarray();
+        //执行下载
+        $this->ViolationCompany_export_download($result);
+    }
+
+    /**
+     * 禁止挂网公司月度统计-导出下载
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function ViolationCompany_export_download($data)
+    {
+        // 创建一个新的 Spreadsheet 对象
+        $spreadsheet = new Spreadsheet();
+        $sheet = $spreadsheet->getActiveSheet();
+
+        //合并单元格
+        $sheet->mergeCells('A1:B1');
+        $sheet->setCellValue('A1', '禁止挂网公司月度统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
+        // 获取合并后的单元格样式对象
+        $style = $sheet->getStyle('A1');
+        // 设置水平居中和垂直居中
+        $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
+        // 然后设置行高以适应两行文本
+        $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
+        // 设置表头
+        $sheet->setCellValue('A2', '公司名称');
+        $sheet->setCellValue('B2', '挂网数量');
+
+        // 填充数据
+        $row = 3; // 从第3行开始
+        foreach ($data as $item) {
+            $sheet->setCellValue('A' . $row, $item['company_name']);
+            $sheet->setCellValue('B' . $row, $item['count']);
+            $row++;
+        }
+        // 生成 Excel 文件
+        $writer = new Xlsx($spreadsheet);
+
+        // 直接输出到浏览器(下载)
+        $filename = '禁止挂网公司月度统计数据' . date('YmdHis') . '.xlsx';
+        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        header('Content-Disposition: attachment;filename="' . $filename . '"');
+        header('Cache-Control: max-age=0');
+        $writer->save('php://output');
+        exit;
+    }
+
+
+    /*
+     * 低价违规挂网链接数统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function getLowPriceLinkCount(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
+    {
+        $request->scene('getLowPriceLinkCount')->validate();
+        $limit = request('limit', config('page_num', 10));
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $LowPriceGoodsModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /**
+     * 低价违规挂网链接数统计-导出
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function low_price_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
+    {
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $LowPriceGoodsModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->get()->toarray();
+        //执行下载
+        $this->LowPrice_export_download($result);
+    }
+
+    /**
+     * 低价违规挂网链接数统计-导出下载
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function LowPrice_export_download($data)
+    {
+        // 创建一个新的 Spreadsheet 对象
+        $spreadsheet = new Spreadsheet();
+        $sheet = $spreadsheet->getActiveSheet();
+
+        //合并单元格
+        $sheet->mergeCells('A1:B1');
+        $sheet->setCellValue('A1', '低价违规挂网链接数统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
+        // 获取合并后的单元格样式对象
+        $style = $sheet->getStyle('A1');
+        // 设置水平居中和垂直居中
+        $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
+        // 然后设置行高以适应两行文本
+        $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
+        // 设置表头
+        $sheet->setCellValue('A2', '公司名称');
+        $sheet->setCellValue('B2', '链接挂网数量');
+
+        // 填充数据
+        $row = 3; // 从第3行开始
+        foreach ($data as $item) {
+            $sheet->setCellValue('A' . $row, $item['company_name']);
+            $sheet->setCellValue('B' . $row, $item['count']);
+            $row++;
+        }
+        // 生成 Excel 文件
+        $writer = new Xlsx($spreadsheet);
+
+        // 直接输出到浏览器(下载)
+        $filename = '低价违规挂网链接数统计数据' . date('YmdHis') . '.xlsx';
+        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        header('Content-Disposition: attachment;filename="' . $filename . '"');
+        header('Cache-Control: max-age=0');
+        $writer->save('php://output');
+        exit;
+    }
+
+    /*
+     * 低价违规挂网公司月度统计
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function getLowPriceCompanyCount(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
+    {
+        $request->scene('getLowPriceCompanyCount')->validate();
+        $limit = request('limit', config('page_num', 10));
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $LowPriceGoodsModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->paginate($limit);
+        return  json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
+    }
+
+    /**
+     * 低价违规挂网公司月度统计-导出
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function low_price_company_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
+    {
+        $start_time = request('start_time', '');
+        $end_time = request('end_time', '');
+        // 时间条件
+        $map  = [];
+        if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
+        if ($end_time) $map[]   = ['insert_time', '<=', strtotime($end_time)];
+        $result = $LowPriceGoodsModel->where($map)->where('status', 0)
+            ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
+            ->groupby('company_name')->get()->toarray();
+        //执行下载
+        $this->LowPriceCompany_export_download($result);
+    }
+    /**
+     * 低价违规挂网公司月度统计-导出下载
+     * @author 唐远望
+     * @version   1.0
+     * @date      2025-12-26
+     * 
+     */
+    public function LowPriceCompany_export_download($data)
+    {
+        // 创建一个新的 Spreadsheet 对象
+        $spreadsheet = new Spreadsheet();
+        $sheet = $spreadsheet->getActiveSheet();
+
+        //合并单元格
+        $sheet->mergeCells('A1:B1');
+        $sheet->setCellValue('A1', '低价违规挂网公司月度统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
+        // 获取合并后的单元格样式对象
+        $style = $sheet->getStyle('A1');
+        // 设置水平居中和垂直居中
+        $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
+        // 然后设置行高以适应两行文本
+        $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
+        // 设置表头
+        $sheet->setCellValue('A2', '公司名称');
+        $sheet->setCellValue('B2', '挂网数量');
+
+        // 填充数据
+        $row = 3; // 从第3行开始
+        foreach ($data as $item) {
+            $sheet->setCellValue('A' . $row, $item['company_name']);
+            $sheet->setCellValue('B' . $row, $item['count']);
+            $row++;
+        }
+        // 生成 Excel 文件
+        $writer = new Xlsx($spreadsheet);
+
+        // 直接输出到浏览器(下载)
+        $filename = '低价违规挂网公司月度统计数据' . date('YmdHis') . '.xlsx';
+        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        header('Content-Disposition: attachment;filename="' . $filename . '"');
+        header('Cache-Control: max-age=0');
+        $writer->save('php://output');
+        exit;
+    }
+}

+ 78 - 0
app/Http/Requests/Manager/Statistics/OverviewPanel.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Http\Requests\Manager\Statistics;
+
+use App\Http\Requests\BaseRequest;
+
+/**
+ * 报表统计-概览面板
+ * @author 唐远望
+ * @version 1.0
+ * @date 2025-12-26
+ * 
+ */
+class OverviewPanel extends BaseRequest
+{
+    /**
+     * 获取应用于请求的规则
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        // 返回结果
+        return      [
+            'name'                 => 'required',
+            'id'                => 'required|integer|gt:0',
+            'status'            => 'required|integer|in:0,1',
+            'page'              => 'integer|min:1',
+            'limit'             => 'integer|min:1',
+            'image_url'         => 'required',
+            'link_url'          => 'required',
+            'sort'              => 'required|integer|min:0',
+        ];
+    }
+
+
+    // 场景列表
+    protected   $scenes         = [
+        'detail'             => ['id'],
+        'list'               => ['page', 'limit'],
+        'add'                      => [''],
+        'edit'                      => [''],
+        'set_status'              => ['id', 'status'],
+        'delete'                  => ['id'],
+        'data_cleaning'           => [''],
+        'export_excel'            => [''],
+        'getViolationLinkCount'   => ['page','limit'],
+        'getLowPriceLinkCount'   => ['page','limit'],
+        'get_violation_company_count'   => ['page','limit'],
+    ];
+
+    /**
+     * 获取已定义验证规则的错误消息
+     *
+     * @return array
+     */
+    public function messages()
+    {
+        return [
+            'name.required'     => '名称必填',
+            'id.required'       => 'ID未知',
+            'id.integer'        => 'ID格式错误',
+            'id.gt'               => 'ID格式错误',
+            'status.required'   => '状态未知',
+            'status.integer'    => '状态格式错误',
+            'status.in'         => '状态格式错误',
+            'page.integer'      => '页码格式错误',
+            'page.min'          => '页码格式错误',
+            'limit.integer'     => '每页数量格式错误',
+            'limit.min'         => '每页数量格式错误',
+            'image_url.required'    => '图片链接未知',
+            'link_url.required'     => '链接地址未知',
+            'sort.required'         => '排序未知',
+            'sort.integer'          => '排序格式错误',
+            'sort.min'              => '排序格式错误',
+        ];
+    }
+}

+ 18 - 1
routes/manager.php

@@ -241,4 +241,21 @@ Route::any('upload/get_sign_url',[App\Http\Controllers\Manager\Upload::class,'ge
 Route::any('upload/uploadimg',[App\Http\Controllers\Manager\Upload::class,'uploadimg']);
 Route::any('upload/uploadimg',[App\Http\Controllers\Manager\Upload::class,'uploadimg']);
 
 
 // 操作日志-列表
 // 操作日志-列表
-Route::any('operation_log/list', [App\Http\Controllers\Manager\AdminHistory::class, 'list']);
+Route::any('operation_log/list', [App\Http\Controllers\Manager\AdminHistory::class, 'list']);
+
+//报表统计-禁止挂网链接数统计
+Route::any('statistics/overview_panel/get_violation_link_count', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'getViolationLinkCount']);
+//报表统计-禁止挂网链接数统计-导出
+Route::any('statistics/overview_panel/violation_export', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'Violation_export']);
+//报表统计-禁止挂网公司月度统计
+Route::any('statistics/overview_panel/get_violation_company_count', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'get_violation_company_count']);
+//报表统计-禁止挂网公司月度统计-导出
+Route::any('statistics/overview_panel/violation_company_export', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'violation_company_export']);
+//报表统计-低价违规挂网链接数统计
+Route::any('statistics/overview_panel/get_low_price_link_count', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'getLowPriceLinkCount']);
+//报表统计-低价违规挂网链接数统计-导出
+Route::any('statistics/overview_panel/low_price_export', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'low_price_export']);
+//报表统计-低价违规挂网公司月度统计
+Route::any('statistics/overview_panel/get_low_price_company_count', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'getLowPriceCompanyCount']);
+//报表统计-低价违规挂网公司月度统计-导出
+Route::any('statistics/overview_panel/low_price_company_export', [App\Http\Controllers\Manager\Statistics\OverviewPanel::class, 'low_price_company_export']);