|
|
|
@ -440,24 +440,28 @@ class Goods extends GoodsModel |
|
|
|
|
//$this->dealGoodsImage($goodsInfo); |
|
|
|
|
|
|
|
|
|
// 商品规格列表 |
|
|
|
|
if ($goodsInfo->spu_id && $goodsInfo->spu_id != $goodsInfo->goods_id) { |
|
|
|
|
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['spu_id']); |
|
|
|
|
} else { |
|
|
|
|
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']); |
|
|
|
|
$GoodsCategoryRelModel = new GoodsCategoryRelModel(); |
|
|
|
|
$category = $GoodsCategoryRelModel |
|
|
|
|
->alias('a') |
|
|
|
|
->join('category b', 'a.category_id = b.category_id') |
|
|
|
|
->where([ |
|
|
|
|
'a.goods_id' => $goodsId, |
|
|
|
|
'a.store_id' => request()->header()['storeid'] |
|
|
|
|
])->find(); |
|
|
|
|
$goodsInfo->category = $category ? $category->toArray() : []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $GoodsCategoryRelModel = new GoodsCategoryRelModel(); |
|
|
|
|
// $category = $GoodsCategoryRelModel |
|
|
|
|
// ->alias('a') |
|
|
|
|
// ->join('category b', 'a.category_id = b.category_id') |
|
|
|
|
// ->where([ |
|
|
|
|
// 'a.goods_id' => $goodsId, |
|
|
|
|
// 'a.store_id' => request()->header()['storeid'] |
|
|
|
|
// ])->find(); |
|
|
|
|
// $goodsInfo->category = $category ? $category->toArray() : []; |
|
|
|
|
//多规格 |
|
|
|
|
$goodsInfo->specifications = []; |
|
|
|
|
//$goodsInfo = $goodsInfo->toArray(); |
|
|
|
|
|
|
|
|
|
$goodsInfo = $goodsInfo->toArray(); |
|
|
|
|
|
|
|
|
|
if (isset($goodsInfo['skuList1'])) { |
|
|
|
|
$goodsInfo['skuList'] = $goodsInfo['skuList1']; |
|
|
|
|
unset($goodsInfo['skuList1']); |
|
|
|
|
if (isset($goodsInfo->skuList1)) { |
|
|
|
|
unset($goodsInfo->skuList1); |
|
|
|
|
} |
|
|
|
|
//加入足迹 |
|
|
|
|
$userId = UserService::getCurrentLoginUserId(false) ?? ''; |
|
|
|
@ -541,18 +545,10 @@ class Goods extends GoodsModel |
|
|
|
|
//单规格和多规格处理不一致 |
|
|
|
|
$goodsInfo->skuList = $goodsInfo->skuList1 ? $goodsInfo->skuList1 : $goodsInfo->skuList; |
|
|
|
|
|
|
|
|
|
if ($goodsInfo->skuList) { |
|
|
|
|
foreach ($goodsInfo->skuList as &$value) { |
|
|
|
|
$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'] = 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; |
|
|
|
|
if ($goodsInfo->spu_id && $goodsInfo->spu_id != $goodsInfo->goods_id) { |
|
|
|
|
$goodsInfo->skuList = GoodsSkuModel::where('spu_id', $goodsInfo->spu_id)->select(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 判断商品是否存在 |
|
|
|
|
if (empty($goodsInfo) || $goodsInfo['is_delete']) { |
|
|
|
|
throwError('很抱歉,商品信息不存在'); |
|
|
|
@ -561,6 +557,7 @@ class Goods extends GoodsModel |
|
|
|
|
if ($verifyStatus && $goodsInfo['status'] == GoodsStatusEnum::OFF_SALE) { |
|
|
|
|
throwError('很抱歉,当前商品已下架'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 整理商品数据并返回 |
|
|
|
|
return $this->setGoodsDataFromApi($goodsInfo); |
|
|
|
|
} |
|
|
|
@ -667,6 +664,14 @@ class Goods extends GoodsModel |
|
|
|
|
if ($goods->getRelation('skuList') || $goods->getRelation('skuList1')) { |
|
|
|
|
|
|
|
|
|
foreach ($goods['skuList'] as &$skuItem) { |
|
|
|
|
//处理图片和库 |
|
|
|
|
$goods_image = GoodsImage::where('goods_id', $skuItem['goods_id'])->order("id asc")->find(); |
|
|
|
|
$file_path = UploadFile::where('file_id', $goods_image['image_id'] ?? 0)->find(); |
|
|
|
|
if ($file_path) { |
|
|
|
|
$skuItem['image_url'] = getUrlValue($file_path['file_path'], $file_path['domain'], $file_path['storage']); |
|
|
|
|
} |
|
|
|
|
$skuItem['stock_num'] = $goods['stock_total'] ?? 0; |
|
|
|
|
|
|
|
|
|
//价格判断 |
|
|
|
|
if (UserService::isstore()) { |
|
|
|
|
$priceArr = \app\common\model\PriceSet::distributionPrice($skuItem['goods_price'], $skuItem['cost_price'], $catIds); |
|
|
|
@ -681,9 +686,6 @@ class Goods extends GoodsModel |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//exit(); |
|
|
|
|
// var_dump(111); |
|
|
|
|
// exit(); |
|
|
|
|
// 折扣价: 已选择的商品sku(用于购物车) |
|
|
|
|
if ($goods->getAttr('skuInfo')) { |
|
|
|
|
|
|
|
|
|