mirror of
https://gitee.com/ShopeX/OMS
synced 2026-04-01 05:26:43 +08:00
86 lines
3.1 KiB
PHP
86 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
class wms_print_tmpl {
|
|
|
|
/**
|
|
* 上传快递单模板
|
|
*
|
|
* @param object $file 待上传的快递单模板文件
|
|
* @return string 返回上传的消息
|
|
*/
|
|
function upload_tmpl($file){
|
|
|
|
$print_tmplObj = app::get('wms')->model('print_tmpl');
|
|
|
|
$extname = strtolower($this->extName($file['name']));
|
|
$tar = kernel::single('ome_utility_tar');
|
|
if($extname=='.dtp'){
|
|
if($tar->openTAR($file['tmp_name'],'') && $tar->containsFile('info')){
|
|
if(!($info = unserialize($tar->getContents($tar->getFile('info'))))){
|
|
$error_msg = "无法读取结构信息,模板包可能已损坏";
|
|
return $error_msg;
|
|
}
|
|
if ($tar->containsFile('background.jpg')){ //包含背景图
|
|
$rand = md5(time());
|
|
if(function_exists('sys_get_temp_dir')){
|
|
$tmpPath = sys_get_temp_dir().'/'.$rand.'.jpg';
|
|
}else{
|
|
$mark = kernel::single('ome_utility_tool');
|
|
$tmpPath = $mark->get_temp_dir().'/'.$rand.'.jpg';
|
|
}
|
|
|
|
file_put_contents($tmpPath,$tar->getContents($tar->getFile('background.jpg')));
|
|
}
|
|
if (file_exists($tmpPath)){//保存图片
|
|
$ss = kernel::single('base_storager');
|
|
$Path = substr($tmpPath,strrpos($tmpPath,'dly_bg_'));
|
|
$file['name'] = $Path;
|
|
$file['type'] = 'image/jpeg';
|
|
$file['size'] = filesize($tmpPath);
|
|
$file['tmp_name'] = $tmpPath;
|
|
$id = $ss->save_upload($file,"file","",$msg);//返回file_id;
|
|
}
|
|
unlink($tmpPath);
|
|
$info['file_id'] = $id;
|
|
$re = $print_tmplObj->save($info);//保存快递单模板
|
|
|
|
if ($re){
|
|
$error_msg = "success";
|
|
return $error_msg;
|
|
}
|
|
$error_msg = "上传失败";
|
|
return $error_msg;
|
|
}else{
|
|
$error_msg = "无法解压缩,模板包可能已损坏";
|
|
return $error_msg;
|
|
}
|
|
}else{
|
|
$error_msg = "必须是shopex快递单模板包(.dtp)";
|
|
return $error_msg;
|
|
}
|
|
$error_msg = "success";
|
|
return $error_msg;
|
|
}
|
|
/*
|
|
* 提取扩展名
|
|
*/
|
|
function extName($file){
|
|
return substr($file,strrpos($file,'.'));
|
|
}
|
|
|
|
} |