|
|
@@ -0,0 +1,165 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\system\controller;
|
|
|
+
|
|
|
+use app\BaseController;
|
|
|
+use app\model\api\GroupModel;
|
|
|
+use think\facade\Request;
|
|
|
+use think\route\dispatch\Controller;
|
|
|
+use think\facade\View;
|
|
|
+use think\model;
|
|
|
+
|
|
|
+
|
|
|
+class Groupcontroller extends BaseController
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取分组列表
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $groupModel = new GroupModel();
|
|
|
+ $groups = $groupModel->select();
|
|
|
+
|
|
|
+ return view('index', [
|
|
|
+ 'groups' => $groups
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 添加分组
|
|
|
+// *
|
|
|
+// * @return mixed
|
|
|
+// */
|
|
|
+// public function add(GroupModel $groupModel)
|
|
|
+// {
|
|
|
+// if ($this->request->isPost()) {
|
|
|
+// $data = $this->request->post();
|
|
|
+// $result = $groupModel->save($data);
|
|
|
+// if ($result) {
|
|
|
+// return $this->success('添加成功', url('index'));
|
|
|
+// } else {
|
|
|
+// return $this->error('添加失败');
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// return View::fetch();
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑分组
|
|
|
+ *
|
|
|
+ * @param int $id 分组ID
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function edit($id)
|
|
|
+ {
|
|
|
+ if (!$id) {
|
|
|
+ return ['code' => -1, 'msg' => '参数错误'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $groupModel = new GroupModel();
|
|
|
+ $group = $groupModel->find($id);
|
|
|
+ if (!$group) {
|
|
|
+ return ['code' => -1, 'msg' => '分组不存在'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $name = $this->request->post('name/s', '');
|
|
|
+ $status = $this->request->post('status/d', 0);
|
|
|
+
|
|
|
+ if (!$name) {
|
|
|
+ return ['code' => -1, 'msg' => '分组名称不能为空'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'gr_name' => $name,
|
|
|
+ 'gr_status' => $status,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $result = $groupModel->edit($id, $data);
|
|
|
+
|
|
|
+ if ($result) {
|
|
|
+ return ['code' => 0, 'msg' => '保存成功'];
|
|
|
+ } else {
|
|
|
+ return ['code' => -1, 'msg' => '保存失败'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return View::fetch('edit', ['group' => $group]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改分组审核状态
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed|\think\response\Json
|
|
|
+ */
|
|
|
+ public function changeStatus(Request $request)
|
|
|
+ {
|
|
|
+ $id = $request->param('id/d', 0);
|
|
|
+ if (!$id) {
|
|
|
+ return json(['code' => -1, 'msg' => '参数错误']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $groupModel = new GroupModel();
|
|
|
+ $group = $groupModel->find($id);
|
|
|
+ if (!$group) {
|
|
|
+ return json(['code' => -1, 'msg' => '分组不存在']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = $request->param('status/d', 0);
|
|
|
+ $data = [
|
|
|
+ 'audit' => $status,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $result = $groupModel->where('id', $id)->update($data);
|
|
|
+
|
|
|
+ if ($result) {
|
|
|
+ return json(['code' => 0, 'msg' => '保存成功']);
|
|
|
+ } else {
|
|
|
+ return json(['code' => -1, 'msg' => '保存失败']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除分组
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed|\think\response\Json
|
|
|
+ */
|
|
|
+ public function delete(Request $request)
|
|
|
+ {
|
|
|
+ $id = $request->param('id/d', 0);
|
|
|
+ if (!$id) {
|
|
|
+ return json(['code' => -1, 'msg' => '参数错误']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $groupModel = new GroupModel();
|
|
|
+ $result = $groupModel->where('gr_id', $id)->delete();
|
|
|
+
|
|
|
+ if ($result) {
|
|
|
+ return json(['code' => 0, 'msg' => '删除成功']);
|
|
|
+ } else {
|
|
|
+ return json(['code' => -1, 'msg' => '删除失败']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|