acw.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class acw extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '通用网关');
  12. $lists = $this->model()->select()->from('acw')->orderby('id asc')->fetchAll();
  13. $data += array('lists' => $lists);
  14. $this->put('acw.php', $data);
  15. }
  16. public function save()
  17. {
  18. $name = $this->req->post('name');
  19. $code = $this->req->post('code');
  20. $price = $this->req->post('price');
  21. $length = $this->req->post('length');
  22. $img = $this->req->post('img');
  23. if ($name == '' || $code == '') {
  24. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  25. exit;
  26. }
  27. $data = array('name' => $name, 'code' => $code, 'price' => $price ? json_encode(explode('|', $price)) : '', 'length' => $length ? json_encode(explode('|', $length)) : '', 'img' => $img);
  28. if ($this->model()->from('acw')->insertData($data)->insert()) {
  29. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'acw'));
  30. exit;
  31. }
  32. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  33. exit;
  34. }
  35. public function edit()
  36. {
  37. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  38. $data = array('title' => '编辑通用网关');
  39. $acw = $this->model()->select()->from('acw')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  40. $data += array('data' => $acw);
  41. $this->put('acwedit.php', $data);
  42. }
  43. public function editsave()
  44. {
  45. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  46. $name = $this->req->post('name');
  47. $code = $this->req->post('code');
  48. $price = $this->req->post('price');
  49. $length = $this->req->post('length');
  50. $img = $this->req->post('img');
  51. if ($name == '' || $code == '') {
  52. echo json_encode(array('status' => 0, 'msg' => '选项填写不完整'));
  53. exit;
  54. }
  55. $data = array('name' => $name, 'code' => $code, 'price' => $price ? json_encode(explode('|', $price)) : '', 'length' => $length ? json_encode(explode('|', $length)) : '', 'img' => $img);
  56. if ($this->model()->from('acw')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  57. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'acw'));
  58. exit;
  59. }
  60. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  61. exit;
  62. }
  63. public function del()
  64. {
  65. $id = $this->req->get('id');
  66. if ($id) {
  67. if ($this->model()->from('acw')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  68. echo json_encode(array('status' => 1));
  69. exit;
  70. }
  71. }
  72. echo json_encode(array('status' => 0));
  73. exit;
  74. }
  75. }