lqmac 9 months ago
parent bb722423b1
commit bf96894f56
  1. 15
      app/api/controller/Goods.php
  2. 21
      app/api/model/Goods.php
  3. 9
      app/api/model/Order.php
  4. 2
      app/api/service/Cart.php

@ -24,6 +24,7 @@ use cores\exception\BaseException;
use think\db\exception\DbException;
use think\response\Json;
use app\common\enum\goods\GoodsDeliveryTime;
use think\facade\Cache;
/**
* 商品控制器
* Class Goods
@ -142,7 +143,7 @@ class Goods extends Controller
];
break;
default:
if ($goods->stock_total > ($value['num'] ?? 1)) {
if ($goods->stock_total >= ($value['num'] ?? 1)) {
$res = "有货";
}
$data = [
@ -288,13 +289,13 @@ class Goods extends Controller
public function recommended(): Json
{
$service = new GoodsService;
// $cache_key = "goods_recommended".$this->storeId;
// if(Cache::has($cache_key)) {
// $goodsList = Cache::get($cache_key);
// return $this->renderSuccess(compact('goodsList'));
// }
$cache_key = "goods_recommended".$this->storeId;
if(Cache::has($cache_key)) {
$goodsList = Cache::get($cache_key);
return $this->renderSuccess(compact('goodsList'));
}
$goodsList = $service->recommended();
// Cache::set($cache_key, $goodsList, 60*60);
Cache::set($cache_key, $goodsList, 60*60);
return $this->renderSuccess(compact('goodsList'));
}

@ -583,12 +583,25 @@ class Goods extends GoodsModel
* @return \app\common\model\GoodsSku|array|null
* @throws BaseException
*/
public static function getSkuInfo($goodsInfo, string $goodsSkuId, bool $enableGradeMoney = true)
public static function getSkuInfo($goods, string $goodsSkuId, bool $enableGradeMoney = true)
{
$goodsInfo['skuInfo'] = GoodsService::getSkuInfo($goodsInfo['goods_id'], $goodsSkuId);
$goods['skuInfo'] = GoodsService::getSkuInfo($goods['goods_id'], $goodsSkuId);
//$enableGradeMoney && (new static)->setGoodsGradeMoney($goodsInfo);
(new static)->setGoodsMoney($goodsInfo);
return $goodsInfo['skuInfo'];
$catService = new GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
if ($goods->getAttr('skuInfo')) {
if (UserService::isPlusMember()) {
$goods['skuInfo']['goods_price'] = \app\common\model\PriceSet::membershipPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds);
} elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price'], $catIds);
$goods['skuInfo']['goods_price'] = $priceArr['distributionPrice'];
}
}
//(new static)->setGoodsMoney($goodsInfo);
return $goods['skuInfo'];
}
/**

@ -80,9 +80,13 @@ class Order extends OrderModel
// 获取商品列表
$model = new GoodsModel;
$goodsList = $model->setEnableGradeMoney(false)->getListByIdsFromApi([$goodsId]);
if ($goodsList->isEmpty()) {
throwError('未找到商品信息');
}
// echo "<pre>";
// print_r($goodsList->toArray());
// exit();
// 隐藏冗余的属性
$goodsList->hidden(GoodsModel::getHidden(['content', 'goods_images', 'images']));
foreach ($goodsList as &$item) {
@ -92,7 +96,7 @@ class Order extends OrderModel
$item['goods_image'] = $item['skuInfo']['goods_image'] ?: $item['goods_image'];
// 商品单价
$item['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $item['skuInfo']['goods_price'], $item['skuInfo']['cost_price']);
$item['goods_price'] = $item['skuInfo']['goods_price'];//\app\api\service\Goods::getGoodsPrice($item['goods_id'], $item['skuInfo']['goods_price'], $item['skuInfo']['cost_price']);
// 商品购买数量
$item['total_num'] = $goodsNum;
// 商品SKU索引
@ -100,6 +104,9 @@ class Order extends OrderModel
// 商品购买总金额
$item['total_price'] = helper::bcmul($item['goods_price'], $goodsNum);
}
// echo "<pre>";
// print_r($goodsList->toArray());
// exit();
return $goodsList;
}

@ -80,7 +80,7 @@ class Cart extends BaseService
// 商品记录
$goods = $item['goods'];
// 商品单价
$goods['goods_price'] = \app\api\service\Goods::getGoodsPrice($item['goods_id'], $goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price']);
$goods['goods_price'] = $goods['skuInfo']['goods_price'];//\app\api\service\Goods::getGoodsPrice($item['goods_id'], $goods['skuInfo']['goods_price'], $goods['skuInfo']['cost_price']);
//$goods['goods_price'] = $goods['skuInfo']['goods_price'];
// 商品购买数量
$goods['total_num'] = $item['goods_num'];

Loading…
Cancel
Save