修复规格导入图片

This commit is contained in:
mkm 2023-11-30 10:45:06 +08:00
parent 395492c7b7
commit 4a57b4e344
2 changed files with 18 additions and 7 deletions

View File

@ -30,7 +30,7 @@ class Demo extends BaseController
{
public function index()
{
$mer_id = 36;
$mer_id = 104;
$file = request()->file('file');
$zip_name = explode('.', $file->getOriginalName())[0];
// 上传到本地服务器
@ -136,11 +136,17 @@ class Demo extends BaseController
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
/**更新规格图片 */
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();
$sku = explode(',', $k);
if(count($sku)==2){
$sku_name=$sku[0];
}else{
continue;
}
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name])->find();
if ($store_product_attr_value) {
$oss = $upload->to($dir)->stream(file_get_contents($v));
Db::name('store_product_attr_value')
->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])
->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name])
->update(['image' => $oss->filePath]);
}
}
@ -158,9 +164,8 @@ class Demo extends BaseController
}
} else {
$update_content['product_id'] = $find['product_id'];
$a=Db::name('store_product_content')
Db::name('store_product_content')
->insert(['product_id' => $find['product_id'], 'type' => 1, 'content' => json_encode($update_content)]);
halt($a,2222);
}
} catch (Exception $e) {
halt($e->getMessage(), $e->getLine());

View File

@ -89,11 +89,17 @@ class ImportPicJob implements JobInterface
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
/**更新规格图片 */
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();
$sku = explode(',', $k);
if(count($sku)==2){
$sku_name=$sku[0];
}else{
continue;
}
$store_product_attr_value = Db::name('store_product_attr_value')->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name])->find();
if ($store_product_attr_value) {
$oss = $upload->to($dir)->stream(file_get_contents($v));
Db::name('store_product_attr_value')
->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $k])
->where(['mer_id' => $mer_id, 'product_id' => $find['product_id'], 'sku' => $sku_name])
->update(['image' => $oss->filePath]);
}
}