| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?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()
- {
- $title = Request::param('title');
- $page = Request::param('page', 1, 'intval');
- $pagesize = Request::param('pagesize', 10, 'intval');
- $groupModel = new GroupModel();
- $query = $groupModel->order('gr_id ASC');
- if (!empty($title)) {
- $query->whereLike('title', '%' . $title . '%');
- }
- $list = $query->paginate([
- 'page' => $page,
- 'list_rows' => $pagesize,
- ]);
- $data = [
- 'list' => $list->items(),
- 'total' => $list->total(),
- 'page' => $list->currentPage(),
- 'pagesize' => $list->listRows(),
- ];
- return app('json')->success($data);
- }
- // /**
- // * 添加分组
- // *
- // * @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 json(['code' => -1, 'msg' => '参数错误']);
- }
- $groupModel = new GroupModel();
- $group = $groupModel->find($id);
- if (!$group) {
- return json(['code' => -1, 'msg' => '分组不存在']);
- }
- if ($this->request->isPost()) {
- $name = $this->request->post('name/s', '');
- $status = $this->request->post('status/d', 0);
- if (!$name) {
- return json(['code' => -1, 'msg' => '分组名称不能为空']);
- }
- $data = [
- 'name' => $name,
- 'status' => $status,
- ];
- $result = $groupModel->edit($id, $data);
- if ($result) {
- return json(['code' => 0, 'msg' => '保存成功']);
- } else {
- return json(['code' => -1, 'msg' => '保存失败']);
- }
- }
- return json(['code' => 0, 'data' => $group]);
- }
- /**
- * 修改审核状态
- *
- * @return mixed|\think\response\Json
- */
- public function changeStatus()
- {
- $id = Request::param('gr_id/d', 0);
- if (!$id) {
- return app('json')->fail('参数错误');
- }
- var_dump($id);
- $groupModel = new GroupModel();
- $group = $groupModel->find($id);
- if (!$group) {
- return app('json')->fail('分组不存在');
- }
- $status = Request::param('audit/d', 0);
- $data = [
- 'audit' => $status,
- ];
- var_dump($status);
- $result = $groupModel->where('gr_id', $id)->update($data);
- if ($result) {
- return app('json')->success('保存成功');
- } else {
- return app('json')->fail('保存失败');
- }
- }
- /**
- * 修改是否轮播状态
- *
- * @return mixed|\think\response\Json
- */
- public function changeRecommend()
- {
- $id = Request::param('gr_id/d', 0);
- if (!$id) {
- return app('json')->fail('参数错误');
- }
- $groupModel = new GroupModel();
- $group = $groupModel->find($id);
- if (!$group) {
- return app('json')->fail('分组不存在');
- }
- $recommend = Request::param('recommend/d', 0);
- $data = [
- 'recommend' => $recommend,
- ];
- $result = $groupModel->where('gr_id', $id)->update($data);
- if ($result) {
- return app('json')->success('保存成功');
- } else {
- return app('json')->fail('保存失败');
- }
- }
- /**
- * 删除分组
- *
- * @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' => '删除失败']);
- }
- }
- }
|