|
|
|
@ -433,7 +433,7 @@ class Goods extends GoodsModel |
|
|
|
|
* @throws \think\db\exception\DbException |
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException |
|
|
|
|
*/ |
|
|
|
|
public function getDetails(int $goodsId, bool $verifyStatus = true) |
|
|
|
|
public function getDetails(int $goodsId, bool $verifyStatus = true, array $storeInfo = []) |
|
|
|
|
{ |
|
|
|
|
// 关联查询(商品图片、sku列表) |
|
|
|
|
//$with = ['images.file', 'skuList.image', 'video', 'videoCover']; |
|
|
|
@ -448,7 +448,7 @@ class Goods extends GoodsModel |
|
|
|
|
$with = ['images.file', 'skuList.image', 'video', 'videoCover']; |
|
|
|
|
} |
|
|
|
|
// 获取商品记录 |
|
|
|
|
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus); |
|
|
|
|
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus, $storeInfo); |
|
|
|
|
//$this->dealGoodsImage($goodsInfo); |
|
|
|
|
|
|
|
|
|
// 商品规格列表 |
|
|
|
@ -576,10 +576,14 @@ class Goods extends GoodsModel |
|
|
|
|
* @return mixed |
|
|
|
|
* @throws BaseException |
|
|
|
|
*/ |
|
|
|
|
private function getGoodsMain(int $goodsId, array $with = [], bool $verifyStatus = true) |
|
|
|
|
private function getGoodsMain(int $goodsId, array $with = [], bool $verifyStatus = true, array $storeInfo = []) |
|
|
|
|
{ |
|
|
|
|
// 获取商品记录 |
|
|
|
|
$goodsInfo = static::detail($goodsId, $with); |
|
|
|
|
//处理子商户的成本价 |
|
|
|
|
if ($storeInfo && $storeInfo['p_store_id'] > 0) { |
|
|
|
|
$goodsInfo->cost_price_min = round($goodsInfo->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01)); |
|
|
|
|
} |
|
|
|
|
//单规格和多规格处理不一致 |
|
|
|
|
$goodsInfo->skuList = $goodsInfo->skuList1 ? $goodsInfo->skuList1 : $goodsInfo->skuList; |
|
|
|
|
|
|
|
|
@ -592,6 +596,10 @@ class Goods extends GoodsModel |
|
|
|
|
if (in_array($goodsInfo['channel'], ['sn','sn1']) && $goodsInfo['link_other'] && $value->goods_id == $goodsId) { |
|
|
|
|
$value->goods_sku_no = $goodsInfo['goods_no_other']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($storeInfo && $storeInfo['p_store_id'] > 0) { |
|
|
|
|
$value->cost_price = round($value->cost_price / (1 - $storeInfo['markup_rate'] * 0.01)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//使用总后台的商品的图片作为商城商品的图片 |
|
|
|
|
|
|
|
|
@ -630,10 +638,17 @@ class Goods extends GoodsModel |
|
|
|
|
* @param array $goodsIds |
|
|
|
|
* @return mixed |
|
|
|
|
*/ |
|
|
|
|
public function getListByIdsFromApi(array $goodsIds) |
|
|
|
|
public function getListByIdsFromApi(array $goodsIds, array $storeInfo = []) |
|
|
|
|
{ |
|
|
|
|
// 获取商品列表 |
|
|
|
|
$data = $this->getListByIds($goodsIds, GoodsStatusEnum::ON_SALE); |
|
|
|
|
|
|
|
|
|
foreach ($data as $key => &$goods) { |
|
|
|
|
//处理子商户的成本价 |
|
|
|
|
if ($storeInfo && $storeInfo['p_store_id'] > 0) { |
|
|
|
|
$goods->cost_price_min = round($goods->cost_price_min / (1 - $storeInfo['markup_rate'] * 0.01)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 整理列表数据并返回 |
|
|
|
|
return $this->setGoodsListDataFromApi($data); |
|
|
|
|
} |
|
|
|
@ -646,13 +661,18 @@ class Goods extends GoodsModel |
|
|
|
|
* @return \app\common\model\GoodsSku|array|null |
|
|
|
|
* @throws BaseException |
|
|
|
|
*/ |
|
|
|
|
public static function getSkuInfo($goods, string $goodsSkuId, bool $enableGradeMoney = true) |
|
|
|
|
public static function getSkuInfo($goods, string $goodsSkuId, bool $enableGradeMoney = true, array $storeInfo = []) |
|
|
|
|
{ |
|
|
|
|
$goods['skuInfo'] = GoodsService::getSkuInfo($goods['goods_id'], $goodsSkuId); |
|
|
|
|
//处理子商户的成本价 |
|
|
|
|
if ($storeInfo && $storeInfo['p_store_id'] > 0) { |
|
|
|
|
$goods->skuInfo->cost_price = round($goods->skuInfo->cost_price / (1 - $storeInfo['markup_rate'] * 0.01)); |
|
|
|
|
} |
|
|
|
|
//$enableGradeMoney && (new static)->setGoodsGradeMoney($goodsInfo); |
|
|
|
|
|
|
|
|
|
$catService = new GoodsCategoryRel(); |
|
|
|
|
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); |
|
|
|
|
// $catService = new GoodsCategoryRel(); |
|
|
|
|
// $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); |
|
|
|
|
$catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id'); |
|
|
|
|
$currtime = time(); |
|
|
|
|
if ($goods->getAttr('skuInfo')) { |
|
|
|
|
if (UserService::isPlusMember()) { |
|
|
|
@ -715,10 +735,12 @@ class Goods extends GoodsModel |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
$currtime = time(); |
|
|
|
|
$catService = new GoodsCategoryRel(); |
|
|
|
|
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); |
|
|
|
|
// $catService = new GoodsCategoryRel(); |
|
|
|
|
// $catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); |
|
|
|
|
$catIds = GoodsCategoryRel::withoutGlobalScope()->where(['goods_id' => $goods->goods_id])->column('category_id'); |
|
|
|
|
$goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价 |
|
|
|
|
$goods['discount'] = 0.0; |
|
|
|
|
|
|
|
|
|
//价格判断 |
|
|
|
|
if (UserService::isstore()) { |
|
|
|
|
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds); |
|
|
|
|