From f3d0694fe1b6c34ab5f12322e8673a47c299ae69 Mon Sep 17 00:00:00 2001
From: Alone <675061370@qq.com>
Date: Fri, 26 Apr 2024 12:07:45 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/admin/QfShop.php | 26 +++-----------
app/admin/controller/Source.php | 55 ++++++++++++++++++++++++++++--
app/qfadmin/view/source/index.html | 13 +++++++
3 files changed, 69 insertions(+), 25 deletions(-)
diff --git a/app/admin/QfShop.php b/app/admin/QfShop.php
index ac13d0c..2b06d41 100644
--- a/app/admin/QfShop.php
+++ b/app/admin/QfShop.php
@@ -631,44 +631,26 @@ abstract class QfShop
->setDescription("Export by qfshop"); //设置备注
$PHPSheet = $PHPExcel->getActiveSheet();
- $PHPSheet->setTitle($this->excelTitle); //给当前活动sheet设置名称
- $PHPSheet->mergeCells('A1:' . $this->excelCells[count($excelField) - 1] . "1");
- $PHPSheet->setCellValue('A1', $this->excelTitle);
- $PHPSheet->getRowDimension(1)->setRowHeight(40);
- $PHPSheet->getStyle('A1')->getFont()->setSize(16)->setBold(true); //字体大小
-
- $PHPSheet->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //水平方向上对齐
- $PHPSheet->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); //垂直方向上中间居中
- $PHPSheet->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); //垂直方向上中间居中
if (count($excelField) > count($this->excelCells)) {
echo 'Error and you need check Excel Cells Keys...';
die;
}
- $PHPSheet->getRowDimension(2)->setRowHeight(30);
+ $PHPSheet->getRowDimension(1)->setRowHeight(30);
for ($column = 0; $column < count($excelField); $column++) {
- $PHPSheet->setCellValue($this->excelCells[$column] . "2", $excelField[$column][1]);
+ $PHPSheet->setCellValue($this->excelCells[$column] . "1", $excelField[$column][1]);
$PHPSheet->getStyle($this->excelCells[$column])->getNumberFormat()
->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_TEXT);
for ($line = 0; $line < count($datalist); $line++) {
$string = $datalist[$line][$excelField[$column][0]];
$PHPSheet->getColumnDimension($this->excelCells[$column])->setWidth(20);
- $PHPSheet->setCellValueExplicit($this->excelCells[$column] . ($line + 3), $string, \PHPExcel_Cell_DataType::TYPE_STRING);
+ $PHPSheet->setCellValueExplicit($this->excelCells[$column] . ($line + 2), $string, \PHPExcel_Cell_DataType::TYPE_STRING);
}
}
//***********************画出单元格边框*****************************
$styleArray = array(
- 'borders' => array(
- 'inside' => array(
- 'style' => \PHPExcel_Style_Border::BORDER_THIN, //细边框
- //'color' => array('argb' => 'FFFF0000'),
- ),
- 'outline' => array(
- 'style' => \PHPExcel_Style_Border::BORDER_THICK, //边框是粗的
- //'color' => array('argb' => 'FFFF0000'),
- ),
- ),
+
);
$PHPSheet->getStyle('A2:' . $this->excelCells[count($excelField) - 1] . (count(
$datalist
diff --git a/app/admin/controller/Source.php b/app/admin/controller/Source.php
index 27ead6e..b24398b 100644
--- a/app/admin/controller/Source.php
+++ b/app/admin/controller/Source.php
@@ -217,16 +217,15 @@ class Source extends QfShop
//删除这个文件
unlink("./uploads/".$saveName);
-
// 生成二维码
foreach ($excel_array as $k => $v) {
$patterns = '/^\d+\.|\d+\-/';
$title = '';
- if (preg_match('/http[^ ]+/', $v[2], $matches)) {
+ if (!empty($v[2]) && preg_match('/http[^ ]+/', $v[2], $matches)) {
$title = preg_replace($patterns, '', $v[1]);
$url = $matches[0];
} else {
- if (preg_match('/http[^ ]+/', $v[3], $matches)) {
+ if (!empty($v[3]) && preg_match('/http[^ ]+/', $v[3], $matches)) {
$title = preg_replace($patterns, '', $v[2]);
$url = $matches[0];
} else {
@@ -420,5 +419,55 @@ class Source extends QfShop
}
return jok('获取成功',$res['data']);
}
+
+
+ /**
+ * 导出
+ *
+ * @return void
+ */
+ public function excel()
+ {
+ $error = $this->access();
+ if ($error) {
+ return $error;
+ }
+
+ //查询数据
+ $map = [];
+ $filter = input('');
+ foreach ($filter as $k => $v) {
+ if ($k == 'filter') {
+ $k = input('filter');
+ $v = input('keyword');
+ }
+ if ($v === '' || $v === null) {
+ continue;
+ }
+ if (array_key_exists($k, $this->searchFilter)) {
+ switch ($this->searchFilter[$k]) {
+ case "like":
+ array_push($map, [$k, 'like', "%" . $v . "%"]);
+ break;
+ case "=":
+ array_push($map, [$k, '=', $v]);
+ break;
+ default:
+ }
+ }
+ }
+
+ $field = 'title,url';
+ $dataList = $this->model->field($field)->where($map)->select();
+ $excelField = [
+ "title" => "资源名称",
+ "url" => "资源地址",
+ ];
+ $data = $dataList->toArray();
+
+ $this->excelField = $excelField;
+ $this->exportExcelData($dataList);
+ print_r(12);
+ }
}
diff --git a/app/qfadmin/view/source/index.html b/app/qfadmin/view/source/index.html
index 6edeb70..2275533 100644
--- a/app/qfadmin/view/source/index.html
+++ b/app/qfadmin/view/source/index.html
@@ -9,6 +9,7 @@