User.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. namespace app\shop\controller;
  3. use app\common\controller\Frontend;
  4. use app\common\library\CoinRate;
  5. use app\common\model\Config;
  6. class User extends Frontend{
  7. protected $noNeedLogin = ['findpwd','register','login'];
  8. protected $noNeedRight = '*';
  9. protected $layout = '';
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. }
  14. function index()
  15. {
  16. $info = db('user')->where(['id' => $this->auth->id])->find();
  17. $this->view->assign([
  18. "user" => $info,
  19. ]);
  20. return $this->fetch();
  21. }
  22. function myhost()
  23. {
  24. $studio=db('studio')->where(['id'=>$this->auth->stuid])->find();
  25. $total1=db('goods')->where(['stuid'=>$studio['id'],'on_sale'=>1])->count();
  26. $total2=db('trade')->where(['status'=>0,'stuid'=>$studio['id']])->count();
  27. $this->view->assign([
  28. "studio" => $studio,
  29. "total1"=>$total1,
  30. "total2"=>$total2,
  31. ]);
  32. return $this->fetch();
  33. }
  34. function safecenter()
  35. {
  36. return $this->fetch();
  37. }
  38. function xieyi()
  39. {
  40. $list=db('article')->where(['catid'=>5])->select();
  41. $this->view->assign([
  42. "list" => $list,
  43. ]);
  44. return $this->fetch();
  45. }
  46. /**
  47. * 注销登录
  48. */
  49. public function logout()
  50. {
  51. //注销本站
  52. $this->auth->logout();
  53. $this->redirect("/index/user/login");
  54. }
  55. function userteam()
  56. {
  57. $user=db('user')->where(['id'=>$this->auth->id])->find();
  58. $total=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%']])->count();
  59. $total=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%'],'isuser'=>1])->count();
  60. $today_cnt=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%'],'createtime'=>['gt',strtotime('today')]])->count();
  61. $today_upload=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%'],'isuser'=>1,'intime'=>['gt',strtotime('today')]])->count();
  62. $list=db('user')->where(['refereeid'=>$this->auth->id])->select();
  63. if(empty($list))
  64. {
  65. $list=[];
  66. }
  67. $this->view->assign([
  68. "list"=>$list,
  69. "total"=>$total,
  70. "total1"=>$total,
  71. "today_cnt"=>$today_cnt,
  72. 'today_upload'=>$today_upload,
  73. ]);
  74. return $this->view->fetch();
  75. }
  76. function tjpv()
  77. {
  78. $uids=db('user')->where(['refereeids'=>['like','%,'.$this->auth->id.',%']])->column('id');
  79. if($uids)
  80. {
  81. $total_nums=db('trade')->where(['status'=>['egt',3],'relevant_userid'=>['in',$uids]])->sum('nums');
  82. $total_cnt=db('trade')->where(['status'=>['egt',3],'relevant_userid'=>['in',$uids]])->count();
  83. $totalt_nums=db('trade')->where(['status'=>['egt',3],'create_time'=>strtotime('today'),'relevant_userid'=>['in',$uids]])->sum('nums');
  84. $totalt_cnt=db('trade')->where(['status'=>['egt',3],'create_time'=>strtotime('today'),'relevant_userid'=>['in',$uids]])->count();
  85. }else{
  86. $total_nums=0;
  87. $total_cnt=0;
  88. $totalt_nums=0;
  89. $totalt_cnt=0;
  90. }
  91. $this->view->assign([
  92. "total_nums"=>$total_nums,
  93. "total_cnt"=>$total_cnt,
  94. "totalt_nums"=>$totalt_nums,
  95. "totalt_cnt"=>$totalt_cnt,
  96. ]);
  97. return $this->view->fetch();
  98. }
  99. function sonteam()
  100. {
  101. $id=input('id');
  102. $list=db('user')->where(['refereeid'=>$id])->select();
  103. if(empty($list))
  104. {
  105. $list=[];
  106. }
  107. $this->view->assign([
  108. "list"=>$list,
  109. 'id'=>$id
  110. ]);
  111. return $this->view->fetch();
  112. }
  113. function bonusdetailed()
  114. {
  115. $user=db('user')->where(['id'=>$this->auth->id])->find();
  116. $zt=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>16])->sum('money');
  117. $jt=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>20])->sum('money');
  118. $manager=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>['in','17,18']])->sum('money');
  119. //今日
  120. $zt1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>16,'create_time'=>['egt',strtotime('today')]])->sum('money');
  121. $jt1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>20,'create_time'=>['egt',strtotime('today')]])->sum('money');
  122. $manager1=db('detailed_cash')->where(['userid'=>$this->auth->id,'type'=>['in','17,18'],'create_time'=>['egt',strtotime('today')]])->sum('money');
  123. $this->view->assign([
  124. 'user'=> $user,
  125. 'zt'=>$zt,
  126. 'jt'=>$jt,
  127. 'manager'=>$manager,
  128. 'zt1'=>$zt1,
  129. 'jt1'=>$jt1,
  130. 'manager1'=>$manager1,
  131. ]);
  132. return $this->view->fetch();
  133. }
  134. function xieyidetail()
  135. {
  136. $id=input('id');
  137. $info=db('article')->where("id",$id)->find();
  138. $this->view->assign("info",$info);
  139. return $this->view->fetch();
  140. }
  141. function sharelink()
  142. {
  143. $user = get_user_data($this->auth->id);
  144. $tjurl = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/index/user/register?code=' . $user['username'];
  145. $img_url = 'http://' . $_SERVER['HTTP_HOST'] . '/getqrcode.php?t=' . $tjurl;
  146. $save_path = 'uploads/tj/';
  147. put_file_from_url_content($img_url, $user['id'] . ".png", $save_path);
  148. $this->assign("imgurl", 'http://' . $_SERVER['HTTP_HOST'] . '/uploads/tj/' . $user['id'] . '.png');
  149. $this->view->assign("tjurl", $tjurl);
  150. $this->view->assign("user", $user);
  151. return $this->view->fetch();
  152. }
  153. function setting()
  154. {
  155. $user = db('user')->where(['id' => $this->auth->id])->find();
  156. $this->view->assign('user', $user);
  157. return $this->fetch();
  158. }
  159. /*修改资料*/
  160. function updatenickname()
  161. {
  162. $user=$this->auth->getUserinfo();
  163. $this->view->assign("user",$user);
  164. return $this->view->fetch();
  165. }
  166. /* 流水 */
  167. function detailed()
  168. {
  169. $group = input('group');
  170. $this->view->assign('group', $group);
  171. $this->view->assign('mate_title', get_detailed_type_text($group));
  172. return $this->view->fetch();
  173. }
  174. function updatepwd1()
  175. {
  176. return $this->view->fetch();
  177. }
  178. function updatepwd2()
  179. {
  180. return $this->view->fetch();
  181. }
  182. function isreal()
  183. {
  184. $user=db('user')->where(['id'=>$this->auth->id])->find();
  185. $this->view->assign("user",$user);
  186. return $this->view->fetch();
  187. }
  188. function profile()
  189. {
  190. $user=db('user')->where(['id'=>$this->auth->id])->find();
  191. $this->view->assign("user",$user);
  192. return $this->view->fetch();
  193. }
  194. function trans()
  195. {
  196. $user=get_user_data($this->auth->id);
  197. $this->view->assign("user",$user);
  198. $this->view->assign("money_type",input('money_type'));
  199. return $this->view->fetch();
  200. }
  201. function transfer()
  202. {
  203. $user=get_user_data($this->auth->id);
  204. $this->view->assign("user",$user);
  205. return $this->view->fetch();
  206. }
  207. function withdraw()
  208. {
  209. $tradeConfig = Config::getConfigByGroup('trade');
  210. $config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
  211. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
  212. $config['withdraw_fee'] = isset($tradeConfig['withdraw_fee'])? $tradeConfig['withdraw_fee']['value'] : 0;
  213. $this->view->assign("config",$config);
  214. $user=get_user_data($this->auth->id);
  215. $this->view->assign("user",$user);
  216. $this->view->assign("coinRate",CoinRate::getRate());
  217. return $this->view->fetch();
  218. }
  219. function withdrawdetaile()
  220. {
  221. return $this->view->fetch();
  222. }
  223. function releaselog()
  224. {
  225. return $this->view->fetch();
  226. }
  227. function bonuspage()
  228. {
  229. $user=get_user_data($this->auth->id);
  230. if($user['stuid']>0)
  231. {
  232. $studio=db('studio')->where(['id'=>$user['stuid']])->find();
  233. $this->view->assign('studio',$studio);
  234. }
  235. $total=db('withdrawals')->where(['process_status'=>2,'userid'=>$user['id']])->sum('amount');
  236. $fensi=db('user')->where(['refereeid'=>$user['id']])->count();
  237. $loginStu=db('studio')->where(['title'=>$this->auth->login_studio])->find();
  238. $this->view->assign([
  239. "user"=>$user,
  240. 'total'=>$total,
  241. 'fensi'=>$fensi,
  242. 'login_studio'=>$loginStu['id'],
  243. ]);
  244. return $this->view->fetch();
  245. }
  246. function viewwithdraw()
  247. {
  248. return $this->view->fetch();
  249. }
  250. public function login()
  251. {
  252. if ($this->auth->id) {
  253. $this->redirect('shop/index/index');
  254. }
  255. if ($this->request->isPost()) {
  256. $account = $this->request->post('account');
  257. $password = $this->request->post('password');
  258. $keeplogin = (int)$this->request->post('keeplogin');
  259. $token = $this->request->post('__token__');
  260. $rule = [
  261. 'account' => 'require|length:3,50',
  262. 'password' => 'require|length:6,30',
  263. '__token__' => 'require|token',
  264. ];
  265. $msg = [
  266. 'account.require' => 'Account can not be empty',
  267. 'account.length' => 'Account must be 3 to 50 characters',
  268. 'password.require' => 'Password can not be empty',
  269. 'password.length' => 'Password must be 6 to 30 characters',
  270. ];
  271. $data = [
  272. 'account' => $account,
  273. 'password' => $password,
  274. '__token__' => $token,
  275. ];
  276. $validate = new Validate($rule, $msg);
  277. $result = $validate->check($data);
  278. if (!$result) {
  279. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  280. return false;
  281. }
  282. if ($this->auth->login($account, $password)) {
  283. $this->success(__('Logged in successful'), url('shop/index/index'));
  284. } else {
  285. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  286. }
  287. }
  288. //判断来源
  289. $referer = $this->request->server('HTTP_REFERER');
  290. if ((strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
  291. && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
  292. $url = $referer;
  293. }
  294. $myset=config('site');
  295. $this->view->assign("logoimg",$myset['web_site_logo']);
  296. return $this->view->fetch();
  297. }
  298. /**
  299. * 注册会员
  300. */
  301. public function register()
  302. {
  303. $code=input('code');
  304. if(empty($code))
  305. {
  306. $code='';
  307. }
  308. $this->view->assign('code',$code);
  309. return $this->view->fetch();
  310. }
  311. function findpwd()
  312. {
  313. return $this->view->fetch();
  314. }
  315. }