User.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. {
  8. protected $noNeedLogin = ['findpwd', 'register', 'login'];
  9. protected $noNeedRight = '*';
  10. protected $layout = '';
  11. public function _initialize()
  12. {
  13. parent::_initialize();
  14. }
  15. function index()
  16. {
  17. $info = db('user')->where(['id' => $this->auth->id])->find();
  18. $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find();
  19. $stuid = isset($loginStu['id'])? $loginStu['id'] : 0;
  20. $counts = [
  21. 'status1'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>1,'stuid'=>$stuid])->count('id'),
  22. 'status2'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>2,'stuid'=>$stuid])->count('id'),
  23. 'status3'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>3,'issell'=>[['egt',0],['elt',2]],'stuid'=>$stuid])->count('id'),
  24. ];
  25. $this->view->assign('counts', $counts);
  26. $this->view->assign([
  27. "user" => $info,
  28. ]);
  29. return $this->fetch();
  30. }
  31. function myhost()
  32. {
  33. $studio = db('studio')->where(['id' => $this->auth->stuid])->find();
  34. $total1 = db('goods')->where(['stuid' => $studio['id'], 'on_sale' => 1, 'on_resale' => 2])->count();
  35. $total2 = db('trade')->where(['status' => 0, 'stuid' => $studio['id']])->count();
  36. $this->view->assign([
  37. "studio" => $studio,
  38. "total1" => $total1,
  39. "total2" => $total2,
  40. ]);
  41. return $this->fetch();
  42. }
  43. function safecenter()
  44. {
  45. return $this->fetch();
  46. }
  47. function xieyi()
  48. {
  49. $list = db('article')->where(['catid' => 5])->select();
  50. $this->view->assign([
  51. "list" => $list,
  52. ]);
  53. return $this->fetch();
  54. }
  55. /**
  56. * 注销登录
  57. */
  58. public function logout()
  59. {
  60. //注销本站
  61. $this->auth->logout();
  62. $this->redirect("/index/user/login");
  63. }
  64. function userteam()
  65. {
  66. $user = db('user')->where(['id' => $this->auth->id])->find();
  67. $total = db('user')->where(['refereeids' => ['like', '%,' . $this->auth->id . ',%'], 'status' => 1])->count();
  68. $total1 = db('user')->where(['refereeids' => ['like', '%,' . $this->auth->id . ',%'], 'isuser' => 1, 'status' => 1])->count();
  69. $today_cnt = db('user')->where(['refereeids' => ['like', '%,' . $this->auth->id . ',%'], 'createtime' => ['gt', strtotime('today')], 'status' => 1])->count();
  70. $today_upload = db('user')->where(['refereeids' => ['like', '%,' . $this->auth->id . ',%'], 'isuser' => 1, 'intime' => ['gt', strtotime('today')], 'status' => 1])->count();
  71. $list = db('user')->where(['refereeid' => $this->auth->id, 'status' => 1])->select();
  72. if (empty($list)) {
  73. $list = [];
  74. }
  75. $this->view->assign([
  76. "list" => $list,
  77. "total" => $total,
  78. "total1" => $total1,
  79. "today_cnt" => $today_cnt,
  80. 'today_upload' => $today_upload,
  81. ]);
  82. return $this->view->fetch();
  83. }
  84. function tjpv()
  85. {
  86. $config = Config::getConfigByGroup('trade');
  87. $releaseRate = isset($config['release_rate'])? floatval($config['release_rate']['value']) : 0;
  88. $this->view->assign('release_rate', $releaseRate);
  89. return $this->fetch();
  90. }
  91. function tjpv1()
  92. {
  93. $uids = db('user')->where(['refereeids' => ['like', '%,' . $this->auth->id . ',%']])->column('id');
  94. if ($uids) {
  95. $total_nums = db('trade')->where(['status' => ['egt', 3], 'relevant_userid' => ['in', $uids]])->sum('nums');
  96. $total_cnt = db('trade')->where(['status' => ['egt', 3], 'relevant_userid' => ['in', $uids]])->count();
  97. $totalt_nums = db('trade')->where(['status' => ['egt', 3], 'create_time' => strtotime('today'), 'relevant_userid' => ['in', $uids]])->sum('nums');
  98. $totalt_cnt = db('trade')->where(['status' => ['egt', 3], 'create_time' => strtotime('today'), 'relevant_userid' => ['in', $uids]])->count();
  99. } else {
  100. $total_nums = 0;
  101. $total_cnt = 0;
  102. $totalt_nums = 0;
  103. $totalt_cnt = 0;
  104. }
  105. $this->view->assign([
  106. "total_nums" => $total_nums,
  107. "total_cnt" => $total_cnt,
  108. "totalt_nums" => $totalt_nums,
  109. "totalt_cnt" => $totalt_cnt,
  110. ]);
  111. return $this->view->fetch();
  112. }
  113. function sonteam()
  114. {
  115. $id = input('id');
  116. $list = db('user')->where(['refereeid' => $id])->select();
  117. if (empty($list)) {
  118. $list = [];
  119. }
  120. $this->view->assign([
  121. "list" => $list,
  122. 'id' => $id
  123. ]);
  124. return $this->view->fetch();
  125. }
  126. function bonusdetailed()
  127. {
  128. $user = db('user')->where(['id' => $this->auth->id])->find();
  129. $zt = db('detailed_cash')->where(['userid' => $this->auth->id, 'type' => 16])->sum('money');
  130. $jt = db('detailed_cash')->where(['userid' => $this->auth->id, 'type' => 20])->sum('money');
  131. $manager = db('detailed_cash')->where(['userid' => $this->auth->id, 'type' => ['in', '17,18']])->sum('money');
  132. //今日
  133. $zt1 = db('detailed_cash')->where(['userid' => $this->auth->id, 'type' => 16, 'create_time' => ['egt', strtotime('today')]])->sum('money');
  134. $jt1 = db('detailed_cash')->where(['userid' => $this->auth->id, 'type' => 20, 'create_time' => ['egt', strtotime('today')]])->sum('money');
  135. $manager1 = db('detailed_cash')->where(['userid' => $this->auth->id, 'type' => ['in', '17,18'], 'create_time' => ['egt', strtotime('today')]])->sum('money');
  136. $this->view->assign([
  137. 'user' => $user,
  138. 'zt' => $zt,
  139. 'jt' => $jt,
  140. 'manager' => $manager,
  141. 'zt1' => $zt1,
  142. 'jt1' => $jt1,
  143. 'manager1' => $manager1,
  144. ]);
  145. return $this->view->fetch();
  146. }
  147. function xieyidetail()
  148. {
  149. $id = input('id');
  150. $info = db('article')->where("id", $id)->find();
  151. $this->view->assign("info", $info);
  152. return $this->view->fetch();
  153. }
  154. function sharelink()
  155. {
  156. $user = get_user_data($this->auth->id);
  157. $tjurl = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/index/user/register?code=' . $user['username'];
  158. $img_url = 'http://' . $_SERVER['HTTP_HOST'] . '/getqrcode.php?t=' . $tjurl;
  159. $save_path = 'uploads/tj/';
  160. put_file_from_url_content($img_url, $user['id'] . ".png", $save_path);
  161. $this->assign("imgurl", 'http://' . $_SERVER['HTTP_HOST'] . '/uploads/tj/' . $user['id'] . '.png');
  162. $myset = \app\common\model\Config::getConfigByGroup('Iindex');
  163. $this->view->assign("shareBg", $myset['share_bg']['value']);
  164. $this->view->assign("tjurl", $tjurl);
  165. $this->view->assign("user", $user);
  166. return $this->view->fetch();
  167. }
  168. /**
  169. * 推广素材
  170. * @return string
  171. * @throws \think\Exception
  172. * @throws \think\db\exception\DataNotFoundException
  173. * @throws \think\db\exception\ModelNotFoundException
  174. * @throws \think\exception\DbException
  175. */
  176. function material()
  177. {
  178. $lists = db('material')->where(['status' => 1])
  179. ->order('create_time desc,id desc')
  180. ->limit(100)
  181. ->select();
  182. if ($lists) {
  183. foreach ($lists as &$item) {
  184. $item['images'] = $item['images'] ? explode(',', $item['images']) : [];
  185. }
  186. }
  187. $this->view->assign("lists", $lists);
  188. return $this->view->fetch();
  189. }
  190. function setting()
  191. {
  192. $user = db('user')->where(['id' => $this->auth->id])->find();
  193. $this->view->assign('user', $user);
  194. return $this->fetch();
  195. }
  196. /**
  197. * 联系我们
  198. * @return mixed
  199. */
  200. function aboutus()
  201. {
  202. $config = Config::getConfigByGroup('basic');
  203. $about = isset($config['site_about']) ? htmlspecialchars_decode($config['site_about']['value']) : '';
  204. $this->view->assign('about', $about);
  205. return $this->fetch();
  206. }
  207. /*修改资料*/
  208. function updatenickname()
  209. {
  210. $user = $this->auth->getUserinfo();
  211. $this->view->assign("user", $user);
  212. return $this->view->fetch();
  213. }
  214. /* 流水 */
  215. function detailed()
  216. {
  217. $group = input('group');
  218. $this->view->assign('group', $group);
  219. $this->view->assign('mate_title', get_detailed_type_text($group));
  220. return $this->view->fetch();
  221. }
  222. function updatepwd1()
  223. {
  224. return $this->view->fetch();
  225. }
  226. function updatepwd2()
  227. {
  228. return $this->view->fetch();
  229. }
  230. function isreal()
  231. {
  232. $user = db('user')->where(['id' => $this->auth->id])->find();
  233. $this->view->assign("user", $user);
  234. return $this->view->fetch();
  235. }
  236. function profile()
  237. {
  238. $user = db('user')->where(['id' => $this->auth->id])->find();
  239. $this->view->assign("user", $user);
  240. return $this->view->fetch();
  241. }
  242. function trans()
  243. {
  244. $user = get_user_data($this->auth->id);
  245. $this->view->assign("user", $user);
  246. $this->view->assign("money_type", input('money_type'));
  247. return $this->view->fetch();
  248. }
  249. function transfer()
  250. {
  251. $user = get_user_data($this->auth->id);
  252. $this->view->assign("user", $user);
  253. return $this->view->fetch();
  254. }
  255. function withdraw()
  256. {
  257. $tradeConfig = Config::getConfigByGroup('trade');
  258. $config['withdraw_min'] = isset($tradeConfig['withdraw_min']) ? $tradeConfig['withdraw_min']['value'] : 0;
  259. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap']) ? $tradeConfig['withdraw_cap']['value'] : 0;
  260. $config['withdraw_fee'] = isset($tradeConfig['withdraw_fee']) ? $tradeConfig['withdraw_fee']['value'] : 0;
  261. $this->view->assign("config", $config);
  262. $user = get_user_data($this->auth->id);
  263. $user['usdt_address_text'] = $user['usdt_address'] ? substr($user['usdt_address'], 0, 4) . '***' . substr($user['usdt_address'], -4, 4) : '';
  264. $this->view->assign("user", $user);
  265. $this->view->assign("coinRate", CoinRate::getRate());
  266. return $this->view->fetch();
  267. }
  268. /**
  269. * 佣金提现
  270. * @return string
  271. * @throws \think\Exception
  272. * @throws \think\db\exception\DataNotFoundException
  273. * @throws \think\db\exception\ModelNotFoundException
  274. * @throws \think\exception\DbException
  275. */
  276. function withdraw1()
  277. {
  278. $tradeConfig = Config::getConfigByGroup('trade');
  279. $config['withdraw_min'] = isset($tradeConfig['withdraw_min']) ? $tradeConfig['withdraw_min']['value'] : 0;
  280. $config['withdraw_cap'] = isset($tradeConfig['withdraw_cap']) ? $tradeConfig['withdraw_cap']['value'] : 0;
  281. $config['withdraw_fee'] = isset($tradeConfig['withdraw_bonus_fee']) ? $tradeConfig['withdraw_bonus_fee']['value'] : 0;
  282. $this->view->assign("config", $config);
  283. $user = get_user_data($this->auth->id);
  284. $this->view->assign("user", $user);
  285. $this->view->assign("coinRate", CoinRate::getRate());
  286. return $this->view->fetch();
  287. }
  288. function withdrawdetaile()
  289. {
  290. return $this->view->fetch();
  291. }
  292. function withdrawdetaile1()
  293. {
  294. return $this->view->fetch();
  295. }
  296. function releaselog()
  297. {
  298. return $this->view->fetch();
  299. }
  300. function bonuspage()
  301. {
  302. $user = get_user_data($this->auth->id);
  303. if ($user['stuid'] > 0) {
  304. $studio = db('studio')->where(['id' => $user['stuid']])->find();
  305. $this->view->assign('studio', $studio);
  306. }
  307. $total = db('withdrawals')->where(['process_status' => 2, 'userid' => $user['id']])->sum('amount');
  308. $fensi = db('user')->where(['refereeid' => $user['id']])->count();
  309. //var_dump($user);
  310. $loginStu = db('studio')->where(['title' => $this->auth->login_studio])->find();
  311. $stuid = isset($loginStu['id'])? $loginStu['id'] : 0;
  312. $counts = [
  313. 'status1'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>1,'stuid'=>$stuid])->count('id'),
  314. 'status2'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>2,'stuid'=>$stuid])->count('id'),
  315. 'status3'=> db('trade')->where(['relevant_userid'=>$this->auth->id,'status'=>3,'issell'=>[['egt',0],['elt',2]],'stuid'=>$stuid])->count('id'),
  316. ];
  317. $this->view->assign('counts', $counts);
  318. $this->view->assign([
  319. "user" => $user,
  320. 'total' => $total,
  321. 'fensi' => $fensi,
  322. 'studio' => $loginStu,
  323. 'login_studio' => $this->auth->login_studio,
  324. ]);
  325. return $this->view->fetch();
  326. }
  327. function viewwithdraw()
  328. {
  329. return $this->view->fetch();
  330. }
  331. public function login()
  332. {
  333. if ($this->auth->id) {
  334. $this->redirect('shop/index/index');
  335. }
  336. if ($this->request->isPost()) {
  337. $account = $this->request->post('account');
  338. $password = $this->request->post('password');
  339. $keeplogin = (int)$this->request->post('keeplogin');
  340. $token = $this->request->post('__token__');
  341. $rule = [
  342. 'account' => 'require|length:3,50',
  343. 'password' => 'require|length:6,30',
  344. '__token__' => 'require|token',
  345. ];
  346. $msg = [
  347. 'account.require' => 'Account can not be empty',
  348. 'account.length' => 'Account must be 3 to 50 characters',
  349. 'password.require' => 'Password can not be empty',
  350. 'password.length' => 'Password must be 6 to 30 characters',
  351. ];
  352. $data = [
  353. 'account' => $account,
  354. 'password' => $password,
  355. '__token__' => $token,
  356. ];
  357. $validate = new Validate($rule, $msg);
  358. $result = $validate->check($data);
  359. if (!$result) {
  360. $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
  361. return false;
  362. }
  363. if ($this->auth->login($account, $password)) {
  364. $this->success(__('Logged in successful'), url('shop/index/index'));
  365. } else {
  366. $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
  367. }
  368. }
  369. //判断来源
  370. $referer = $this->request->server('HTTP_REFERER');
  371. if ((strtolower(parse_url($referer, PHP_URL_HOST)) == strtolower($this->request->host()))
  372. && !preg_match("/(user\/login|user\/register|user\/logout)/i", $referer)) {
  373. $url = $referer;
  374. }
  375. $myset = config('site');
  376. $this->view->assign("logoimg", $myset['web_site_logo']);
  377. return $this->view->fetch();
  378. }
  379. /**
  380. * 注册会员
  381. */
  382. public function register()
  383. {
  384. $code = input('code');
  385. if (empty($code)) {
  386. $code = '';
  387. }
  388. $this->view->assign('code', $code);
  389. return $this->view->fetch();
  390. }
  391. function findpwd()
  392. {
  393. return $this->view->fetch();
  394. }
  395. }