更新图片上传
This commit is contained in:
parent
c317fc9225
commit
a6f088e5f5
@ -42,7 +42,7 @@ class Demo extends BaseController
|
||||
} else {
|
||||
throw new \think\exception\HttpException(404, '解压失败');
|
||||
}
|
||||
$mer_id = 35;
|
||||
$mer_id = 48;
|
||||
$directory = $destination_path;
|
||||
$files = scandir($directory);
|
||||
$dir = 'def/' . date('Y-m-d');
|
||||
@ -99,7 +99,7 @@ class Demo extends BaseController
|
||||
$update_content['title'] = '';
|
||||
$update_content['image'] = [];
|
||||
$update_content['type'] = 1;
|
||||
$find = Db::name('store_product')->where($where)->where('store_name', 'like', '%' . $file . '%')->find();
|
||||
$find = Db::name('store_product')->where($where)->where('store_name',$file)->find();
|
||||
if ($find) {
|
||||
try {
|
||||
/**更新商品图片 */
|
||||
@ -109,8 +109,10 @@ class Demo extends BaseController
|
||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
||||
$update['slider_image'][] = $oss->filePath;
|
||||
}
|
||||
$update['slider_image'] = implode(',', $update['slider_image']);
|
||||
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
||||
if(isset($update['slider_image'])){
|
||||
$update['slider_image'] = implode(',', $update['slider_image']);
|
||||
}
|
||||
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();
|
||||
@ -128,16 +130,18 @@ class Demo extends BaseController
|
||||
$update_content['image'][] = $oss->filePath;
|
||||
}
|
||||
if ($store_product_content) {
|
||||
Db::name('store_product_content')
|
||||
if(isset($update_content['image']) && !empty($update_content['image'])){
|
||||
Db::name('store_product_content')
|
||||
->where(['product_id' => $find['product_id']])
|
||||
->update(json_encode($update_content));
|
||||
->update(['content' => json_encode($update_content)]);
|
||||
}
|
||||
} 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) {
|
||||
halt($e->getMessage(), $e->getLine());
|
||||
// halt($e->getMessage(), $e->getLine());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ class ImportPicJob implements JobInterface
|
||||
$update = [];
|
||||
$update_content['title'] = '';
|
||||
$update_content['image'] = [];
|
||||
$find = Db::name('store_product')->where($where)->where('store_name', 'like', '%' . $file . '%')->find();
|
||||
$find = Db::name('store_product')->where($where)->where('store_name',$file)->find();
|
||||
if ($find) {
|
||||
try {
|
||||
/**更新商品图片 */
|
||||
@ -85,7 +85,9 @@ class ImportPicJob implements JobInterface
|
||||
$oss = $upload->to($dir)->stream(file_get_contents($v));
|
||||
$update['slider_image'][] = $oss->filePath;
|
||||
}
|
||||
$update['slider_image'] = implode(',', $update['slider_image']);
|
||||
if(isset($update['slider_image'])){
|
||||
$update['slider_image'] = implode(',', $update['slider_image']);
|
||||
}
|
||||
Db::name('store_product')->where('product_id', $find['product_id'])->update($update);
|
||||
/**更新规格图片 */
|
||||
foreach ($sku_arr as $k => $v) {
|
||||
@ -104,9 +106,11 @@ class ImportPicJob implements JobInterface
|
||||
$update_content['image'][] = $oss->filePath;
|
||||
}
|
||||
if ($store_product_content) {
|
||||
Db::name('store_product_content')
|
||||
if(isset($update_content['image']) && !empty($update_content['image'])){
|
||||
Db::name('store_product_content')
|
||||
->where(['product_id' => $find['product_id']])
|
||||
->update();
|
||||
->update(['content' => json_encode($update_content)]);
|
||||
}
|
||||
} else {
|
||||
$update_content['product_id'] = $find['product_id'];
|
||||
Db::name('store_product_content')
|
||||
|
Loading…
x
Reference in New Issue
Block a user