User.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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,'on_resale'=>2])->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. $myset= \app\common\model\Config::getConfigByGroup('Iindex');
  150. $this->view->assign("shareBg",$myset['share_bg']['value']);
  151. $this->view->assign("tjurl", $tjurl);
  152. $this->view->assign("user", $user);
  153. return $this->view->fetch();
  154. }
  155. function material(){
  156. $lists = [];
  157. $this->view->assign("lists", $lists);
  158. return $this->view->fetch();
  159. }
  160. function setting()
  161. {
  162. $user = db('user')->where(['id' => $this->auth->id])->find();
  163. $this->view->assign('user', $user);
  164. return $this->fetch();
  165. }
  166. /**
  167. * 联系我们
  168. * @return mixed
  169. */
  170. function aboutus(){
  171. return $this->fetch();
  172. }
  173. /*修改资料*/
  174. function updatenickname()
  175. {
  176. $user=$this->auth->getUserinfo();
  177. $this->view->assign("user",$user);
  178. return $this->view->fetch();
  179. }
  180. /* 流水 */
  181. function detailed()
  182. {
  183. $group = input('group');
  184. $this->view->assign('group', $group);
  185. $this->view->assign('mate_title', get_detailed_type_text($group));
  186. return $this->view->fetch();
  187. }
  188. function updatepwd1()
  189. {
  190. return $this->view->fetch();
  191. }
  192. function updatepwd2()
  193. {
  194. return $this->view->fetch();
  195. }
  196. function isreal()
  197. {
  198. $user=db('user')->where(['id'=>$this->auth->id])->find();
  199. $this->view->assign("user",$user);
  200. return $this->view->fetch();
  201. }
  202. function profile()
  203. {
  204. $user=db('user')->where(['id'=>$this->auth->id])->find();
  205. $this->view->assign("user",$user);
  206. return $this->view->fetch();
  207. }
  208. function trans()
  209. {
  210. $user=get_user_data($this->auth->id);
  211. $this->view->assign("user",$user);
  212. $this->view->assign("money_type",input('money_type'));
  213. return $this->view->fetch();
  214. }
  215. function transfer()
  216. {
  217. $user=get_user_data($this->auth->id);
  218. $this->view->assign("user",$user);
  219. return $this->view->fetch();
  220. }
  221. function withdraw()
  222. {
  223. $tradeConfig = Config::getConfigByGroup('trade');
  224. $config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
  225. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
  226. $config['withdraw_fee'] = isset($tradeConfig['withdraw_fee'])? $tradeConfig['withdraw_fee']['value'] : 0;
  227. $this->view->assign("config",$config);
  228. $user=get_user_data($this->auth->id);
  229. $user['usdt_address_text'] = $user['usdt_address']? substr($user['usdt_address'],0,4).'***'.substr($user['usdt_address'],-4,4) : '';
  230. $this->view->assign("user",$user);
  231. $this->view->assign("coinRate",CoinRate::getRate());
  232. return $this->view->fetch();
  233. }
  234. /**
  235. * 佣金提现
  236. * @return string
  237. * @throws \think\Exception
  238. * @throws \think\db\exception\DataNotFoundException
  239. * @throws \think\db\exception\ModelNotFoundException
  240. * @throws \think\exception\DbException
  241. */
  242. function withdraw1()
  243. {
  244. $tradeConfig = Config::getConfigByGroup('trade');
  245. $config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
  246. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
  247. $config['withdraw_fee'] = isset($tradeConfig['withdraw_bonus_fee'])? $tradeConfig['withdraw_bonus_fee']['value'] : 0;
  248. $this->view->assign("config",$config);
  249. $user=get_user_data($this->auth->id);
  250. $this->view->assign("user",$user);
  251. $this->view->assign("coinRate",CoinRate::getRate());
  252. return $this->view->fetch();
  253. }
  254. function withdrawdetaile()
  255. {
  256. return $this->view->fetch();
  257. }
  258. function withdrawdetaile1()
  259. {
  260. return $this->view->fetch();
  261. }
  262. function releaselog()
  263. {
  264. return $this->view->fetch();
  265. }
  266. function bonuspage()
  267. {
  268. $user=get_user_data($this->auth->id);
  269. if($user['stuid']>0)
  270. {
  271. $studio=db('studio')->where(['id'=>$user['stuid']])->find();
  272. $this->view->assign('studio',$studio);
  273. }
  274. $total=db('withdrawals')->where(['process_status'=>2,'userid'=>$user['id']])->sum('amount');
  275. $fensi=db('user')->where(['refereeid'=>$user['id']])->count();
  276. //var_dump($user);
  277. $loginStu=db('studio')->where(['title'=>$this->auth->login_studio])->find();
  278. $this->view->assign([
  279. "user"=>$user,
  280. 'total'=>$total,
  281. 'fensi'=>$fensi,
  282. 'studio'=>$loginStu,
  283. 'login_studio'=> $this->auth->login_studio,
  284. ]);
  285. return $this->view->fetch();
  286. }
  287. function viewwithdraw()
  288. {
  289. return $this->view->fetch();
  290. }
  291. public function login()
  292. {
  293. if ($this->auth->id) {
  294. $this->redirect('shop/index/index');
  295. }
  296. if ($this->request->isPost()) {
  297. $account = $this->request->post('account');
  298. $password = $this->request->post('password');
  299. $keeplogin = (int)$this->request->post('keeplogin');
  300. $token = $this->request->post('__token__');
  301. $rule = [
  302. 'account' => 'require|length:3,50',
  303. 'password' => 'require|length:6,30',
  304. '__token__' => 'require|token',
  305. ];
  306. $msg = [
  307. 'account.require' => 'Account can not be empty',
  308. 'account.length' => 'Account must be 3 to 50 characters',
  309. 'password.require' => 'Password can not be empty',
  310. 'password.length' => 'Password must be 6 to 30 characters',
  311. ];
  312. $data = [
  313. 'account' => $account,
  314. 'password' => $password,
  315. '__token__' => $token,
  316. ];
  317. $validate = new Validate($rule, $msg);
  318. $result = $validate->check($data);
  319. if (!$result) {
  320. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  321. return false;
  322. }
  323. if ($this->auth->login($account, $password)) {
  324. $this->success(__('Logged in successful'), url('shop/index/index'));
  325. } else {
  326. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  327. }
  328. }
  329. //判断来源
  330. $referer = $this->request->server('HTTP_REFERER');
  331. if ((strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
  332. && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
  333. $url = $referer;
  334. }
  335. $myset=config('site');
  336. $this->view->assign("logoimg",$myset['web_site_logo']);
  337. return $this->view->fetch();
  338. }
  339. /**
  340. * 注册会员
  341. */
  342. public function register()
  343. {
  344. $code=input('code');
  345. if(empty($code))
  346. {
  347. $code='';
  348. }
  349. $this->view->assign('code',$code);
  350. return $this->view->fetch();
  351. }
  352. function findpwd()
  353. {
  354. return $this->view->fetch();
  355. }
  356. }