| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189 |
- <?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;
- use Illuminate\Support\Carbon;
- use App\Models\Manager\Process\LowPriceGoodsMember as LowPriceGoodsMemberModel;
- use App\Models\Manager\Process\ViolationProductMember as ViolationProductMemberModel;
- use App\Servers\Aliyun\Oss;
- /**
- * 报表统计-概览面板
- * @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();
- //执行下载
- $oss_url = $this->Violation_export_download($result);
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
- }
- /**
- * 禁止挂网链接数统计-导出下载
- * @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++;
- }
- $file_id = date('YmdHis');
- // 创建Excel文件
- $filename = '禁止挂网链接数统计数据' . $file_id . '.xlsx';
- $path = public_path('uploads/exports/');
- $fullPath = $path. $filename;
- if (!is_dir($path)) mkdir($path, 0777, true);
- // 生成 Excel 文件
- $writer = new Xlsx($spreadsheet);
- $writer->save($fullPath);
- // 清理
- $spreadsheet->disconnectWorksheets();
- unset($spreadsheet, $writer);
- $Oss = new Oss();
- $oss_url = $Oss->uploadFile($filename, $fullPath);
- if ($oss_url) @unlink($fullPath);
- return $oss_url;
- }
- /**
- * 禁止挂网公司月度统计
- * @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();
- //执行下载
- $oss_url = $this->ViolationCompany_export_download($result);
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
- }
- /**
- * 禁止挂网公司月度统计-导出下载
- * @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++;
- }
- $file_id = date('YmdHis');
- // 创建Excel文件
- $filename = '禁止挂网公司月度统计数据' . $file_id . '.xlsx';
- $path = public_path('uploads/exports/');
- $fullPath = $path. $filename;
- if (!is_dir($path)) mkdir($path, 0777, true);
- // 生成 Excel 文件
- $writer = new Xlsx($spreadsheet);
- $writer->save($fullPath);
- // 清理
- $spreadsheet->disconnectWorksheets();
- unset($spreadsheet, $writer);
- $Oss = new Oss();
- $oss_url = $Oss->uploadFile($filename, $fullPath);
- if ($oss_url) @unlink($fullPath);
- return $oss_url;
- }
- /*
- * 低价违规挂网链接数统计
- * @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();
- //执行下载
- $oss_url = $this->LowPrice_export_download($result);
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
- }
- /**
- * 低价违规挂网链接数统计-导出下载
- * @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++;
- }
- $file_id = date('YmdHis');
- // 创建Excel文件
- $filename = '低价违规挂网链接数统计数据' . $file_id . '.xlsx';
- $path = public_path('uploads/exports/');
- $fullPath = $path. $filename;
- if (!is_dir($path)) mkdir($path, 0777, true);
- // 生成 Excel 文件
- $writer = new Xlsx($spreadsheet);
- $writer->save($fullPath);
- // 清理
- $spreadsheet->disconnectWorksheets();
- unset($spreadsheet, $writer);
- $Oss = new Oss();
- $oss_url = $Oss->uploadFile($filename, $fullPath);
- if ($oss_url) @unlink($fullPath);
- return $oss_url;
- }
- /*
- * 低价违规挂网公司月度统计
- * @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();
- //执行下载
- $oss_url = $this->LowPriceCompany_export_download($result);
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
- }
- /**
- * 低价违规挂网公司月度统计-导出下载
- * @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++;
- }
- $file_id = date('YmdHis');
- // 创建Excel文件
- $filename = '低价违规挂网公司月度统计数据' . $file_id . '.xlsx';
- $path = public_path('uploads/exports/');
- $fullPath = $path. $filename;
- if (!is_dir($path)) mkdir($path, 0777, true);
- // 生成 Excel 文件
- $writer = new Xlsx($spreadsheet);
- $writer->save($fullPath);
- // 清理
- $spreadsheet->disconnectWorksheets();
- unset($spreadsheet, $writer);
- $Oss = new Oss();
- $oss_url = $Oss->uploadFile($filename, $fullPath);
- if ($oss_url) @unlink($fullPath);
- return $oss_url;
- }
- /**
- * 商品数量趋势
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-29
- *
- */
- public function get_product_trend(request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
- {
- $request->scene('get_product_trend')->validate();
- // 查询条件
- $map = [];
- $status = request('status', '');
- $start_time = request('start_time', '');
- $end_time = request('end_time', '');
- $product_name = request('product_name', '');
- $product_names = request('product_names', '');
- $first_responsible_person = request('first_responsible_person', '');
- $responsible_person = request('responsible_person', '');
- $platform = request('platform', '');
- $company_name = request('company_name', '');
- $store_name = request('store_name', '');
- $store_names = request('store_names', '');
- $source_responsible_person = request('source_responsible_person', '');
- $processing_status = request('processing_status', '');
- $product_specs = request('product_specs', '');
- $online_posting_count = request('online_posting_count', '');
- $category_name = request('category_name', '');
- // 其他条件
- if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
- if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
- if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
- //多选平台查询
- if ($platform && is_string($platform)) {
- $platform = explode(',', $platform);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- $violationProductModel = $violationProductModel->whereIn('platform', $platform);
- }
- //多选处理状态查询
- if ($processing_status && is_string($processing_status)) {
- $processing_status = explode(',', $processing_status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
- $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
- }
- //多选状态查询
- if ($status && is_string($status)) {
- $status = explode(',', $status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
- $violationProductModel = $violationProductModel->whereIn('status', $status);
- }
- //多选店铺名称查询
- if ($store_names && is_string($store_names)) {
- $store_names = explode(',', $store_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
- $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
- }
- //多选违规挂网次数查询
- if ($online_posting_count && is_string($online_posting_count)) {
- $online_posting_count = explode(',', $online_posting_count);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
- $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
- }
- //多选规格查询
- if ($product_specs && is_string($product_specs)) {
- $product_specs = explode(',', $product_specs);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
- $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
- }
- //多选商品查询
- if ($product_names && is_string($product_names)) {
- $product_names = explode(',', $product_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
- $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
- }
- //多选公司查询
- if ($company_name && is_string($company_name)) {
- $company_name = explode(',', $company_name);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
- $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
- }
- //多选第一责任人
- if ($first_responsible_person && is_string($first_responsible_person)) {
- $first_responsible_person = explode(',', $first_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选责任人
- if ($responsible_person && is_string($responsible_person)) {
- $responsible_person = explode(',', $responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选溯源责任人
- if ($source_responsible_person && is_string($source_responsible_person)) {
- $source_responsible_person = explode(',', $source_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- if ($start_time == '' || $end_time == '') {
- $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
- $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
- } else {
- $start_time = strtotime($start_time . ' 00:00:00');
- $end_time = strtotime($end_time . ' 23:59:59');
- }
- $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(id) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(id) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $moth_list = [];
- $key_index = 0;
- for ($i = $end_time; $i >= $start_time; $i -= 86400) {
- $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
- $moth_list[$key_index]['date'] = $key_day;
- $moth_list[$key_index]['low_price_totle'] = 0;
- $moth_list[$key_index]['violation_product_totle'] = 0;
- $moth_list[$key_index]['product_totle'] = 0;
- if (isset($low_price_result[$key_day])) {
- $moth_list[$key_index]['low_price_totle'] = $low_price_result[$key_day]['daily_total'];
- }
- if (isset($violation_product_result[$key_day])) {
- $moth_list[$key_index]['violation_product_totle'] = $violation_product_result[$key_day]['daily_total'];
- }
- $moth_list[$key_index]['product_totle'] = $moth_list[$key_index]['low_price_totle'] + $moth_list[$key_index]['violation_product_totle'];
- $key_index++;
- }
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $moth_list]);
- }
- /**
- * 商品数量趋势-导出
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-29
- *
- */
- public function product_trend_export(request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
- {
- $request->scene('product_trend_export')->validate();
- // 查询条件
- $map = [];
- $status = request('status', '');
- $start_time = request('start_time', '');
- $end_time = request('end_time', '');
- $product_name = request('product_name', '');
- $product_names = request('product_names', '');
- $first_responsible_person = request('first_responsible_person', '');
- $responsible_person = request('responsible_person', '');
- $platform = request('platform', '');
- $company_name = request('company_name', '');
- $store_name = request('store_name', '');
- $store_names = request('store_names', '');
- $source_responsible_person = request('source_responsible_person', '');
- $processing_status = request('processing_status', '');
- $product_specs = request('product_specs', '');
- $online_posting_count = request('online_posting_count', '');
- $category_name = request('category_name', '');
- // 其他条件
- if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
- if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
- if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
- //多选平台查询
- if ($platform && is_string($platform)) {
- $platform = explode(',', $platform);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- $violationProductModel = $violationProductModel->whereIn('platform', $platform);
- }
- //多选处理状态查询
- if ($processing_status && is_string($processing_status)) {
- $processing_status = explode(',', $processing_status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
- $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
- }
- //多选状态查询
- if ($status && is_string($status)) {
- $status = explode(',', $status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
- $violationProductModel = $violationProductModel->whereIn('status', $status);
- }
- //多选店铺名称查询
- if ($store_names && is_string($store_names)) {
- $store_names = explode(',', $store_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
- $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
- }
- //多选违规挂网次数查询
- if ($online_posting_count && is_string($online_posting_count)) {
- $online_posting_count = explode(',', $online_posting_count);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
- $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
- }
- //多选规格查询
- if ($product_specs && is_string($product_specs)) {
- $product_specs = explode(',', $product_specs);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
- $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
- }
- //多选商品查询
- if ($product_names && is_string($product_names)) {
- $product_names = explode(',', $product_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
- $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
- }
- //多选公司查询
- if ($company_name && is_string($company_name)) {
- $company_name = explode(',', $company_name);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
- $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
- }
- //多选第一责任人
- if ($first_responsible_person && is_string($first_responsible_person)) {
- $first_responsible_person = explode(',', $first_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选责任人
- if ($responsible_person && is_string($responsible_person)) {
- $responsible_person = explode(',', $responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选溯源责任人
- if ($source_responsible_person && is_string($source_responsible_person)) {
- $source_responsible_person = explode(',', $source_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- if ($start_time == '' || $end_time == '') {
- $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
- $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
- } else {
- $start_time = strtotime($start_time . ' 00:00:00');
- $end_time = strtotime($end_time . ' 23:59:59');
- }
- $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(id) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(id) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $moth_list = [];
- $key_index = 0;
- for ($i = $end_time; $i >= $start_time; $i -= 86400) {
- $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
- $moth_list[$key_index]['date'] = $key_day;
- $moth_list[$key_index]['low_price_totle'] = 0;
- $moth_list[$key_index]['violation_product_totle'] = 0;
- $moth_list[$key_index]['product_totle'] = 0;
- if (isset($low_price_result[$key_day])) {
- $moth_list[$key_index]['low_price_totle'] = $low_price_result[$key_day]['daily_total'];
- }
- if (isset($violation_product_result[$key_day])) {
- $moth_list[$key_index]['violation_product_totle'] = $violation_product_result[$key_day]['daily_total'];
- }
- $moth_list[$key_index]['product_totle'] = $moth_list[$key_index]['low_price_totle'] + $moth_list[$key_index]['violation_product_totle'];
- $key_index++;
- }
- //执行下载
- $oss_url = $this->product_trend_export_download($moth_list);
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
- }
- /**
- * 商品数量趋势-导出下载
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-29
- *
- */
- public function product_trend_export_download($data)
- {
- // 创建一个新的 Spreadsheet 对象
- $spreadsheet = new Spreadsheet();
- $sheet = $spreadsheet->getActiveSheet();
- //合并单元格
- $sheet->mergeCells('A1:D1');
- $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', '低价商品数量');
- $sheet->setCellValue('C2', '禁止商品数量');
- $sheet->setCellValue('D2', '总商品数量');
- // 填充数据
- $row = 3; // 从第3行开始
- foreach ($data as $item) {
- $sheet->setCellValue('A' . $row, $item['date']);
- $sheet->setCellValue('B' . $row, $item['low_price_totle']);
- $sheet->setCellValue('C' . $row, $item['violation_product_totle']);
- $sheet->setCellValue('D' . $row, $item['product_totle']);
- $row++;
- }
- $file_id = date('YmdHis');
- // 创建Excel文件
- $filename = '商品数量趋势统计数据' . $file_id . '.xlsx';
- $path = public_path('uploads/exports/');
- $fullPath = $path. $filename;
- if (!is_dir($path)) mkdir($path, 0777, true);
- // 生成 Excel 文件
- $writer = new Xlsx($spreadsheet);
- $writer->save($fullPath);
- // 清理
- $spreadsheet->disconnectWorksheets();
- unset($spreadsheet, $writer);
- $Oss = new Oss();
- $oss_url = $Oss->uploadFile($filename, $fullPath);
- if ($oss_url) @unlink($fullPath);
- return $oss_url;
- }
- /**
- * 商家数量趋势
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-29
- *
- */
- public function get_store_trend(Request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
- {
- $request->scene('get_store_trend')->validate();
- // 查询条件
- $map = [];
- $status = request('status', '');
- $start_time = request('start_time', '');
- $end_time = request('end_time', '');
- $product_name = request('product_name', '');
- $product_names = request('product_names', '');
- $first_responsible_person = request('first_responsible_person', '');
- $responsible_person = request('responsible_person', '');
- $platform = request('platform', '');
- $company_name = request('company_name', '');
- $store_name = request('store_name', '');
- $store_names = request('store_names', '');
- $source_responsible_person = request('source_responsible_person', '');
- $processing_status = request('processing_status', '');
- $product_specs = request('product_specs', '');
- $online_posting_count = request('online_posting_count', '');
- $category_name = request('category_name', '');
- // 其他条件
- if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
- if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
- if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
- //多选平台查询
- if ($platform && is_string($platform)) {
- $platform = explode(',', $platform);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- $violationProductModel = $violationProductModel->whereIn('platform', $platform);
- }
- //多选处理状态查询
- if ($processing_status && is_string($processing_status)) {
- $processing_status = explode(',', $processing_status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
- $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
- }
- //多选状态查询
- if ($status && is_string($status)) {
- $status = explode(',', $status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
- $violationProductModel = $violationProductModel->whereIn('status', $status);
- }
- //多选店铺名称查询
- if ($store_names && is_string($store_names)) {
- $store_names = explode(',', $store_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
- $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
- }
- //多选违规挂网次数查询
- if ($online_posting_count && is_string($online_posting_count)) {
- $online_posting_count = explode(',', $online_posting_count);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
- $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
- }
- //多选规格查询
- if ($product_specs && is_string($product_specs)) {
- $product_specs = explode(',', $product_specs);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
- $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
- }
- //多选商品查询
- if ($product_names && is_string($product_names)) {
- $product_names = explode(',', $product_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
- $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
- }
- //多选公司查询
- if ($company_name && is_string($company_name)) {
- $company_name = explode(',', $company_name);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
- $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
- }
- //多选第一责任人
- if ($first_responsible_person && is_string($first_responsible_person)) {
- $first_responsible_person = explode(',', $first_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选责任人
- if ($responsible_person && is_string($responsible_person)) {
- $responsible_person = explode(',', $responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选溯源责任人
- if ($source_responsible_person && is_string($source_responsible_person)) {
- $source_responsible_person = explode(',', $source_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- if ($start_time == '' || $end_time == '') {
- $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
- $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
- } else {
- $start_time = strtotime($start_time . ' 00:00:00');
- $end_time = strtotime($end_time . ' 23:59:59');
- }
- $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(DISTINCT store_name) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(DISTINCT store_name) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $moth_list = [];
- $key_index = 0;
- for ($i = $end_time; $i >= $start_time; $i -= 86400) {
- $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
- $moth_list[$key_index]['date'] = $key_day;
- $moth_list[$key_index]['low_price_store_totle'] = 0;
- $moth_list[$key_index]['violation_product_store_totle'] = 0;
- $moth_list[$key_index]['product_store_totle'] = 0;
- if (isset($low_price_result[$key_day])) {
- $moth_list[$key_index]['low_price_store_totle'] = $low_price_result[$key_day]['daily_total'];
- }
- if (isset($violation_product_result[$key_day])) {
- $moth_list[$key_index]['violation_product_store_totle'] = $violation_product_result[$key_day]['daily_total'];
- }
- $moth_list[$key_index]['product_store_totle'] = $moth_list[$key_index]['low_price_store_totle'] + $moth_list[$key_index]['violation_product_store_totle'];
- $key_index++;
- }
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $moth_list]);
- }
- /**
- * 商家数量趋势-导出
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-29
- *
- */
- public function store_trend_export(Request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationProductModel $violationProductModel, LowPriceGoodsMemberModel $LowPriceGoodsMemberModel, ViolationProductMemberModel $ViolationProductMemberModel)
- {
- $request->scene('store_trend_export')->validate();
- // 查询条件
- $map = [];
- $status = request('status', '');
- $start_time = request('start_time', '');
- $end_time = request('end_time', '');
- $product_name = request('product_name', '');
- $product_names = request('product_names', '');
- $first_responsible_person = request('first_responsible_person', '');
- $responsible_person = request('responsible_person', '');
- $platform = request('platform', '');
- $company_name = request('company_name', '');
- $store_name = request('store_name', '');
- $store_names = request('store_names', '');
- $source_responsible_person = request('source_responsible_person', '');
- $processing_status = request('processing_status', '');
- $product_specs = request('product_specs', '');
- $online_posting_count = request('online_posting_count', '');
- $category_name = request('category_name', '');
- // 其他条件
- if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
- if ($store_name) $map[] = ['store_name', 'like', "%$store_name%"];
- if ($category_name) $map[] = ['category_name', 'like', "%$category_name%"];
- //多选平台查询
- if ($platform && is_string($platform)) {
- $platform = explode(',', $platform);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
- $violationProductModel = $violationProductModel->whereIn('platform', $platform);
- }
- //多选处理状态查询
- if ($processing_status && is_string($processing_status)) {
- $processing_status = explode(',', $processing_status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('processing_status', $processing_status);
- $violationProductModel = $violationProductModel->whereIn('processing_status', $processing_status);
- }
- //多选状态查询
- if ($status && is_string($status)) {
- $status = explode(',', $status);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('status', $status);
- $violationProductModel = $violationProductModel->whereIn('status', $status);
- }
- //多选店铺名称查询
- if ($store_names && is_string($store_names)) {
- $store_names = explode(',', $store_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('store_name', $store_names);
- $violationProductModel = $violationProductModel->whereIn('store_name', $store_names);
- }
- //多选违规挂网次数查询
- if ($online_posting_count && is_string($online_posting_count)) {
- $online_posting_count = explode(',', $online_posting_count);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('online_posting_count', $online_posting_count);
- $violationProductModel = $violationProductModel->whereIn('online_posting_count', $online_posting_count);
- }
- //多选规格查询
- if ($product_specs && is_string($product_specs)) {
- $product_specs = explode(',', $product_specs);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_specs', $product_specs);
- $violationProductModel = $violationProductModel->whereIn('product_specs', $product_specs);
- }
- //多选商品查询
- if ($product_names && is_string($product_names)) {
- $product_names = explode(',', $product_names);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('product_name', $product_names);
- $violationProductModel = $violationProductModel->whereIn('product_name', $product_names);
- }
- //多选公司查询
- if ($company_name && is_string($company_name)) {
- $company_name = explode(',', $company_name);
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('company_name', $company_name);
- $violationProductModel = $violationProductModel->whereIn('company_name', $company_name);
- }
- //多选第一责任人
- if ($first_responsible_person && is_string($first_responsible_person)) {
- $first_responsible_person = explode(',', $first_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $first_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选责任人
- if ($responsible_person && is_string($responsible_person)) {
- $responsible_person = explode(',', $responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- //多选溯源责任人
- if ($source_responsible_person && is_string($source_responsible_person)) {
- $source_responsible_person = explode(',', $source_responsible_person);
- $subQuery = $LowPriceGoodsMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- $subQuery = $ViolationProductMemberModel->whereIn('employee_id', $source_responsible_person)->distinct('lowprice_product_logid')->select('lowprice_product_logid');
- $violationProductModel = $violationProductModel->whereIn('id', function ($query1) use ($subQuery) {
- $query1->select('lowprice_product_logid')->fromSub($subQuery, 'sub1');
- });
- }
- if ($start_time == '' || $end_time == '') {
- $start_time = Carbon::now()->startOfMonth()->getTimestamp(); // 本月开始时间
- $end_time = Carbon::today()->endOfDay()->getTimestamp(); // 今天结束时间 23:59:59
- } else {
- $start_time = strtotime($start_time . ' 00:00:00');
- $end_time = strtotime($end_time . ' 23:59:59');
- }
- $low_price_result = $LowPriceGoodsModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(DISTINCT store_name) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $violation_product_result = $violationProductModel->where('insert_time', '>=', $start_time)
- ->where('insert_time', '<=', $end_time)->where($map)
- ->select(
- DB::raw("FROM_UNIXTIME(insert_time, '%Y-%m-%d') AS date"),
- DB::raw('COUNT(DISTINCT store_name) as daily_total'),
- )
- ->groupBy('date')
- ->orderBy('date')
- ->get()->keyBy('date')->toarray();
- $moth_list = [];
- $key_index = 0;
- for ($i = $end_time; $i >= $start_time; $i -= 86400) {
- $key_day = Carbon::createFromTimestamp($i)->format('Y-m-d');
- $moth_list[$key_index]['date'] = $key_day;
- $moth_list[$key_index]['low_price_store_totle'] = 0;
- $moth_list[$key_index]['violation_product_store_totle'] = 0;
- $moth_list[$key_index]['product_store_totle'] = 0;
- if (isset($low_price_result[$key_day])) {
- $moth_list[$key_index]['low_price_store_totle'] = $low_price_result[$key_day]['daily_total'];
- }
- if (isset($violation_product_result[$key_day])) {
- $moth_list[$key_index]['violation_product_store_totle'] = $violation_product_result[$key_day]['daily_total'];
- }
- $moth_list[$key_index]['product_store_totle'] = $moth_list[$key_index]['low_price_store_totle'] + $moth_list[$key_index]['violation_product_store_totle'];
- $key_index++;
- }
- // 执行下载
- $oss_url = $this->store_trend_export_download($moth_list);
- return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $oss_url]);
- }
- /**
- * 商家数量趋势-导出下载
- * @author 唐远望
- * @version 1.0
- * @date 2025-12-29
- *
- */
- public function store_trend_export_download($data)
- {
- // 创建一个新的 Spreadsheet 对象
- $spreadsheet = new Spreadsheet();
- $sheet = $spreadsheet->getActiveSheet();
- //合并单元格
- $sheet->mergeCells('A1:D1');
- $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', '低价商品商家数量');
- $sheet->setCellValue('C2', '禁止商品商家数量');
- $sheet->setCellValue('D2', '总商品商家数量');
- // 填充数据
- $row = 3; // 从第3行开始
- foreach ($data as $item) {
- $sheet->setCellValue('A' . $row, $item['date']);
- $sheet->setCellValue('B' . $row, $item['low_price_store_totle']);
- $sheet->setCellValue('C' . $row, $item['violation_product_store_totle']);
- $sheet->setCellValue('D' . $row, $item['product_store_totle']);
- $row++;
- }
- $file_id = date('YmdHis');
- // 创建Excel文件
- $filename = '商家数量趋势统计数据_' . $file_id . '.xlsx';
- $path = public_path('uploads/exports/');
- $fullPath = $path. $filename;
- if (!is_dir($path)) mkdir($path, 0777, true);
- // 生成 Excel 文件
- $writer = new Xlsx($spreadsheet);
- $writer->save($fullPath);
- // 清理
- $spreadsheet->disconnectWorksheets();
- unset($spreadsheet, $writer);
- $Oss = new Oss();
- $oss_url = $Oss->uploadFile($filename, $fullPath);
- if ($oss_url) @unlink($fullPath);
- return $oss_url;
- }
- }
|