Notice.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\admin\controller\qingdong\notice;
  3. use app\common\controller\Backend;
  4. use addons\qingdong\model\Notice as NoticeModel;
  5. use think\DB;
  6. use fast\Tree;
  7. /**
  8. * 通知列表
  9. */
  10. class Notice extends Backend {
  11. public function _initialize() {
  12. parent::_initialize();
  13. $this->model = new NoticeModel();
  14. }
  15. /**
  16. * 通知列表
  17. */
  18. public function index() {
  19. $this->request->filter(['strip_tags']);
  20. if ($this->request->isAjax()) {
  21. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  22. $list = $this->model->where($where)->order($sort, $order)->paginate($limit);
  23. $row = $list->items();
  24. $result = array("total" => $list->total(), "rows" => $row);
  25. return json($result);
  26. }
  27. return $this->view->fetch();
  28. }
  29. /**
  30. * 添加
  31. */
  32. public function add() {
  33. if ($this->request->isAjax()) {
  34. $data = $this->request->post('row/a');
  35. $result = $this->model->save($data);
  36. if (!$result) {
  37. $this->error('提交失败');
  38. }
  39. $this->success('提交成功');
  40. }
  41. return $this->view->fetch();
  42. }
  43. /**
  44. * 修改
  45. */
  46. public function edit($ids = null) {
  47. $map['id'] = $ids;
  48. if ($this->request->isAjax()) {
  49. $data = $this->request->post('row/a');
  50. $result = $this->model->save($data, $map);
  51. if (!$result) {
  52. $this->error('修改失败');
  53. }
  54. $this->success('修改成功');
  55. }
  56. $data = NoticeModel::where($map)->find();
  57. $this->view->assign("row", $data);
  58. return $this->view->fetch();
  59. }
  60. /**
  61. * 删除通知
  62. */
  63. public function del($ids = null) {
  64. if ($this->request->isAjax()) {
  65. $map['id'] = array('in', $ids);
  66. $result = NoticeModel::destroy($map);
  67. if (!$result) {
  68. $this->error('删除失败');
  69. }
  70. $this->success('删除成功');
  71. }
  72. return $this->view->fetch();
  73. }
  74. }