From a0887cc2de7b9cf4e6154e23ac6aa6aa42d41c7a Mon Sep 17 00:00:00 2001 From: lqmac Date: Thu, 25 Apr 2024 01:04:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=A4=9A=E8=A7=84=E6=A0=BC=E6=B2=A1=E6=9C=89=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=88=86=E7=B1=BB=E4=B8=8B=E6=B2=A1=E6=9C=89=E5=95=86?= =?UTF-8?q?=E5=93=81wenti?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Category.php | 26 +++++++++++++++++++++++++- app/admin/model/Store.php | 24 ++++++++++++++++++++++++ app/api/model/Goods.php | 2 +- app/common.php | 13 ++++++++++++- 4 files changed, 62 insertions(+), 3 deletions(-) diff --git a/app/admin/controller/Category.php b/app/admin/controller/Category.php index ffd3b869..e9465acc 100644 --- a/app/admin/controller/Category.php +++ b/app/admin/controller/Category.php @@ -87,7 +87,7 @@ class Category extends Controller return $this->renderError($model->getError() ?: '更新失败'); } public function copyCategory(int $new_store_id){ - $store_id = 10001; + $store_id = 0; $model = new CategoryModel; $list = $model->getList(['store_id' =>$store_id]); if (!$list) { @@ -101,6 +101,7 @@ class Category extends Controller $value['update_time'] = time(); $value['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0; $value['rank_image_id'] = $value['rank_image_id'] ? $this->copyImage($value['rank_image_id'], $new_store_id) : 0; + $value['original_category_id'] = $value['category_id']; $temp = $value; unset($temp['children']); unset($temp['image']); @@ -119,6 +120,7 @@ class Category extends Controller $value1['update_time'] = time(); $value1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0; $value1['rank_image_id'] = $value1['rank_image_id'] ? $this->copyImage($value1['rank_image_id'], $new_store_id) : 0; + $value1['original_category_id'] = $value1['category_id']; $temp1 = $value1; unset($temp1['children']); unset($temp1['image']); @@ -137,6 +139,7 @@ class Category extends Controller $value2['update_time'] = time(); $value2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0; $value2['rank_image_id'] = $value2['rank_image_id'] ? $this->copyImage($value2['rank_image_id'], $new_store_id) : 0; + $value2['original_category_id'] = $value2['category_id']; $temp2 = $value2; unset($temp2['children']); unset($temp2['image']); @@ -155,6 +158,7 @@ class Category extends Controller $value3['update_time'] = time(); $value3['image_id'] = $value3['image_id'] ? $this->copyImage($value3['image_id'], $new_store_id) : 0; $value3['rank_image_id'] = $value3['rank_image_id'] ? $this->copyImage($value3['rank_image_id'], $new_store_id) : 0; + $value3['original_category_id'] = $value3['category_id']; $temp3 = $value3; unset($temp3['children']); unset($temp3['image']); @@ -162,6 +166,26 @@ class Category extends Controller unset($temp3['category_id']); Db::table('yoshop_category')->insertGetId($temp3); + if (!isset($value3['children']) || !$value3['children']) { + continue; + } + foreach ($value3['children'] as $value4) { + $value4 = $value4->toArray(); + $value4['parent_id'] = $secondid; + $value4['store_id'] = $new_store_id; + $value4['create_time'] = time(); + $value4['update_time'] = time(); + $value4['image_id'] = $value4['image_id'] ? $this->copyImage($value4['image_id'], $new_store_id) : 0; + $value4['rank_image_id'] = $value4['rank_image_id'] ? $this->copyImage($value4['rank_image_id'], $new_store_id) : 0; + $value4['original_category_id'] = $value4['category_id']; + $temp4 = $value4; + unset($temp4['children']); + unset($temp4['image']); + unset($temp4['rankimage']); + unset($temp4['category_id']); + + Db::table('yoshop_category')->insertGetId($temp4); + } } } } diff --git a/app/admin/model/Store.php b/app/admin/model/Store.php index 2fdebc8e..43a2e622 100644 --- a/app/admin/model/Store.php +++ b/app/admin/model/Store.php @@ -88,6 +88,7 @@ class Store extends StoreModel $value['update_time'] = time(); $value['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0; $value['rank_image_id'] = $value['rank_image_id'] ? $this->copyImage($value['rank_image_id'], $new_store_id) : 0; + $value['original_category_id'] = $value['category_id']; $temp = $value; unset($temp['children']); unset($temp['rankimage']); @@ -108,6 +109,7 @@ class Store extends StoreModel $value1['update_time'] = time(); $value1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0; $value1['rank_image_id'] = $value1['rank_image_id'] ? $this->copyImage($value1['rank_image_id'], $new_store_id) : 0; + $value1['original_category_id'] = $value1['category_id']; $temp1 = $value1; unset($temp1['children']); unset($temp1['image']); @@ -126,6 +128,7 @@ class Store extends StoreModel $value2['update_time'] = time(); $value2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0; $value2['rank_image_id'] = $value2['rank_image_id'] ? $this->copyImage($value2['rank_image_id'], $new_store_id) : 0; + $value2['original_category_id'] = $value2['category_id']; $temp2 = $value2; unset($temp2['children']); unset($temp2['image']); @@ -144,6 +147,7 @@ class Store extends StoreModel $value3['update_time'] = time(); $value3['image_id'] = $value3['image_id'] ? $this->copyImage($value3['image_id'], $new_store_id) : 0; $value3['rank_image_id'] = $value3['rank_image_id'] ? $this->copyImage($value3['rank_image_id'], $new_store_id) : 0; + $value3['original_category_id'] = $value3['category_id']; $temp3 = $value3; unset($temp3['children']); unset($temp3['image']); @@ -151,6 +155,26 @@ class Store extends StoreModel unset($temp3['category_id']); Db::table('yoshop_category')->insertGetId($temp3); + if (!isset($value3['children']) || !$value3['children']) { + continue; + } + foreach ($value3['children'] as $value4) { + $value4 = $value4->toArray(); + $value4['parent_id'] = $secondid; + $value4['store_id'] = $new_store_id; + $value4['create_time'] = time(); + $value4['update_time'] = time(); + $value4['image_id'] = $value4['image_id'] ? $this->copyImage($value4['image_id'], $new_store_id) : 0; + $value4['rank_image_id'] = $value4['rank_image_id'] ? $this->copyImage($value4['rank_image_id'], $new_store_id) : 0; + $value4['original_category_id'] = $value4['category_id']; + $temp4 = $value4; + unset($temp4['children']); + unset($temp4['image']); + unset($temp4['rankimage']); + unset($temp4['category_id']); + + Db::table('yoshop_category')->insertGetId($temp4); + } } } } diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index db63360c..80446c50 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -544,7 +544,7 @@ class Goods extends GoodsModel $goods_image = GoodsImage::where('goods_id', $value['goods_id'])->order("id asc")->find(); $file_path = UploadFile::where('file_id', $goods_image['image_id'] ?? 0)->find(); if ($file_path) { - $value['image_url'] = getUrl($file_path['file_path'], $file_path['domain']); + $value['image_url'] = getUrlValue($file_path['file_path'], $file_path['domain'], $file_path['storage']); } $goods = GoodsModel::where('goods_id', $value['goods_id'])->find(); $value['stock_num'] = $goods['stock_total'] ?? 0; diff --git a/app/common.php b/app/common.php index 98252ff5..53199696 100644 --- a/app/common.php +++ b/app/common.php @@ -461,7 +461,18 @@ function getUrl($value, $host = ''){ $host = $host ? $host : getHost(); return $value ? $host."/".$value : ""; } - +function getUrlValue($value, $host = '', $storage = ""){ + if (strpos($value, "http") !== false) { + return $value; + } + $host = $host ? $host : getHost(); + if ($storage == 'local') { + return uploads_url() .$value; + } else { + return $value ? $host."/".$value : ""; + } + +} function calc_time($startTime, $endTime) { $diffTime = ($endTime - $startTime);