OverviewPanel.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <?php
  2. namespace App\Http\Controllers\manager\Statistics;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\Statistics\OverviewPanel as request;
  5. use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
  6. use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
  7. use Illuminate\Support\Facades\DB;
  8. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  9. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  10. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  11. /**
  12. * 报表统计-概览面板
  13. * @author 唐远望
  14. * @version 1.0
  15. * @date 2025-12-26
  16. *
  17. */
  18. class OverviewPanel extends Controller
  19. {
  20. /**
  21. * 禁止挂网链接数统计
  22. * @author 唐远望
  23. * @version 1.0
  24. * @date 2025-12-26
  25. *
  26. */
  27. public function getViolationLinkCount(request $request, ViolationProductModel $violationProductModel)
  28. {
  29. $request->scene('getViolationLinkCount')->validate();
  30. $limit = request('limit', config('page_num', 10));
  31. $start_time = request('start_time', '');
  32. $end_time = request('end_time', '');
  33. // 时间条件
  34. $map = [];
  35. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  36. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  37. $result = $violationProductModel->where($map)->where('status', 0)
  38. ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
  39. ->groupby('company_name')->paginate($limit);
  40. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  41. }
  42. /**
  43. * 禁止挂网链接数统计-导出
  44. * @author 唐远望
  45. * @version 1.0
  46. * @date 2025-12-26
  47. *
  48. */
  49. public function Violation_export(request $request, ViolationProductModel $violationProductModel)
  50. {
  51. $start_time = request('start_time', '');
  52. $end_time = request('end_time', '');
  53. // 时间条件
  54. $map = [];
  55. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  56. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  57. $result = $violationProductModel->where($map)->where('status', 0)
  58. ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
  59. ->groupby('company_name')->get()->toarray();
  60. //执行下载
  61. $this->Violation_export_download($result);
  62. }
  63. /**
  64. * 禁止挂网链接数统计-导出下载
  65. * @author 唐远望
  66. * @version 1.0
  67. * @date 2025-06-17
  68. */
  69. public function Violation_export_download($data)
  70. {
  71. // 创建一个新的 Spreadsheet 对象
  72. $spreadsheet = new Spreadsheet();
  73. $sheet = $spreadsheet->getActiveSheet();
  74. //合并单元格
  75. $sheet->mergeCells('A1:B1');
  76. $sheet->setCellValue('A1', '禁止挂网链接数统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  77. // 获取合并后的单元格样式对象
  78. $style = $sheet->getStyle('A1');
  79. // 设置水平居中和垂直居中
  80. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  81. // 然后设置行高以适应两行文本
  82. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  83. // 设置表头
  84. $sheet->setCellValue('A2', '公司名称');
  85. $sheet->setCellValue('B2', '链接挂网数量');
  86. // 填充数据
  87. $row = 3; // 从第3行开始
  88. foreach ($data as $item) {
  89. $sheet->setCellValue('A' . $row, $item['company_name']);
  90. $sheet->setCellValue('B' . $row, $item['count']);
  91. $row++;
  92. }
  93. // 生成 Excel 文件
  94. $writer = new Xlsx($spreadsheet);
  95. // 直接输出到浏览器(下载)
  96. $filename = '禁止挂网链接数统计数据' . date('YmdHis') . '.xlsx';
  97. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  98. header('Content-Disposition: attachment;filename="' . $filename . '"');
  99. header('Cache-Control: max-age=0');
  100. $writer->save('php://output');
  101. exit;
  102. }
  103. /**
  104. * 禁止挂网公司月度统计
  105. * @author 唐远望
  106. * @version 1.0
  107. * @date 2025-12-26
  108. *
  109. */
  110. public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
  111. {
  112. $request->scene('get_violation_company_count')->validate();
  113. $limit = request('limit', config('page_num', 10));
  114. $start_time = request('start_time', '');
  115. $end_time = request('end_time', '');
  116. // 时间条件
  117. $map = [];
  118. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  119. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  120. $result = $violationProductModel->where($map)->where('status', 0)
  121. ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
  122. ->groupby('company_name')->paginate($limit);
  123. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  124. }
  125. /**
  126. * 禁止挂网公司月度统计-导出
  127. * @author 唐远望
  128. * @version 1.0
  129. * @date 2025-12-26
  130. *
  131. */
  132. public function violation_company_export(request $request, ViolationProductModel $violationProductModel)
  133. {
  134. $start_time = request('start_time', '');
  135. $end_time = request('end_time', '');
  136. // 时间条件
  137. $map = [];
  138. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  139. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  140. $result = $violationProductModel->where($map)->where('status', 0)
  141. ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
  142. ->groupby('company_name')->get()->toarray();
  143. //执行下载
  144. $this->ViolationCompany_export_download($result);
  145. }
  146. /**
  147. * 禁止挂网公司月度统计-导出下载
  148. * @author 唐远望
  149. * @version 1.0
  150. * @date 2025-12-26
  151. *
  152. */
  153. public function ViolationCompany_export_download($data)
  154. {
  155. // 创建一个新的 Spreadsheet 对象
  156. $spreadsheet = new Spreadsheet();
  157. $sheet = $spreadsheet->getActiveSheet();
  158. //合并单元格
  159. $sheet->mergeCells('A1:B1');
  160. $sheet->setCellValue('A1', '禁止挂网公司月度统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  161. // 获取合并后的单元格样式对象
  162. $style = $sheet->getStyle('A1');
  163. // 设置水平居中和垂直居中
  164. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  165. // 然后设置行高以适应两行文本
  166. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  167. // 设置表头
  168. $sheet->setCellValue('A2', '公司名称');
  169. $sheet->setCellValue('B2', '挂网数量');
  170. // 填充数据
  171. $row = 3; // 从第3行开始
  172. foreach ($data as $item) {
  173. $sheet->setCellValue('A' . $row, $item['company_name']);
  174. $sheet->setCellValue('B' . $row, $item['count']);
  175. $row++;
  176. }
  177. // 生成 Excel 文件
  178. $writer = new Xlsx($spreadsheet);
  179. // 直接输出到浏览器(下载)
  180. $filename = '禁止挂网公司月度统计数据' . date('YmdHis') . '.xlsx';
  181. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  182. header('Content-Disposition: attachment;filename="' . $filename . '"');
  183. header('Cache-Control: max-age=0');
  184. $writer->save('php://output');
  185. exit;
  186. }
  187. /*
  188. * 低价违规挂网链接数统计
  189. * @author 唐远望
  190. * @version 1.0
  191. * @date 2025-12-26
  192. *
  193. */
  194. public function getLowPriceLinkCount(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  195. {
  196. $request->scene('getLowPriceLinkCount')->validate();
  197. $limit = request('limit', config('page_num', 10));
  198. $start_time = request('start_time', '');
  199. $end_time = request('end_time', '');
  200. // 时间条件
  201. $map = [];
  202. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  203. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  204. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  205. ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
  206. ->groupby('company_name')->paginate($limit);
  207. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  208. }
  209. /**
  210. * 低价违规挂网链接数统计-导出
  211. * @author 唐远望
  212. * @version 1.0
  213. * @date 2025-12-26
  214. *
  215. */
  216. public function low_price_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  217. {
  218. $start_time = request('start_time', '');
  219. $end_time = request('end_time', '');
  220. // 时间条件
  221. $map = [];
  222. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  223. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  224. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  225. ->select(['company_name', DB::raw('count(link_url) as count')])->orderby('count', 'desc')
  226. ->groupby('company_name')->get()->toarray();
  227. //执行下载
  228. $this->LowPrice_export_download($result);
  229. }
  230. /**
  231. * 低价违规挂网链接数统计-导出下载
  232. * @author 唐远望
  233. * @version 1.0
  234. * @date 2025-12-26
  235. *
  236. */
  237. public function LowPrice_export_download($data)
  238. {
  239. // 创建一个新的 Spreadsheet 对象
  240. $spreadsheet = new Spreadsheet();
  241. $sheet = $spreadsheet->getActiveSheet();
  242. //合并单元格
  243. $sheet->mergeCells('A1:B1');
  244. $sheet->setCellValue('A1', '低价违规挂网链接数统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  245. // 获取合并后的单元格样式对象
  246. $style = $sheet->getStyle('A1');
  247. // 设置水平居中和垂直居中
  248. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  249. // 然后设置行高以适应两行文本
  250. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  251. // 设置表头
  252. $sheet->setCellValue('A2', '公司名称');
  253. $sheet->setCellValue('B2', '链接挂网数量');
  254. // 填充数据
  255. $row = 3; // 从第3行开始
  256. foreach ($data as $item) {
  257. $sheet->setCellValue('A' . $row, $item['company_name']);
  258. $sheet->setCellValue('B' . $row, $item['count']);
  259. $row++;
  260. }
  261. // 生成 Excel 文件
  262. $writer = new Xlsx($spreadsheet);
  263. // 直接输出到浏览器(下载)
  264. $filename = '低价违规挂网链接数统计数据' . date('YmdHis') . '.xlsx';
  265. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  266. header('Content-Disposition: attachment;filename="' . $filename . '"');
  267. header('Cache-Control: max-age=0');
  268. $writer->save('php://output');
  269. exit;
  270. }
  271. /*
  272. * 低价违规挂网公司月度统计
  273. * @author 唐远望
  274. * @version 1.0
  275. * @date 2025-12-26
  276. *
  277. */
  278. public function getLowPriceCompanyCount(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  279. {
  280. $request->scene('getLowPriceCompanyCount')->validate();
  281. $limit = request('limit', config('page_num', 10));
  282. $start_time = request('start_time', '');
  283. $end_time = request('end_time', '');
  284. // 时间条件
  285. $map = [];
  286. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  287. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  288. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  289. ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
  290. ->groupby('company_name')->paginate($limit);
  291. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  292. }
  293. /**
  294. * 低价违规挂网公司月度统计-导出
  295. * @author 唐远望
  296. * @version 1.0
  297. * @date 2025-12-26
  298. *
  299. */
  300. public function low_price_company_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  301. {
  302. $start_time = request('start_time', '');
  303. $end_time = request('end_time', '');
  304. // 时间条件
  305. $map = [];
  306. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  307. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  308. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  309. ->select(['company_name', DB::raw('count(company_name) as count')])->orderby('count', 'desc')
  310. ->groupby('company_name')->get()->toarray();
  311. //执行下载
  312. $this->LowPriceCompany_export_download($result);
  313. }
  314. /**
  315. * 低价违规挂网公司月度统计-导出下载
  316. * @author 唐远望
  317. * @version 1.0
  318. * @date 2025-12-26
  319. *
  320. */
  321. public function LowPriceCompany_export_download($data)
  322. {
  323. // 创建一个新的 Spreadsheet 对象
  324. $spreadsheet = new Spreadsheet();
  325. $sheet = $spreadsheet->getActiveSheet();
  326. //合并单元格
  327. $sheet->mergeCells('A1:B1');
  328. $sheet->setCellValue('A1', '低价违规挂网公司月度统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  329. // 获取合并后的单元格样式对象
  330. $style = $sheet->getStyle('A1');
  331. // 设置水平居中和垂直居中
  332. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  333. // 然后设置行高以适应两行文本
  334. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  335. // 设置表头
  336. $sheet->setCellValue('A2', '公司名称');
  337. $sheet->setCellValue('B2', '挂网数量');
  338. // 填充数据
  339. $row = 3; // 从第3行开始
  340. foreach ($data as $item) {
  341. $sheet->setCellValue('A' . $row, $item['company_name']);
  342. $sheet->setCellValue('B' . $row, $item['count']);
  343. $row++;
  344. }
  345. // 生成 Excel 文件
  346. $writer = new Xlsx($spreadsheet);
  347. // 直接输出到浏览器(下载)
  348. $filename = '低价违规挂网公司月度统计数据' . date('YmdHis') . '.xlsx';
  349. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  350. header('Content-Disposition: attachment;filename="' . $filename . '"');
  351. header('Cache-Control: max-age=0');
  352. $writer->save('php://output');
  353. exit;
  354. }
  355. }