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' => '删除失败']); } } }