pull/1/head
wmc 1 year ago
parent 34d5087fb2
commit a2569eea77
  1. 3
      app/api/controller/Goods.php
  2. 33
      app/api/model/Goods.php

@ -54,6 +54,9 @@ class Goods extends Controller
public function detail(int $goodsId, bool $verifyStatus = true): Json
{
// wmc商品详情
$storeid = request()->header()['storeid'];
$param = $this->request->param();
$param['store_id'] = $storeid;
$model = new GoodsModel;
$goodsInfo = $model->getDetails($goodsId, $verifyStatus);
return $this->renderSuccess(['detail' => $goodsInfo]);

@ -16,6 +16,7 @@ use app\api\service\Goods as GoodsService;
use app\api\service\user\Grade as UserGradeService;
use app\api\model\GoodsSku as GoodsSkuModel;
use app\api\model\store\Module as StoreModuleModel;
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel;
use app\api\model\GoodsSpecRel as GoodsSpecRelModel;
use app\common\model\Goods as GoodsModel;
use app\common\enum\goods\Status as GoodsStatusEnum;
@ -94,7 +95,7 @@ class Goods extends GoodsModel
* @return mixed|\think\model\Collection|\think\Paginator
* @throws \think\db\exception\DbException
*/
public function getList(array $param = [],int $listRows = 15)
public function getList(array $param = [], int $listRows = 15)
{
// 整理查询参数
@ -130,6 +131,36 @@ class Goods extends GoodsModel
$goodsInfo = $this->getGoodsMain($goodsId, $with, $verifyStatus);
// 商品规格列表
$goodsInfo['specList'] = GoodsSpecRelModel::getSpecList($goodsInfo['goods_id']);
$GoodsCategoryRelModel = new GoodsCategoryRelModel();
$category = $GoodsCategoryRelModel
->alias('a')
->join('category b', 'a.category_id = b.category_id')
->where([
'a.goods_id' => $goodsId,
'a.store_id' => request()->header()['storeid']
])->find()->toArray();
$goodsInfo->category = $category;
//多规格
$goodsInfo->specifications = [];
if ($goodsInfo->spu_id > 0) {
//查同规格的商品
$spe = GoodsModel::where([
'spu_id' => $goodsInfo->spu_id,
'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];
}
$newList = [
'skuList' => $skuList,
'specList' => $specList
];
$goodsInfo->specifications = $newList;
}
return $goodsInfo->hidden(static::getHidden(['images']));
}

Loading…
Cancel
Save