mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-23 02:45:33 +08:00
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
||
/**
|
||
* Copyright © ShopeX (http://www.shopex.cn). All rights reserved.
|
||
* See LICENSE file for license details.
|
||
*/
|
||
|
||
|
||
class omecsv_io_io{
|
||
|
||
var $charset = null;
|
||
var $limitRow = 20000;
|
||
|
||
public function __construct(){
|
||
if(!setlocale(LC_ALL, 'zh_CN.gbk')){
|
||
setlocale(LC_ALL, "chs");
|
||
}
|
||
$this->charset = kernel::single('base_charset');
|
||
|
||
}
|
||
|
||
public function getTitle(&$cols){
|
||
$title = array();
|
||
foreach( $cols as $col => $val ){
|
||
if( !$val['deny_export'] )
|
||
$title[$col] = $val['label'].'('.$col.')';
|
||
}
|
||
return $title;
|
||
}
|
||
|
||
public function init( &$model ){
|
||
$model->charset = $this->charset;
|
||
$model->io = $this;
|
||
$this->model->$model;
|
||
}
|
||
|
||
/**
|
||
* @param String $inputFileName 导入文件名
|
||
* @param Array $contents 数量
|
||
* @return Void
|
||
**/
|
||
public function fgethandle($inputFileName,&$contents){
|
||
$path = pathinfo($inputFileName);
|
||
$excel = new \Vtiful\Kernel\Excel(['path' => $path['dirname']]);
|
||
$excel->openFile($path['basename'])
|
||
->openSheet();
|
||
$row = $excel->nextRow();
|
||
if(!is_array($row)) {
|
||
throw new exception('Don\'t find import title');
|
||
}
|
||
$contents = $excel->setType(array_pad([], count($row), \Vtiful\Kernel\Excel::TYPE_STRING))
|
||
->getSheetData();
|
||
$contents = array_merge([0 => $row], $contents);
|
||
}
|
||
|
||
public function prepared_import( $appId,$mdl ){
|
||
$this->model = app::get($appId)->model($mdl);
|
||
$this->model->ioObj = $this;
|
||
if( method_exists( $this->model,'prepared_import_csv' ) ){
|
||
$this->model->prepared_import_csv();
|
||
}
|
||
return;
|
||
}
|
||
|
||
public function finish_import(){
|
||
if( method_exists( $this->model,'finish_import_csv' ) ){
|
||
$this->model->finish_import_csv();
|
||
}
|
||
}
|
||
|
||
}
|