更新导入
This commit is contained in:
parent
5d706254df
commit
5c5dc50bc0
@ -52,6 +52,9 @@ class Demo extends BaseController
|
||||
if ($file === '.' || $file === '..' ||$file ==='__MACOSX') {
|
||||
continue;
|
||||
}
|
||||
if(!is_dir($directory . '/' . $file)){
|
||||
continue;
|
||||
}
|
||||
$files_two = scandir($directory . '/' . $file);
|
||||
|
||||
$image_extensions = array('jpg', 'jpeg', 'png');
|
||||
@ -59,26 +62,26 @@ class Demo extends BaseController
|
||||
$slider_image = [];
|
||||
$details = [];
|
||||
$sku_arr = [];
|
||||
/**清洗图片
|
||||
* file_two 商品名对应目录
|
||||
*/
|
||||
/**清洗图片 */
|
||||
foreach ($files_two as $file_two) {
|
||||
$arr = $file_two;
|
||||
|
||||
if (in_array($arr, $image_extensions)) {
|
||||
if ($file_two === '.' || $file_two === '..' ||$file_two ==='__MACOSX') {
|
||||
continue;
|
||||
}
|
||||
$arr = explode('.', $file_two);
|
||||
if (in_array($arr[1], $image_extensions)) {
|
||||
/**首图 */
|
||||
$images[] = $file_two;
|
||||
if ($image == '' && is_int((int)$arr[0])) {
|
||||
if ($image == '' && is_numeric($arr[0])) {
|
||||
$image = $directory . '/' . $file . '/' . $file_two;
|
||||
continue;
|
||||
}
|
||||
/**轮播图 */
|
||||
if (is_int((int)$arr[0]) && count($slider_image) < 4) {
|
||||
if (is_numeric($arr[0]) && count($slider_image) < 4) {
|
||||
$slider_image[] = $directory . '/' . $file . '/' . $file_two;
|
||||
continue;
|
||||
}
|
||||
/**详情图 */
|
||||
if (is_int((int)$arr[0])) {
|
||||
if (is_numeric($arr[0])) {
|
||||
$details[] = $directory . '/' . $file_two;
|
||||
continue;
|
||||
}
|
||||
@ -87,9 +90,8 @@ class Demo extends BaseController
|
||||
if ($sku) {
|
||||
$sku = implode(',', $sku);
|
||||
$sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two;
|
||||
|
||||
}
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$where = ['mer_id' => $mer_id, 'is_del' => 0];
|
||||
|
@ -171,7 +171,9 @@ class StoreImport extends BaseController
|
||||
$zip_name = explode('.', $file->getOriginalName())[0];
|
||||
// 上传到本地服务器
|
||||
$savename = \think\facade\Filesystem::putFile('zippic', $file);
|
||||
$destination_path = public_path('uploads/pic') . $zip_name;
|
||||
$mer_id = $this->request->merId();
|
||||
$dir=date('Y-m-d_H-i-s').'_'.$mer_id;
|
||||
$destination_path = public_path('uploads/pic/'.$dir) . $zip_name;
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open(public_path('uploads').$savename) === true) {
|
||||
$zip->extractTo($destination_path);
|
||||
@ -179,10 +181,8 @@ class StoreImport extends BaseController
|
||||
} else {
|
||||
throw new \think\exception\HttpException(404, '解压失败');
|
||||
}
|
||||
$mer_id = $this->request->merId();
|
||||
Queue::push(ImportPicJob::class,['mer_id'=>$mer_id,'path'=>$destination_path]);
|
||||
return app('json')->success('开始导入数据,请稍后在列表中查看!');
|
||||
|
||||
return app('json')->success('开始导入数据,请稍后在列表中查看!,如果未导入请检查格式');
|
||||
}
|
||||
public function getXlsList($type_id,$path){
|
||||
if($type_id==12){
|
||||
|
@ -29,33 +29,36 @@ class ImportPicJob implements JobInterface
|
||||
if ($file === '.' || $file === '..' ||$file ==='__MACOSX') {
|
||||
continue;
|
||||
}
|
||||
if(!is_dir($directory . '/' . $file)){
|
||||
continue;
|
||||
}
|
||||
$files_two = scandir($directory . '/' . $file);
|
||||
|
||||
$image_extensions = array('jpg', 'jpeg', 'png');
|
||||
$image = '';
|
||||
$slider_image = [];
|
||||
$details = [];
|
||||
$sku_arr = [];
|
||||
|
||||
/**清洗图片
|
||||
* file_two 商品名对应目录
|
||||
*/
|
||||
/**清洗图片 */
|
||||
foreach ($files_two as $file_two) {
|
||||
$arr = $file_two;
|
||||
|
||||
if (in_array($arr, $image_extensions)) {
|
||||
if ($file_two === '.' || $file_two === '..' ||$file_two ==='__MACOSX') {
|
||||
continue;
|
||||
}
|
||||
$arr = explode('.', $file_two);
|
||||
if (in_array($arr[1], $image_extensions)) {
|
||||
/**首图 */
|
||||
$images[] = $file_two;
|
||||
if ($image == '' && is_int((int)$arr[0])) {
|
||||
if ($image == '' && is_numeric($arr[0])) {
|
||||
$image = $directory . '/' . $file . '/' . $file_two;
|
||||
continue;
|
||||
}
|
||||
/**轮播图 */
|
||||
if (is_int((int)$arr[0]) && count($slider_image) < 4) {
|
||||
if (is_numeric($arr[0]) && count($slider_image) < 4) {
|
||||
$slider_image[] = $directory . '/' . $file . '/' . $file_two;
|
||||
continue;
|
||||
}
|
||||
/**详情图 */
|
||||
if (is_int((int)$arr[0])) {
|
||||
if (is_numeric($arr[0])) {
|
||||
$details[] = $directory . '/' . $file_two;
|
||||
continue;
|
||||
}
|
||||
@ -64,16 +67,14 @@ class ImportPicJob implements JobInterface
|
||||
if ($sku) {
|
||||
$sku = implode(',', $sku);
|
||||
$sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two;
|
||||
|
||||
}
|
||||
}else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$where = ['mer_id' => $mer_id, 'is_del' => 0];
|
||||
$update = [];
|
||||
$update_content['title'] = '';
|
||||
$update_content['image'] = [];
|
||||
$update_content['type'] = 1;
|
||||
$find = Db::name('store_product')->where($where)->where('store_name', 'like', '%' . $file . '%')->find();
|
||||
if ($find) {
|
||||
try {
|
||||
@ -105,14 +106,14 @@ class ImportPicJob implements JobInterface
|
||||
if ($store_product_content) {
|
||||
Db::name('store_product_content')
|
||||
->where(['product_id' => $find['product_id']])
|
||||
->update(json_encode($update_content));
|
||||
->update();
|
||||
} else {
|
||||
$update_content['product_id'] = $find['product_id'];
|
||||
Db::name('store_product_content')
|
||||
->insert(json_encode($update_content));
|
||||
->insert(['product_id'=>$find['product_id'],'type'=>1,'content'=>json_encode($update_content)]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
Log::error('导入商品图片失败'.$e->getMessage().'line:'.$e->getLine());
|
||||
halt($e->getMessage(), $e->getLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user