From d985dd564a9c5f2ee0b94bb76a062992e7607566 Mon Sep 17 00:00:00 2001 From: wmc Date: Fri, 2 Feb 2024 15:35:03 +0800 Subject: [PATCH] 111 --- app/api/model/Goods.php | 14 +++++++++----- app/common/model/Goods.php | 25 ++++++++++++++----------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/api/model/Goods.php b/app/api/model/Goods.php index d6ce4147..28f452c3 100644 --- a/app/api/model/Goods.php +++ b/app/api/model/Goods.php @@ -187,6 +187,8 @@ class Goods extends GoodsModel $goodsInfo->category = $category; //多规格 $goodsInfo->specifications = []; + $skuList = []; + $specList = []; if ($goodsInfo->spu_id > 0) { //查同规格的商品 $spe = GoodsModel::where([ @@ -194,11 +196,9 @@ class Goods extends GoodsModel 'store_id' => request()->header()['storeid'], 'is_delete' => 0 ])->column('goods_id'); - $skuList = []; - $specList = []; foreach ($spe as $v) { - $skuList = $this->getSpecData($v)['skuList']->toArray()[0]; - $specList = $this->getSpecData($v)['specList'][0]; + $skuList[] = $this->getSpecData($v)['skuList']->toArray()[0]; + $specList[] = $this->getSpecData($v)['specList'][0]; } $newList = [ 'skuList' => $skuList, @@ -206,6 +206,10 @@ class Goods extends GoodsModel ]; $goodsInfo->specifications = $newList; } + $goodsInfo = $goodsInfo->toArray(); + //替换原规格数组 + $goodsInfo['skuList2'] = $skuList; + $goodsInfo['specList2'] = $specList; //加入足迹 $userId = UserService::getCurrentLoginUserId(false) ?? ''; if ($userId) { @@ -225,7 +229,7 @@ class Goods extends GoodsModel } } - return $goodsInfo->hidden(static::getHidden(['images'])); + return $goodsInfo; } public function getDetails2(int $goodsId, bool $verifyStatus = true) diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index 24e277ab..77689a0c 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -181,40 +181,43 @@ class Goods extends BaseModel $query = $this->getQueryFilter($param); // 设置显示的销量 goods_sales - $query->field(['(sales_initial + sales_actual) as goods_sales']); + $query->field(['(sales_initial + sales_actual) as goods_sales', '(line_price_max - goods_price_min) as discount']); // 排序条件 $sort = $this->setQuerySort($param); $order = request()->get()['order'] ?? ''; if (!empty($order)) { if ($order == 1) { - $sort['goods_price_min'] = 'asc'; + $sort = ['goods_price_min' => 'asc']; } if ($order == 2) { - $sort['goods_price_min'] = 'desc'; + $sort = ['goods_price_min' => 'desc']; } - //todo wmc + if ($order == 3) { - $sort['goods_price_min'] = 'asc'; + $sort = ['discount' => 'asc']; } if ($order == 4) { - $sort['goods_price_min'] = 'desc'; + $sort = ['discount' => 'desc']; } if ($order == 5) { - $sort['goods_sales'] = 'asc'; + $sort = ['goods_sales' => 'asc']; + } if ($order == 6) { - $sort['goods_sales'] = 'desc'; + $sort = ['goods_sales' => 'desc']; } - //todo wmc + if ($order == 7) { - $sort['goods_sales'] = 'asc'; + $sort = ['goods_sales' => 'asc']; } if ($order == 8) { - $sort['goods_sales'] = 'desc'; + $sort = ['goods_sales' => 'desc']; } } + + $field = $this->getAliasFields($this->name, ['content']); $field[] = 'selling_point'; // 执行查询