|
|
|
@ -26,6 +26,7 @@ use cores\exception\BaseException; |
|
|
|
|
use think\db\exception\DataNotFoundException; |
|
|
|
|
use think\db\exception\DbException; |
|
|
|
|
use think\db\exception\ModelNotFoundException; |
|
|
|
|
use app\store\model\goods\GoodsPrice as GoodsPriceModel; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 商品模型 |
|
|
|
@ -346,9 +347,51 @@ class Goods extends GoodsModel |
|
|
|
|
return $this->setGoodsData($goodsInfo, function ($goods) { |
|
|
|
|
// 计算并设置商品会员价 |
|
|
|
|
$this->getEnableGradeMoney() && $this->setGoodsGradeMoney($goods); |
|
|
|
|
//计算plus 分销价格 |
|
|
|
|
$this->setGoodsMoney($goods); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置商品plus 分销价格 |
|
|
|
|
* @param Goods $goods |
|
|
|
|
* @throws BaseException |
|
|
|
|
*/ |
|
|
|
|
private function setGoodsMoney(self $goods) |
|
|
|
|
{ |
|
|
|
|
// 判断是否登录 |
|
|
|
|
if (!UserService::isLogin()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
$catService = new \app\store\model\GoodsCategoryRel(); |
|
|
|
|
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id'); |
|
|
|
|
//读取分类集 |
|
|
|
|
$price_list_plus = $price_list_dealer = []; |
|
|
|
|
foreach ($catIds as $k => $v) { |
|
|
|
|
$price_list_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['goods_price_min']); |
|
|
|
|
$price_list_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['goods_price_min']); |
|
|
|
|
} |
|
|
|
|
//价格判断 |
|
|
|
|
if (UserService::isstore()) { |
|
|
|
|
$goods['goods_price_min_plus'] = min($price_list_plus); |
|
|
|
|
$goods['goods_price_min_dealer'] = min($price_list_dealer); |
|
|
|
|
} elseif (UserService::isPlusMember()) { |
|
|
|
|
$goods['goods_price_min_plus'] = min($price_list_plus); |
|
|
|
|
} elseif (UserService::isDealerMember()) { |
|
|
|
|
$goods['goods_price_min_dealer'] = min($price_list_dealer); |
|
|
|
|
} |
|
|
|
|
// 会员折扣价: 商品sku列表 |
|
|
|
|
if ($goods->getRelation('skuList')) { |
|
|
|
|
foreach ($goods['skuList'] as &$skuItem) { |
|
|
|
|
$skuItem['goods_price'] = $skuItem['goods_price']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 会员折扣价: 已选择的商品sku(用于购物车) |
|
|
|
|
if ($goods->getAttr('skuInfo')) { |
|
|
|
|
$goods['skuInfo']['goods_price'] = $goods['skuInfo']['goods_price']; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置商品的会员价 |
|
|
|
|
* @param Goods $goods |
|
|
|
|