diff --git a/app/common/repositories/store/product/ProductRepository.php b/app/common/repositories/store/product/ProductRepository.php index d1c0d087..8ab0f376 100644 --- a/app/common/repositories/store/product/ProductRepository.php +++ b/app/common/repositories/store/product/ProductRepository.php @@ -239,7 +239,14 @@ class ProductRepository extends BaseRepository $result = $this->dao->create($product); $settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0, $data['mer_id']); - if (isset($data['mer_cate_id']) && count($data['mer_cate_id']) != 0) { + if (isset($data['mer_cate_id']) && $data['mer_cate_id'] != '') { + if (is_array($data['mer_cate_id'])) { + if (count($data['mer_cate_id']) == 0) { + $data['mer_cate_id'] = []; + } elseif ($data['mer_cate_id'][0] == 0) { + $data['mer_cate_id'] = []; + } + } $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']); } $settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id); @@ -277,10 +284,15 @@ class ProductRepository extends BaseRepository event('product.update.before', compact('id', 'data', 'merId', 'productType', 'conType')); $spuData = $product = $this->setProduct($data); $settleParams = $this->setAttrValue($data, $id, $productType, 1, $merId); - if (isset($data['mer_cate_id']) && count($data['mer_cate_id']) != 0 ) { - if($data['mer_cate_id'][0]!=0){ - $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); + if (isset($data['mer_cate_id'])) { + if (is_array($data['mer_cate_id'])) { + if (count($data['mer_cate_id']) == 0) { + $data['mer_cate_id'] = []; + } elseif ($data['mer_cate_id'][0] == 0) { + $data['mer_cate_id'] = []; + } } + $settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId); } $settleParams['attr'] = $this->setAttr($data['attr'], $id); $content = [ diff --git a/app/controller/admin/ProductLibrary.php b/app/controller/admin/ProductLibrary.php index 32ffa8db..319dd69c 100644 --- a/app/controller/admin/ProductLibrary.php +++ b/app/controller/admin/ProductLibrary.php @@ -7,6 +7,7 @@ use think\facade\Db; use think\facade\Log; use crmeb\services\UploadService; use think\api\Client; +use GuzzleHttp\Client as http_client; class ProductLibrary extends BaseController { @@ -129,9 +130,8 @@ class ProductLibrary extends BaseController $data['create_time'] = date('Y-m-d H:i:s'); $data['images'] = ''; $arr=[]; - if ($param['img'] != '') { - $oss = $upload->to($dir)->stream(file_get_contents($param['img'])); + $oss = $upload->to($dir)->stream($this->getPic($param['img'])); $data['image'] = $oss->filePath; $arr[]=$oss->filePath; } else { @@ -139,7 +139,7 @@ class ProductLibrary extends BaseController $data['slider_image'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230130/00ebcfdf75684f5494c0193075055d1.png'; } foreach($param['imgList'] as $k=>$v){ - $oss=$upload->to($dir)->stream(file_get_contents($v)); + $oss=$upload->to($dir)->stream($this->getPic($v)); $arr[] = $oss->filePath; } if(count($arr)>0){ @@ -173,4 +173,10 @@ class ProductLibrary extends BaseController throw new \think\exception\ValidateException('一维码商品采集错误:'.$e->getMessage()); } } + + public function getPic($url){ + $client = new http_client(); + $a=$client->get($url); + return $a->getBody()->getContents(); + } }