FuJiTong.php
6.0 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
157
158
159
160
161
162
163
164
165
<?php
namespace app\products\controller;
use app\common\model\serviceapi\Product as ProductModel;
use app\common\model\serviceapi\ProductUser as ProductUserModel;
use app\common\model\serviceapi\ProductOrder as ProductOrderModel;
use app\web\controller\BaseController;
use think\Log;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
* 功能描述 妇记通获客
* Class Product
* @package app\FuJiTong\controller
* Date: 2021/5/6
* Time: 10:00
* @author nyq
*/
class FuJiTong extends BaseController
{
private $api_domain ="www.aisigit.com/products/fu/customer_list"; //测试平台
//private $api_domain = "http://hzy.sosyun.com/products/fu/customer_list";
/**
* 函数功能描述 获取客户列表
* Date: 2021/5/6
* Time: 10:00
* @author nyq
*/
public function customer_list(Request $request)
{
$data = $request->param();
//return json($data);
Cookie::set('fu_data', $data);
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset=($page-1)*$rows;
$data['offset']=$offset;
$data['rows']=$rows;
$json=[
"offset"=>$offset,
"rows"=>$rows,
"result"=>isset($data['result']) && !empty($data['result']) ? $data['result'] : '',
"type"=>isset($data['new_type']) && !empty($data['new_type']) ? $data['new_type'] : '',
"start"=>!empty($data['start']) ? $data['start'] : '',
"end"=>!empty($data['end']) ? $data['end'] : '',
"phone"=>!empty($data['phone']) ? $data['phone'] : '',
];
// return json($json);
$data_http = http_build_query($json);
$row=MCurl::instance($this->api_domain)->post($data_http);
$data_list=json_decode($row,true);
$data_json=$data_list['rows'];
foreach($data_json as $key=>$val ){
$data_json[$key]['sex']=$val['sex'] == 1? '女' : '男';
}
$result["total"] =$data_list['total'];
$result['rows']=$data_json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 导出数据到表格
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function to_excel()
{
$data= Cookie::get('fu_data');
$json=[
"offset"=>1,
"rows"=>1,
"result"=>isset($data['result']) && !empty($data['result']) ? $data['result'] : '',
"type"=>isset($data['new_type']) && !empty($data['new_type']) ? $data['new_type'] : '',
"start"=>!empty($data['start']) ? $data['start'] : '',
"end"=>!empty($data['end']) ? $data['end'] : '',
"phone"=>!empty($data['phone']) ? $data['phone'] : '',
'to_excel'=>1
];
$data_http = http_build_query($json);
$row=MCurl::instance($this->api_domain)->post($data_http);
$data_list=json_decode($row,true);
$data_json=$data_list['rows'];
foreach($data_json as $key=>$val ){
$data_json[$key]['sex']=$val['sex'] == 1? '女' : '男';
}
ob_end_clean();//清除缓冲区,避免乱码
Vendor('PHPExcel.PHPExcel');
$objPHPExcel=new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '用户名称')
->setCellValue('B1', '性别')
->setCellValue('C1', '电话')
->setCellValue('D1', '证件号码')
->setCellValue('E1', '推送结果')
->setCellValue('F1', '推送时间');
$rowIndex = 2;
foreach ($data_json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['username'])
->setCellValue('B' . $rowIndex, $v['sex'])
->setCellValue('C' . $rowIndex, $v['phone'])
->setCellValue('D' . $rowIndex, $v['certificateNo'].',')
->setCellValue('E' . $rowIndex, $v['result'].',')
->setCellValue('F' . $rowIndex, $v['create_time']);
$rowIndex++;
}
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
$filename = '用户信息列表';
header('Content-Type: application/vnd.ms-excel');
$ua = $_SERVER["HTTP_USER_AGENT"];
header('Content-type: text/html; charset=gbk');
header("Content-type:application/vnd.ms-excel;charset=gbk");
//兼容IE11
if (preg_match("/MSIE/", $ua) || preg_match("/Trident\/7.0/", $ua)) {
header('Content-Disposition: attachment;filename="' . urlencode($filename) . '.xls"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment;filename*="' . $filename . '.xls"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '.xls"');
}
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: cache, must-revalidate');
header('Pragma: public');
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
}
}