From 46f01860784459ef3dda7d784f1b625b006d7802 Mon Sep 17 00:00:00 2001 From: lqmac Date: Fri, 8 Mar 2024 15:19:20 +0800 Subject: [PATCH] 1 --- app/api/controller/goods/Collector.php | 69 ++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 app/api/controller/goods/Collector.php diff --git a/app/api/controller/goods/Collector.php b/app/api/controller/goods/Collector.php new file mode 100644 index 00000000..a078900a --- /dev/null +++ b/app/api/controller/goods/Collector.php @@ -0,0 +1,69 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\controller\goods; + +use think\response\Json; +use app\store\controller\Controller; +use app\store\model\goods\Collector as CollectorModel; +use cores\exception\BaseException; + +/** + * 商品采集管理 + * Class Collector + * @package app\store\controller\goods + */ +class Collector extends Controller +{ + /** + * 获取列表记录 + * @return Json + * @throws \think\db\exception\DbException + */ + public function list(): Json + { + $model = new CollectorModel; + $list = $model->getList($this->request->param()); + return $this->renderSuccess(compact('list')); + } + + /** + * 执行商品采集 + * @return Json + * @throws BaseException + * @throws \PhpOffice\PhpSpreadsheet\Exception + * @throws \PhpOffice\PhpSpreadsheet\Reader\Exception + */ + public function batch(): Json + { + // 新增记录 + $model = new CollectorModel; + if ($model->batch($this->postData())) { + return $this->renderSuccess('已添加到采集任务中,请在采集记录中查看结果'); + } + return $this->renderError($model->getError() ?: '操作失败'); + } + + /** + * 删除记录 + * @param int $id + * @return Json + */ + public function delete(int $id): Json + { + $model = CollectorModel::detail($id); + if (!$model->setDelete()) { + return $this->renderError($model->getError() ?: '删除失败'); + } + return $this->renderSuccess('删除成功'); + } +}