Product.php
13.7 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
<?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\products\controller
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
class Product extends BaseController
{
private $api_back_url = "http://sosapi.com/commapi/generator_data/sosBxCarInfoAdd";
public function carOrder()
{
//$res = MCurl::instance($this->api_back_url)->post($data);
$data=[];
$res=[];
for($i=0;$i<10;$i++){
$res[$i] = json_decode(MCurl::instance($this->api_back_url)->post($data),true);
}
$this->to($res);
var_dump($res);
die;
//var_dump();
//echo 111;die;
return $res;
}
public function to($json)
{
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 ($json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['uname'])
->setCellValue('B' . $rowIndex, $v['pai'])
->setCellValue('C' . $rowIndex, $v['shen'])
->setCellValue('D' . $rowIndex, $v['tel'])
->setCellValue('E' . $rowIndex, $v['age'])
->setCellValue('F' . $rowIndex, $v['sex']);
$rowIndex++;
}
// echo 3321;die;
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(100
);
// $objPHPExcel->getActiveSheet()->getStyle('C')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
$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');
}
/**
* 函数功能描述 删除订单
* Date: 2020/8/07
* Time: 10:00
* @author nyq
*/
public function order_del()
{
$data = $this->request->post();
$product_order_model = new ProductOrderModel();
$res = $product_order_model->orderDel($data);
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'删除成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'删除失败'
];
}
return $data;
}
/**
* 函数功能描述 生成订单
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function addOrde(Request $request)
{
$data = $request->param();
//用户信息
$user['name']=$data['name'];
$user['phone']=$data['phone'];
// $user['sheng']=$data['sheng'];
// $user['shi']=$data['shi'];
// $user['qu']=$data['qu'];
$user['address']=$data['address'];
$user['addTime']=time();
$product_user_model = new ProductUserModel();
$res = $product_user_model->add($user);
//订单信息
$order['order_code']=time().mt_rand(999, 9999);
$order['user_id']=$res;
$order['goods_id']=$data['goods_id'];
$order['num']=$data['num'];
$order['price']=$data['price'];
// $order['sheng']=$data['sheng'];
// $order['shi']=$data['shi'];
// $order['qu']=$data['qu'];
$order['address']=$data['address'];
$order['addTime']=time();
$order['upTime']=time();
$product_order_model = new ProductOrderModel();
$order_res = $product_order_model->add($order);
$json=json_decode($order_res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'失败'
];
}
return $data;
}
/**
* 函数功能描述 获取订单列表
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function get_order_list(Request $request)
{
$data = $request->param();
$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;
$where=[];
$product_user_model = new ProductUserModel();
$res = $product_user_model->getUserlist($where,$data['offset'],$data['rows']);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
//$json[$key]['address']=$json[$key]['sheng'].$json[$key]['shi'].$json[$key]['qu'].$json[$key]['address'];
}
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 根据id查询商品信息
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function get_one_list(Request $request)
{
$data = $request->param();
$product_model = new ProductModel();
$res = $product_model->getGoodsList($data);
$res['content'] = htmlspecialchars_decode($res['content']);
$img[]=explode(',',$res['images']);
$res['img']=$img[0][0];
$res['img2']=$img[0][1];
$res['img3']=$img[0][2];
unset($res['images']);
return $res;
}
/**
* 函数功能描述 获取商品列表
* Date: 2020/11/2
* Time: 10:00
* @author nyq
*/
public function goods_list(Request $request)
{
$data = $request->param();
$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;
$product_model = new ProductModel();
$where=[];
$res = $product_model->goodsList($where,$data['offset'],$data['rows']);
$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
}
$result["total"] =count($json);
$result['rows']=$json;
echo json_encode($result);
//return $json;
}
/**
* 函数功能描述 添加商品
* Date: 2020/11/02
* Time: 10:00
* @author nyq
*/
public function goods_add(Request $request)
{
$data = $request->param();
$data['images']=$data['img'].','.$data['img2'].','.$data['img3'];
unset($data['img'],$data['img2'],$data['img3']);
$product_model = new ProductModel();
if(isset($data['goods_id']) && !empty($data['goods_id'])){
$data['upTime']=time();
$where['id']=$data['goods_id'];
unset($data['goods_id']);
$res = $product_model->productUp($where,$data);
}else{
unset($data['goods_id']);
$data['addTime']=time();
$data['upTime']=time();
$res = $product_model->add($data);
}
$json=json_decode($res,true);
if(is_numeric($json)){
$data=[
'code'=>200,
'msg'=>'成功'
];
}else{
$data=[
'code'=>100,
'msg'=>'失败'
];
}
return $data;
}
/**
* 函数功能描述 文件上传
* Date: 2020/11/02
* Time: 10:00
* @author nyq
*/
public function uploadFileImgs(){
$files = request()->file('files');
$path = input('path');
if($files){
$imgarr = [];
foreach($files as $file){
$info = $file->validate(['size'=>204800000,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public/web/' . DS . 'product');
if($info){
$newurl = '/web/product/'.$info->getSaveName();
$img= str_replace('\\','/',$newurl);
$imgarr[]=$img;
}
}
return json_encode($imgarr);
}else{
echo '没有图片上传';
}
}
/**
* 函数功能描述 导出数据到表格
* Date: 2020/8/26
* Time: 10:00
* @author nyq
*/
public function to_excel()
{
//$data = $this->request->Post();
// $data= Cookie::get('data');
// $data['to_excel']=1;
$product_user_model = new ProductUserModel();
$json = $product_user_model->getUserlistToEx();
//$res = MCurl::instance($this->api_url."prizeUserList")->post($data);
//$json=json_decode($res,true);
foreach($json as $key=>$val ){
$json[$key]['addTime']=date('Y-m-d H:i:s',$val['addTime']);
$json[$key]['address']=$json[$key]['sheng'].$json[$key]['shi'].$json[$key]['qu'].$json[$key]['address'];
}
ob_end_clean();//清除缓冲区,避免乱码
Vendor('PHPExcel.PHPExcel');
$objPHPExcel=new \PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', '订单编号')
->setCellValue('B1', '商品名称')
->setCellValue('C1', '用户名')
->setCellValue('D1', '电话')
->setCellValue('E1', '详细地址')
->setCellValue('F1', '产品数量')
->setCellValue('G1', '总金额')
->setCellValue('H1', '下单时间');
$rowIndex = 2;
foreach ($json as $k => $v) {
$objPHPExcel->getActiveSheet()
->setCellValue('A' . $rowIndex, $v['order_code'])
->setCellValue('B' . $rowIndex, $v['goods_name'])
->setCellValue('C' . $rowIndex, $v['name'])
->setCellValue('D' . $rowIndex, $v['phone'])
->setCellValue('E' . $rowIndex, $v['address'])
->setCellValue('F' . $rowIndex, $v['num'])
->setCellValue('G' . $rowIndex, $v['price'])
->setCellValue('H' . $rowIndex, $v['addTime']);
$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);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->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');
}
}