User.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. $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. $user['usdt_address_text'] = $user['usdt_address']? substr($user['usdt_address'],0,4).'***'.substr($user['usdt_address'],-4,4) : '';
  216. $this->view->assign("user",$user);
  217. $this->view->assign("coinRate",CoinRate::getRate());
  218. return $this->view->fetch();
  219. }
  220. /**
  221. * 佣金提现
  222. * @return string
  223. * @throws \think\Exception
  224. * @throws \think\db\exception\DataNotFoundException
  225. * @throws \think\db\exception\ModelNotFoundException
  226. * @throws \think\exception\DbException
  227. */
  228. function withdraw1()
  229. {
  230. $tradeConfig = Config::getConfigByGroup('trade');
  231. $config['withdraw_min'] = isset($tradeConfig['withdraw_min'])? $tradeConfig['withdraw_min']['value'] : 0;
  232. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap'])? $tradeConfig['withdraw_cap']['value'] : 0;
  233. $config['withdraw_fee'] = isset($tradeConfig['withdraw_fee'])? $tradeConfig['withdraw_fee']['value'] : 0;
  234. $this->view->assign("config",$config);
  235. $user=get_user_data($this->auth->id);
  236. $this->view->assign("user",$user);
  237. $this->view->assign("coinRate",CoinRate::getRate());
  238. return $this->view->fetch();
  239. }
  240. function withdrawdetaile()
  241. {
  242. return $this->view->fetch();
  243. }
  244. function withdrawdetaile1()
  245. {
  246. return $this->view->fetch();
  247. }
  248. function releaselog()
  249. {
  250. return $this->view->fetch();
  251. }
  252. function bonuspage()
  253. {
  254. $user=get_user_data($this->auth->id);
  255. if($user['stuid']>0)
  256. {
  257. $studio=db('studio')->where(['id'=>$user['stuid']])->find();
  258. $this->view->assign('studio',$studio);
  259. }
  260. $total=db('withdrawals')->where(['process_status'=>2,'userid'=>$user['id']])->sum('amount');
  261. $fensi=db('user')->where(['refereeid'=>$user['id']])->count();
  262. $loginStu=db('studio')->where(['title'=>$this->auth->login_studio])->find();
  263. $this->view->assign([
  264. "user"=>$user,
  265. 'total'=>$total,
  266. 'fensi'=>$fensi,
  267. 'login_studio'=>$loginStu['id'],
  268. ]);
  269. return $this->view->fetch();
  270. }
  271. function viewwithdraw()
  272. {
  273. return $this->view->fetch();
  274. }
  275. public function login()
  276. {
  277. if ($this->auth->id) {
  278. $this->redirect('shop/index/index');
  279. }
  280. if ($this->request->isPost()) {
  281. $account = $this->request->post('account');
  282. $password = $this->request->post('password');
  283. $keeplogin = (int)$this->request->post('keeplogin');
  284. $token = $this->request->post('__token__');
  285. $rule = [
  286. 'account' => 'require|length:3,50',
  287. 'password' => 'require|length:6,30',
  288. '__token__' => 'require|token',
  289. ];
  290. $msg = [
  291. 'account.require' => 'Account can not be empty',
  292. 'account.length' => 'Account must be 3 to 50 characters',
  293. 'password.require' => 'Password can not be empty',
  294. 'password.length' => 'Password must be 6 to 30 characters',
  295. ];
  296. $data = [
  297. 'account' => $account,
  298. 'password' => $password,
  299. '__token__' => $token,
  300. ];
  301. $validate = new Validate($rule, $msg);
  302. $result = $validate->check($data);
  303. if (!$result) {
  304. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  305. return false;
  306. }
  307. if ($this->auth->login($account, $password)) {
  308. $this->success(__('Logged in successful'), url('shop/index/index'));
  309. } else {
  310. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  311. }
  312. }
  313. //判断来源
  314. $referer = $this->request->server('HTTP_REFERER');
  315. if ((strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
  316. && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
  317. $url = $referer;
  318. }
  319. $myset=config('site');
  320. $this->view->assign("logoimg",$myset['web_site_logo']);
  321. return $this->view->fetch();
  322. }
  323. /**
  324. * 注册会员
  325. */
  326. public function register()
  327. {
  328. $code=input('code');
  329. if(empty($code))
  330. {
  331. $code='';
  332. }
  333. $this->view->assign('code',$code);
  334. return $this->view->fetch();
  335. }
  336. function findpwd()
  337. {
  338. return $this->view->fetch();
  339. }
  340. }