acc.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class acc extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $acp = $this->model()->select()->from('acp')->fetchAll();
  12. $lists = $this->model()->select()->from('acc')->orderby('sortid asc,id desc')->fetchAll();
  13. $data = array('title' => '通道列表', 'lists' => $lists, 'acp' => $acp);
  14. $this->put('acc.php', $data);
  15. }
  16. public function save()
  17. {
  18. $data = isset($_POST) ? $_POST : false;
  19. if ($data) {
  20. $acwid = $this->model()->select('acwid')->from('acl')->where(array('fields' => 'gateway=? and acpcode=?', 'values' => array($data['gateway'], $data['acpcode'])))->fetchRow();
  21. $data += $acwid;
  22. if ($this->model()->from('acc')->where(array('fields' => 'acwid=? and is_display=?', 'values' => array($acwid['acwid'], 0)))->count()) {
  23. $data['is_display'] = 1;
  24. }
  25. $acw = $this->model()->select('price')->from('acw')->where(array('fields' => 'id=?', 'values' => array($acwid['acwid'])))->fetchRow();
  26. if ($acw && $acw['price']) {
  27. $data += array('is_card' => 1);
  28. }
  29. if ($accid = $this->model()->from('acc')->insertData($data)->insert()) {
  30. if ($data['is_display'] == 0) {
  31. $users = $this->model()->select('id')->from('users')->fetchAll();
  32. if ($users) {
  33. foreach ($users as $key => $val) {
  34. $insertData = array('userid' => $val['id'], 'channelid' => $accid, 'uprice' => $this->req->post('uprice'), 'gprice' => $this->req->post('gprice'), 'is_state' => $this->req->post('is_state'));
  35. $this->model()->from('userprice')->insertData($insertData)->insert();
  36. }
  37. }
  38. }
  39. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'acc'));
  40. exit;
  41. }
  42. }
  43. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  44. exit;
  45. }
  46. public function edit()
  47. {
  48. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  49. $acp = $this->model()->select()->from('acp')->fetchAll();
  50. $acc = $this->model()->select()->from('acc')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  51. $acl = $this->model()->select('a.gateway,b.name')->left('acw b')->on('a.acwid=b.id')->join()->from('acl a')->where(array('fields' => 'a.acpcode=?', 'values' => array($acc['acpcode'])))->fetchAll();
  52. $data = array('title' => '编辑通道', 'data' => $acc, 'acp' => $acp, 'acl' => $acl);
  53. $this->put('accedit.php', $data);
  54. }
  55. public function editsave()
  56. {
  57. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  58. $data = isset($_POST) ? $_POST : false;
  59. $is_check = $this->req->post('is_check');
  60. $acwid = $this->model()->select('acwid')->from('acl')->where(array('fields' => 'gateway=? and acpcode=?', 'values' => array($data['gateway'], $data['acpcode'])))->fetchRow();
  61. $data += $acwid;
  62. if ($this->model()->from('acc')->where(array('fields' => 'acwid=? and is_display=? and id<>?', 'values' => array($acwid['acwid'], 0, $id)))->count()) {
  63. $data['is_display'] = 1;
  64. }
  65. $acw = $this->model()->select('price')->from('acw')->where(array('fields' => 'id=?', 'values' => array($acwid['acwid'])))->fetchRow();
  66. if ($acw && $acw['price']) {
  67. $data += array('is_card' => 1);
  68. }
  69. if ($data) {
  70. $newData = array();
  71. foreach ($data as $key => $val) {
  72. if ($key != 'is_check') {
  73. $newData[$key] = $val;
  74. }
  75. }
  76. }
  77. //print_r($newData);
  78. //echo $this->model()->from('acc')->updateSet($newData)->where(array('fields' => 'id=?', 'values' => array($id)))->update();
  79. if ($newData && $this->model()->from('acc')->updateSet($newData)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  80. //echo "22222222222222";
  81. if ($is_check) {
  82. $data = array('is_state' => $newData['is_state'], 'uprice' => $newData['uprice'], 'gprice' => $newData['gprice']);
  83. $this->model()->from('userprice')->updateSet($data)->where(array('fields' => 'channelid=?', 'values' => array($id)))->update();
  84. /*$users=$this->model()->select('id')->from('users')->fetchAll();if($users){foreach($users as $key=>$val){if(!$this->model()->from('userprice')->where(array('fields'=>'userid=? and channelid=?','values'=>array($val['id'],$id)))->count()){$insertData=array('is_state'=>$newData['is_state'],'uprice'=>$newData['uprice'],'gprice'=>$newData['gprice'],'userid'=>$val['id'],'channelid'=>$id,);$this->model()->from('userprice')->insertData($insertData)->insert();}}}*/
  85. }
  86. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', 'url' => $this->dir . 'acc'));
  87. exit;
  88. }
  89. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  90. exit;
  91. }
  92. public function del()
  93. {
  94. $id = $this->req->get('id');
  95. if ($id) {
  96. if ($this->model()->from('acc')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  97. $this->model()->from('userprice')->where(array('fields' => 'channelid=?', 'values' => array($id)))->delete();
  98. echo json_encode(array('status' => 1));
  99. exit;
  100. }
  101. }
  102. echo json_encode(array('status' => 0));
  103. exit;
  104. }
  105. public function change()
  106. {
  107. $acpcode = isset($this->action[3]) ? $this->action[3] : false;
  108. if ($acpcode) {
  109. $cons = array('fields' => 'acpcode=?', 'values' => array($acpcode));
  110. $acl = $this->model()->select()->from('acl')->where($cons)->fetchAll();
  111. if ($acl) {
  112. foreach ($acl as $key => $val) {
  113. $data = array('acpcode' => $val['acpcode'], 'gateway' => $val['gateway']);
  114. $cons = array('fields' => 'acwid=?', 'values' => array($val['acwid']));
  115. $this->model()->from('acc')->updateSet($data)->where($cons)->update();
  116. }
  117. }
  118. }
  119. $this->res->redirect($this->dir . 'acc');
  120. }
  121. public function getAcl()
  122. {
  123. $acpcode = $this->req->post('acpcode');
  124. $data = $this->model()->select('a.gateway,b.name')->left('acw b')->on('a.acwid=b.id')->join()->from('acl a')->where(array('fields' => 'a.acpcode=?', 'values' => array($acpcode)))->fetchAll();
  125. $str = '';
  126. if ($data) {
  127. foreach ($data as $key => $val) {
  128. $str .= '<option value="' . $val['gateway'] . '">' . $val['name'] . '</option>';
  129. }
  130. }
  131. echo $str;
  132. }
  133. }