UserController.class.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. <?php
  2. namespace Admin\Controller;
  3. class UserController extends AdminController
  4. {
  5. protected function _initialize()
  6. {
  7. parent::_initialize(); $allow_action=array("index","edit","status","admin","adminEdit","coinEditz","adminStatus","updateRules","log","logEdit","logStatus","qianbao","qianbaoEdit","qianbaoStatus","coin","coinEdit","coinFreeze","coinLog","setpwd","amountlog","loginadmin","billdel","sendnotice","upsendnotice","noticelist","noticedel","authrz","upanthrz","online","onlinelist","sendonline","uponline","setagent","agent","cancelagent","settax");
  8. if(!in_array(ACTION_NAME,$allow_action)){
  9. $this->error("页面不存在!");
  10. }
  11. }
  12. public function setTax($id=null,$st=null){
  13. $uid = $id;
  14. if($uid <= 0 || $uid == ''){
  15. $this->erro("参数重要参数");
  16. }
  17. if($st <= 0 || $st == ''){
  18. $this->error("参数重要参数");
  19. }
  20. $uinfo = M("user")->where(array('id'=>$uid))->find();
  21. if(empty($uinfo)){
  22. $this->error("参数重要参数");
  23. }
  24. if($st == 1){
  25. $result = M("user")->where(array('id'=>$uid))->save(array('is_tax'=>1));
  26. }elseif($st == 2){
  27. $result = M("user")->where(array('id'=>$uid))->save(array('is_tax'=>0));
  28. }
  29. if($result){
  30. $this->success("设置成功");
  31. }else{
  32. $this->error("设置失败");
  33. }
  34. }
  35. //取消代理资格
  36. public function cancelagent($id){
  37. $uid = $id;
  38. if($uid <= 0 || $uid == ''){
  39. $this->error("参数重要参数");
  40. }
  41. $uinfo = M("user")->where(array('id'=>$uid))->field("is_agent")->find();
  42. if(empty($uinfo)){
  43. $this->error("参数重要参数");
  44. }
  45. if($uinfo['is_agent'] == 0){
  46. $this->error("该会员不是代理");
  47. }
  48. $result = M("user")->where(array('id'=>$uid))->save(array('is_agent'=>0));
  49. if($result){
  50. $this->success("设置成功");
  51. }else{
  52. $this->error("设置失败");
  53. }
  54. }
  55. //代理管理
  56. public function agent(){
  57. $where['is_agent'] = 1;
  58. $count = M('User')->where($where)->count();
  59. $Page = new \Think\Page($count, 15);
  60. $show = $Page->show();
  61. $list = M('User')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  62. foreach ($list as $k => $v) {
  63. $uid = $v['id'];
  64. $one = M('User')->where(array('invit_1'=>$uid))->count();
  65. if($one <= 0){
  66. $one = 0;
  67. }
  68. $two = M('User')->where(array('invit_2'=>$uid))->count();
  69. if($two <= 0){
  70. $two = 0;
  71. }
  72. $three = M('User')->where(array('invit_3'=>$uid))->count();
  73. if($three <= 0){
  74. $three = 0;
  75. }
  76. $all = $one + $two + $three;
  77. if($all <= 0){
  78. $all = 0;
  79. }
  80. $list[$k]['all'] = $all;
  81. $list[$k]['one'] = $one;
  82. $list[$k]['two'] = $two;
  83. $list[$k]['three'] = $three;
  84. }
  85. $this->assign('list', $list);
  86. $this->assign('page', $show);
  87. $this->display();
  88. }
  89. //设置代理
  90. public function setagent($id){
  91. $uid = $id;
  92. if($uid <= 0 || $uid == ''){
  93. $this->error("参数得要参数");
  94. }
  95. $uinfo = M("user")->where(array('id'=>$uid))->field("is_agent")->find();
  96. if(empty($uinfo)){
  97. $this->error("参数得要参数");
  98. }
  99. if($uinfo['is_agent'] == 1){
  100. $this->error("该会员已是代理");
  101. }
  102. $result = M("user")->where(array('id'=>$uid))->save(array('is_agent'=>1));
  103. if($result){
  104. $this->success("设置成功");
  105. }else{
  106. $this->error("设置失败");
  107. }
  108. }
  109. //实名认证处理
  110. public function upanthrz(){
  111. $rzstatus = $_POST['rzstatus'];
  112. $uid = $_POST['uid'];
  113. if($uid <= 0 || $uid == ''){
  114. $this->error("参数得要参数");
  115. }
  116. if($rzstatus== 2){//表示认证成功
  117. $result = M("user")->where(array('id'=>$uid))->save(array('rzstatus'=>2,'rzuptime'=>time()));
  118. if($result){
  119. $kjid = $_POST['kjid'];
  120. $minfo = M("kuangji")->where(array('id'=>$kjid))->find();
  121. //建仓矿机订单数据
  122. $odate['kid'] = $minfo['id'];
  123. $odate['type'] = 1;
  124. $odate['sharebl'] = 0;
  125. $odate['uid'] = $uid;
  126. $odate['username'] = $_POST['username'];
  127. $odate['kjtitle'] = $minfo['title'];
  128. $odate['imgs'] = $minfo['imgs'];
  129. $odate['status'] = 1;
  130. $odate['cycle'] = $minfo['cycle'];
  131. $odate['synum'] = $minfo['cycle'];
  132. $odate['outtype'] = $minfo['outtype'];
  133. $odate['outcoin'] = $minfo['outcoin'];
  134. if($minfo['outtype'] == 1){//按产值收益
  135. $odate['outnum'] = 0;
  136. $odate['outusdt'] = $minfo['dayoutnum'];
  137. }elseif($minfo['outtype'] == 2){//按币量收益
  138. $odate['outnum'] = $minfo['dayoutnum'];
  139. $odate['outusdt'] = 0;
  140. }
  141. $odate['djout'] = $minfo['djout'];
  142. if($minfo['djout'] == 2){
  143. $odate['djnum'] = $minfo['djday'];
  144. }else{
  145. $odate['djnum'] = $minfo['djday'];
  146. }
  147. $odate['addtime'] = date("Y-m-d H:i:s",time());
  148. $odate['endtime'] = date("Y-m-d H:i:s",(time() + 86400 * $minfo['cycle']));
  149. $odate['intaddtime'] = time();
  150. $odate['intendtime'] = time() + 86400 * $minfo['cycle'];
  151. $adre = M("kjorder")->add($odate);
  152. $notice['uid'] = $uid;
  153. $notice['account'] = $_POST['username'];
  154. $notice['title'] = L('认证审核成功');
  155. $notice['content'] = L('您的认证申请已审核成功');
  156. $notice['addtime'] = date("Y-m-d H:i:s",time());
  157. $notice['status'] = 1;
  158. M("notice")->add($notice);
  159. $this->redirect('user/index');
  160. $this->success("认证成功");
  161. }else{
  162. $this->error("操作失败");
  163. }
  164. }elseif($rzstatus == 3){//表示驳回认证
  165. $result = M("user")->where(array('id'=>$uid))->save(array('rzstatus'=>3,'rzuptime'=>time()));
  166. if($result){
  167. $notice['uid'] = $uid;
  168. $notice['account'] = $_POST['username'];
  169. $notice['title'] = L('认证驳回');
  170. $notice['content'] = L('您的认证申请被管理员驳回,请联系管理员');
  171. $notice['addtime'] = date("Y-m-d H:i:s",time());
  172. $notice['status'] = 1;
  173. M("notice")->add($notice);
  174. $this->success("操作成功");
  175. }else{
  176. $this->error("操作失败");
  177. }
  178. }
  179. }
  180. //实名认证页面
  181. public function authrz($id){
  182. $klist = M("kuangji")->where(array('rtype'=>2))->field("id,title")->select();
  183. $this->assign("klist",$klist);
  184. $info = M("user")->where(array('id'=>$id))->find();
  185. $this->assign('info',$info);
  186. $this->display();
  187. }
  188. //删除通知
  189. public function noticedel($id = null, $type = null){
  190. if(empty($id)){
  191. $this->error("缺少重要参数");exit();
  192. }
  193. $where['id'] = array('in',$id);
  194. $result = M("notice")->where($where)->delete();
  195. if($result){
  196. $this->success("删除成功");
  197. }else{
  198. $this->error("删除失败");
  199. }
  200. }
  201. //会员管理列表
  202. public function noticelist($username=NULL){
  203. $where = array();
  204. if($username != ''){
  205. $where['account'] = $username;
  206. }
  207. $count = M('notice')->where($where)->count();
  208. $Page = new \Think\Page($count, 15);
  209. $show = $Page->show();
  210. $list = M('notice')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  211. $this->assign('list', $list);
  212. $this->assign('page', $show);
  213. $this->display();
  214. }
  215. //给会员发送通知
  216. public function sendnotice($id = null,$type= null){
  217. $this->assign('id',$id);
  218. $this->assign('type',$type);
  219. $this->display();
  220. }
  221. //给会员发送通知处理
  222. public function upsendnotice($id = null,$type = null,$title = null,$content = null,$imgs=null){
  223. //if(checkstr($title) || checkstr($content)){
  224. //$this->error("不能输入特殊字符!");exit();
  225. //}
  226. if($type == 1){
  227. if($id <= 0){
  228. $this->error("缺少重要参数!");exit();
  229. }
  230. $uinfo = M("user")->where(array('id'=>$id))->field("id,username")->find();
  231. if(empty($uinfo)){
  232. $this->error("缺少重要参数!");exit();
  233. }
  234. $data['uid'] = $uinfo['id'];
  235. $data['account'] = $uinfo['username'];
  236. $data['title'] = $title;
  237. $data['content'] = $content;
  238. $data['imgs'] = $imgs;
  239. $data['addtime'] = date("Y-m-d H:i:s",time());
  240. $data['status'] = 1;
  241. $result = M("notice")->add($data);
  242. if($result){
  243. $this->success("通知发送成功");
  244. }else{
  245. $this->success("通知发送失败");
  246. }
  247. }elseif($type == 2){
  248. $ulist = M("user")->field("id,username")->select();
  249. if(!empty($ulist)){
  250. foreach($ulist as $key=>$vo){
  251. $data['uid'] = $vo['id'];
  252. $data['account'] = $vo['username'];
  253. $data['title'] = $title;
  254. $data['content'] = $content;
  255. $data['imgs'] = $imgs;
  256. $data['addtime'] = date("Y-m-d H:i:s",time());
  257. $data['status'] = 1;
  258. M("notice")->add($data);
  259. }
  260. $this->success("群发通知发送成功");
  261. }
  262. }else{
  263. $this->error("非法操作!");exit();
  264. }
  265. }
  266. //修改会员状态
  267. public function status($id = NULL, $type = null){
  268. if(empty($id)){
  269. $this->error("请选择会员!");exit();
  270. }
  271. $where['id'] = array('in', $id);
  272. switch (strtolower($type)) {
  273. case 1:
  274. //冻结
  275. $result = M("user")->where($where)->save(array('status'=>1));
  276. break;
  277. case 2:
  278. //解封
  279. $result = M("user")->where($where)->save(array('status'=>2));
  280. break;
  281. case 3:
  282. //启动提币
  283. $result = M("user")->where($where)->save(array('txstate'=>1));
  284. break;
  285. case 4:
  286. //禁止提币
  287. $result = M("user")->where($where)->save(array('txstate'=>2));
  288. break;
  289. case 5:
  290. //删除会员
  291. $result = M("user")->where($where)->delete();
  292. break;
  293. default:
  294. $this->error('操作失败!');
  295. }
  296. if($result){
  297. $this->success('操作成功!');
  298. }else{
  299. $this->error('操作失败!');
  300. }
  301. }
  302. public function onlinelist($id = null){
  303. $where['uid'] = $id;
  304. $where['type'] = 2;
  305. $where['state'] = 0;
  306. $count = M('online')->where($where)->count();
  307. $Page = new \Think\Page($count, 50);
  308. $show = $Page->show();
  309. $list = M('online')->where($where)->order('state desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  310. $this->assign('list', $list);
  311. $this->assign('page', $show);
  312. $this->display();
  313. }
  314. //客服回复详情页面
  315. public function sendonline($id = null){
  316. $info = M("online")->where(array('id'=>$id))->find();
  317. $this->assign("info",$info);
  318. $this->display();
  319. }
  320. //客服回复
  321. public function uponline($oid=null,$content=null){
  322. if (checkstr($content)){
  323. $this->error("输入的信息有误");
  324. }
  325. if($oid <= 0 || $oid == ''){
  326. $this->error("缺少重要参数");
  327. }
  328. $info = M("online")->where(array('id'=>$oid))->find();
  329. $uid = $info['uid'];
  330. $data['uid'] = $uid;
  331. $data['username'] = $info['username'];
  332. $data['content'] = $content;
  333. $data['type'] = 1;
  334. $data['addtime'] = date("Y-m-d H:i:s",time());
  335. $data['state'] = 1;
  336. $result = M("online")->add($data);
  337. if($result){
  338. M("online")->where(array('id'=>$oid))->save(array('state'=>1));
  339. $this->success("回复成功");
  340. }else{
  341. $this->error("回复失败");
  342. }
  343. }
  344. //会员管理列表
  345. public function online($name=NULL, $field=NULL, $status=NULL){
  346. $where = array();
  347. if ($field && $name) {
  348. $where[$field] = $name;
  349. }
  350. if ($status) {
  351. $where['status'] = $status;
  352. }
  353. $count = M('User')->where($where)->count();
  354. $Page = new \Think\Page($count, 50);
  355. $show = $Page->show();
  356. $list = M('User')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->field("id,username")->select();
  357. foreach($list as $key=>$vo){
  358. $map['uid'] = $vo['id'];
  359. $map['state'] = array('eq',0);
  360. $list[$key]['nor'] = M("online")->where($map)->count();
  361. }
  362. $new_arr = array_column($list, 'nor');
  363. array_multisort($new_arr, SORT_DESC, $list);
  364. foreach($list as $k=>$v){
  365. if($v['nor'] == 0){
  366. unset($list[$k]);
  367. }
  368. }
  369. $this->assign('list', $list);
  370. $this->assign('page', $show);
  371. $this->display();
  372. }
  373. //会员管理列表
  374. public function index($name=NULL, $field=NULL, $status=NULL){
  375. $where = array();
  376. if ($field && $name) {
  377. $where[$field] = $name;
  378. }
  379. if ($status) {
  380. $where['status'] = $status;
  381. }
  382. $count = M('User')->where($where)->count();
  383. $Page = new \Think\Page($count, 15);
  384. $show = $Page->show();
  385. $list = M('User')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  386. foreach ($list as $k => $v) {
  387. $list[$k]['invit_1'] = M('User')->where(array('id' => $v['invit_1']))->getField('username');
  388. $list[$k]['invit_2'] = M('User')->where(array('id' => $v['invit_2']))->getField('username');
  389. $list[$k]['invit_3'] = M('User')->where(array('id' => $v['invit_3']))->getField('username');
  390. $user_login_state=M('user_log')->where(array('userid'=>$v['id'],'type' => 'login'))->order('id desc')->find();
  391. $list[$k]['state']=$user_login_state['state'];
  392. }
  393. $this->assign('list', $list);
  394. $this->assign('page', $show);
  395. $this->display();
  396. }
  397. //编辑或新增会员
  398. public function edit($id = NULL)
  399. {
  400. if (empty($_POST)) {
  401. if (empty($id)) {
  402. $this->data = '';
  403. } else {
  404. $this->data = M('User')->where(array('id' => trim($id)))->find();
  405. }
  406. $this->display();
  407. } else {
  408. //新增会员
  409. if($id <= 0 || $id == null){
  410. $username = trim($_POST['username']);
  411. if($username == ''){
  412. $this->error("请输入会员账号");exit();
  413. }else{
  414. $add['username'] = $username;
  415. }
  416. if($_POST['password'] == ""){
  417. $this->error("请输入登陆密码");exit();
  418. }else{
  419. $add['password'] = md5($_POST['password']);
  420. }
  421. if($_POST['paypassword'] != ""){
  422. $add['paypassword'] = md5($_POST['paypassword']);
  423. }
  424. if($_POST['invit'] != 0 || $_POST['invit'] != ''){
  425. $inv_user = M('User')->where(array('invit' => $_POST['invit']))->field("id,username,invit_1,invit_2,path")->find();
  426. if(empty($inv_user)){
  427. $this->error("推荐人不存在");exit();
  428. }
  429. $add['invit_1'] = $inv_user['id'];
  430. $add['invit_2'] = $inv_user['invit_1'];
  431. $add['invit_3'] = $inv_user['invit_2'];
  432. $path = $inv_user['path'].','.$inv_user['id'];
  433. }else{
  434. $add['invit_1'] = 0;
  435. $add['invit_2'] = 0;
  436. $add['invit_3'] = 0;
  437. $path = '';
  438. }
  439. $add['status'] = $_POST['status'];
  440. $add['txstate'] = $_POST['txstate'];
  441. $add['addtime'] = time();
  442. $add['addip'] = get_client_ip();
  443. $add['addr'] = get_city_ip();
  444. $add['invit'] = tradenoa();
  445. $re = M("user")->add($add);
  446. if($re){
  447. M('user_coin')->add(array('userid' => $re));
  448. $this->success("新增成功");exit();
  449. }else{
  450. $this->error("新增失败");exit();
  451. }
  452. //编辑会员
  453. }else{
  454. if ($_POST['password']) {
  455. $_POST['password'] = md5($_POST['password']);
  456. } else {
  457. unset($_POST['password']);
  458. }
  459. if ($_POST['paypassword']) {
  460. $_POST['paypassword'] = md5($_POST['paypassword']);
  461. } else {
  462. unset($_POST['paypassword']);
  463. }
  464. $result = M("user")->where(array('id'=>$id))->save($_POST);
  465. if($result){
  466. $this->success("编辑成功");exit();
  467. }else{
  468. $this->error("编辑失败");exit();
  469. }
  470. }
  471. }
  472. }
  473. //管理列表
  474. public function admin($name = NULL, $field = NULL, $status = NULL)
  475. {
  476. $DbFields = M('Admin')->getDbFields();
  477. if (!in_array('email', $DbFields)) {
  478. M()->execute('ALTER TABLE `tw_admin` ADD COLUMN `email` VARCHAR(200) NOT NULL COMMENT \'\' AFTER `id`;');
  479. }
  480. $where = array();
  481. if ($field && $name) {
  482. if ($field == 'username') {
  483. $where['userid'] = M('User')->where(array('username' => $name))->getField('id');
  484. } else {
  485. $where[$field] = $name;
  486. }
  487. }
  488. if ($status) {
  489. $where['status'] = $status - 1;
  490. }
  491. $count = M('Admin')->where($where)->count();
  492. $Page = new \Think\Page($count, 15);
  493. $show = $Page->show();
  494. $list = M('Admin')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  495. foreach ($list as $k => $v) {
  496. $aga = 0;
  497. $aga = M('AuthGroupAccess')->where(array('uid'=>$v['id']))->find();
  498. $ag = M('AuthGroup')->where(array('id'=>$aga['group_id']))->find();
  499. }
  500. $this->assign('list', $list);
  501. $this->assign('page', $show);
  502. $this->display();
  503. }
  504. //管理编辑
  505. public function adminEdit(){
  506. if (empty($_POST)) {
  507. if (empty($_GET['id'])) {
  508. $this->data = null;
  509. } else {
  510. $this->data = M('Admin')->where(array('id' => trim($_GET['id'])))->find();
  511. }
  512. $this->display();
  513. } else {
  514. $input = I('post.');
  515. if (!check($input['username'], 'username')) {
  516. //$this->error('用户名格式错误!');
  517. }
  518. if ($input['nickname'] && !check($input['nickname'], 'A')) {
  519. $this->error('昵称格式错误!');
  520. }
  521. if ($input['password'] && !check($input['password'], 'password')) {
  522. $this->error('登录密码格式错误!');
  523. }
  524. if ($input['mobile'] && !check($input['mobile'], 'mobile')) {
  525. $this->error('手机号码格式错误!');
  526. }
  527. if ($input['email'] && !check($input['email'], 'email')) {
  528. $this->error('邮箱格式错误!');
  529. }
  530. if ($input['password']) {
  531. $input['password'] = md5($input['password']);
  532. } else {
  533. unset($input['password']);
  534. }
  535. if ($_POST['id']) {
  536. $rs = M('Admin')->save($input);
  537. } else {
  538. $_POST['addtime'] = time();
  539. $rs = M('Admin')->add($input);
  540. }
  541. if ($rs) {
  542. $this->success('编辑成功!');
  543. } else {
  544. $this->error('编辑失败!');
  545. }
  546. }
  547. }
  548. //管理员状态编辑
  549. public function adminStatus($id = NULL, $type = NULL, $mobile = 'Admin'){
  550. if (empty($id)) {
  551. $this->error('参数错误!');
  552. }
  553. if (empty($type)) {
  554. $this->error('参数错误1!');
  555. }
  556. if (strpos(',', $id)) {
  557. $id = implode(',', $id);
  558. }
  559. $where['id'] = array('in', $id);
  560. switch (strtolower($type)) {
  561. case 'forbid':
  562. $data = array('status' => 0);
  563. break;
  564. case 'resume':
  565. $data = array('status' => 1);
  566. break;
  567. case 'repeal':
  568. $data = array('status' => 2, 'endtime' => time());
  569. break;
  570. case 'delete':
  571. $data = array('status' => -1);
  572. break;
  573. case 'del':
  574. if (M($mobile)->where($where)->delete()) {
  575. $this->success('操作成功!');
  576. } else {
  577. $this->error('操作失败!');
  578. }
  579. break;
  580. default:
  581. $this->error('操作失败!');
  582. }
  583. if (M($mobile)->where($where)->save($data)) {
  584. $this->success('操作成功!');
  585. } else {
  586. $this->error('操作失败!');
  587. }
  588. }
  589. protected function updateRules()
  590. {
  591. $nodes = $this->returnNodes(false);
  592. $AuthRule = M('AuthRule');
  593. $map = array(
  594. 'module' => 'admin',
  595. 'type' => array('in', '1,2')
  596. );
  597. $rules = $AuthRule->where($map)->order('name')->select();
  598. $data = array();
  599. foreach ($nodes as $value) {
  600. $temp['name'] = $value['url'];
  601. $temp['title'] = $value['title'];
  602. $temp['module'] = 'admin';
  603. if (0 < $value['pid']) {
  604. $temp['type'] = \Common\Model\AuthRuleModel::RULE_URL;
  605. } else {
  606. $temp['type'] = \Common\Model\AuthRuleModel::RULE_MAIN;
  607. }
  608. $temp['status'] = 1;
  609. $data[strtolower($temp['name'] . $temp['module'] . $temp['type'])] = $temp;
  610. }
  611. $update = array();
  612. $ids = array();
  613. foreach ($rules as $index => $rule) {
  614. $key = strtolower($rule['name'] . $rule['module'] . $rule['type']);
  615. if (isset($data[$key])) {
  616. $data[$key]['id'] = $rule['id'];
  617. $update[] = $data[$key];
  618. unset($data[$key]);
  619. unset($rules[$index]);
  620. unset($rule['condition']);
  621. $diff[$rule['id']] = $rule;
  622. } else if ($rule['status'] == 1) {
  623. $ids[] = $rule['id'];
  624. }
  625. }
  626. if (count($update)) {
  627. foreach ($update as $k => $row) {
  628. if ($row != $diff[$row['id']]) {
  629. $AuthRule->where(array('id' => $row['id']))->save($row);
  630. }
  631. }
  632. }
  633. if (count($ids)) {
  634. $AuthRule->where(array(
  635. 'id' => array('IN', implode(',', $ids))
  636. ))->save(array('status' => -1));
  637. }
  638. if (count($data)) {
  639. $AuthRule->addAll(array_values($data));
  640. }
  641. if ($AuthRule->getDbError()) {
  642. trace('[' . 'Admin\\Controller\\UserController::updateRules' . ']:' . $AuthRule->getDbError());
  643. return false;
  644. } else {
  645. return true;
  646. }
  647. }
  648. //会员登陆记录
  649. public function log($name = NULL, $field = NULL, $status = NULL)
  650. {
  651. $where = array();
  652. if ($field && $name) {
  653. if ($field == 'username') {
  654. $where['userid'] = M('User')->where(array('username' => $name))->getField('id');
  655. } else {
  656. $where[$field] = $name;
  657. }
  658. }
  659. if ($status) {
  660. $where['status'] = $status - 1;
  661. }
  662. $count = M('UserLog')->where($where)->count();
  663. $Page = new \Think\Page($count, 15);
  664. $show = $Page->show();
  665. $list = M('UserLog')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  666. foreach ($list as $k => $v) {
  667. $list[$k]['username'] = M('User')->where(array('id' => $v['userid']))->getField('username');
  668. }
  669. $this->assign('list', $list);
  670. $this->assign('page', $show);
  671. $this->display();
  672. }
  673. //编辑登陆记录
  674. public function logEdit($id = NULL){
  675. if (empty($_POST)) {
  676. if (empty($id)) {
  677. $this->data = null;
  678. } else {
  679. $this->data = M('UserLog')->where(array('id' => trim($id)))->find();
  680. }
  681. $this->display();
  682. } else {
  683. $_POST['addtime'] = strtotime($_POST['addtime']);
  684. if (M('UserLog')->save($_POST)) {
  685. $this->success('编辑成功!');
  686. } else {
  687. $this->error('编辑失败!');
  688. }
  689. }
  690. }
  691. //修改登陆记录状态
  692. public function logStatus($id = NULL, $type = NULL, $mobile = 'UserLog'){
  693. if (empty($id)) {
  694. $this->error('参数错误!');
  695. }
  696. if (empty($type)) {
  697. $this->error('参数错误1!');
  698. }
  699. if (strpos(',', $id)) {
  700. $id = implode(',', $id);
  701. }
  702. $where['id'] = array('in', $id);
  703. switch (strtolower($type)) {
  704. case 'forbid':
  705. $data = array('status' => 0);
  706. break;
  707. case 'resume':
  708. $data = array('status' => 1);
  709. break;
  710. case 'repeal':
  711. $data = array('status' => 2, 'endtime' => time());
  712. break;
  713. case 'delete':
  714. $data = array('status' => -1);
  715. break;
  716. case 'del':
  717. if (M($mobile)->where($where)->delete()) {
  718. $this->success('操作成功!');
  719. }
  720. else {
  721. $this->error('操作失败!');
  722. }
  723. break;
  724. default:
  725. $this->error('操作失败!');
  726. }
  727. if (M($mobile)->where($where)->save($data)) {
  728. $this->success('操作成功!');
  729. } else {
  730. $this->error('操作失败!');
  731. }
  732. }
  733. //会员钱包管理
  734. public function qianbao($name = NULL, $field = NULL, $coinname = NULL, $status = NULL)
  735. {
  736. $where = array();
  737. if ($field && $name) {
  738. if ($field == 'username') {
  739. $where['userid'] = M('User')->where(array('username' => $name))->getField('id');
  740. } else {
  741. $where[$field] = $name;
  742. }
  743. }
  744. if ($coinname) {
  745. $where['name'] = trim($coinname);
  746. }
  747. $coinlist = M("coin")->where("type = 1")->order("id desc")->field("name,title")->select();
  748. $this->assign("coinlist",$coinlist);
  749. $count = M('UserQianbao')->where($where)->count();
  750. $Page = new \Think\Page($count, 15);
  751. $show = $Page->show();
  752. $list = M('UserQianbao')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  753. foreach ($list as $k => $v) {
  754. $list[$k]['username'] = M('User')->where(array('id' => $v['userid']))->getField('username');
  755. }
  756. $this->assign('list', $list);
  757. $this->assign('page', $show);
  758. $this->display();
  759. }
  760. //编辑会员钱包地址
  761. public function qianbaoEdit($id = NULL)
  762. {
  763. if (empty($_POST)) {
  764. if (empty($id)) {
  765. $this->data = null;
  766. } else {
  767. $this->data = M('UserQianbao')->where(array('id' => trim($id)))->find();
  768. }
  769. $coinlist = M("coin")->where("type = 1")->order("id desc")->field("name,title")->select();
  770. $this->assign("coinlist",$coinlist);
  771. $this->display();
  772. } else {
  773. $_POST['addtime'] = strtotime($_POST['addtime']);
  774. if (M('UserQianbao')->save($_POST)) {
  775. $this->success('编辑成功!');
  776. } else {
  777. $this->error('编辑失败!');
  778. }
  779. }
  780. }
  781. //会员资产
  782. public function coin($name = NULL, $field = NULL)
  783. {
  784. $where = array();
  785. if ($field && $name) {
  786. if ($field == 'username') {
  787. $where['userid'] = M('User')->where(array('username' => $name))->getField('id');
  788. } else {
  789. $where[$field] = $name;
  790. }
  791. }
  792. $count = M('UserCoin')->where($where)->count();
  793. $Page = new \Think\Page($count, 15);
  794. $show = $Page->show();
  795. $list = M('UserCoin')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  796. foreach ($list as $k => $v) {
  797. $list[$k]['username'] = M('User')->where(array('id' => $v['userid']))->getField('username');
  798. }
  799. $this->assign('list', $list);
  800. $this->assign('page', $show);
  801. $coinlist = M("coin")->where("type = 1 or type = 2")->order("id asc")->field("name,title")->select();
  802. $this->assign("coinlist",$coinlist);
  803. $this->display();
  804. }
  805. public function coinEdit($id=NULL)
  806. {
  807. if($id != ''){
  808. $coinlist = M('User')->where(array('id' => $id))->getField('username');
  809. }
  810. $this->assign('name',$coinlist);
  811. $this->assign('id', $id);
  812. $this->display();
  813. }
  814. public function coinEditz(){
  815. if ($_POST['coin'] == 1){
  816. $name = 'usdt';
  817. $coinlist = M('User_coin')->where(array('userid' => $_POST['id']))->getField('usdt');
  818. }elseif ($_POST['coin'] == 2){
  819. $name = 'gcb';
  820. $coinlist = M('User_coin')->where(array('userid' => $_POST['id']))->getField('gcb');
  821. }
  822. if($_POST['id'] == ''){
  823. $this->error("参数得要参数");
  824. }
  825. if($_POST['status'] == 1){
  826. $prinum = $coinlist+$_POST['num'];
  827. }else{
  828. $prinum = $coinlist-$_POST['num'];
  829. }
  830. $notice = [];
  831. if($_POST['comm'] != '1'){
  832. $notice['uid'] = $_POST['id'];
  833. $notice['username'] = $_POST['username'];
  834. $notice['coinname'] = strtoupper($name);
  835. $notice['num'] = $_POST['num'];
  836. $notice['afternum'] = $prinum;
  837. $notice['type'] = '55';
  838. $notice['addtime'] = date("Y-m-d H:i:s");
  839. $notice['st'] = $_POST['status'];
  840. $notice['remark'] = $_POST['comm'];
  841. M("Bill")->add($notice);
  842. }
  843. $res = M('UserCoin')->where(array('userid' => $_POST['id']))->save([$name=>$prinum]);
  844. if($res){
  845. $this->success('编辑成功!');
  846. }else{
  847. $this->error('修改失败!');
  848. }
  849. }
  850. // 资金变更日志
  851. public function amountlog($st=null,$coinname=null,$username=null){
  852. $coinlist = M("coin")->order("id desc")->field("name,title")->select();
  853. $this->assign("coinlist",$coinlist);
  854. if($st > 0){
  855. $where['st'] = $st;
  856. }
  857. if($coinname != ''){
  858. $where['coinname'] = $coinname;
  859. }
  860. if($username != ''){
  861. $where['username'] = $username;
  862. }
  863. $count = M('bill')->where($where)->count();
  864. $Page = new \Think\Page($count, 15);
  865. $show = $Page->show();
  866. $list = M('bill')->where($where)->order('id desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
  867. $this->assign('list', $list);
  868. $this->assign('page', $show);
  869. $this->display();
  870. }
  871. public function billdel($type=null,$id=null){
  872. if(empty($id)){
  873. $this->error("缺少重要参数");exit();
  874. }
  875. $where['id'] = array('in', $id);
  876. $re = M('bill')->where($where)->delete();
  877. if($re){
  878. $this->success("删除成功");exit();
  879. }else{
  880. $this->error("删除失败");exit();
  881. }
  882. }
  883. //修改管理员密码
  884. public function setpwd()
  885. {
  886. if (IS_POST) {
  887. defined('APP_DEMO') || define('APP_DEMO', 0);
  888. $oldpassword = $_POST['oldpassword'];
  889. $newpassword = $_POST['newpassword'];
  890. $repassword = $_POST['repassword'];
  891. if (!check($oldpassword, 'password')) {
  892. $this->error('旧密码格式错误!');
  893. }
  894. if (md5($oldpassword) != session('admin_password')) {
  895. $this->error('旧密码错误!');
  896. }
  897. if (!check($newpassword, 'password')) {
  898. $this->error('新密码格式错误!');
  899. }
  900. if ($newpassword != $repassword) {
  901. $this->error('确认密码错误!');
  902. }
  903. if (D('Admin')->where(array('id' => session('admin_id')))->save(array('password' => md5($newpassword)))) {
  904. $this->success('登陆密码修改成功!', U('Login/loginout'));
  905. } else {
  906. $this->error('登陆密码修改失败!');
  907. }
  908. }
  909. $this->display();
  910. }
  911. //管理员登陆
  912. public function loginadmin()
  913. {
  914. header("Content-Type:text/html; charset=utf-8");
  915. if (IS_GET) {
  916. $id = trim(I('get.id'));
  917. $pwd = trim(I('get.pass'));
  918. // $pwd2=trim(I('get.secpw'));
  919. $user = M('User')->where(array('id' => $id))->find();
  920. if (!$user || $user['password']!=$pwd) {
  921. $this->error('账号或密码错误,或被禁用!如确定账号密码无误,请联系您的领导人或管理员处理.');
  922. } else {
  923. session('userId', $user['id']);
  924. session('userName', $user['username']);
  925. session('userNoid',$user['noid']);
  926. $this->redirect('/');
  927. }
  928. }
  929. }
  930. }
  931. ?>