Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xxmp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chan
xxmp
Commits
d9da0bd3
Commit
d9da0bd3
authored
May 07, 2019
by
chenzq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加excel表导入数据库
parent
0b6a33ab
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
excel.inc.php
addons/longbing_company/inc/web/manage/excel.inc.php
+108
-0
No files found.
addons/longbing_company/inc/web/manage/excel.inc.php
0 → 100644
View file @
d9da0bd3
<?php
global
$_GPC
;
global
$_W
;
define
(
'ROOT_PATH'
,
IA_ROOT
.
'/addons/longbing_company/'
);
is_file
(
ROOT_PATH
.
'/inc/we7.php'
)
||
exit
(
'Access Denied Longbing'
);
require_once
ROOT_PATH
.
'/inc/we7.php'
;
//引入自定义公共类
$uniacid
=
$_W
[
'uniacid'
];
$module_name
=
$_W
[
'current_module'
][
'name'
];
set_time_limit
(
0
);
include_once
IA_ROOT
.
'/framework/library/phpexcel/PHPExcel.php'
;
include_once
IA_ROOT
.
'/framework/library/phpexcel/PHPExcel/IOFactory.php'
;
if
(
$_GPC
[
'action'
]
==
'import'
)
{
$file
=
$_FILES
[
'file'
];
if
(
!
$file
[
'size'
])
{
message
(
'文件上传不能为空!'
,
''
,
'error'
);
}
if
(
$file
[
'name'
]
&&
$file
[
'error'
]
==
0
)
{
$type
=
@
end
(
explode
(
'.'
,
$file
[
'name'
]));
$type
=
strtolower
(
$type
);
if
(
!
in_array
(
$type
,
array
(
'xls'
,
'xlsx'
,
'csv'
)))
{
message
(
'文件类型错误!'
,
''
,
'error'
);
}
if
(
$type
==
'xls'
)
{
$inputFileType
=
'Excel5'
;
//这个是读 xls的
}
else
{
$inputFileType
=
'Excel2007'
;
//这个是计xlsx的
}
$objReader
=
PHPExcel_IOFactory
::
createReader
(
$inputFileType
);
$objPHPExcel
=
$objReader
->
load
(
$file
[
'tmp_name'
]);
$sheet
=
$objPHPExcel
->
getSheet
(
0
);
//获取行数与列数,注意列数需要转换
$highestRow
=
$sheet
->
getHighestRow
();
$highestColumn
=
$sheet
->
getHighestColumn
();
$highestColumnNum
=
PHPExcel_Cell
::
columnIndexFromString
(
$highestColumn
);
// $i = 0;
// file_put_contents(IA_ROOT .'/data/company_log.txt',"\n\nhighestRow:{$highestRow},highestColumnNum:{$highestColumnNum}\n",FILE_APPEND);
for
(
$row
=
2
;
$row
<=
$highestRow
;
$row
++
)
{
$yinggong
=
$sheet
->
getCellByColumnAndRow
(
0
,
$row
)
->
getValue
();
//应用名称
$company_name
=
$sheet
->
getCellByColumnAndRow
(
1
,
$row
)
->
getValue
();
//公司名称
$company_address
=
$sheet
->
getCellByColumnAndRow
(
2
,
$row
)
->
getValue
();
//公司地址
$province
=
$sheet
->
getCellByColumnAndRow
(
3
,
$row
)
->
getValue
();
//省份
$city
=
$sheet
->
getCellByColumnAndRow
(
4
,
$row
)
->
getValue
();
//市
$logo
=
$sheet
->
getCellByColumnAndRow
(
5
,
$row
)
->
getValue
();
//公司logo
$status
=
$sheet
->
getCellByColumnAndRow
(
13
,
$row
)
->
getValue
();
//上架状态
// switch ($excel_uniacid)
// {
// case '禅吻':
// $excel_uniacid = 3;
// break;
// case '诗蒂莲':
// $excel_uniacid = 5;
// break;
// }
// message($sheet->getCellByColumnAndRow(12, 1)->getValue());die;
//$item = pdo_get('longbing_card_shop_order', array('id' => $order_id,'uniacid'=>$excel_uniacid));
// file_put_contents(IA_ROOT . '/data/order_log.txt',"row:{$row},order_id:{$order_id},excel_uniacid:{$excel_uniacid},express_company:{$express_company},courier_number:{$courier_number},express_phone:{$express_phone}\n",FILE_APPEND);
// if($item && $excel_uniacid == $uniacid && $express_company && $courier_number && $express_phone){
// $data = array(
// 'order_status' => 2,
// 'update_time' => time()
// );
//判断表头是否正确 trim过滤左右空格
// if ($company=='快递公司'){
// $data['express_company'] = trim($express_company);
// }else{
// message('请查看快递公司表头是否正确,位置为-M1','','error');
// }
// if ($number=='快递单号'){
// $data['courier_number'] = trim($courier_number);
// }else{
// message('请查看快递单号表头是否正确,位置为-N1','','error');
// }
// if ($phone=='发货人电话'){
// $data['express_phone'] = trim($express_phone);
// }else{
// message('请查看发货人电话表头是否正确,位置为-O1','','error');
// }
$province_id
=
pdo_get
(
'sys_region'
,
array
(
'name'
=>
$province
),
'id'
);
$city_id
=
pdo_get
(
'sys_region'
,
array
(
'name'
=>
$city
),
'id'
);
$data
=
array
(
'uniacid'
=>
$yinggong
,
'name'
=>
$company_name
,
'addr'
=>
$company_address
,
'province'
=>
$province_id
[
'id'
],
'city'
=>
$city_id
[
'id'
],
'logo'
=>
$logo
,
'status'
=>
$status
);
pdo_insert
(
'longbing_company_company'
,
$data
);
}
}
message
(
'成功导入'
,
''
,
'success'
);
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment