request->get('page', 1); $page_size = $this->request->get('pageSize', 10); $category_id = $this->request->get('categoryId', 0); $keywords = $this->request->get('keywords', 0); $where = []; if ($category_id) { $subCateIds = Category::where('pid', $category_id)->column('id'); $where['category_id'] = ['in', array_merge([$category_id], $subCateIds)]; } if ($keywords) { $where['title|etitle'] = ['like', "%$keywords%"]; } $goodsList = GoodsService::getList($where, $page_size, 'weigh desc,sold_num desc,id desc')->toArray(); foreach ($goodsList['data'] as $key => &$value) { $value['skuList'] = []; $value['thumb'] = $value['primary_image']; } //转换格式 // print_r($goodsList); $result = [ 'algId' => 0, 'pageNum' => $page, 'pageSize' => $page_size, 'saasId' => null, 'spuList' => convert_keys_to_camelcase($goodsList['data']), 'storeId' => null, 'totalCount' => $goodsList['total'], ]; $this->success('', $result); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } public function detail() { try { $id = $this->request->get('id', 0); $where = [ 'id' => $id ]; $info = GoodsService::getOne($where); if (!$info) { throw new Exception('该商品不存在或已删除'); } //格式转换 $info = convert_keys_to_camelcase($info->append(['images_arr', 'desc'])->hidden(['video'])->toArray()); $info['skuList'] = []; $info['thumb'] = $info['primaryImage']; $info['images'] = $info['imagesArr']; $info['isPutOnSale'] = $info['isPutOnSaleSwitch']; $this->success('', $info); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } }