|
|
@@ -0,0 +1,124 @@
|
|
|
+<?php
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | 商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Copyright (c) 2017~2021 https://www.thinkphp.com All rights reserved.
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+// | Author: thinkphp <admin@yiovo.com>
|
|
|
+// +----------------------------------------------------------------------
|
|
|
+declare (strict_types = 1);
|
|
|
+
|
|
|
+namespace app\store\controller;
|
|
|
+
|
|
|
+use think\response\Json;
|
|
|
+use app\store\model\Goods as GoodsModel;
|
|
|
+use app\common\model\School as SchoolsModel;
|
|
|
+use app\common\exception\BaseException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 学校管理控制器
|
|
|
+ * Class Schools
|
|
|
+ * @package app\store\controller
|
|
|
+ */
|
|
|
+class Schools extends Controller
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 列表
|
|
|
+ * @return Json
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ */
|
|
|
+ public function list(): Json
|
|
|
+ {
|
|
|
+ // 获取列表记录
|
|
|
+ $model = new SchoolsModel();
|
|
|
+ $list = $model->getList($this->request->param());
|
|
|
+ return $this->renderSuccess(compact('list'));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商品详情
|
|
|
+ * @param int $goodsId
|
|
|
+ * @return Json
|
|
|
+ * @throws BaseException
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \cores\exception\BaseException
|
|
|
+ */
|
|
|
+ public function detail(int $id): Json
|
|
|
+ {
|
|
|
+ // 获取详情
|
|
|
+ $model = new SchoolsModel();
|
|
|
+ $info = $model->detail($id);
|
|
|
+ return $this->renderSuccess(compact('info'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ * @return Json
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \cores\exception\BaseException
|
|
|
+ */
|
|
|
+ public function add(): Json
|
|
|
+ {
|
|
|
+ $model = new SchoolsModel();
|
|
|
+ if ($model->add($this->postForm())) {
|
|
|
+ return $this->renderSuccess('添加成功');
|
|
|
+ }
|
|
|
+ return $this->renderError($model->getError() ?: '添加失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ * @param int $id
|
|
|
+ * @return Json
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \cores\exception\BaseException
|
|
|
+ */
|
|
|
+ public function edit(int $id): Json
|
|
|
+ {
|
|
|
+ // 详情
|
|
|
+ $model = SchoolsModel::detail($id);
|
|
|
+ // 更新记录
|
|
|
+ if ($model->edit($this->postForm())) {
|
|
|
+ return $this->renderSuccess('更新成功');
|
|
|
+ }
|
|
|
+ return $this->renderError($model->getError() ?: '更新失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改状态(审核通过)
|
|
|
+ * @param array $ids id集
|
|
|
+ * @param bool $state 为true表示通过
|
|
|
+ * @return Json
|
|
|
+ */
|
|
|
+ public function state(array $ids, bool $state): Json
|
|
|
+ {
|
|
|
+ $model = new SchoolsModel();
|
|
|
+ if (!$model->setStatus($ids, $state)) {
|
|
|
+ return $this->renderError($model->getError() ?: '操作失败');
|
|
|
+ }
|
|
|
+ return $this->renderSuccess('操作成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @param array $ids
|
|
|
+ * @return Json
|
|
|
+ */
|
|
|
+ public function delete(array $ids): Json
|
|
|
+ {
|
|
|
+ $model = new SchoolsModel();
|
|
|
+ if (!$model->setDelete($ids)) {
|
|
|
+ return $this->renderError($model->getError() ?: '删除失败');
|
|
|
+ }
|
|
|
+ return $this->renderSuccess('删除成功');
|
|
|
+ }
|
|
|
+}
|