// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\store\controller; use app\common\model\successful as SuccessfulModel; use app\common\model\UploadFile; use think\response\Json; class Successful extends Controller { /** * 成功案例列表 * @return json */ public function getList() { $model = new SuccessfulModel; $page = $this->request->param('page',1); $pageSize = $this->request->param('pageSize',15); $list = $model->list($page,$pageSize); if(empty($list)){ return $this->renderSuccess('暂无数据'); } $list->each(function ($item, $key) { $imageUrl = UploadFile::withoutGlobalScope()->where('file_id', $item['image_id'])->find(); if ($imageUrl) { $item['image_url'] = $imageUrl['preview_url']; } else { $item['image_url'] = null; // 或者设置默认图片 URL } }); return $this->renderSuccess(compact('list')); } /** * @notes:新增 * @return Json * */ public function add(): Json { $data = $this->postForm(); if (!$data) { return $this->renderError('缺少必要参数'); } $model = new SuccessfulModel(); if ($model->add($data)) { return $this->renderSuccess('添加成功'); } return $this->renderError($model->getError() ?: '添加失败'); } /** * @notes:编辑 * @param int $id * @return Json * @author: */ public function edit(int $id): Json { $data = $this->postForm(); if (!$data) { return $this->renderError('缺少必要参数'); } $model = SuccessfulModel::where('id', $id)->find(); if (!$model) { return $this->renderError('找不到指定的数据'); } $data['update_time']=time(); SuccessfulModel::where('id', $id)->update($data); return $this->renderSuccess('编辑成功'); } /** * @notes:删除 * @param array $ids * @return Json * @author: */ public function delete(array $ids): Json { $model = new SuccessfulModel; if ($model->remove($ids)) { return $this->renderSuccess('删除成功'); } return $this->renderError('删除失败'); } }