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