AdminLockController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\teahouse\controller;
  12. use app\teahouse\model\LockModel;
  13. use cmf\controller\AdminBaseController;
  14. class AdminLockController extends AdminBaseController
  15. {
  16. public function index()
  17. {
  18. $param = $this->request->param();
  19. //搜索条件
  20. $where = [];
  21. if (!empty($param['keyword'])) {
  22. $where[] = ['name', 'like', "%{$param['keyword']}%"];
  23. }
  24. if (!empty($param['is_show'])) {
  25. $where[] = ['is_show', '=', $param['is_show']];
  26. }
  27. $list = LockModel::where($where)
  28. ->append(['is_show_text'])
  29. ->paginate(10, false, ['query' => $param]);
  30. $this->assign('is_show', isset($param['is_show']) ? $param['is_show'] : 0);
  31. $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
  32. $this->assign('list', $list->items());
  33. $this->assign('page', $list->render());
  34. return $this->fetch();
  35. }
  36. public function add()
  37. {
  38. return $this->fetch();
  39. }
  40. public function addPost()
  41. {
  42. if ($this->request->isPost()) {
  43. $data = $this->request->post();
  44. LockModel::create($data);
  45. $this->success('添加成功!', url('index'));
  46. }
  47. }
  48. public function edit()
  49. {
  50. $id = $this->request->param('id', 0, 'intval');
  51. $info = LockModel::get($id);
  52. $this->assign('info', $info);
  53. return $this->fetch();
  54. }
  55. public function editPost()
  56. {
  57. if ($this->request->isPost()) {
  58. $data = $this->request->post();
  59. LockModel::update($data, ['id' => $data['id']]);
  60. $this->success('编辑成功!', url('index'));
  61. }
  62. }
  63. public function delete()
  64. {
  65. $id = $this->request->param('id', 0, 'intval');
  66. LockModel::destroy($id);
  67. $this->success('删除成功');
  68. }
  69. }