where($where); $totalCount = $query->count(); $list = $query ->order('sort', 'desc') ->order('id', 'desc') ->page($page, $pageSize) ->select() ->toArray(); return [ 'list' => $list, 'totalCount' => $totalCount, 'pageSize' => $pageSize, 'page' => $page ]; } /** * 获取商品详情 * @param int $id * @return array|null */ public function getDetail($id) { $product = $this->where('id', $id)->find(); if (!$product) { return null; } $data = $product->toArray(); // 获取SKU列表 $skuList = (new StoreProductAttrValue())->where('product_id', $id)->select()->toArray(); $data['sku_list'] = $skuList; return $data; } }