users.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class users 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. $superid = $this->req->get('superid');
  16. $is_state = isset($_GET['is_state']) ? $is_state : -1;
  17. $cons = 'a.is_agent=?';
  18. $consOR = '';
  19. $consArr = array('0');
  20. if ($superid) {
  21. $cons .= $cons ? ' and ' : '';
  22. $cons .= 'a.superid=?';
  23. $consArr[] = $superid;
  24. }
  25. if ($is_state >= 0) {
  26. $cons .= $cons ? ' and ' : '';
  27. $cons .= 'a.is_state=?';
  28. $consArr[] = $is_state;
  29. }
  30. if ($kw) {
  31. $consOR .= $consOR ? ' or ' : '';
  32. $consOR .= 'a.username like ?';
  33. $consArr[] = '%' . $kw . '%';
  34. }
  35. if ($kw) {
  36. $consOR .= $consOR ? ' or ' : '';
  37. $consOR .= 'a.id = ?';
  38. $consArr[] = $kw;
  39. }
  40. if ($consOR) {
  41. $cons .= $cons ? ' and ' : '';
  42. $cons .= '(' . $consOR . ')';
  43. }
  44. if ($fdate) {
  45. $cons .= $cons ? ' and ' : '';
  46. $cons .= 'a.addtime>=?';
  47. $consArr[] = strtotime($fdate);
  48. }
  49. if ($tdate) {
  50. $cons .= $cons ? ' and ' : '';
  51. $cons .= 'a.addtime<=?';
  52. $consArr[] = strtotime($tdate . ' 23:59:59');
  53. }
  54. $page = $this->req->get('p');
  55. $page = $page ? $page : 1;
  56. $pagesize = 15;
  57. $totalsize = $this->model()->select()->from('users a')->where(array('fields' => $cons, 'values' => $consArr))->count();
  58. $lists = array();
  59. if ($totalsize) {
  60. $totalpage = ceil($totalsize / $pagesize);
  61. $page = $page > $totalpage ? $totalpage : $page;
  62. $offset = ($page - 1) * $pagesize;
  63. $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))->orderby('a.id desc')->fetchAll();
  64. }
  65. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?is_state=' . $is_state . '&kw=' . $kw . '&fdate=' . $fdate . '&tdate=' . $tdate . '&p='));
  66. $data = array('title' => '用户列表', 'lists' => $lists, 'pagelist' => $pagelist, 'search' => array('is_state' => $is_state, 'kw' => $kw, 'fdate' => $fdate, 'tdate' => $tdate));
  67. $this->put('users.php', $data);
  68. }
  69. public function tongdao()
  70. {
  71. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  72. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  73. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  74. $data = array('user' => $user, 'userinfo' => $userinfo);
  75. // $this->put('userstongdao.php', $data);
  76. $userprice = $this->model()->select('a.id,a.userid,a.uprice,a.is_state,b.name')->from('userprice a')->left('acc b')->on('a.channelid=b.id')->join()->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchAll();
  77. $data = array('title' => '我的费率', 'userprice' => $userprice,'user' => $user);
  78. $this->put('userstongdao.php', $data);
  79. }
  80. public function tongdao_edit()
  81. {
  82. $data = isset($_POST) ? $_POST : false;
  83. $id =$data['id'];
  84. $userid =$data['userid'];
  85. if ($id) {
  86. if ($data = $this->model()->select('is_state')->from('userprice')->where(array('fields' => 'userid=? and id=?', 'values' => array($userid, $id)))->fetchRow()) {
  87. $st = $data['is_state'] ? 0 : 1;
  88. $this->model()->from('userprice')->updateSet(array('is_state' => $st))->where(array('fields' => 'userid=? and id=?', 'values' => array($userid, $id)))->update();
  89. echo json_encode(array('status' => 1, 'st' => $st));
  90. exit;
  91. }
  92. }
  93. echo json_encode(array('status' => 0));
  94. }
  95. public function edit()
  96. {
  97. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  98. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  99. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  100. $data = array('user' => $user, 'userinfo' => $userinfo);
  101. $this->put('usersedit.php', $data);
  102. }
  103. public function editsave()
  104. {
  105. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  106. $data = isset($_POST) ? $_POST : false;
  107. if ($data['superid'] && $data['is_agent']) {
  108. echo json_encode(array('status' => 0, 'msg' => '此用户不能设为代理'));
  109. exit;
  110. }
  111. $userpass = '';
  112. if ($data && $data['userpass']) {
  113. if (strlen($data['userpass']) < 6 || strlen($data['userpass']) > 20) {
  114. echo json_encode(array('status' => 0, 'msg' => '密码长度在6-20个字符之间'));
  115. exit;
  116. }
  117. $userpass = sha1($data['userpass']);
  118. }
  119. $newData = array();
  120. foreach ($data as $key => $val) {
  121. if ($key != 'userpass') {
  122. $newData[$key] = $val;
  123. }
  124. }
  125. if ($userpass) {
  126. $newData['userpass'] = $userpass;
  127. }
  128. $acc = $this->model()->select('id,uprice,gprice,is_state')->from('acc')->where(array('fields' => 'is_display=?', 'values' => array(0)))->fetchAll();
  129. if ($acc && !$this->model()->select()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($id)))->count()) {
  130. foreach ($acc as $key => $val) {
  131. $userprice = array('userid' => $id, 'channelid' => $val['id'], 'is_state' => $val['is_state'], 'uprice' => $val['uprice'], 'gprice' => $val['gprice']);
  132. $this->model()->from('userprice')->insertData($userprice)->insert();
  133. }
  134. }
  135. if ($this->model()->from('users')->updateSet($newData)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  136. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', $this->dir . 'users/edit/' . $id));
  137. exit;
  138. }
  139. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  140. exit;
  141. }
  142. public function editsave2()
  143. {
  144. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  145. $data = isset($_POST) ? $_POST : false;
  146. if ($data && $this->model()->from('userinfo')->updateSet($data)->where(array('fields' => 'userid=?', 'values' => array($id)))->update()) {
  147. echo json_encode(array('status' => 1, 'msg' => '设置保存成功', $this->dir . 'users/edit/' . $id));
  148. exit;
  149. }
  150. echo json_encode(array('status' => 0, 'msg' => '设置保存失败'));
  151. exit;
  152. }
  153. public function del()
  154. {
  155. $id = $this->req->get('id');
  156. if ($id) {
  157. if ($this->model()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  158. $this->model()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  159. $this->model()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  160. $this->model()->from('userlogs')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  161. $this->model()->from('payments')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  162. $this->model()->from('paylogs')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  163. $this->model()->from('orders')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  164. $this->model()->from('orderinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  165. echo json_encode(array('status' => 1));
  166. exit;
  167. }
  168. }
  169. echo json_encode(array('status' => 0));
  170. exit;
  171. }
  172. public function getuserinfo()
  173. {
  174. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  175. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  176. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  177. $data = array('user' => $user, 'userinfo' => $userinfo);
  178. $this->put('getuserinfo.php', $data);
  179. }
  180. public function getapidata()
  181. {
  182. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  183. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  184. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  185. $data = array('user' => $user, 'userinfo' => $userinfo);
  186. $this->put('getapidata.php', $data);
  187. }
  188. public function resetapikey()
  189. {
  190. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  191. if ($id) {
  192. $data = array('apikey' => sha1($this->res->getRandomString(40)));
  193. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  194. $this->put('woodyapp.php', array('msg' => '接入密钥已重新生成'));
  195. exit;
  196. }
  197. }
  198. $this->put('woodyapp.php', array('msg' => '接入密钥生成失败'));
  199. exit;
  200. }
  201. public function getbadata()
  202. {
  203. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  204. $cfoid = $this->req->get('cfoid');
  205. $user = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  206. if ($cfoid) {
  207. $userinfo = $this->model()->select()->from('cfo')->where(array('fields' => 'id=?', 'values' => array($cfoid)))->fetchRow();
  208. } else {
  209. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($id)))->fetchRow();
  210. }
  211. $data = array('user' => $user, 'userinfo' => $userinfo, 'cfoid' => $cfoid);
  212. $this->put('getbadata.php', $data);
  213. }
  214. public function getuserprice()
  215. {
  216. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  217. if (!($userprice = $this->model()->select()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($id)))->orderby('channelid asc')->fetchAll())) {
  218. $userprice = $this->model()->select()->from('acc')->where(array('fields' => 'is_display=?', 'values' => array(0)))->orderby('id asc')->fetchAll();
  219. } else {
  220. foreach ($userprice as $key => $val) {
  221. if (array_key_exists('channelid', $val)) {
  222. $userprice[$key]['id'] = $val['channelid'];
  223. }
  224. $acc = $this->model()->select('name,acwid,uprice')->from('acc')->where(array('fields' => 'id=?', 'values' => array($val['channelid'])))->fetchRow();
  225. $userprice[$key]['name'] = $acc['name'];
  226. $userprice[$key]['acwid'] = $acc['acwid'];
  227. $userprice[$key]['uprice_default'] = $acc['uprice'];
  228. }
  229. }
  230. $this->put('getuserprice.php', array('data' => $userprice, 'userid' => $id));
  231. }
  232. public function saveprice()
  233. {
  234. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  235. $is_mod = false;
  236. $users = $this->model()->select('superid')->from('users')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow();
  237. if ($users['superid']) {
  238. $is_mod = true;
  239. }
  240. $this->model()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($id)))->delete();
  241. $uprice = isset($_POST) ? $_POST['uprice'] : false;
  242. $is_state = isset($_POST) ? $_POST['is_state'] : false;
  243. $channelid = isset($_POST) ? $_POST['channelid'] : false;
  244. if ($uprice && $is_state) {
  245. foreach ($uprice as $key => $val) {
  246. $data = array('uprice' => $val, 'is_state' => $is_state[$key], 'channelid' => $is_mod && $channelid[$key] != $key ? $key : $channelid[$key], 'userid' => $id);
  247. $this->model()->from('userprice')->insertData($data)->insert();
  248. }
  249. }
  250. $this->put('woodyapp.php', array('msg' => '设置保存成功'));
  251. }
  252. public function resetprice()
  253. {
  254. $userid = isset($this->action[3]) ? intval($this->action[3]) : 0;
  255. $this->model()->from('userprice')->where(array('fields' => 'userid=?', 'values' => array($userid)))->delete();
  256. $acc = $this->model()->select('id,uprice,gprice,is_state')->from('acc')->where(array('fields' => 'is_display=?', 'values' => array(0)))->fetchAll();
  257. if ($acc) {
  258. foreach ($acc as $key => $val) {
  259. $userprice = array('userid' => $userid, 'channelid' => $val['id'], 'is_state' => $val['is_state'], 'uprice' => $val['uprice'], 'gprice' => $val['gprice']);
  260. $this->model()->from('userprice')->insertData($userprice)->insert();
  261. }
  262. }
  263. $this->put('woodyapp.php', array('msg' => '用户分成比率重置成功!'));
  264. }
  265. }