agent.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class agent extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $is_state = $this->req->get('is_state');
  12. $kw = $this->req->get('kw');
  13. $fdate = $this->req->get('fdate');
  14. $tdate = $this->req->get('tdate');
  15. $is_state = isset($_GET['is_state']) ? $is_state : -1;
  16. $cons = 'a.is_agent=?';
  17. $consOR = '';
  18. $consArr = array('1');
  19. if ($is_state >= 0) {
  20. $cons .= $cons ? ' and ' : '';
  21. $cons .= 'a.is_state=?';
  22. $consArr[] = $is_state;
  23. }
  24. if ($kw) {
  25. $consOR .= $consOR ? ' or ' : '';
  26. $consOR .= 'a.username like ?';
  27. $consArr[] = '%' . $kw . '%';
  28. }
  29. if ($kw) {
  30. $consOR .= $consOR ? ' or ' : '';
  31. $consOR .= 'a.id = ?';
  32. $consArr[] = $kw;
  33. }
  34. if ($consOR) {
  35. $cons .= $cons ? ' and ' : '';
  36. $cons .= '(' . $consOR . ')';
  37. }
  38. if ($fdate) {
  39. $cons .= $cons ? ' and ' : '';
  40. $cons .= 'a.addtime>=?';
  41. $consArr[] = strtotime($fdate);
  42. }
  43. if ($tdate) {
  44. $cons .= $cons ? ' and ' : '';
  45. $cons .= 'a.addtime<=?';
  46. $consArr[] = strtotime($tdate . ' 23:59:59');
  47. }
  48. $page = $this->req->get('p');
  49. $page = $page ? $page : 1;
  50. $pagesize = 20;
  51. $totalsize = $this->model()->select()->from('users a')->where(array('fields' => $cons, 'values' => $consArr))->count();
  52. $lists = array();
  53. if ($totalsize) {
  54. $totalpage = ceil($totalsize / $pagesize);
  55. $page = $page > $totalpage ? $totalpage : $page;
  56. $offset = ($page - 1) * $pagesize;
  57. $lists = $this->model()->select('a.*,b.realname,b.phone,b.qq')->from('users a')->left('userinfo b')->on('b.userid=a.id')->join()->offset($offset)->limit($pagesize)->where(array('fields' => $cons, 'values' => $consArr))->fetchAll();
  58. }
  59. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?is_state=' . $is_state . '&kw=' . $kw . '&fdate=' . $fdate . '&tdate=' . $tdate . '&p='));
  60. $data = array('title' => '代理列表', 'lists' => $lists, 'pagelist' => $pagelist, 'search' => array('is_state' => $is_state, 'kw' => $kw, 'fdate' => $fdate, 'tdate' => $tdate));
  61. $this->put('agents.php', $data);
  62. }
  63. public function edit()
  64. {
  65. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  66. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  67. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  68. $data = array('user' => $user, 'userinfo' => $userinfo);
  69. $this->put('agentedit.php', $data);
  70. }
  71. public function editsave()
  72. {
  73. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  74. $data = isset($_POST) ? $_POST : false;
  75. $userpass = '';
  76. if ($data && $data['userpass']) {
  77. if (strlen($data['userpass']) < 6 || strlen($data['userpass']) > 20) {
  78. echo json_encode(array('status' => 0, 'msg' => '密码长度在6-20个字符之间'));
  79. exit;
  80. }
  81. $userpass = sha1($data['userpass']);
  82. }
  83. foreach ($data as $key => $val) {
  84. if ($key != 'userpass') {
  85. $data[$key] = $val;
  86. }
  87. }
  88. if ($userpass) {
  89. $data['userpass'] = $userpass;
  90. }
  91. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  92. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', $this->dir . 'agent/edit/' . $id));
  93. exit;
  94. }
  95. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  96. exit;
  97. }
  98. public function editsave2()
  99. {
  100. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  101. $data = isset($_POST) ? $_POST : false;
  102. if ($data && $this->model()->from('userinfo')->updateSet($data)->where(array('fields' => 'userid=?', 'values' => array($id)))->update()) {
  103. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', $this->dir . 'agent/edit/' . $id));
  104. exit;
  105. }
  106. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  107. exit;
  108. }
  109. public function del()
  110. {
  111. $id = $this->req->get('id');
  112. if ($id) {
  113. if ($this->model()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  114. $this->model()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  115. $this->model()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  116. $this->model()->from('userlogs')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  117. echo json_encode(array('status' => 1));
  118. exit;
  119. }
  120. }
  121. echo json_encode(array('status' => 0));
  122. exit;
  123. }
  124. public function getuserinfo()
  125. {
  126. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  127. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  128. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  129. $data = array('user' => $user, 'userinfo' => $userinfo);
  130. $this->put('getuserinfo.php', $data);
  131. }
  132. public function getapidata()
  133. {
  134. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  135. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  136. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  137. $data = array('user' => $user, 'userinfo' => $userinfo);
  138. $this->put('getapidata.php', $data);
  139. }
  140. public function getbadata()
  141. {
  142. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  143. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  144. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  145. $data = array('user' => $user, 'userinfo' => $userinfo);
  146. $this->put('getbadata.php', $data);
  147. }
  148. public function getuserprice()
  149. {
  150. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  151. if (!($userprice = $this->model()->select()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($id)))->orderby('channelid asc')->fetchAll())) {
  152. $userprice = $this->model()->select()->from('acc')->where(array('fields' => 'is_display=?', 'values' => array(0)))->orderby('id asc')->fetchAll();
  153. } else {
  154. foreach ($userprice as $key => $val) {
  155. if (array_key_exists('channelid', $val)) {
  156. $userprice[$key]['id'] = $val['channelid'];
  157. }
  158. $acc = $this->model()->select('name,gprice')->from('acc')->where(array('fields' => 'id=?', 'values' => array($val['channelid'])))->fetchRow();
  159. $userprice[$key]['name'] = $acc['name'];
  160. $userprice[$key]['gprice_default'] = $acc['gprice'];
  161. }
  162. }
  163. $this->put('getagentprice.php', array('data' => $userprice, 'userid' => $id));
  164. }
  165. public function resetprice()
  166. {
  167. $userid = isset($this->action[3]) ? intval($this->action[3]) : 0;
  168. $this->model()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($userid)))->delete();
  169. $acc = $this->model()->select('id,uprice,gprice,is_state')->from('acc')->where(array('fields' => 'is_display=?', 'values' => array(0)))->fetchAll();
  170. if ($acc) {
  171. foreach ($acc as $key => $val) {
  172. $userprice = array('userid' => $userid, 'channelid' => $val['id'], 'is_state' => $val['is_state'], 'uprice' => $val['uprice'], 'gprice' => $val['gprice']);
  173. $this->model()->from('userprice')->insertData($userprice)->insert();
  174. }
  175. }
  176. $this->put('woodyapp.php', array('msg' => '用户分成比率重置成功!'));
  177. }
  178. public function saveprice()
  179. {
  180. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  181. $this->model()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  182. $gprice = isset($_POST) ? $_POST['gprice'] : false;
  183. if ($gprice) {
  184. foreach ($gprice as $key => $val) {
  185. $data = array('channelid' => $key, 'gprice' => $gprice[$key], 'userid' => $id);
  186. $this->model()->from('userprice')->insertData($data)->insert();
  187. }
  188. }
  189. $this->put('woodyapp.php', array('msg' => '设置保存成功'));
  190. }
  191. }