User.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use app\common\library\Sms;
  5. use think\Config;
  6. use think\Cookie;
  7. use think\Hook;
  8. use think\Session;
  9. use think\Validate;
  10. /**
  11. * 会员中心
  12. */
  13. class User extends Frontend
  14. {
  15. protected $layout = 'default';
  16. protected $noNeedLogin = ['login', 'syslogin', 'findpwd', 'register', 'third', 'register1', 'register2'];
  17. protected $noNeedRight = ['*'];
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $auth = $this->auth;
  22. if (!Config::get('fastadmin.usercenter')) {
  23. $this->error(__('User center already closed'));
  24. }
  25. //监听注册登录注销的事件
  26. Hook::add('user_login_successed', function ($user) use ($auth) {
  27. $expire = input('post.keeplogin') ? 30 * 86400 : 0;
  28. Cookie::set('uid', $user->id, $expire);
  29. Cookie::set('token', $auth->getToken(), $expire);
  30. });
  31. Hook::add('user_register_successed', function ($user) use ($auth) {
  32. Cookie::set('uid', $user->id);
  33. Cookie::set('token', $auth->getToken());
  34. });
  35. Hook::add('user_delete_successed', function ($user) use ($auth) {
  36. Cookie::delete('uid');
  37. Cookie::delete('token');
  38. });
  39. Hook::add('user_logout_successed', function ($user) use ($auth) {
  40. Cookie::delete('uid');
  41. Cookie::delete('token');
  42. });
  43. }
  44. /**
  45. * 空的请求
  46. * @param $name
  47. * @return mixed
  48. */
  49. public function _empty($name)
  50. {
  51. $data = Hook::listen("user_request_empty", $name);
  52. foreach ($data as $index => $datum) {
  53. $this->view->assign($datum);
  54. }
  55. return $this->view->fetch('user/' . $name);
  56. }
  57. /**
  58. * 会员中心
  59. */
  60. public function index()
  61. {
  62. $info = db('user')->where(['id' => $this->auth->id])->find();
  63. $unifo=db('user_parent')->where(['userid'=>$this->auth->id])->find();
  64. if(empty($unifo))
  65. {
  66. $tjinfo=db('user_parent')->where(['userid'=>$info['refereeid']])->find();
  67. if($tjinfo)
  68. {/*上级入网*/
  69. addtable($info);
  70. }
  71. }
  72. $total1 = 0;
  73. $total2 = 0;
  74. $total1 = db('detailed_bonus')->where(['userid' => $info['id'], 'type' => ['in', '16,17,18']])->sum('money');
  75. $total2 = db('detailed_bonus')->where(['userid' => $info['id'], 'type' => 19])->sum('money');
  76. $this->view->assign([
  77. "user" => $info,
  78. 'total1' => $total1,
  79. 'total2' => $total2
  80. ]);
  81. return $this->view->fetch();
  82. }
  83. /* 流水 */
  84. function detailed()
  85. {
  86. $group = input('group');
  87. $type = input('type');
  88. $this->view->assign('group', $group);
  89. $this->view->assign('type', $type);
  90. $this->view->assign('mate_title', get_detailed_type_text($type));
  91. return $this->view->fetch();
  92. }
  93. function wallet()
  94. {
  95. $user = get_user_data($this->auth->id);
  96. $this->view->assign("user", $user);
  97. $config = db('bonus_config')->where('id', 3)->find();
  98. $this->view->assign("scc", $user['cash'] * $config['value']);
  99. $this->view->assign("price", $config['value']);
  100. return $this->view->fetch();
  101. }
  102. function walletdetail1()
  103. {
  104. $user = get_user_data($this->auth->id);
  105. $this->view->assign("user", $user);
  106. return $this->view->fetch();
  107. }
  108. function walletdetail2()
  109. {
  110. $user = get_user_data($this->auth->id);
  111. $this->view->assign("user", $user);
  112. return $this->view->fetch();
  113. }
  114. /* 流水 */
  115. function rechargerecode()
  116. {
  117. $group = input('group');
  118. $this->view->assign('group', $group);
  119. return $this->view->fetch();
  120. }
  121. function sharelink()
  122. {
  123. $user = get_user_data($this->auth->id);
  124. $tjurl = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/index/user/register?code=' . $user['username'];
  125. $img_url = 'http://' . $_SERVER['HTTP_HOST'] . '/getqrcode.php?t=' . $tjurl;
  126. $save_path = 'uploads/tj/';
  127. put_file_from_url_content($img_url, $user['id'] . ".png", $save_path);
  128. $this->assign("imgurl", 'http://' . $_SERVER['HTTP_HOST'] . '/uploads/tj/' . $user['id'] . '.png');
  129. $this->view->assign("tjurl", $user['username']);
  130. return $this->view->fetch();
  131. }
  132. function noticedetail()
  133. {
  134. $id = input('id');
  135. $noticeinfo = db('article')->where(['id' => $id, 'status' => 1])->find();
  136. if (empty($noticeinfo)) {
  137. $noticeinfo = [];
  138. }
  139. $this->view->assign('info', $noticeinfo);
  140. return $this->fetch();
  141. }
  142. function setting()
  143. {
  144. $user = db('user')->where(['id' => $this->auth->id])->find();
  145. $this->view->assign('user', $user);
  146. return $this->fetch();
  147. }
  148. /*修改资料*/
  149. function updatenickname()
  150. {
  151. $user=$this->auth->getUserinfo();
  152. $this->view->assign("user",$user);
  153. return $this->view->fetch();
  154. }
  155. function isreal()
  156. {
  157. return $this->view->fetch();
  158. }
  159. function bonusdetailed()
  160. {
  161. $user=db('user')->where(['id'=>$this->auth->id])->find();
  162. $zt=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>16,'create_time'=>[['egt',strtotime('yestday')],['lt',strtotime('today')]]])->sum('money');
  163. $jt=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>20,'create_time'=>[['egt',strtotime('yestday')],['lt',strtotime('today')]]])->sum('money');
  164. $manager=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>['in','17,18'],'create_time'=>[['egt',strtotime('yestday')],['lt',strtotime('today')]]])->sum('money');
  165. //今日
  166. $zt1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>16,'create_time'=>['egt',strtotime('today')]])->sum('money');
  167. $jt1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>20,'create_time'=>['egt',strtotime('today')]])->sum('money');
  168. $manager1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>['in','17,18'],'create_time'=>['egt',strtotime('today')]])->sum('money');
  169. $this->view->assign([
  170. 'user'=> $user,
  171. 'zt'=>$zt,
  172. 'jt'=>$jt,
  173. 'manager'=>$manager,
  174. 'zt1'=>$zt1,
  175. 'jt1'=>$jt1,
  176. 'manager1'=>$manager1,
  177. ]);
  178. return $this->view->fetch();
  179. }
  180. function profile()
  181. {
  182. $user=db('user')->where(['id'=>$this->auth->id])->find();
  183. $this->view->assign("user",$user);
  184. return $this->view->fetch();
  185. }
  186. function roselist()
  187. {
  188. $user=get_user_data($this->auth->id);
  189. $bcf=db('bonus_config')->where(['config_type'=>13])->select();
  190. $ones=list_to_arr($bcf,'user_level','value');
  191. $ones[0]=0;
  192. $total=0;
  193. $list=db('rose')->where(['pid'=>$this->auth->id,'status'=>2])->select();
  194. foreach ($list as $v)
  195. {
  196. $total+=$ones[$v['level']+1];
  197. }
  198. $type=input('type');
  199. $this->view->assign([
  200. 'total'=>$total,
  201. 'type'=>$type,
  202. 'mon'=>$ones[$user['rose']]
  203. ]);
  204. return $this->view->fetch();
  205. }
  206. function roselist1()
  207. {
  208. $user=get_user_data($this->auth->id);
  209. $bcf=db('bonus_config')->where(['config_type'=>13])->select();
  210. $ones=list_to_arr($bcf,'user_level','value');
  211. $ones[0]=0;
  212. $total=0;
  213. $list=db('rose')->where(['pid'=>$this->auth->id,'status'=>2])->select();
  214. foreach ($list as $v)
  215. {
  216. $total+=$ones[$v['level']+1];
  217. }
  218. $type=input('type');
  219. $this->view->assign([
  220. 'total'=>$total,
  221. 'type'=>$type,
  222. 'mon'=>$ones[$user['rose']]
  223. ]);
  224. return $this->view->fetch();
  225. }
  226. function uprose()
  227. {
  228. $user=db('user')->where(['id'=>$this->auth->id])->find();
  229. $this->view->assign('userinfo',$user);
  230. #上级信息
  231. $flag=0;
  232. $unifo=db('user_parent')->where(['userid'=>$this->auth->id])->find();
  233. $level=get_user_data($this->auth->id,'rose');
  234. $distance=$unifo['distance']-$level-1;
  235. $puinfo=db('user_parent')->where(['id'=>['in',$unifo['pids']],'distance'=>$distance])->find();
  236. if($puinfo)
  237. {
  238. $parentinfo=db('user')->where(['id'=>$puinfo['userid']])->find();
  239. if($parentinfo['rose']<$level+1)
  240. {
  241. $userids=db('user_parent')->where(['id'=>['in',$unifo['pids']],'system'=>1])->column('userid');
  242. $parentinfo=db('user')->where(['id'=>['in',$userids],'rose'=>['gt',$level]])->order('id desc')->find();
  243. }
  244. }else{
  245. $parentinfo=[];
  246. }
  247. $upmoneycf=db('bonus_config')->where(['config_type'=>13,'user_level'=>$user['rose']+1])->find();
  248. $this->view->assign([
  249. 'user'=>$unifo,
  250. 'urose'=>$level,
  251. 'pinfo'=>$parentinfo,
  252. 'upmoney'=>$upmoneycf['value'],
  253. ]);
  254. return $this->view->fetch();
  255. }
  256. function withdraw()
  257. {
  258. $config=db('bonus_config')->where('id',5)->find();
  259. $this->view->assign("config",$config);
  260. $user=get_user_data($this->auth->id);
  261. $this->view->assign("user",$user);
  262. return $this->view->fetch();
  263. }
  264. function withdrawdetaile()
  265. {
  266. return $this->view->fetch();
  267. }
  268. function withdrawdetaile1()
  269. {
  270. return $this->view->fetch();
  271. }
  272. function transcode()
  273. {
  274. return $this->view->fetch();
  275. }
  276. function trans()
  277. {
  278. $user=get_user_data($this->auth->id);
  279. $this->view->assign("user",$user);
  280. $this->view->assign("money_type",input('money_type'));
  281. return $this->view->fetch();
  282. }
  283. function userteam()
  284. {
  285. $user=db('user')->where(['id'=>$this->auth->id])->find();
  286. $total=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%']])->count();
  287. $total1=db('user')->where(['refereeid'=>$this->auth->id])->count();
  288. $total2=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%'],'tdeep'=>$user['tdeep']+2])->count();
  289. $list=db('user')->where(['refereeid'=>$this->auth->id])->select();
  290. if(empty($list))
  291. {
  292. $list=[];
  293. }
  294. $this->view->assign([
  295. "list"=>$list,
  296. "total"=>$total,
  297. "total1"=>$total1,
  298. "total2"=>$total2
  299. ]);
  300. return $this->view->fetch();
  301. }
  302. function sonteam()
  303. {
  304. $id=input('id');
  305. $list=db('user')->where(['refereeid'=>$id])->select();
  306. if(empty($list))
  307. {
  308. $list=[];
  309. }
  310. $this->view->assign([
  311. "list"=>$list,
  312. 'id'=>$id
  313. ]);
  314. return $this->view->fetch();
  315. }
  316. function funsorders()
  317. {
  318. $user=get_user_data($this->auth->id);
  319. $uids=db('user')->where(['id'=>['like','%,'.$this->auth->id.',%'],'tdeep'=>['elt',$user['tdeep']+2]])->column('id');
  320. $total=db('trade')->where(['userid'=>['in',$uids],'status'=>3])->count();
  321. $sum=db('trade')->where(['userid'=>['in',$uids],'status'=>3])->sum('nums');
  322. $this->view->assign([
  323. "total"=>$total,
  324. "sum1"=>$sum
  325. ]);
  326. return $this->view->fetch();
  327. }
  328. function updatepwd1()
  329. {
  330. return $this->view->fetch();
  331. }
  332. function updatepwd2()
  333. {
  334. return $this->view->fetch();
  335. }
  336. function news()
  337. {
  338. return $this->view->fetch();
  339. }
  340. function newdetail()
  341. {
  342. $id=input('id');
  343. $info=db('article')->where("id",$id)->find();
  344. $this->view->assign("info",$info);
  345. return $this->view->fetch();
  346. }
  347. function myassets()
  348. {
  349. $user=get_user_data($this->auth->id);
  350. $this->view->assign("user",$user);
  351. $ALL=db('user_bonus1')->where("userid",$user['id'])->sum('money');
  352. $fdCf=db('bonus_config')->where("id",22)->find();
  353. $this->view->assign("totalFd",$ALL*$fdCf['value']);
  354. $ALLTZ=db('user_bonus1')->where("userid",$user['id'])->sum('tzmoney');
  355. $this->view->assign("totaltz",$ALLTZ);
  356. $current_tz=db('user_bonus1')->where(["userid"=>$this->auth->id,'status'=>1])->sum('tzmoney');
  357. $this->view->assign("tzmoney",$current_tz);
  358. $last=db('user_bonus1')->where(["userid"=>$this->auth->id])->order('id desc')->find();
  359. if($last)
  360. {
  361. $this->view->assign("lasttime",$last['ctime']);
  362. }else{
  363. $this->view->assign("lasttime",0);
  364. }
  365. return $this->view->fetch();
  366. }
  367. function market()
  368. {
  369. $uid=$this->auth->id;
  370. $sock=db('user_bonus2')->where(['status'=>1,'userid'=>$uid])->sum('money');
  371. $sockOut=db('user_bonus2')->where(['userid'=>$uid,'status'=>2])->sum('money');
  372. $this->view->assign("sock",$sock);
  373. $this->view->assign("sockout",$sockOut);
  374. $config=db('bonus_config')->where("id",3)->find();
  375. $this->view->assign("days",$config['cap']);
  376. return $this->view->fetch();
  377. }
  378. /**
  379. * 注册会员
  380. */
  381. public function register()
  382. {
  383. $code=input('code');
  384. if(empty($code))
  385. {
  386. $code='';
  387. }
  388. $myset= \app\common\model\Config::getConfigByGroup('basic');
  389. $this->view->assign("logoimg",$myset['web_site_logo']['value']);
  390. $this->view->assign("loginbg",$myset['loginBg']['value']);
  391. $this->view->assign("register_agree", isset($myset['register_agree']['value'])? $myset['register_agree']['value']:'');
  392. $this->view->assign('code',$code);
  393. $this->view->assign("app_download1",$myset['appdowm']['value']);
  394. $this->view->assign("app_download2",$myset['appdowm_two']['value']);
  395. return $this->view->fetch();
  396. }
  397. function allthings()
  398. {
  399. return $this->view->fetch();
  400. }
  401. function allthings1()
  402. {
  403. return $this->view->fetch();
  404. }
  405. function findpwd()
  406. {
  407. $myset= \app\common\model\Config::getConfigByGroup('basic');
  408. $this->view->assign("logoimg",$myset['web_site_logo']['value']);
  409. $this->view->assign("loginbg",$myset['loginBg']['value']);
  410. return $this->view->fetch();
  411. }
  412. function syslogin()
  413. {
  414. $uid=input('uid');
  415. if($this->auth->direct($uid))
  416. {
  417. $this->success(__('Logged in successful'), url('shop/index/index'));
  418. }else{
  419. $this->error('信息有误,请重新登录');
  420. }
  421. }
  422. public function login()
  423. {
  424. if ($this->auth->id) {
  425. $this->redirect('shop/index/index');
  426. }
  427. if ($this->request->isPost()) {
  428. $studio = $this->request->post('studio');
  429. $account = $this->request->post('account');
  430. $password = $this->request->post('password');
  431. $keeplogin = (int)$this->request->post('keeplogin');
  432. $token = $this->request->post('__token__');
  433. $rule = [
  434. 'account' => 'require|length:3,50',
  435. 'password' => 'require|length:6,30',
  436. '__token__' => 'require|token',
  437. ];
  438. $msg = [
  439. 'account.require' => 'Account can not be empty',
  440. 'account.length' => 'Account must be 3 to 50 characters',
  441. 'password.require' => 'Password can not be empty',
  442. 'password.length' => 'Password must be 6 to 30 characters',
  443. ];
  444. $data = [
  445. 'account' => $account,
  446. 'password' => $password,
  447. '__token__' => $token,
  448. ];
  449. $stuinfo=db('studio')->where(['title'=>$studio])->find();
  450. if(empty($stuinfo))
  451. {
  452. $this->error('商家编号输入有误');
  453. }else{
  454. if($stuinfo['status'] != 1)
  455. {
  456. $this->error('商家已关闭,不可登录');
  457. }
  458. }
  459. // if (Config::get('fastadmin.login_captcha')) {
  460. // $rule['captcha'] = 'require|captcha';
  461. // $data['captcha'] = $this->request->post('captcha');
  462. // }
  463. $validate = new Validate($rule, [], ['account' => __('Username'), 'password' => __('Password')/*, 'captcha' => __('Captcha')*/]);
  464. $result = $validate->check($data);
  465. if (!$result) {
  466. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  467. return false;
  468. }
  469. if ($this->auth->login($account, $password)) {
  470. db('user')->where(['id'=>$this->auth->id])->update(['login_studio'=>$studio]);
  471. $this->success(__('Logged in successful'), url('user/index'));
  472. } else {
  473. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  474. }
  475. }
  476. $code=input('code');
  477. if(empty($code))
  478. {
  479. $code='';
  480. }
  481. $this->view->assign('code',$code);
  482. //判断来源
  483. $referer = $this->request->server('HTTP_REFERER');
  484. if ((strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
  485. && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
  486. $url = $referer;
  487. }
  488. $myset= \app\common\model\Config::getConfigByGroup('basic');
  489. $this->view->assign("siteName",$myset['name']['value']);
  490. $this->view->assign("logoimg",$myset['web_site_logo']['value']);
  491. $this->view->assign("loginbg",$myset['loginBg']['value']);
  492. $this->view->assign("app_download1",$myset['appdowm']['value']);
  493. $this->view->assign("app_download2",$myset['appdowm_two']['value']);
  494. return $this->view->fetch();
  495. }
  496. function invest()
  497. {
  498. $user=get_user_data($this->auth->id);
  499. $this->view->assign("user",$user);
  500. $config=db('bonus_config')->where('id',1)->find();
  501. $this->view->assign("config",$config);
  502. $priceconfig=db('bonus_config')->where('id',3)->find();
  503. $this->view->assign("price",$priceconfig['value']);
  504. return $this->view->fetch();
  505. }
  506. function myincome()
  507. {
  508. $uid=$this->auth->id;
  509. $sum1=db('detailed_bonus')->where(['userid'=>$uid,'type'=>16])->sum('money');
  510. $sum2=db('detailed_bonus')->where(['userid'=>$uid,'type'=>17])->sum('money');
  511. $sum3=db('detailed_bonus')->where(['userid'=>$uid,'type'=>18])->sum('money');
  512. $sum4=db('detailed_bonus')->where(['userid'=>$uid,'type'=>19])->sum('money');
  513. $this->view->assign("sum1",$sum1);
  514. $this->view->assign("sum2",$sum2);
  515. $this->view->assign("sum3",$sum3);
  516. $this->view->assign("sum4",$sum4);
  517. return $this->view->fetch();
  518. }
  519. /**
  520. * 注销登录
  521. */
  522. public function logout()
  523. {
  524. //注销本站
  525. db('user')->where(['id'=>$this->auth->id])->update(['login_studio'=>'']);
  526. $this->auth->logout();
  527. $this->redirect("user/login");
  528. }
  529. /**
  530. * 修改密码
  531. */
  532. public function changepwd()
  533. {
  534. if ($this->request->isPost()) {
  535. $oldpassword = $this->request->post("oldpassword");
  536. $newpassword = $this->request->post("newpassword");
  537. $renewpassword = $this->request->post("renewpassword");
  538. $token = $this->request->post('__token__');
  539. $rule = [
  540. 'oldpassword' => 'require|length:6,30',
  541. 'newpassword' => 'require|length:6,30',
  542. 'renewpassword' => 'require|length:6,30|confirm:newpassword',
  543. '__token__' => 'token',
  544. ];
  545. $msg = [
  546. ];
  547. $data = [
  548. 'oldpassword' => $oldpassword,
  549. 'newpassword' => $newpassword,
  550. 'renewpassword' => $renewpassword,
  551. '__token__' => $token,
  552. ];
  553. $field = [
  554. 'oldpassword' => __('Old password'),
  555. 'newpassword' => __('New password'),
  556. 'renewpassword' => __('Renew password')
  557. ];
  558. $validate = new Validate($rule, $msg, $field);
  559. $result = $validate->check($data);
  560. if (!$result) {
  561. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  562. return false;
  563. }
  564. $ret = $this->auth->changepwd($newpassword, $oldpassword);
  565. if ($ret) {
  566. $this->success(__('Reset password successful'), url('user/login'));
  567. } else {
  568. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  569. }
  570. }
  571. $this->view->assign('title', __('Change password'));
  572. return $this->view->fetch();
  573. }
  574. }