pull/1/head
wmc 10 months ago
parent bcc12d55ad
commit d985dd564a
  1. 14
      app/api/model/Goods.php
  2. 25
      app/common/model/Goods.php

@ -187,6 +187,8 @@ class Goods extends GoodsModel
$goodsInfo->category = $category; $goodsInfo->category = $category;
//多规格 //多规格
$goodsInfo->specifications = []; $goodsInfo->specifications = [];
$skuList = [];
$specList = [];
if ($goodsInfo->spu_id > 0) { if ($goodsInfo->spu_id > 0) {
//查同规格的商品 //查同规格的商品
$spe = GoodsModel::where([ $spe = GoodsModel::where([
@ -194,11 +196,9 @@ class Goods extends GoodsModel
'store_id' => request()->header()['storeid'], 'store_id' => request()->header()['storeid'],
'is_delete' => 0 'is_delete' => 0
])->column('goods_id'); ])->column('goods_id');
$skuList = [];
$specList = [];
foreach ($spe as $v) { foreach ($spe as $v) {
$skuList = $this->getSpecData($v)['skuList']->toArray()[0]; $skuList[] = $this->getSpecData($v)['skuList']->toArray()[0];
$specList = $this->getSpecData($v)['specList'][0]; $specList[] = $this->getSpecData($v)['specList'][0];
} }
$newList = [ $newList = [
'skuList' => $skuList, 'skuList' => $skuList,
@ -206,6 +206,10 @@ class Goods extends GoodsModel
]; ];
$goodsInfo->specifications = $newList; $goodsInfo->specifications = $newList;
} }
$goodsInfo = $goodsInfo->toArray();
//替换原规格数组
$goodsInfo['skuList2'] = $skuList;
$goodsInfo['specList2'] = $specList;
//加入足迹 //加入足迹
$userId = UserService::getCurrentLoginUserId(false) ?? ''; $userId = UserService::getCurrentLoginUserId(false) ?? '';
if ($userId) { 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) public function getDetails2(int $goodsId, bool $verifyStatus = true)

@ -181,40 +181,43 @@ class Goods extends BaseModel
$query = $this->getQueryFilter($param); $query = $this->getQueryFilter($param);
// 设置显示的销量 goods_sales // 设置显示的销量 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); $sort = $this->setQuerySort($param);
$order = request()->get()['order'] ?? ''; $order = request()->get()['order'] ?? '';
if (!empty($order)) { if (!empty($order)) {
if ($order == 1) { if ($order == 1) {
$sort['goods_price_min'] = 'asc'; $sort = ['goods_price_min' => 'asc'];
} }
if ($order == 2) { if ($order == 2) {
$sort['goods_price_min'] = 'desc'; $sort = ['goods_price_min' => 'desc'];
} }
//todo wmc
if ($order == 3) { if ($order == 3) {
$sort['goods_price_min'] = 'asc'; $sort = ['discount' => 'asc'];
} }
if ($order == 4) { if ($order == 4) {
$sort['goods_price_min'] = 'desc'; $sort = ['discount' => 'desc'];
} }
if ($order == 5) { if ($order == 5) {
$sort['goods_sales'] = 'asc'; $sort = ['goods_sales' => 'asc'];
} }
if ($order == 6) { if ($order == 6) {
$sort['goods_sales'] = 'desc'; $sort = ['goods_sales' => 'desc'];
} }
//todo wmc
if ($order == 7) { if ($order == 7) {
$sort['goods_sales'] = 'asc'; $sort = ['goods_sales' => 'asc'];
} }
if ($order == 8) { if ($order == 8) {
$sort['goods_sales'] = 'desc'; $sort = ['goods_sales' => 'desc'];
} }
} }
$field = $this->getAliasFields($this->name, ['content']); $field = $this->getAliasFields($this->name, ['content']);
$field[] = 'selling_point'; $field[] = 'selling_point';
// 执行查询 // 执行查询

Loading…
Cancel
Save