Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
89f9b4b64b |
@ -30,29 +30,52 @@ class Demo extends BaseController
|
|||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
$mer_id = 65;
|
||||||
$file = request()->file('file');
|
$file = request()->file('file');
|
||||||
$zip_name = explode('.', $file->getOriginalName())[0];
|
$zip_name = explode('.', $file->getOriginalName())[0];
|
||||||
// 上传到本地服务器
|
// 上传到本地服务器
|
||||||
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
||||||
$destination_path = public_path('uploads/pic') . $zip_name;
|
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id;
|
||||||
$zip = new ZipArchive;
|
$path = public_path('uploads/pic').$dir;
|
||||||
if ($zip->open(public_path('uploads').$savename) === TRUE) {
|
try {
|
||||||
$zip->extractTo($destination_path);
|
$zip = new ZipArchive;
|
||||||
|
$filePath = public_path('uploads') . $savename;
|
||||||
|
$zip->open($filePath);
|
||||||
|
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||||
|
$statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW);
|
||||||
|
$filename = $this->transcoding($statInfo['name']);
|
||||||
|
$mkdFile = explode('/',$filename);
|
||||||
|
if ($statInfo['crc'] == 0) {
|
||||||
|
// 新建目录
|
||||||
|
if (!file_exists($path . '/' . $filename)) {
|
||||||
|
mkdir($path . '/' . $filename, 0777, true);
|
||||||
|
}
|
||||||
|
// $this->createDirectories($path . '/' . $filename);
|
||||||
|
} else {
|
||||||
|
// 拷贝文件
|
||||||
|
if(count($mkdFile)==3){
|
||||||
|
if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) {
|
||||||
|
mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true);
|
||||||
|
}
|
||||||
|
copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
} else {
|
} catch (\Exception $e) {
|
||||||
throw new \think\exception\HttpException(404, '解压失败');
|
throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine());
|
||||||
}
|
}
|
||||||
$mer_id = 48;
|
|
||||||
$directory = $destination_path;
|
$directory = $destination_path;
|
||||||
$files = scandir($directory);
|
$files = scandir($directory);
|
||||||
$dir = 'def/' . date('Y-m-d');
|
$dir = 'def/' . date('Y-m-d');
|
||||||
$upload = UploadService::create();
|
$upload = UploadService::create();
|
||||||
/**循环目录 */
|
/**循环目录 */
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if ($file === '.' || $file === '..' ||$file ==='__MACOSX') {
|
if ($file === '.' || $file === '..' || $file === '__MACOSX') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!is_dir($directory . '/' . $file)){
|
if (!is_dir($directory . '/' . $file)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$files_two = scandir($directory . '/' . $file);
|
$files_two = scandir($directory . '/' . $file);
|
||||||
@ -64,7 +87,7 @@ class Demo extends BaseController
|
|||||||
$sku_arr = [];
|
$sku_arr = [];
|
||||||
/**清洗图片 */
|
/**清洗图片 */
|
||||||
foreach ($files_two as $file_two) {
|
foreach ($files_two as $file_two) {
|
||||||
if ($file_two === '.' || $file_two === '..' ||$file_two ==='__MACOSX') {
|
if ($file_two === '.' || $file_two === '..' || $file_two === '__MACOSX') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$arr = explode('.', $file_two);
|
$arr = explode('.', $file_two);
|
||||||
@ -90,7 +113,6 @@ class Demo extends BaseController
|
|||||||
if ($sku) {
|
if ($sku) {
|
||||||
$sku = implode(',', $sku);
|
$sku = implode(',', $sku);
|
||||||
$sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two;
|
$sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,7 +121,7 @@ class Demo extends BaseController
|
|||||||
$update_content['title'] = '';
|
$update_content['title'] = '';
|
||||||
$update_content['image'] = [];
|
$update_content['image'] = [];
|
||||||
$update_content['type'] = 1;
|
$update_content['type'] = 1;
|
||||||
$find = Db::name('store_product')->where($where)->where('store_name',$file)->find();
|
$find = Db::name('store_product')->where($where)->where('store_name', $file)->find();
|
||||||
if ($find) {
|
if ($find) {
|
||||||
try {
|
try {
|
||||||
/**更新商品图片 */
|
/**更新商品图片 */
|
||||||
@ -109,10 +131,10 @@ class Demo extends BaseController
|
|||||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
||||||
$update['slider_image'][] = $oss->filePath;
|
$update['slider_image'][] = $oss->filePath;
|
||||||
}
|
}
|
||||||
if(isset($update['slider_image'])){
|
if (isset($update['slider_image'])) {
|
||||||
$update['slider_image'] = implode(',', $update['slider_image']);
|
$update['slider_image'] = implode(',', $update['slider_image']);
|
||||||
}
|
}
|
||||||
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
||||||
/**更新规格图片 */
|
/**更新规格图片 */
|
||||||
foreach ($sku_arr as $k => $v) {
|
foreach ($sku_arr as $k => $v) {
|
||||||
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find();
|
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])->find();
|
||||||
@ -130,15 +152,15 @@ class Demo extends BaseController
|
|||||||
$update_content['image'][] = $oss->filePath;
|
$update_content['image'][] = $oss->filePath;
|
||||||
}
|
}
|
||||||
if ($store_product_content) {
|
if ($store_product_content) {
|
||||||
if(isset($update_content['image']) && !empty($update_content['image'])){
|
if (isset($update_content['image']) && !empty($update_content['image'])) {
|
||||||
Db::name('store_product_content')
|
Db::name('store_product_content')
|
||||||
->where(['product_id' => $find['product_id']])
|
->where(['product_id' => $find['product_id']])
|
||||||
->update(['content' => json_encode($update_content)]);
|
->update(['content' => json_encode($update_content)]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$update_content['product_id'] = $find['product_id'];
|
$update_content['product_id'] = $find['product_id'];
|
||||||
Db::name('store_product_content')
|
Db::name('store_product_content')
|
||||||
->insert(['product_id'=>$find['product_id'],'type'=>1,'content'=>json_encode($update_content)]);
|
->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// halt($e->getMessage(), $e->getLine());
|
// halt($e->getMessage(), $e->getLine());
|
||||||
@ -147,4 +169,38 @@ class Demo extends BaseController
|
|||||||
}
|
}
|
||||||
halt(1);
|
halt(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function transcoding($fileName)
|
||||||
|
{
|
||||||
|
$encoding = mb_detect_encoding($fileName, ['UTF-8', 'GBK', 'BIG5', 'CP936']);
|
||||||
|
if (DIRECTORY_SEPARATOR == '/') { // linux
|
||||||
|
$fileName = iconv($encoding, 'UTF-8', $fileName);
|
||||||
|
} else { // win
|
||||||
|
$fileName = iconv($encoding, 'GBK', $fileName);
|
||||||
|
}
|
||||||
|
return $fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDirectories($path) {
|
||||||
|
if (is_dir($path)) {
|
||||||
|
return true ;
|
||||||
|
} else {
|
||||||
|
$parts = explode(DIRECTORY_SEPARATOR, $path);
|
||||||
|
$part = null;
|
||||||
|
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
if ($part === '' || $part === '.' || $part === '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dir = dirname($path) . DIRECTORY_SEPARATOR . $part;
|
||||||
|
if (!file_exists($dir)) {
|
||||||
|
mkdir($dir, 0777, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -172,16 +172,36 @@ class StoreImport extends BaseController
|
|||||||
// 上传到本地服务器
|
// 上传到本地服务器
|
||||||
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
||||||
$mer_id = $this->request->merId();
|
$mer_id = $this->request->merId();
|
||||||
$dir=date('Y-m-d_H-i-s').'_'.$mer_id;
|
$dir = date('Y-m-d_H-i-s') . '_' . $mer_id;
|
||||||
$destination_path = public_path('uploads/pic/'.$dir) . $zip_name;
|
$path = public_path('uploads/pic').$dir;
|
||||||
$zip = new ZipArchive;
|
try {
|
||||||
if ($zip->open(public_path('uploads').$savename) === true) {
|
$zip = new ZipArchive;
|
||||||
$zip->extractTo($destination_path);
|
$filePath = public_path('uploads') . $savename;
|
||||||
|
$zip->open($filePath);
|
||||||
|
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||||
|
$statInfo = $zip->statIndex($i, ZipArchive::FL_ENC_RAW);
|
||||||
|
$filename = $this->transcoding($statInfo['name']);
|
||||||
|
$mkdFile = explode('/',$filename);
|
||||||
|
if ($statInfo['crc'] == 0) {
|
||||||
|
// 新建目录
|
||||||
|
if (!file_exists($path . '/' . $filename)) {
|
||||||
|
mkdir($path . '/' . $filename, 0777, true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 拷贝文件
|
||||||
|
if(count($mkdFile)==3){
|
||||||
|
if (!file_exists($path . '/' . $mkdFile[0].'/'.$mkdFile[1])) {
|
||||||
|
mkdir($path . '/' .$mkdFile[0].'/'.$mkdFile[1], 0777, true);
|
||||||
|
}
|
||||||
|
copy('zip://' . $file . '#' . $zip->getNameIndex($i), $path . '/' . $filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
} else {
|
} catch (\Exception $e) {
|
||||||
throw new \think\exception\HttpException(404, '解压失败');
|
throw new \think\exception\HttpException(404, $e->getMessage() . '。line:' . $e->getLine());
|
||||||
}
|
}
|
||||||
Queue::push(ImportPicJob::class,['mer_id'=>$mer_id,'path'=>$destination_path]);
|
Queue::push(ImportPicJob::class,['mer_id'=>$mer_id,'path'=>$path.'/'.$zip_name]);
|
||||||
return app('json')->success('开始导入数据,请稍后在列表中查看!,如果未导入请检查格式');
|
return app('json')->success('开始导入数据,请稍后在列表中查看!,如果未导入请检查格式');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,5 +261,37 @@ class StoreImport extends BaseController
|
|||||||
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$type_id);
|
app()->make(StoreOrderRepository::class)->setProduct($data['data'],$data['mer_id'],$type_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public function transcoding($fileName)
|
||||||
|
{
|
||||||
|
$encoding = mb_detect_encoding($fileName, ['UTF-8', 'GBK', 'BIG5', 'CP936']);
|
||||||
|
if (DIRECTORY_SEPARATOR == '/') { // linux
|
||||||
|
$fileName = iconv($encoding, 'UTF-8', $fileName);
|
||||||
|
} else { // win
|
||||||
|
$fileName = iconv($encoding, 'GBK', $fileName);
|
||||||
|
}
|
||||||
|
return $fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDirectories($path) {
|
||||||
|
if (is_dir($path)) {
|
||||||
|
return true ;
|
||||||
|
} else {
|
||||||
|
$parts = explode(DIRECTORY_SEPARATOR, $path);
|
||||||
|
$part = null;
|
||||||
|
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
if ($part === '' || $part === '.' || $part === '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dir = dirname($path) . DIRECTORY_SEPARATOR . $part;
|
||||||
|
if (!file_exists($dir)) {
|
||||||
|
mkdir($dir, 0777, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true ;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user