Test.php
6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
namespace app\api\controller;
use qx\Qx;
use app\common\controller\Api;
use app\common\model\User;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Db;
/**
* 验证接口
*/
class Test extends Api
{
protected $noNeedLogin = '*';
protected $layout = '';
protected $error = null;
public function _initialize()
{
parent::_initialize();
}
public function index()
{
$qx = new Qx();
// $info = $qx->geturl("http://openapi.qxwz.com/rest/linkx.devices.list/ack/U48c2jnr9901?pageNo=1&pageSize=2000");
$info = $qx->geturl("http://openapi.qxwz.com/rest/linkx.devices.data/ack/U48c2jnr9901?deviceId=1000000792&startTime=1642651366000&endTime=1644379366000");
var_dump(json_decode($info, true));
// exit;
$this->success('', json_decode($info, true));
// $api = new Api();
// var_dump($api->getPreviewUrl('1ef84de21c0e4aa19cde1c17b38bd065'));
}
/**
* 导出
*/
public function export()
{
//获取数据
$list = Db::name("user")->field("id,username,mobile,createtime")->select();
//vendor('PHPExcel.PHPExcel');
Vendor('PHPExcel.PHPExcel');//调用类库,路径是基于vendor文件夹的
Vendor('PHPExcel.PHPExcel.Worksheet.Drawing');
Vendor('PHPExcel.PHPExcel.Writer.Excel2007');
//实例化
$objExcel = new \PHPExcel();
//设置文档属性
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
//设置内容
$objActSheet = $objExcel->getActiveSheet();
$key = ord("A");
$letter = explode(',', "A,B,C,D");
$arrHeader = array('ID', '姓名', '手机号', "创建时间");
//填充表头信息
$lenth = count($arrHeader);
for ($i = 0; $i < $lenth; $i++) {
$objActSheet->setCellValue("$letter[$i]1", "$arrHeader[$i]");
};
//填充表格信息
foreach ($list as $k => $v) {
$k += 2;
//表格内容
$objActSheet->setCellValue('A' . $k, $v['id']);
$objActSheet->setCellValue('B' . $k, $v['name']);
$objActSheet->setCellValue('C' . $k, $v['mobile']);
$objActSheet->setCellValue('D' . $k, date('Y-m-d H:i:s', $v['createtime']));
//$objActSheet->setCellValue('E' . $k, $v['goods_images']);
// 图片生成
//$objDrawing[$k] = new \PHPExcel_Worksheet_Drawing();
//$objDrawing[$k]->setPath(ROOT_PATH."public/static/image/playbtn.png");
// 设置宽度高度
//$objDrawing[$k]->setHeight(40);//照片高度
//$objDrawing[$k]->setWidth(40); //照片宽度
// 设置图片要插入的单元格
//$objDrawing[$k]->setCoordinates('C' . $k);
// 图片偏移距离
//$objDrawing[$k]->setOffsetX(30);
//$objDrawing[$k]->setOffsetY(12);
//$objDrawing[$k]->setWorksheet($objExcel->getActiveSheet());
// 表格高度
//$objActSheet->getRowDimension($k)->setRowHeight(20);
}
/*
$width = array(20, 20, 15, 10, 10, 30, 10, 15);
//设置表格的宽度
$objActSheet->getColumnDimension('A')->setWidth($width[5]);
$objActSheet->getColumnDimension('B')->setWidth($width[1]);
$objActSheet->getColumnDimension('C')->setWidth($width[0]);
$objActSheet->getColumnDimension('D')->setWidth($width[5]);
$objActSheet->getColumnDimension('E')->setWidth($width[5]);
*/
$outfile = md5("扫描文本" . time()) . ".xlsx";
ob_end_clean();
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="' . $outfile . '"');
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$objWriter->save('php://output');
}
/**
* 批量导入地区
*/
public function import_village()
{
$param = $this->request->param();
if (!empty($param['code'])) {
$data = Db::name("area_code")->where("pcode", $param['code'])->where("code", "gt", 532503005000)->select();
if (!empty($data)) {
// $this->success("", $data);
foreach ($data as $k => $v) {
$w1 = [];
$w1 = [
"name" => $v['name'],
"province_id" => 1,//云南省
"state_id" => 1,//红河州
"county_id" => 1,//蒙自市
];
$id = Db::name("reservoir_street")->where($w1)->value("id");
if (!empty($id)) {
$createtime =time();
$village = Db::name("area_code")->where(["pcode"=>$v['code']])->select();
if(!empty($village)){
foreach ($village as $vk=>$vv){
$insert_data = [];
$insert_data = [
"name"=>$vv['name'],
"province_id" => 1,//云南省
"state_id" => 1,//红河州
"county_id" => 1,//蒙自市
"street_id"=>$id,
];
$count = Db::name("reservoir_village")->where($insert_data)->count();
if($count==0){
$insert_data["createtime"] = $createtime;
Db::name("reservoir_village")->insertGetId($insert_data);
}
}
}
}
}
}
}
$this->error("无数据");
}
}