arlist.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class arlist extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $lists = array();
  12. $page = $this->req->get('p');
  13. $page = $page ? $page : 1;
  14. $pagesize = 20;
  15. $totalsize = $this->model()->from('arlist')->count();
  16. if ($totalsize) {
  17. $totalpage = ceil($totalsize / $pagesize);
  18. $page = $page > $totalpage ? $totalpage : $page;
  19. $offset = ($page - 1) * $pagesize;
  20. $lists = $this->model()->select('a.*,c.cname')->from('arlist a')->limit($pagesize)->left('arclass c')->on('c.id=a.cid')->join()->offset($offset)->orderby('a.id desc')->fetchAll();
  21. }
  22. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?p='));
  23. $class = $this->model()->select()->from('arclass')->fetchAll();
  24. $data = array('title' => '公告列表', 'lists' => $lists, 'class' => $class, 'pagelist' => $pagelist);
  25. $this->put('arlist.php', $data);
  26. }
  27. public function save()
  28. {
  29. $data = array();
  30. if (isset($_POST)) {
  31. foreach ($_POST as $key => $val) {
  32. if ($key == 'addtime') {
  33. $data[$key] = strtotime($this->req->post($key));
  34. } else {
  35. $data[$key] = $this->req->post($key);
  36. }
  37. }
  38. }
  39. if ($data) {
  40. if ($this->model()->from('arlist')->insertData($data)->insert()) {
  41. $this->res->redirect($this->dir . 'arlist');
  42. }
  43. }
  44. $this->res->redirect($this->dir . 'arlist');
  45. }
  46. public function edit()
  47. {
  48. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  49. $data = $this->model()->select()->from('arlist')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  50. $class = $this->model()->select()->from('arclass')->fetchAll();
  51. $this->put('arlistedit.php', array('title' => '编辑公告', 'data' => $data, 'class' => $class));
  52. }
  53. public function editsave()
  54. {
  55. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  56. $data = array();
  57. if (isset($_POST)) {
  58. foreach ($_POST as $key => $val) {
  59. if ($key == 'addtime') {
  60. $data[$key] = strtotime($this->req->post($key));
  61. } else {
  62. $data[$key] = $this->req->post($key);
  63. }
  64. }
  65. }
  66. if ($id && $data) {
  67. $this->model()->from('arlist')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($id)))->update();
  68. }
  69. $this->res->redirect($this->dir . 'arlist');
  70. }
  71. public function del()
  72. {
  73. $id = $this->req->get('id');
  74. if ($id) {
  75. if ($this->model()->from('arlist')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  76. echo json_encode(array('status' => 1));
  77. exit;
  78. }
  79. }
  80. echo json_encode(array('status' => 0));
  81. exit;
  82. }
  83. }