修复上传

This commit is contained in:
mkm 2023-11-23 18:09:36 +08:00
parent ad847cec10
commit c08e286f74
3 changed files with 25 additions and 7 deletions

View File

@ -224,8 +224,6 @@ class ProductRepository extends BaseRepository
public function create(array $data, int $productType = 0, $conType = 0) public function create(array $data, int $productType = 0, $conType = 0)
{ {
if (!$data['spec_type']) { if (!$data['spec_type']) {
halt($data['spec_type']);
$data['attr'] = []; $data['attr'] = [];
if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误'); if (count($data['attrValue']) > 1) throw new ValidateException('单规格商品属性错误');
} }

View File

@ -80,6 +80,9 @@ class StoreImport extends BaseController
*/ */
public function Import($type) public function Import($type)
{ {
if($type=='import_images'){
return $this->import_images();
}
$file = $this->request->file('file'); $file = $this->request->file('file');
if (!$file) return app('json')->fail('请上传EXCEL文件'); if (!$file) return app('json')->fail('请上传EXCEL文件');
$file = is_array($file) ? $file[0] : $file; $file = is_array($file) ? $file[0] : $file;
@ -178,6 +181,7 @@ class StoreImport extends BaseController
} }
$mer_id = $this->request->merId(); $mer_id = $this->request->merId();
Queue::push(ImportPicJob::class,['mer_id'=>$mer_id,'path'=>$destination_path]); Queue::push(ImportPicJob::class,['mer_id'=>$mer_id,'path'=>$destination_path]);
return app('json')->success('开始导入数据,请稍后在列表中查看!');
} }
public function getXlsList($type_id,$path){ public function getXlsList($type_id,$path){

View File

@ -13,6 +13,11 @@ class ImportPicJob implements JobInterface
{ {
public function fire($job, $data) public function fire($job, $data)
{ {
Log::error('开始导入商品图片:'.$job->attempts());
if ($job->attempts() > 3) {
$job->delete();
$this->failed($data);
}
$directory = $data['path']; $directory = $data['path'];
$mer_id = $data['mer_id']; $mer_id = $data['mer_id'];
$files = scandir($directory); $files = scandir($directory);
@ -25,17 +30,19 @@ class ImportPicJob implements JobInterface
continue; continue;
} }
$files_two = scandir($directory . '/' . $file); $files_two = scandir($directory . '/' . $file);
$image_extensions = array('jpg', 'jpeg', 'png'); $image_extensions = array('jpg', 'jpeg', 'png');
$image = ''; $image = '';
$slider_image = []; $slider_image = [];
$details = []; $details = [];
$sku_arr = []; $sku_arr = [];
/**清洗图片 */ /**清洗图片
* file_two 商品名对应目录
*/
foreach ($files_two as $file_two) { foreach ($files_two as $file_two) {
$arr = explode('.', $file_two); $arr = $file_two;
if (in_array($arr[1], $image_extensions)) {
if (in_array($arr, $image_extensions)) {
/**首图 */ /**首图 */
$images[] = $file_two; $images[] = $file_two;
if ($image == '' && is_int((int)$arr[0])) { if ($image == '' && is_int((int)$arr[0])) {
@ -59,7 +66,7 @@ class ImportPicJob implements JobInterface
$sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two; $sku_arr[$sku] = $directory . '/' . $file . '/' . $file_two;
} }
}else{ }else{
throw new \think\exception\HttpException(404, '请上传jpg,jpeg,png的图片'); continue;
} }
} }
$where = ['mer_id' => $mer_id, 'is_del' => 0]; $where = ['mer_id' => $mer_id, 'is_del' => 0];
@ -109,5 +116,14 @@ class ImportPicJob implements JobInterface
} }
} }
} }
$job->delete();
}
public function failed($data)
{
Log::error('导入商品图片失败:'.json_encode($data));
// TODO: Implement failed() method.
} }
} }