User.php 13 KB

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