arcate.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class arcate extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '公告分类');
  12. $lists = $this->model()->select()->from('arclass')->fetchAll();
  13. $data += array('lists' => $lists);
  14. $this->put('arclass.php', $data);
  15. }
  16. public function save()
  17. {
  18. $data = array();
  19. if (isset($_POST)) {
  20. foreach ($_POST as $key => $val) {
  21. $data[$key] = $this->req->post($key);
  22. }
  23. }
  24. if ($data) {
  25. if ($this->model()->from('arclass')->insertData($data)->insert()) {
  26. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'arcate'));
  27. exit;
  28. }
  29. }
  30. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  31. exit;
  32. }
  33. public function edit()
  34. {
  35. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  36. $data = $this->model()->select()->from('arclass')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  37. $this->put('arclassedit.php', $data);
  38. }
  39. public function editsave()
  40. {
  41. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  42. $cname = $this->req->post('cname');
  43. if ($id && $cname) {
  44. $this->model()->from('arclass')->updateSet(array('cname' => $cname))->where(array('fields' => 'id=?', 'values' => array($id)))->update();
  45. }
  46. $this->res->redirect($this->dir . 'arcate');
  47. }
  48. public function del()
  49. {
  50. $id = $this->req->get('id');
  51. if ($id) {
  52. if ($this->model()->from('arclass')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  53. echo json_encode(array('status' => 1));
  54. exit;
  55. }
  56. }
  57. echo json_encode(array('status' => 0));
  58. exit;
  59. }
  60. }