OverviewPanel.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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. use Illuminate\Support\Carbon;
  12. use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
  13. use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
  14. use App\Servers\Aliyun\Oss;
  15. /**
  16. * 报表统计-概览面板
  17. * @author 唐远望
  18. * @version 1.0
  19. * @date 2025-12-26
  20. *
  21. */
  22. class OverviewPanel extends Controller
  23. {
  24. /**
  25. * 禁止挂网链接数统计
  26. * @author 唐远望
  27. * @version 1.0
  28. * @date 2025-12-26
  29. *
  30. */
  31. public function getViolationLinkCount(request $request, ViolationProductModel $violationProductModel)
  32. {
  33. $request->scene('getViolationLinkCount')->validate();
  34. $company_id = request('access_token.company_id', '0');
  35. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  36. $limit = request('limit', config('page_num', 10));
  37. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  38. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  39. $start_time_string = request('start_time','');
  40. $end_time_string = request('end_time','');
  41. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  42. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  43. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  44. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  45. //校验开始时间结束时间是否在同一天
  46. if(date('Y-m-d', $start_time)!= date('Y-m-d', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一天', 'data' => '']);
  47. // 时间条件
  48. $map = [];
  49. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  50. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  51. $result = $violationProductModel->where($map)->where('status', 0)
  52. ->select(['company_name', DB::raw('count(link_url) as count')])->distinct('link_url')->orderby('count', 'desc')
  53. ->groupby('company_name')->paginate($limit);
  54. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  55. }
  56. /**
  57. * 禁止挂网链接数统计-导出
  58. * @author 唐远望
  59. * @version 1.0
  60. * @date 2025-12-26
  61. *
  62. */
  63. public function Violation_export(request $request, ViolationProductModel $violationProductModel)
  64. {
  65. $company_id = request('access_token.company_id', '0');
  66. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  67. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  68. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  69. $start_time_string = request('start_time','');
  70. $end_time_string = request('end_time','');
  71. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  72. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  73. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  74. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  75. //校验开始时间结束时间是否在同一天
  76. if(date('Y-m-d', $start_time)!= date('Y-m-d', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一天', 'data' => '']);
  77. // 时间条件
  78. $map = [];
  79. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  80. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  81. $result = $violationProductModel->where($map)->where('status', 0)
  82. ->select(['company_name', DB::raw('count(link_url) as count')])->distinct('link_url')->orderby('count', 'desc')
  83. ->groupby('company_name')->get()->toarray();
  84. //执行下载
  85. $oss_url = $this->Violation_export_download($result);
  86. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
  87. }
  88. /**
  89. * 禁止挂网链接数统计-导出下载
  90. * @author 唐远望
  91. * @version 1.0
  92. * @date 2025-06-17
  93. */
  94. public function Violation_export_download($data)
  95. {
  96. // 创建一个新的 Spreadsheet 对象
  97. $spreadsheet = new Spreadsheet();
  98. $sheet = $spreadsheet->getActiveSheet();
  99. //合并单元格
  100. $sheet->mergeCells('A1:B1');
  101. $sheet->setCellValue('A1', '禁止挂网链接数统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  102. // 获取合并后的单元格样式对象
  103. $style = $sheet->getStyle('A1');
  104. // 设置水平居中和垂直居中
  105. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  106. // 然后设置行高以适应两行文本
  107. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  108. // 设置表头
  109. $sheet->setCellValue('A2', '公司名称');
  110. $sheet->setCellValue('B2', '链接挂网数量');
  111. // 填充数据
  112. $row = 3; // 从第3行开始
  113. foreach ($data as $item) {
  114. $sheet->setCellValue('A' . $row, $item['company_name']);
  115. $sheet->setCellValue('B' . $row, $item['count']);
  116. $row++;
  117. }
  118. $file_id = date('YmdHis');
  119. // 创建Excel文件
  120. $filename = '禁止挂网链接数统计数据' . $file_id . '.xlsx';
  121. $path = public_path('uploads/exports/');
  122. $fullPath = $path. $filename;
  123. if (!is_dir($path)) mkdir($path, 0777, true);
  124. // 生成 Excel 文件
  125. $writer = new Xlsx($spreadsheet);
  126. $writer->save($fullPath);
  127. // 清理
  128. $spreadsheet->disconnectWorksheets();
  129. unset($spreadsheet, $writer);
  130. $Oss = new Oss();
  131. $oss_url = $Oss->uploadFile($filename, $fullPath);
  132. if ($oss_url) @unlink($fullPath);
  133. return $oss_url;
  134. }
  135. /**
  136. * 禁止挂网公司月度统计
  137. * @author 唐远望
  138. * @version 1.0
  139. * @date 2025-12-26
  140. *
  141. */
  142. public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
  143. {
  144. $request->scene('get_violation_company_count')->validate();
  145. $company_id = request('access_token.company_id', '0');
  146. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  147. $limit = request('limit', config('page_num', 10));
  148. $yesterdayStart = Carbon::now()->startOfMonth()->getTimestamp(); // 本月第一天 00:00:00
  149. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  150. $start_time_string = request('start_time','');
  151. $end_time_string = request('end_time','');
  152. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  153. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  154. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  155. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  156. //校验开始时间结束时间是否在同一个月
  157. if(date('Y-m', $start_time)!= date('Y-m', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一个月', 'data' => '']);
  158. // 时间条件
  159. $map = [];
  160. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  161. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  162. $result = $violationProductModel->where($map)->where('status', 0)
  163. ->select(['company_name', DB::raw('count(company_name) as count')])->distinct('company_name')->orderby('count', 'desc')
  164. ->groupby('company_name')->paginate($limit);
  165. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  166. }
  167. /**
  168. * 禁止挂网公司月度统计-导出
  169. * @author 唐远望
  170. * @version 1.0
  171. * @date 2025-12-26
  172. *
  173. */
  174. public function violation_company_export(request $request, ViolationProductModel $violationProductModel)
  175. {
  176. $company_id = request('access_token.company_id', '0');
  177. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  178. $yesterdayStart = Carbon::now()->startOfMonth()->getTimestamp(); // 本月第一天 00:00:00
  179. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  180. $start_time_string = request('start_time','');
  181. $end_time_string = request('end_time','');
  182. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  183. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  184. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  185. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  186. //校验开始时间结束时间是否在同一个月
  187. if(date('Y-m', $start_time)!= date('Y-m', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一个月', 'data' => '']);
  188. // 时间条件
  189. $map = [];
  190. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  191. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  192. $result = $violationProductModel->where($map)->where('status', 0)
  193. ->select(['company_name', DB::raw('count(company_name) as count')])->distinct('company_name')->orderby('count', 'desc')
  194. ->groupby('company_name')->get()->toarray();
  195. //执行下载
  196. $oss_url = $this->ViolationCompany_export_download($result);
  197. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
  198. }
  199. /**
  200. * 禁止挂网公司月度统计-导出下载
  201. * @author 唐远望
  202. * @version 1.0
  203. * @date 2025-12-26
  204. *
  205. */
  206. public function ViolationCompany_export_download($data)
  207. {
  208. // 创建一个新的 Spreadsheet 对象
  209. $spreadsheet = new Spreadsheet();
  210. $sheet = $spreadsheet->getActiveSheet();
  211. //合并单元格
  212. $sheet->mergeCells('A1:B1');
  213. $sheet->setCellValue('A1', '禁止挂网公司月度统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  214. // 获取合并后的单元格样式对象
  215. $style = $sheet->getStyle('A1');
  216. // 设置水平居中和垂直居中
  217. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  218. // 然后设置行高以适应两行文本
  219. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  220. // 设置表头
  221. $sheet->setCellValue('A2', '公司名称');
  222. $sheet->setCellValue('B2', '挂网数量');
  223. // 填充数据
  224. $row = 3; // 从第3行开始
  225. foreach ($data as $item) {
  226. $sheet->setCellValue('A' . $row, $item['company_name']);
  227. $sheet->setCellValue('B' . $row, $item['count']);
  228. $row++;
  229. }
  230. $file_id = date('YmdHis');
  231. // 创建Excel文件
  232. $filename = '禁止挂网公司月度统计数据' . $file_id . '.xlsx';
  233. $path = public_path('uploads/exports/');
  234. $fullPath = $path. $filename;
  235. if (!is_dir($path)) mkdir($path, 0777, true);
  236. // 生成 Excel 文件
  237. $writer = new Xlsx($spreadsheet);
  238. $writer->save($fullPath);
  239. // 清理
  240. $spreadsheet->disconnectWorksheets();
  241. unset($spreadsheet, $writer);
  242. $Oss = new Oss();
  243. $oss_url = $Oss->uploadFile($filename, $fullPath);
  244. if ($oss_url) @unlink($fullPath);
  245. return $oss_url;
  246. }
  247. /*
  248. * 低价违规挂网链接数统计
  249. * @author 唐远望
  250. * @version 1.0
  251. * @date 2025-12-26
  252. *
  253. */
  254. public function getLowPriceLinkCount(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  255. {
  256. $request->scene('getLowPriceLinkCount')->validate();
  257. $company_id = request('access_token.company_id', '0');
  258. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  259. $limit = request('limit', config('page_num', 10));
  260. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  261. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  262. $start_time_string = request('start_time','');
  263. $end_time_string = request('end_time','');
  264. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  265. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  266. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  267. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  268. //校验开始时间结束时间是否在同一天
  269. if(date('Y-m-d', $start_time)!= date('Y-m-d', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一天', 'data' => '']);
  270. // 时间条件
  271. $map = [];
  272. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  273. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  274. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  275. ->select(['company_name', DB::raw('count(link_url) as count')])->distinct('link_url')->orderby('count', 'desc')
  276. ->groupby('company_name')->paginate($limit);
  277. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  278. }
  279. /**
  280. * 低价违规挂网链接数统计-导出
  281. * @author 唐远望
  282. * @version 1.0
  283. * @date 2025-12-26
  284. *
  285. */
  286. public function low_price_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  287. {
  288. $company_id = request('access_token.company_id', '0');
  289. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  290. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  291. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  292. $start_time_string = request('start_time','');
  293. $end_time_string = request('end_time','');
  294. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  295. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  296. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  297. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  298. //校验开始时间结束时间是否在同一天
  299. if(date('Y-m-d', $start_time)!= date('Y-m-d', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一天', 'data' => '']);
  300. // 时间条件
  301. $map = [];
  302. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  303. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  304. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  305. ->select(['company_name', DB::raw('count(link_url) as count')])->distinct('link_url')->orderby('count', 'desc')
  306. ->groupby('company_name')->get()->toarray();
  307. //执行下载
  308. $oss_url = $this->LowPrice_export_download($result);
  309. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
  310. }
  311. /**
  312. * 低价违规挂网链接数统计-导出下载
  313. * @author 唐远望
  314. * @version 1.0
  315. * @date 2025-12-26
  316. *
  317. */
  318. public function LowPrice_export_download($data)
  319. {
  320. // 创建一个新的 Spreadsheet 对象
  321. $spreadsheet = new Spreadsheet();
  322. $sheet = $spreadsheet->getActiveSheet();
  323. //合并单元格
  324. $sheet->mergeCells('A1:B1');
  325. $sheet->setCellValue('A1', '低价违规挂网链接数统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  326. // 获取合并后的单元格样式对象
  327. $style = $sheet->getStyle('A1');
  328. // 设置水平居中和垂直居中
  329. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  330. // 然后设置行高以适应两行文本
  331. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  332. // 设置表头
  333. $sheet->setCellValue('A2', '公司名称');
  334. $sheet->setCellValue('B2', '链接挂网数量');
  335. // 填充数据
  336. $row = 3; // 从第3行开始
  337. foreach ($data as $item) {
  338. $sheet->setCellValue('A' . $row, $item['company_name']);
  339. $sheet->setCellValue('B' . $row, $item['count']);
  340. $row++;
  341. }
  342. $file_id = date('YmdHis');
  343. // 创建Excel文件
  344. $filename = '低价违规挂网链接数统计数据' . $file_id . '.xlsx';
  345. $path = public_path('uploads/exports/');
  346. $fullPath = $path. $filename;
  347. if (!is_dir($path)) mkdir($path, 0777, true);
  348. // 生成 Excel 文件
  349. $writer = new Xlsx($spreadsheet);
  350. $writer->save($fullPath);
  351. // 清理
  352. $spreadsheet->disconnectWorksheets();
  353. unset($spreadsheet, $writer);
  354. $Oss = new Oss();
  355. $oss_url = $Oss->uploadFile($filename, $fullPath);
  356. if ($oss_url) @unlink($fullPath);
  357. return $oss_url;
  358. }
  359. /*
  360. * 低价违规挂网公司月度统计
  361. * @author 唐远望
  362. * @version 1.0
  363. * @date 2025-12-26
  364. *
  365. */
  366. public function getLowPriceCompanyCount(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  367. {
  368. $request->scene('getLowPriceCompanyCount')->validate();
  369. $company_id = request('access_token.company_id', '0');
  370. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  371. $limit = request('limit', config('page_num', 10));
  372. $yesterdayStart = Carbon::now()->startOfMonth()->getTimestamp(); // 本月第一天 00:00:00
  373. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  374. $start_time_string = request('start_time','');
  375. $end_time_string = request('end_time','');
  376. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  377. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  378. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  379. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  380. //校验开始时间结束时间是否在同一个月
  381. if(date('Y-m', $start_time)!= date('Y-m', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一个月', 'data' => '']);
  382. // 时间条件
  383. $map = [];
  384. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  385. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  386. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  387. ->select(['company_name', DB::raw('count(company_name) as count')])->distinct('company_name')->orderby('count', 'desc')
  388. ->groupby('company_name')->paginate($limit);
  389. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  390. }
  391. /**
  392. * 低价违规挂网公司月度统计-导出
  393. * @author 唐远望
  394. * @version 1.0
  395. * @date 2025-12-26
  396. *
  397. */
  398. public function low_price_company_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  399. {
  400. $company_id = request('access_token.company_id', '0');
  401. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  402. $yesterdayStart = Carbon::now()->startOfMonth()->getTimestamp(); // 本月第一天 00:00:00
  403. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  404. $start_time_string = request('start_time','');
  405. $end_time_string = request('end_time','');
  406. $start_time = $start_time_string? strtotime($start_time_string.' 00:00:00') : $yesterdayStart;
  407. $end_time = $end_time_string? strtotime($end_time_string.' 23:59:59') : $yesterdayEnd;
  408. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  409. if($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  410. //校验开始时间结束时间是否在同一个月
  411. if(date('Y-m', $start_time)!= date('Y-m', $end_time)) return json_send(['code' => 'error', 'msg' => '开始时间和结束时间必须在同一个月', 'data' => '']);
  412. // 时间条件
  413. $map = [];
  414. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  415. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  416. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  417. ->select(['company_name', DB::raw('count(company_name) as count')])->distinct('company_name')->orderby('count', 'desc')
  418. ->groupby('company_name')->get()->toarray();
  419. //执行下载
  420. $oss_url = $this->LowPriceCompany_export_download($result);
  421. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
  422. }
  423. /**
  424. * 低价违规挂网公司月度统计-导出下载
  425. * @author 唐远望
  426. * @version 1.0
  427. * @date 2025-12-26
  428. *
  429. */
  430. public function LowPriceCompany_export_download($data)
  431. {
  432. // 创建一个新的 Spreadsheet 对象
  433. $spreadsheet = new Spreadsheet();
  434. $sheet = $spreadsheet->getActiveSheet();
  435. //合并单元格
  436. $sheet->mergeCells('A1:B1');
  437. $sheet->setCellValue('A1', '低价违规挂网公司月度统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  438. // 获取合并后的单元格样式对象
  439. $style = $sheet->getStyle('A1');
  440. // 设置水平居中和垂直居中
  441. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  442. // 然后设置行高以适应两行文本
  443. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  444. // 设置表头
  445. $sheet->setCellValue('A2', '公司名称');
  446. $sheet->setCellValue('B2', '挂网数量');
  447. // 填充数据
  448. $row = 3; // 从第3行开始
  449. foreach ($data as $item) {
  450. $sheet->setCellValue('A' . $row, $item['company_name']);
  451. $sheet->setCellValue('B' . $row, $item['count']);
  452. $row++;
  453. }
  454. $file_id = date('YmdHis');
  455. // 创建Excel文件
  456. $filename = '低价违规挂网公司月度统计数据' . $file_id . '.xlsx';
  457. $path = public_path('uploads/exports/');
  458. $fullPath = $path. $filename;
  459. if (!is_dir($path)) mkdir($path, 0777, true);
  460. // 生成 Excel 文件
  461. $writer = new Xlsx($spreadsheet);
  462. $writer->save($fullPath);
  463. // 清理
  464. $spreadsheet->disconnectWorksheets();
  465. unset($spreadsheet, $writer);
  466. $Oss = new Oss();
  467. $oss_url = $Oss->uploadFile($filename, $fullPath);
  468. if ($oss_url) @unlink($fullPath);
  469. return $oss_url;
  470. }
  471. /**
  472. * 商品数量趋势
  473. * @author 唐远望
  474. * @version 1.0
  475. * @date 2025-12-29
  476. *
  477. */
  478. public function get_product_trend(request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
  479. {
  480. $request->scene('get_product_trend')->validate();
  481. $company_id = request('access_token.company_id', '0');
  482. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  483. // 查询条件
  484. $map = [];
  485. $status = request('status', '');
  486. $start_time = request('start_time', '');
  487. $end_time = request('end_time', '');
  488. $product_name = request('product_name', '');
  489. $product_names = request('product_names', '');
  490. $first_responsible_person = request('first_responsible_person', '');
  491. $responsible_person = request('responsible_person', '');
  492. $platform = request('platform', '');
  493. $company_name = request('company_name', '');
  494. $store_name = request('store_name', '');
  495. $store_names = request('store_names', '');
  496. $source_responsible_person = request('source_responsible_person', '');
  497. $processing_status = request('processing_status', '');
  498. $product_specs = request('product_specs', '');
  499. $online_posting_count = request('online_posting_count', '');
  500. $category_name = request('category_name', '');
  501. // 其他条件
  502. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  503. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  504. if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
  505. //多选平台查询
  506. if ($platform && is_string($platform)) {
  507. $platform = explode(',', $platform);
  508. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  509. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  510. }
  511. //多选处理状态查询
  512. if ($processing_status && is_string($processing_status)) {
  513. $processing_status = explode(',', $processing_status);
  514. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
  515. $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
  516. }
  517. //多选状态查询
  518. if ($status && is_string($status)) {
  519. $status = explode(',', $status);
  520. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
  521. $violationProductModel = $violationProductModel->whereIn('status', $status);
  522. }
  523. //多选店铺名称查询
  524. if ($store_names && is_string($store_names)) {
  525. $store_names = explode(',', $store_names);
  526. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
  527. $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
  528. }
  529. //多选违规挂网次数查询
  530. if ($online_posting_count && is_string($online_posting_count)) {
  531. $online_posting_count = explode(',', $online_posting_count);
  532. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
  533. $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
  534. }
  535. //多选规格查询
  536. if ($product_specs && is_string($product_specs)) {
  537. $product_specs = explode(',', $product_specs);
  538. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
  539. $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
  540. }
  541. //多选商品查询
  542. if ($product_names && is_string($product_names)) {
  543. $product_names = explode(',', $product_names);
  544. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
  545. $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
  546. }
  547. //多选公司查询
  548. if ($company_name && is_string($company_name)) {
  549. $company_name = explode(',', $company_name);
  550. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
  551. $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
  552. }
  553. //多选第一责任人
  554. if ($first_responsible_person && is_string($first_responsible_person)) {
  555. $first_responsible_person = explode(',', $first_responsible_person);
  556. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  557. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  558. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  559. });
  560. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  561. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  562. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  563. });
  564. }
  565. //多选责任人
  566. if ($responsible_person && is_string($responsible_person)) {
  567. $responsible_person = explode(',', $responsible_person);
  568. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  569. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  570. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  571. });
  572. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  573. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  574. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  575. });
  576. }
  577. //多选溯源责任人
  578. if ($source_responsible_person && is_string($source_responsible_person)) {
  579. $source_responsible_person = explode(',', $source_responsible_person);
  580. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  581. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  582. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  583. });
  584. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  585. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  586. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  587. });
  588. }
  589. if ($start_time == '' || $end_time == '') {
  590. $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
  591. $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
  592. } else {
  593. $start_time = strtotime($start_time . ' 00:00:00');
  594. $end_time = strtotime($end_time . ' 23:59:59');
  595. }
  596. $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
  597. ->where('insert_time', '<=', $end_time)->where($map)
  598. ->select(
  599. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  600. DB::raw('COUNT(id) as daily_total'),
  601. )
  602. ->groupBy('date')
  603. ->orderBy('date')
  604. ->get()->keyBy('date')->toarray();
  605. $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
  606. ->where('insert_time', '<=', $end_time)->where($map)
  607. ->select(
  608. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  609. DB::raw('COUNT(id) as daily_total'),
  610. )
  611. ->groupBy('date')
  612. ->orderBy('date')
  613. ->get()->keyBy('date')->toarray();
  614. $moth_list = [];
  615. $key_index = 0;
  616. for ($i = $start_time; $i <= $end_time; $i += 86400) {
  617. $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
  618. $moth_list[$key_index]['date'] = $key_day;
  619. $moth_list[$key_index]['low_price_totle'] = 0;
  620. $moth_list[$key_index]['violation_product_totle'] = 0;
  621. $moth_list[$key_index]['product_totle'] = 0;
  622. if (isset($low_price_result[$key_day])) {
  623. $moth_list[$key_index]['low_price_totle'] = $low_price_result[$key_day]['daily_total'];
  624. }
  625. if (isset($violation_product_result[$key_day])) {
  626. $moth_list[$key_index]['violation_product_totle'] = $violation_product_result[$key_day]['daily_total'];
  627. }
  628. $moth_list[$key_index]['product_totle'] = $moth_list[$key_index]['low_price_totle'] + $moth_list[$key_index]['violation_product_totle'];
  629. $key_index++;
  630. }
  631. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $moth_list]);
  632. }
  633. /**
  634. * 商品数量趋势-导出
  635. * @author 唐远望
  636. * @version 1.0
  637. * @date 2025-12-29
  638. *
  639. */
  640. public function product_trend_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
  641. {
  642. $request->scene('product_trend_export')->validate();
  643. $company_id = request('access_token.company_id', '0');
  644. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  645. // 查询条件
  646. $map = [];
  647. $status = request('status', '');
  648. $start_time = request('start_time', '');
  649. $end_time = request('end_time', '');
  650. $product_name = request('product_name', '');
  651. $product_names = request('product_names', '');
  652. $first_responsible_person = request('first_responsible_person', '');
  653. $responsible_person = request('responsible_person', '');
  654. $platform = request('platform', '');
  655. $company_name = request('company_name', '');
  656. $store_name = request('store_name', '');
  657. $store_names = request('store_names', '');
  658. $source_responsible_person = request('source_responsible_person', '');
  659. $processing_status = request('processing_status', '');
  660. $product_specs = request('product_specs', '');
  661. $online_posting_count = request('online_posting_count', '');
  662. $category_name = request('category_name', '');
  663. // 其他条件
  664. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  665. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  666. if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
  667. //多选平台查询
  668. if ($platform && is_string($platform)) {
  669. $platform = explode(',', $platform);
  670. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  671. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  672. }
  673. //多选处理状态查询
  674. if ($processing_status && is_string($processing_status)) {
  675. $processing_status = explode(',', $processing_status);
  676. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
  677. $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
  678. }
  679. //多选状态查询
  680. if ($status && is_string($status)) {
  681. $status = explode(',', $status);
  682. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
  683. $violationProductModel = $violationProductModel->whereIn('status', $status);
  684. }
  685. //多选店铺名称查询
  686. if ($store_names && is_string($store_names)) {
  687. $store_names = explode(',', $store_names);
  688. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
  689. $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
  690. }
  691. //多选违规挂网次数查询
  692. if ($online_posting_count && is_string($online_posting_count)) {
  693. $online_posting_count = explode(',', $online_posting_count);
  694. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
  695. $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
  696. }
  697. //多选规格查询
  698. if ($product_specs && is_string($product_specs)) {
  699. $product_specs = explode(',', $product_specs);
  700. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
  701. $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
  702. }
  703. //多选商品查询
  704. if ($product_names && is_string($product_names)) {
  705. $product_names = explode(',', $product_names);
  706. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
  707. $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
  708. }
  709. //多选公司查询
  710. if ($company_name && is_string($company_name)) {
  711. $company_name = explode(',', $company_name);
  712. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
  713. $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
  714. }
  715. //多选第一责任人
  716. if ($first_responsible_person && is_string($first_responsible_person)) {
  717. $first_responsible_person = explode(',', $first_responsible_person);
  718. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  719. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  720. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  721. });
  722. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  723. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  724. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  725. });
  726. }
  727. //多选责任人
  728. if ($responsible_person && is_string($responsible_person)) {
  729. $responsible_person = explode(',', $responsible_person);
  730. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  731. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  732. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  733. });
  734. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  735. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  736. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  737. });
  738. }
  739. //多选溯源责任人
  740. if ($source_responsible_person && is_string($source_responsible_person)) {
  741. $source_responsible_person = explode(',', $source_responsible_person);
  742. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  743. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  744. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  745. });
  746. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  747. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  748. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  749. });
  750. }
  751. if ($start_time == '' || $end_time == '') {
  752. $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
  753. $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
  754. } else {
  755. $start_time = strtotime($start_time . ' 00:00:00');
  756. $end_time = strtotime($end_time . ' 23:59:59');
  757. }
  758. $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
  759. ->where('insert_time', '<=', $end_time)->where($map)
  760. ->select(
  761. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  762. DB::raw('COUNT(id) as daily_total'),
  763. )
  764. ->groupBy('date')
  765. ->orderBy('date')
  766. ->get()->keyBy('date')->toarray();
  767. $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
  768. ->where('insert_time', '<=', $end_time)->where($map)
  769. ->select(
  770. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  771. DB::raw('COUNT(id) as daily_total'),
  772. )
  773. ->groupBy('date')
  774. ->orderBy('date')
  775. ->get()->keyBy('date')->toarray();
  776. $moth_list = [];
  777. $key_index = 0;
  778. for ($i = $start_time; $i <= $end_time; $i += 86400) {
  779. $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
  780. $moth_list[$key_index]['date'] = $key_day;
  781. $moth_list[$key_index]['low_price_totle'] = 0;
  782. $moth_list[$key_index]['violation_product_totle'] = 0;
  783. $moth_list[$key_index]['product_totle'] = 0;
  784. if (isset($low_price_result[$key_day])) {
  785. $moth_list[$key_index]['low_price_totle'] = $low_price_result[$key_day]['daily_total'];
  786. }
  787. if (isset($violation_product_result[$key_day])) {
  788. $moth_list[$key_index]['violation_product_totle'] = $violation_product_result[$key_day]['daily_total'];
  789. }
  790. $moth_list[$key_index]['product_totle'] = $moth_list[$key_index]['low_price_totle'] + $moth_list[$key_index]['violation_product_totle'];
  791. $key_index++;
  792. }
  793. //执行下载
  794. $oss_url = $this->product_trend_export_download($moth_list);
  795. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
  796. }
  797. /**
  798. * 商品数量趋势-导出下载
  799. * @author 唐远望
  800. * @version 1.0
  801. * @date 2025-12-29
  802. *
  803. */
  804. public function product_trend_export_download($data)
  805. {
  806. // 创建一个新的 Spreadsheet 对象
  807. $spreadsheet = new Spreadsheet();
  808. $sheet = $spreadsheet->getActiveSheet();
  809. //合并单元格
  810. $sheet->mergeCells('A1:D1');
  811. $sheet->setCellValue('A1', '商品数量趋势统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  812. // 获取合并后的单元格样式对象
  813. $style = $sheet->getStyle('A1');
  814. // 设置水平居中和垂直居中
  815. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  816. // 然后设置行高以适应两行文本
  817. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  818. // 设置表头
  819. $sheet->setCellValue('A2', '日期');
  820. $sheet->setCellValue('B2', '低价商品数量');
  821. $sheet->setCellValue('C2', '禁止商品数量');
  822. $sheet->setCellValue('D2', '总商品数量');
  823. // 填充数据
  824. $row = 3; // 从第3行开始
  825. foreach ($data as $item) {
  826. $sheet->setCellValue('A' . $row, $item['date']);
  827. $sheet->setCellValue('B' . $row, $item['low_price_totle']);
  828. $sheet->setCellValue('C' . $row, $item['violation_product_totle']);
  829. $sheet->setCellValue('D' . $row, $item['product_totle']);
  830. $row++;
  831. }
  832. $file_id = date('YmdHis');
  833. // 创建Excel文件
  834. $filename = '商品数量趋势统计数据' . $file_id . '.xlsx';
  835. $path = public_path('uploads/exports/');
  836. $fullPath = $path. $filename;
  837. if (!is_dir($path)) mkdir($path, 0777, true);
  838. // 生成 Excel 文件
  839. $writer = new Xlsx($spreadsheet);
  840. $writer->save($fullPath);
  841. // 清理
  842. $spreadsheet->disconnectWorksheets();
  843. unset($spreadsheet, $writer);
  844. $Oss = new Oss();
  845. $oss_url = $Oss->uploadFile($filename, $fullPath);
  846. if ($oss_url) @unlink($fullPath);
  847. return $oss_url;
  848. }
  849. /**
  850. * 商家数量趋势
  851. * @author 唐远望
  852. * @version 1.0
  853. * @date 2025-12-29
  854. *
  855. */
  856. public function get_store_trend(Request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
  857. {
  858. $request->scene('get_store_trend')->validate();
  859. $company_id = request('access_token.company_id', '0');
  860. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  861. // 查询条件
  862. $map = [];
  863. $status = request('status', '');
  864. $start_time = request('start_time', '');
  865. $end_time = request('end_time', '');
  866. $product_name = request('product_name', '');
  867. $product_names = request('product_names', '');
  868. $first_responsible_person = request('first_responsible_person', '');
  869. $responsible_person = request('responsible_person', '');
  870. $platform = request('platform', '');
  871. $company_name = request('company_name', '');
  872. $store_name = request('store_name', '');
  873. $store_names = request('store_names', '');
  874. $source_responsible_person = request('source_responsible_person', '');
  875. $processing_status = request('processing_status', '');
  876. $product_specs = request('product_specs', '');
  877. $online_posting_count = request('online_posting_count', '');
  878. $category_name = request('category_name', '');
  879. // 其他条件
  880. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  881. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  882. if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
  883. //多选平台查询
  884. if ($platform && is_string($platform)) {
  885. $platform = explode(',', $platform);
  886. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  887. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  888. }
  889. //多选处理状态查询
  890. if ($processing_status && is_string($processing_status)) {
  891. $processing_status = explode(',', $processing_status);
  892. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
  893. $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
  894. }
  895. //多选状态查询
  896. if ($status && is_string($status)) {
  897. $status = explode(',', $status);
  898. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
  899. $violationProductModel = $violationProductModel->whereIn('status', $status);
  900. }
  901. //多选店铺名称查询
  902. if ($store_names && is_string($store_names)) {
  903. $store_names = explode(',', $store_names);
  904. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
  905. $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
  906. }
  907. //多选违规挂网次数查询
  908. if ($online_posting_count && is_string($online_posting_count)) {
  909. $online_posting_count = explode(',', $online_posting_count);
  910. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
  911. $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
  912. }
  913. //多选规格查询
  914. if ($product_specs && is_string($product_specs)) {
  915. $product_specs = explode(',', $product_specs);
  916. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
  917. $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
  918. }
  919. //多选商品查询
  920. if ($product_names && is_string($product_names)) {
  921. $product_names = explode(',', $product_names);
  922. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
  923. $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
  924. }
  925. //多选公司查询
  926. if ($company_name && is_string($company_name)) {
  927. $company_name = explode(',', $company_name);
  928. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
  929. $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
  930. }
  931. //多选第一责任人
  932. if ($first_responsible_person && is_string($first_responsible_person)) {
  933. $first_responsible_person = explode(',', $first_responsible_person);
  934. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  935. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  936. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  937. });
  938. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  939. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  940. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  941. });
  942. }
  943. //多选责任人
  944. if ($responsible_person && is_string($responsible_person)) {
  945. $responsible_person = explode(',', $responsible_person);
  946. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  947. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  948. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  949. });
  950. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  951. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  952. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  953. });
  954. }
  955. //多选溯源责任人
  956. if ($source_responsible_person && is_string($source_responsible_person)) {
  957. $source_responsible_person = explode(',', $source_responsible_person);
  958. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  959. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  960. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  961. });
  962. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  963. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  964. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  965. });
  966. }
  967. if ($start_time == '' || $end_time == '') {
  968. $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
  969. $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
  970. } else {
  971. $start_time = strtotime($start_time . ' 00:00:00');
  972. $end_time = strtotime($end_time . ' 23:59:59');
  973. }
  974. $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
  975. ->where('insert_time', '<=', $end_time)->where($map)
  976. ->select(
  977. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  978. DB::raw('COUNT(DISTINCT store_name) as daily_total'),
  979. )
  980. ->groupBy('date')
  981. ->orderBy('date')
  982. ->get()->keyBy('date')->toarray();
  983. $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
  984. ->where('insert_time', '<=', $end_time)->where($map)
  985. ->select(
  986. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  987. DB::raw('COUNT(DISTINCT store_name) as daily_total'),
  988. )
  989. ->groupBy('date')
  990. ->orderBy('date')
  991. ->get()->keyBy('date')->toarray();
  992. $moth_list = [];
  993. $key_index = 0;
  994. for ($i = $start_time; $i <= $end_time; $i += 86400) {
  995. $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
  996. $moth_list[$key_index]['date'] = $key_day;
  997. $moth_list[$key_index]['low_price_store_totle'] = 0;
  998. $moth_list[$key_index]['violation_product_store_totle'] = 0;
  999. $moth_list[$key_index]['product_store_totle'] = 0;
  1000. if (isset($low_price_result[$key_day])) {
  1001. $moth_list[$key_index]['low_price_store_totle'] = $low_price_result[$key_day]['daily_total'];
  1002. }
  1003. if (isset($violation_product_result[$key_day])) {
  1004. $moth_list[$key_index]['violation_product_store_totle'] = $violation_product_result[$key_day]['daily_total'];
  1005. }
  1006. $moth_list[$key_index]['product_store_totle'] = $moth_list[$key_index]['low_price_store_totle'] + $moth_list[$key_index]['violation_product_store_totle'];
  1007. $key_index++;
  1008. }
  1009. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $moth_list]);
  1010. }
  1011. /**
  1012. * 商家数量趋势-导出
  1013. * @author 唐远望
  1014. * @version 1.0
  1015. * @date 2025-12-29
  1016. *
  1017. */
  1018. public function store_trend_export(Request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
  1019. {
  1020. $request->scene('store_trend_export')->validate();
  1021. $company_id = request('access_token.company_id', '0');
  1022. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  1023. // 查询条件
  1024. $map = [];
  1025. $status = request('status', '');
  1026. $start_time = request('start_time', '');
  1027. $end_time = request('end_time', '');
  1028. $product_name = request('product_name', '');
  1029. $product_names = request('product_names', '');
  1030. $first_responsible_person = request('first_responsible_person', '');
  1031. $responsible_person = request('responsible_person', '');
  1032. $platform = request('platform', '');
  1033. $company_name = request('company_name', '');
  1034. $store_name = request('store_name', '');
  1035. $store_names = request('store_names', '');
  1036. $source_responsible_person = request('source_responsible_person', '');
  1037. $processing_status = request('processing_status', '');
  1038. $product_specs = request('product_specs', '');
  1039. $online_posting_count = request('online_posting_count', '');
  1040. $category_name = request('category_name', '');
  1041. // 其他条件
  1042. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  1043. if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
  1044. if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
  1045. //多选平台查询
  1046. if ($platform && is_string($platform)) {
  1047. $platform = explode(',', $platform);
  1048. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  1049. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  1050. }
  1051. //多选处理状态查询
  1052. if ($processing_status && is_string($processing_status)) {
  1053. $processing_status = explode(',', $processing_status);
  1054. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
  1055. $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
  1056. }
  1057. //多选状态查询
  1058. if ($status && is_string($status)) {
  1059. $status = explode(',', $status);
  1060. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
  1061. $violationProductModel = $violationProductModel->whereIn('status', $status);
  1062. }
  1063. //多选店铺名称查询
  1064. if ($store_names && is_string($store_names)) {
  1065. $store_names = explode(',', $store_names);
  1066. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
  1067. $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
  1068. }
  1069. //多选违规挂网次数查询
  1070. if ($online_posting_count && is_string($online_posting_count)) {
  1071. $online_posting_count = explode(',', $online_posting_count);
  1072. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
  1073. $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
  1074. }
  1075. //多选规格查询
  1076. if ($product_specs && is_string($product_specs)) {
  1077. $product_specs = explode(',', $product_specs);
  1078. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
  1079. $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
  1080. }
  1081. //多选商品查询
  1082. if ($product_names && is_string($product_names)) {
  1083. $product_names = explode(',', $product_names);
  1084. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
  1085. $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
  1086. }
  1087. //多选公司查询
  1088. if ($company_name && is_string($company_name)) {
  1089. $company_name = explode(',', $company_name);
  1090. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
  1091. $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
  1092. }
  1093. //多选第一责任人
  1094. if ($first_responsible_person && is_string($first_responsible_person)) {
  1095. $first_responsible_person = explode(',', $first_responsible_person);
  1096. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  1097. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  1098. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  1099. });
  1100. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  1101. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  1102. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  1103. });
  1104. }
  1105. //多选责任人
  1106. if ($responsible_person && is_string($responsible_person)) {
  1107. $responsible_person = explode(',', $responsible_person);
  1108. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  1109. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  1110. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  1111. });
  1112. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  1113. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  1114. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  1115. });
  1116. }
  1117. //多选溯源责任人
  1118. if ($source_responsible_person && is_string($source_responsible_person)) {
  1119. $source_responsible_person = explode(',', $source_responsible_person);
  1120. $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  1121. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
  1122. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  1123. });
  1124. $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
  1125. $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
  1126. $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
  1127. });
  1128. }
  1129. if ($start_time == '' || $end_time == '') {
  1130. $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
  1131. $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
  1132. } else {
  1133. $start_time = strtotime($start_time . ' 00:00:00');
  1134. $end_time = strtotime($end_time . ' 23:59:59');
  1135. }
  1136. $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
  1137. ->where('insert_time', '<=', $end_time)->where($map)
  1138. ->select(
  1139. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  1140. DB::raw('COUNT(DISTINCT store_name) as daily_total'),
  1141. )
  1142. ->groupBy('date')
  1143. ->orderBy('date')
  1144. ->get()->keyBy('date')->toarray();
  1145. $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
  1146. ->where('insert_time', '<=', $end_time)->where($map)
  1147. ->select(
  1148. DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
  1149. DB::raw('COUNT(DISTINCT store_name) as daily_total'),
  1150. )
  1151. ->groupBy('date')
  1152. ->orderBy('date')
  1153. ->get()->keyBy('date')->toarray();
  1154. $moth_list = [];
  1155. $key_index = 0;
  1156. for ($i = $start_time; $i <= $end_time; $i += 86400) {
  1157. $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
  1158. $moth_list[$key_index]['date'] = $key_day;
  1159. $moth_list[$key_index]['low_price_store_totle'] = 0;
  1160. $moth_list[$key_index]['violation_product_store_totle'] = 0;
  1161. $moth_list[$key_index]['product_store_totle'] = 0;
  1162. if (isset($low_price_result[$key_day])) {
  1163. $moth_list[$key_index]['low_price_store_totle'] = $low_price_result[$key_day]['daily_total'];
  1164. }
  1165. if (isset($violation_product_result[$key_day])) {
  1166. $moth_list[$key_index]['violation_product_store_totle'] = $violation_product_result[$key_day]['daily_total'];
  1167. }
  1168. $moth_list[$key_index]['product_store_totle'] = $moth_list[$key_index]['low_price_store_totle'] + $moth_list[$key_index]['violation_product_store_totle'];
  1169. $key_index++;
  1170. }
  1171. // 执行下载
  1172. $oss_url = $this->store_trend_export_download($moth_list);
  1173. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
  1174. }
  1175. /**
  1176. * 商家数量趋势-导出下载
  1177. * @author 唐远望
  1178. * @version 1.0
  1179. * @date 2025-12-29
  1180. *
  1181. */
  1182. public function store_trend_export_download($data)
  1183. {
  1184. // 创建一个新的 Spreadsheet 对象
  1185. $spreadsheet = new Spreadsheet();
  1186. $sheet = $spreadsheet->getActiveSheet();
  1187. //合并单元格
  1188. $sheet->mergeCells('A1:D1');
  1189. $sheet->setCellValue('A1', '商家数量趋势统计数据(导出时间:' . date('Y-m-d H:i:s', time()) . ')'); // 设置合并后的单元格内容
  1190. // 获取合并后的单元格样式对象
  1191. $style = $sheet->getStyle('A1');
  1192. // 设置水平居中和垂直居中
  1193. $style->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
  1194. // 然后设置行高以适应两行文本
  1195. $sheet->getRowDimension(1)->setRowHeight(40); // 设置行高,单位是磅(point)
  1196. // 设置表头
  1197. $sheet->setCellValue('A2', '日期');
  1198. $sheet->setCellValue('B2', '低价商品商家数量');
  1199. $sheet->setCellValue('C2', '禁止商品商家数量');
  1200. $sheet->setCellValue('D2', '总商品商家数量');
  1201. // 填充数据
  1202. $row = 3; // 从第3行开始
  1203. foreach ($data as $item) {
  1204. $sheet->setCellValue('A' . $row, $item['date']);
  1205. $sheet->setCellValue('B' . $row, $item['low_price_store_totle']);
  1206. $sheet->setCellValue('C' . $row, $item['violation_product_store_totle']);
  1207. $sheet->setCellValue('D' . $row, $item['product_store_totle']);
  1208. $row++;
  1209. }
  1210. $file_id = date('YmdHis');
  1211. // 创建Excel文件
  1212. $filename = '商家数量趋势统计数据_' . $file_id . '.xlsx';
  1213. $path = public_path('uploads/exports/');
  1214. $fullPath = $path. $filename;
  1215. if (!is_dir($path)) mkdir($path, 0777, true);
  1216. // 生成 Excel 文件
  1217. $writer = new Xlsx($spreadsheet);
  1218. $writer->save($fullPath);
  1219. // 清理
  1220. $spreadsheet->disconnectWorksheets();
  1221. unset($spreadsheet, $writer);
  1222. $Oss = new Oss();
  1223. $oss_url = $Oss->uploadFile($filename, $fullPath);
  1224. if ($oss_url) @unlink($fullPath);
  1225. return $oss_url;
  1226. }
  1227. }