ImportController.class.php
1.31 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
<?php
/**
* 【后台】解析员工激励导入模板接口
* ImportController.class.php
* @author:daijun
* @date:2017-08-31
*/
namespace Apicp\Controller\Incentives;
use Com\PythonExcel;
use Common\Service\IncentivesService;
class ImportController extends \Apicp\Controller\AbstractController
{
/**
* 解析员工激励导入模板接口
* @author daijun
*/
public function Index_post()
{
// 获取上传文件详情
$file = $_FILES['file'];
// 获取培训ID
$ed_id = I('post.ed_id');
$incentives_serv = new IncentivesService();
// 验证数据
if (!$incentives_serv->xls_validation($ed_id, $file)) {
return false;
}
// xls文件名称
$filename = $file['tmp_name'];
$data = PythonExcel::instance()->read($filename, 0);
// 如果数据为空
if (empty($data)) {
E('_EMPTY_XLS_DATA');
}
// 循环组装返回数据
$res_data = $incentives_serv->format_excel_list($data);
if (!$res_data) {
return false;
}
// 返回给前端的数据结构
$this->_result = [
'head' => $res_data['heads'],
'list' => array_values($res_data['list']),
];
return true;
}
}