价格读取

pull/1/head
limu 10 months ago
parent 250a660114
commit 742b791cc2
  1. 33
      app/api/model/Goods.php
  2. 23
      app/api/service/Goods.php

@ -383,12 +383,39 @@ class Goods extends GoodsModel
// 会员折扣价: 商品sku列表
if ($goods->getRelation('skuList')) {
foreach ($goods['skuList'] as &$skuItem) {
$skuItem['goods_price'] = $skuItem['goods_price'];
$temp_price_plus = $temp_price_dealer = [];
foreach ($catIds as $k => $v) {
$temp_price_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $skuItem['goods_price']);
$temp_price_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $skuItem['goods_price']);
}
//价格判断
if (UserService::isstore()) {
$skuItem['goods_price_plus'] = min($temp_price_plus);
$skuItem['goods_price_dealer'] = min($temp_price_dealer);
} elseif (UserService::isPlusMember()) {
$skuItem['goods_price_plus'] = min($temp_price_plus);
} elseif (UserService::isDealerMember()) {
$skuItem['goods_price_dealer'] = min($temp_price_dealer);
}
}
// 会员折扣价: 已选择的商品sku(用于购物车)
}
// 折扣价: 已选择的商品sku(用于购物车)
if ($goods->getAttr('skuInfo')) {
$goods['skuInfo']['goods_price'] = $goods['skuInfo']['goods_price'];
if (UserService::isPlusMember()) {
$sku_price_plus = [];
foreach ($catIds as $k => $v) {
$sku_price_plus[] = GoodsPriceModel::getDiscountPrice($v, 1, $goods['skuInfo']['goods_price']);
}
$goods['skuInfo']['goods_price'] = min($sku_price_plus);
} elseif (UserService::isDealerMember()) {
$sku_price_dealer = [];
foreach ($catIds as $k => $v) {
$sku_price_dealer[] = GoodsPriceModel::getDiscountPrice($v, 2, $goods['skuInfo']['goods_price']);
}
$goods['skuInfo']['goods_price'] = min($sku_price_dealer);
}
}
}

@ -16,6 +16,7 @@ use app\api\model\Goods as GoodsModel;
use app\api\model\Setting as SettingModel;
use app\api\model\GoodsSku as GoodsSkuModel;
use app\api\model\Category as CategoryModel;
use app\api\service\User as UserService;
use app\common\model\store\Shop as ShopModel;
use app\api\service\sharp\Active as ActiveService;
use app\common\enum\Setting as SettingEnum;
@ -23,6 +24,7 @@ use app\common\service\Goods as GoodsService;
use app\api\model\sharp\Active as SharpActiveModel;
use app\api\model\sharp\ActiveTime as ActiveTimeModel;
use app\api\controller\sharp\Goods as miaosha;
use app\store\model\goods\GoodsPrice as GoodsPriceModel;
/**
* 商品服务类
@ -278,7 +280,7 @@ class Goods extends GoodsService
{
$data = [];
foreach ($goodsList as $goods) {
$data[] = [
$temp = [
'goods_id' => $goods['goods_id'],
'goods_name' => $goods['goods_name'],
'selling_point' => $goods['selling_point'],
@ -290,6 +292,25 @@ class Goods extends GoodsService
'goods_sales' => $goods['goods_sales'],
'remaizhishu' => $goods['remaizhishu'],
];
if (UserService::isLogin()) {
$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()) {
$temp['goods_price_min_plus'] = min($price_list_plus);
$temp['goods_price_min_dealer'] = min($price_list_dealer);
} elseif (UserService::isPlusMember()) {
$temp['goods_price_min_plus'] = min($price_list_plus);
} elseif (UserService::isDealerMember()) {
$temp['goods_price_min_dealer'] = min($price_list_dealer);
}
}
$data[] = $temp;
}
return $data;
}

Loading…
Cancel
Save