修复商品重复多规格没有图片分类下没有商品wenti

es
lqmac 7 months ago
parent e542192c3f
commit a0887cc2de
  1. 26
      app/admin/controller/Category.php
  2. 24
      app/admin/model/Store.php
  3. 2
      app/api/model/Goods.php
  4. 13
      app/common.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);
}
}
}
}

@ -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);
}
}
}
}

@ -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;

@ -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);

Loading…
Cancel
Save