categoryModel->get(['category.id','category.name','category.image_id']); if (empty($list)) return $this->return->success('success',['list' => []]); $res = $list->toArray(); $ossIds = array_column($res['data'],'image_id'); $ossInfo = $this->getOssObjects($ossIds); foreach ($res['data'] as &$one) { $one['url'] = $ossInfo[$one['image_id']]['url']; } return $this->return->success('success',['list' => $res]); } /** * 添加 * @return array * @throws Exception */ public function add() { $name = $this->request->input('name'); $imageId = $this->request->input('image_id'); $this->updateOssObjects([$imageId]); $category = new Category(); $category->name = $name; $category->image_id = $imageId; if (!$category->save()) throw new ErrException('商品种类添加失败'); return $this->return->success(); } }