User.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. <?php
  2. namespace app\index\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Request;
  6. use login\ThinkOauth;
  7. use app\index\event\LoginEvent;
  8. use app\common\util\Qrcode;
  9. class User extends Base
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. define('THIRD_LOGIN_CALLBACK', $GLOBALS['http_type'] . $_SERVER['HTTP_HOST'] . '/index.php/user/logincallback/type/');
  15. //判断用户登录状态
  16. $ac = request()->action();
  17. $guestAllowedActions = ['login', 'logout', 'ajax_login', 'reg', 'findpass', 'findpass_msg', 'findpass_reset', 'reg_msg', 'oauth', 'logincallback', 'visit', 'index', 'ajax_upgrade'];
  18. $guestAllowedGetActions = ['buy', 'plays', 'upgrade', 'checkin'];
  19. if (in_array($ac, $guestAllowedActions) || (in_array($ac, $guestAllowedGetActions) && !Request()->isPost())) {
  20. // 游客可访问的页面也注入 obj,避免模板判断分支缺少变量
  21. $this->assign('obj', $GLOBALS['user']);
  22. } else {
  23. if ($GLOBALS['user']['user_id'] < 1) {
  24. model('User')->logout();
  25. redirect(url('user/login'))->send();
  26. exit;
  27. }
  28. $this->assign('obj', $GLOBALS['user']);
  29. }
  30. }
  31. public function ajax_login()
  32. {
  33. return $this->fetch('user/ajax_login');
  34. }
  35. public function ajax_info()
  36. {
  37. return $this->fetch('user/ajax_info');
  38. }
  39. public function ajax_ulog()
  40. {
  41. $param = input();
  42. if ($param['ac'] == 'set') {
  43. $data = [];
  44. $data['ulog_mid'] = intval($param['mid']);
  45. $data['ulog_rid'] = intval($param['id']);
  46. $data['ulog_type'] = intval($param['type']);
  47. $data['ulog_sid'] = intval($param['sid']);
  48. $data['ulog_nid'] = intval($param['nid']);
  49. $data['user_id'] = $GLOBALS['user']['user_id'];
  50. if ($data['ulog_mid'] == 1 && $data['ulog_type'] > 3) {
  51. $where2 = [];
  52. $where2['vod_id'] = $data['ulog_rid'];
  53. $res = model('Vod')->infoData($where2);
  54. if ($res['code'] > 1) {
  55. return $res;
  56. }
  57. $flag = $data['ulog_type'] == 4 ? 'play' : 'down';
  58. $data['ulog_points'] = $res['info']['vod_points_' . $flag];
  59. }
  60. $data['ulog_points'] = intval($data['ulog_points']);
  61. $res = model('Ulog')->infoData($data);
  62. if ($res['code'] == 1) {
  63. $r = model('Ulog')->where($data)->update(['ulog_time'=>time()]);
  64. return json($res);
  65. }
  66. if ($data['ulog_points'] == 0) {
  67. $res = model('Ulog')->saveData($data);
  68. } else {
  69. $res = ['code' => 2001, 'msg' => lang('index/ulog_fee')];
  70. }
  71. } else {
  72. $where = [];
  73. $where['user_id'] = $GLOBALS['user']['user_id'];
  74. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  75. $param['limit'] = intval($param['limit']) < 1 ? 10 : intval($param['limit']);
  76. if(intval($param['mid'])>0){
  77. $where['ulog_mid'] = ['eq',intval($param['mid'])];
  78. }
  79. if(intval($param['id'])>0){
  80. $where['ulog_rid'] = ['eq',intval($param['id'])];
  81. }
  82. if(intval($param['type'])>0){
  83. $where['ulog_type'] = ['eq',intval($param['type'])];
  84. }
  85. $order = 'ulog_time desc';
  86. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  87. }
  88. return json($res);
  89. }
  90. public function ajax_buy_popedom()
  91. {
  92. $param = input();
  93. $data = [];
  94. $data['ulog_mid'] = intval($param['mid']) <=0 ? 1: intval($param['mid']);
  95. $data['ulog_rid'] = intval($param['id']);
  96. $data['ulog_sid'] = intval($param['sid']);
  97. $data['ulog_nid'] = intval($param['nid']);
  98. if (!in_array($param['mid'], ['1','2','12']) || !in_array($param['type'], ['1','4','5']) || empty($data['ulog_rid']) ) {
  99. return json(['code' => 2001, 'msg' => lang('param_err')]);
  100. }
  101. $data['ulog_type'] = $param['type'];
  102. $data['user_id'] = $GLOBALS['user']['user_id'];
  103. $where = [];
  104. if($param['mid']=='12'){
  105. // 漫画购买(扣费额与 check_user_popedom 一致)
  106. $where['manga_id'] = $data['ulog_rid'];
  107. $res = model('Manga')->infoData($where);
  108. if ($res['code'] > 1) {
  109. return json([$res]);
  110. }
  111. $data['ulog_points'] = mac_content_read_points_amount('manga', $res['info']);
  112. if($GLOBALS['config']['user']['manga_points_type']=='1'){
  113. $data['ulog_sid']=0;
  114. $data['ulog_nid']=0;
  115. }
  116. }
  117. elseif($param['type']=='1'){
  118. // 文章购买
  119. $where['art_id'] = $data['ulog_rid'];
  120. $res = model('Art')->infoData($where);
  121. if ($res['code'] > 1) {
  122. return json([$res]);
  123. }
  124. $data['ulog_points'] = mac_content_read_points_amount('art', $res['info']);
  125. if($GLOBALS['config']['user']['art_points_type']=='1'){
  126. $data['ulog_sid']=0;
  127. $data['ulog_nid']=0;
  128. }
  129. }
  130. else{
  131. // 视频播放/下载购买
  132. $where['vod_id'] = $data['ulog_rid'];
  133. $res = model('Vod')->infoData($where);
  134. if ($res['code'] > 1) {
  135. return json([$res]);
  136. }
  137. $col = 'vod_points_' . ($param['type'] == '4' ? 'play' : 'down');
  138. if($GLOBALS['config']['user']['vod_points_type']=='1'){
  139. $col='vod_points';
  140. $data['ulog_sid']=0;
  141. $data['ulog_nid']=0;
  142. }
  143. $data['ulog_points'] = intval($res['info'][$col]);
  144. }
  145. $res = model('Ulog')->infoData($data);
  146. if ($res['code'] == 1) {
  147. return json(['code' => 1, 'msg' => lang('index/buy_popedom1')]);
  148. }
  149. if ($data['ulog_points'] > $GLOBALS['user']['user_points']) {
  150. return json(['code' => 2002, 'msg' => lang('index/buy_popedom3',[$data['ulog_points'],$GLOBALS['user']['user_points']])]);
  151. }
  152. // 使用事务 + 条件更新防止并发刷积分
  153. Db::startTrans();
  154. try {
  155. // 带条件的原子扣除:只有积分足够时才扣除
  156. $affected = Db::name('user')
  157. ->where('user_id', $GLOBALS['user']['user_id'])
  158. ->where('user_points', '>=', $data['ulog_points'])
  159. ->setDec('user_points', $data['ulog_points']);
  160. if ($affected === 0 || $affected === false) {
  161. Db::rollback();
  162. return json(['code' => 2002, 'msg' => lang('index/buy_popedom3',[$data['ulog_points'],$GLOBALS['user']['user_points']])]);
  163. }
  164. //积分日志
  165. $data2 = [];
  166. $data2['user_id'] = $GLOBALS['user']['user_id'];
  167. $data2['plog_type'] = 8;
  168. $data2['plog_points'] = $data['ulog_points'];
  169. model('Plog')->saveData($data2);
  170. //分销日志
  171. model('User')->reward($data['ulog_points']);
  172. $res = model('Ulog')->saveData($data);
  173. Db::commit();
  174. return json($res);
  175. } catch (\Exception $e) {
  176. Db::rollback();
  177. return json(['code' => 2003, 'msg' => lang('index/buy_popedom2')]);
  178. }
  179. }
  180. public function index()
  181. {
  182. return $this->fetch('user/index');
  183. }
  184. public function login()
  185. {
  186. if (Request()->isPost()) {
  187. $param = input();
  188. $res = model('User')->login($param);
  189. return json($res);
  190. }
  191. if (!empty(cookie('user_id') && !empty(cookie('user_name')))) {
  192. return redirect('user/index');
  193. }
  194. return $this->fetch('user/login');
  195. }
  196. public function logout()
  197. {
  198. $res = model('User')->logout();
  199. if (request()->isAjax()) {
  200. return json($res);
  201. } else {
  202. return redirect('user/login');
  203. }
  204. }
  205. public function oauth($type = '')
  206. {
  207. empty($type) && $this->error(lang('param_err'));
  208. //加载ThinkOauth类并实例化一个对象
  209. $sns = ThinkOauth::getInstance($type);
  210. //跳转到授权页面
  211. $this->redirect($sns->getRequestCodeURL());
  212. }
  213. //授权回调地址
  214. public function logincallback($type = '', $code = '')
  215. {
  216. if (empty($type) || empty($code)) {
  217. return $this->error(lang('param_err'));
  218. }
  219. //加载ThinkOauth类并实例化一个对象
  220. $sns = ThinkOauth::getInstance($type);
  221. $extend = null;
  222. //请妥善保管这里获取到的Token信息,方便以后API调用
  223. $token = $sns->getAccessToken($code, $extend);
  224. //获取当前登录用户信息
  225. if (is_array($token)) {
  226. $loginEvent = new LoginEvent();
  227. $res = $loginEvent->$type($token);
  228. if ($res['code'] == 1) {
  229. $openid = $res['info']['openid'];
  230. $col = 'user_openid_' . $type;
  231. //如果已登录,是否需要重新绑定
  232. $check = model('User')->checkLogin();
  233. if ($check['code'] == 1) {
  234. if ($check['info'][$col] == $openid) {
  235. //无需再次绑定
  236. return json(['code' => 1001, 'msg' => lang('index/bind_haved')]);
  237. } else {
  238. //解除原有绑定
  239. $where = [];
  240. $where[$col] = $openid;
  241. $update = [];
  242. $update[$col] = '';
  243. model('User')->where($where)->update($update);
  244. //新绑定
  245. $where = [];
  246. $where['user_id'] = $GLOBALS['user']['user_id'];
  247. $update = [];
  248. $update[$col] = $openid;
  249. model('User')->where($where)->update($update);
  250. return json(['code' => 1, 'msg' => lang('index/bind_ok')]);
  251. }
  252. }
  253. $where = [];
  254. $where[$col] = $openid;
  255. $res2 = model('User')->infoData($where);
  256. //未绑定的需要先创建用户并绑定
  257. if ($res2['code'] > 1) {
  258. $data = [];
  259. $data['user_name'] = substr($openid, 0, 10);
  260. $data['user_nick_name'] = htmlspecialchars(urldecode(trim($res['info']['name'])));
  261. $pwd = time();
  262. $data['user_pwd'] = $pwd;
  263. $data['user_pwd2'] = $pwd;
  264. $data[$col] = $openid;
  265. $reg = model('User')->register($data);
  266. if ($reg['code'] > 1) {
  267. //注册失败
  268. return $this->error(lang('index/logincallback1'));
  269. }
  270. }
  271. //直接登录。。。
  272. $login = model('User')->login(['col' => $col, 'openid' => $openid]);
  273. if ($login['code'] > 1) {
  274. return $this->error($login['msg']);
  275. }
  276. $this->redirect('user/index');
  277. } else {
  278. return $this->error($res['msg']);
  279. }
  280. } else {
  281. return $this->error(lang('index/logincallback2'));
  282. }
  283. }
  284. public function bindmsg()
  285. {
  286. $param = input();
  287. $res = model('User')->bindmsg($param);
  288. return json($res);
  289. }
  290. public function bind()
  291. {
  292. $param = input();
  293. if (Request()->isPost()) {
  294. $res = model('User')->bind($param);
  295. return json($res);
  296. }
  297. if (empty($param['ac'])) {
  298. $param['ac'] = 'email';
  299. }
  300. $ac = $param['ac'] === 'phone' ? 'phone' : 'email';
  301. $bind_readonly = ($ac === 'email' && !empty($GLOBALS['user']['user_email']))
  302. || ($ac === 'phone' && !empty($GLOBALS['user']['user_phone']));
  303. $this->assign('ac', $ac);
  304. $this->assign('bind_readonly', $bind_readonly ? 1 : 0);
  305. $this->assign('param', $param);
  306. return $this->fetch('user/bind');
  307. }
  308. public function unbind()
  309. {
  310. $param = input();
  311. if (Request()->isPost()) {
  312. $res = model('User')->unbind($param);
  313. return json($res);
  314. }
  315. $this->assign('param',$param);
  316. return $this->fetch('user/unbind');
  317. }
  318. public function info()
  319. {
  320. $param = input();
  321. if (Request()->isPost()) {
  322. $res = model('User')->info($param);
  323. if ($res['code'] == 1) {
  324. $this->success($res['msg']);
  325. exit;
  326. }
  327. $this->error($res['msg']);
  328. exit;
  329. }
  330. $this->assign('param',$param);
  331. return $this->fetch('user/info');
  332. }
  333. public function regcheck()
  334. {
  335. $param = input();
  336. $t = htmlspecialchars(urldecode(trim($param['t'])));
  337. $str = htmlspecialchars(urldecode(trim($param['str'])));
  338. $res = model('User')->regcheck($t, $str);
  339. if ($res['code'] > 1) {
  340. return $str;
  341. }
  342. return json($res);
  343. }
  344. public function reg()
  345. {
  346. $param = input();
  347. if (Request()->isPost()) {
  348. if (!empty(cookie('uid'))) {
  349. $param['uid'] = intval(cookie('uid'));
  350. }
  351. $res = model('User')->register($param);
  352. if ($res['code'] > 1) {
  353. return json($res);
  354. }
  355. $GLOBALS['config']['user']['login_verify'] = '0';
  356. $res = model('User')->login($param);
  357. $res['msg'] = lang('index/reg_ok').',' . $res['msg'];
  358. return json($res);
  359. }
  360. if (!empty($param['uid'])) {
  361. cookie('uid', $param['uid']);
  362. }
  363. $user_config = $GLOBALS['config']['user'];
  364. $this->assign('user_config', $user_config);
  365. $this->assign('param', $param);
  366. return $this->fetch('user/reg');
  367. }
  368. public function reg_msg()
  369. {
  370. $param = input();
  371. $res = model('User')->reg_msg($param);
  372. return json($res);
  373. }
  374. public function portrait()
  375. {
  376. if(request()->isPost()){
  377. if ($GLOBALS['config']['user']['portrait_status'] == 0) {
  378. return json(['code' => 0, 'msg' => lang('index/portrait_tip1')]);
  379. }
  380. $param=[];
  381. $param['input'] = 'file';
  382. $param['flag'] = 'user';
  383. $param['user_id'] = $GLOBALS['user']['user_id'];
  384. $res = model('Upload')->upload($param);
  385. return json($res);
  386. }
  387. return $this->fetch('user/portrait');
  388. }
  389. public function findpass()
  390. {
  391. $param = input();
  392. if (Request()->isPost()) {
  393. $res = model('User')->findpass($param);
  394. return json($res);
  395. }
  396. $this->assign('param',$param);
  397. return $this->fetch('user/findpass');
  398. }
  399. public function findpass_msg()
  400. {
  401. $param = input();
  402. if (Request()->isPost()) {
  403. $res = model('User')->findpass_msg($param);
  404. return json($res);
  405. }
  406. $param['ac_text'] = $param['ac'] == 'phone' ? lang('mobile') : lang('email');
  407. $this->assign('param', $param);
  408. return $this->fetch('user/findpass_msg');
  409. }
  410. public function findpass_reset()
  411. {
  412. if (Request()->isPost()) {
  413. $param = input();
  414. $res = model('User')->findpass_reset($param);
  415. return json($res);
  416. }
  417. }
  418. public function buy()
  419. {
  420. $param = input();
  421. if (Request()->isPost()) {
  422. $flag = input('param.flag');
  423. if ($flag == 'card') {
  424. $card_no = htmlspecialchars(urldecode(trim($param['card_no'])));
  425. $card_pwd = htmlspecialchars(urldecode(trim($param['card_pwd'])));
  426. $res = model('Card')->useData($card_no, $card_pwd, $GLOBALS['user']);
  427. return json($res);
  428. } else {
  429. $price = input('param.price');
  430. if (empty($price)) {
  431. return json(['code' => 1001, 'msg' => lang('param_err')]);
  432. }
  433. if ($price < $GLOBALS['config']['pay']['min']) {
  434. return json(['code' => 1002, 'msg' =>lang('index/min_pay',[$GLOBALS['config']['pay']['min']])]);
  435. }
  436. $data = [];
  437. $data['user_id'] = $GLOBALS['user']['user_id'];
  438. $data['order_code'] = 'PAY' . mac_get_uniqid_code();
  439. $data['order_price'] = $price;
  440. $data['order_time'] = time();
  441. $data['order_points'] = intval($GLOBALS['config']['pay']['scale'] * $price);
  442. $res = model('Order')->saveData($data);
  443. if ($res['code'] == 1) {
  444. $orderInfo = model('Order')->infoData(['order_code' => $data['order_code'], 'user_id' => $data['user_id']]);
  445. if ($orderInfo['code'] == 1) {
  446. $data['order_id'] = $orderInfo['info']['order_id'];
  447. }
  448. }
  449. $res['data'] = $data;
  450. return json($res);
  451. }
  452. }
  453. $this->assign('param',$param);
  454. $this->assign('config', $GLOBALS['config']['pay']);
  455. $extends = mac_extends_list('pay');
  456. $this->assign('ext_list', $extends['ext_list']);
  457. return $this->fetch('user/buy');
  458. }
  459. public function pay()
  460. {
  461. $param = input();
  462. $order_code = htmlspecialchars(urldecode(trim($param['order_code'])));
  463. $where = [];
  464. $where['order_code'] = $order_code;
  465. $where['user_id'] = $GLOBALS['user']['user_id'];
  466. $res = model('Order')->infoData($where);
  467. if ($res['code'] > 1) {
  468. return $this->error($res['msg']);
  469. }
  470. $this->assign('param',$param);
  471. $this->assign('config', $GLOBALS['config']['pay']);
  472. $this->assign('info', $res['info']);
  473. $extends = mac_extends_list('pay');
  474. $this->assign('extends',$extends);
  475. $this->assign('ext_list',$extends['ext_list']);
  476. return $this->fetch('user/pay');
  477. }
  478. public function gopay()
  479. {
  480. $param = input();
  481. $order_code = htmlspecialchars(urldecode(trim($param['order_code'])));
  482. $order_id = intval((trim($param['order_id'])));
  483. $payment = strtolower(htmlspecialchars(urldecode(trim($param['payment']))));
  484. if (empty($order_code) && empty($order_id) && empty($payment)) {
  485. return $this->error(lang('param_err'));
  486. }
  487. if ($GLOBALS['config']['pay'][$payment]['appid'] == '') {
  488. return $this->error(lang('index/payment_status'));
  489. }
  490. //核实订单
  491. $where['order_id'] = $order_id;
  492. $where['order_code'] = $order_code;
  493. $where['user_id'] = $GLOBALS['user']['user_id'];
  494. $res = model('Order')->infoData($where);
  495. if ($res['code'] > 1) {
  496. return $this->error(lang('index/order_not'));
  497. }
  498. if ($res['info']['order_status'] == 1) {
  499. return $this->error(lang('index/order_payed'));
  500. }
  501. $this->assign('order', $res['info']);
  502. //跳转到相应页面
  503. $this->assign('param',$param);
  504. $cp = 'app\\common\\extend\\pay\\' . ucfirst($payment);
  505. if (class_exists($cp)) {
  506. $c = new $cp;
  507. $payment_res = $c->submit($GLOBALS['user'], $res['info'], $param);
  508. }
  509. //$payment_res = model('Pay' . $payment)->submit($this->user, $res['info'], $param);
  510. if ($payment == 'weixin') {
  511. $this->assign('payment', $payment_res);
  512. return $this->fetch('user/payment_weixin');
  513. }
  514. }
  515. public function qrcode()
  516. {
  517. ob_end_clean();
  518. header('Content-Type:image/png;');
  519. $param = input();
  520. $data = $param['data'];
  521. if(substr($data, 0, 6) == "weixin") {
  522. QRcode::png($data,false,QR_ECLEVEL_L,10);
  523. }
  524. else{
  525. return $this->error(lang('param_err'));
  526. }
  527. }
  528. public function upgrade()
  529. {
  530. $param = input();
  531. if (Request()->isPost()) {
  532. $res = model('User')->upgrade($param);
  533. return json($res);
  534. }
  535. $group_list = model('Group')->getCache();
  536. $this->assign('group_list', $group_list);
  537. $this->assign('pay_config', $GLOBALS['config']['pay']);
  538. $this->assign('param',$param);
  539. return $this->fetch('user/upgrade');
  540. }
  541. /**
  542. * 会员权益说明页(需登录)
  543. */
  544. public function benefits()
  545. {
  546. return $this->fetch('user/benefits');
  547. }
  548. /**
  549. * 每日签到(当前为前端展示页,业务逻辑待接入)
  550. */
  551. public function checkin()
  552. {
  553. return $this->fetch('user/checkin');
  554. }
  555. /**
  556. * 弹窗用:返回升级会员表单 HTML(需登录)
  557. */
  558. public function ajax_upgrade()
  559. {
  560. $group_list = model('Group')->getCache();
  561. $this->assign('group_list', $group_list);
  562. $this->assign('pay_config', $GLOBALS['config']['pay']);
  563. $this->assign('param', input());
  564. $html = $this->fetch('user/ajax_upgrade');
  565. return json($html);
  566. }
  567. public function popedom()
  568. {
  569. $type_tree = model('Type')->getCache('type_tree');
  570. $this->assign('type_tree', $type_tree);
  571. $n = 1;
  572. $ids = [1 => lang('index/page_type'), 2 => lang('index/page_detail'), 3 => lang('index/page_play'), 4 => lang('index/page_down'), '5' => lang('index/try_see')];
  573. foreach ($type_tree as $k1 => $v1) {
  574. unset($type_tree[$k1]['type_extend']);
  575. $max_a = ($v1['type_mid'] == 1) ? 5 : (in_array($v1['type_mid'], [2, 12]) ? 3 : 2);
  576. foreach ($ids as $a => $b) {
  577. if ($a > $max_a) break;
  578. $n++;
  579. $type_tree[$k1]['popedom'][$b] = model('User')->popedom($v1['type_id'], $a, $GLOBALS['user']['group_id']);
  580. }
  581. foreach ($v1['child'] as $k2 => $v2) {
  582. unset($type_tree[$k1]['child'][$k2]['type_extend']);
  583. $max_a = ($v2['type_mid'] == 1) ? 5 : (in_array($v2['type_mid'], [2, 12]) ? 3 : 2);
  584. foreach ($ids as $a => $b) {
  585. if ($a > $max_a) break;
  586. $n++;
  587. $type_tree[$k1]['child'][$k2]['popedom'][$b] = model('User')->popedom($v2['type_id'], $a, $GLOBALS['user']['group_id']);
  588. }
  589. }
  590. }
  591. $this->assign('type_tree', $type_tree);
  592. return $this->fetch('user/popedom');
  593. }
  594. public function plays()
  595. {
  596. $param = input();
  597. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  598. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  599. $param['mid'] = intval($param['mid']);
  600. $where = [];
  601. $where['user_id'] = $GLOBALS['user']['user_id'];
  602. $where['ulog_type'] = 4;
  603. if (in_array($param['mid'], [1, 2, 3, 8, 12])) {
  604. $where['ulog_mid'] = $param['mid'];
  605. }
  606. $order = 'ulog_time desc';
  607. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  608. $this->assign('param',$param);
  609. $this->assign('list', $res['list']);
  610. $page_url = url('user/plays', ['mid' => $param['mid'], 'page' => 'PAGELINK']);
  611. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], $page_url);
  612. $this->assign('__PAGING__', $pages);
  613. return $this->fetch('user/plays');
  614. }
  615. public function downs()
  616. {
  617. $param = input();
  618. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  619. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  620. $where = [];
  621. $where['user_id'] = $GLOBALS['user']['user_id'];
  622. $where['ulog_mid'] = 1;
  623. $where['ulog_type'] = 5;
  624. $order = 'ulog_time desc';
  625. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  626. $this->assign('param',$param);
  627. $this->assign('list', $res['list']);
  628. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/downs', ['page' => 'PAGELINK']));
  629. $this->assign('__PAGING__', $pages);
  630. return $this->fetch('user/downs');
  631. }
  632. public function favs()
  633. {
  634. $param = input();
  635. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  636. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  637. $param['mid'] = intval($param['mid']);
  638. $where = [];
  639. $where['user_id'] = $GLOBALS['user']['user_id'];
  640. if (in_array($param['mid'], [1, 2, 3, 8, 12])) {
  641. $where['ulog_mid'] = $param['mid'];
  642. }
  643. $where['ulog_type'] = 2;
  644. $order = 'ulog_time desc';
  645. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  646. $this->assign('param',$param);
  647. $this->assign('list', $res['list']);
  648. $page_url = url('user/favs', ['mid' => $param['mid'], 'page' => 'PAGELINK']);
  649. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], $page_url);
  650. $this->assign('__PAGING__', $pages);
  651. return $this->fetch('user/favs');
  652. }
  653. public function ulog()
  654. {
  655. $param = input();
  656. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  657. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  658. $where = [];
  659. $where['user_id'] = $GLOBALS['user']['user_id'];
  660. if(in_array($param['mid'],['1','2','3','8'])){
  661. $where['ulog_mid'] = $param['mid'];
  662. }
  663. if(in_array($param['type'],['1','2','3','4','5'])){
  664. $where['ulog_type'] = $param['type'];
  665. }
  666. $order = 'ulog_time desc';
  667. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  668. $this->assign('param',$param);
  669. $this->assign('list', $res['list']);
  670. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/ulog', ['page' => 'PAGELINK']));
  671. $this->assign('__PAGING__', $pages);
  672. return $this->fetch('user/ulog');
  673. }
  674. public function ulog_del()
  675. {
  676. $param = input();
  677. $ids = htmlspecialchars(urldecode(trim($param['ids'])));
  678. $type = $param['type'];
  679. $all = $param['all'];
  680. if (!in_array($type, array('1', '2', '3', '4', '5'))) {
  681. return json(['code' => 1001, 'msg' => lang('param_err')]);
  682. }
  683. if (empty($ids) && empty($all)) {
  684. return json(['code' => 1001, 'msg' => lang('param_err')]);
  685. }
  686. $arr = [];
  687. $ids = explode(',', $ids);
  688. foreach ($ids as $k => $v) {
  689. $v = abs(intval($v));
  690. $arr[$v] = $v;
  691. }
  692. $where = [];
  693. $where['user_id'] = $GLOBALS['user']['user_id'];
  694. $where['ulog_type'] = $type;
  695. if ($all != '1') {
  696. $where['ulog_id'] = array('in', implode(',', $arr));
  697. }
  698. $return = model('Ulog')->delData($where);
  699. return json($return);
  700. }
  701. public function plog()
  702. {
  703. $param = input();
  704. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  705. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  706. $param['filter'] = trim($param['filter']);
  707. $where = [];
  708. $where['user_id'] = $GLOBALS['user']['user_id'];
  709. // 筛选:income=收入(1-6 与任务/里程碑奖励 10-11), expense=支出(7-9)
  710. if ($param['filter'] == 'income') {
  711. $where['plog_type'] = ['in', [1, 2, 3, 4, 5, 6, 10, 11]];
  712. } elseif ($param['filter'] == 'expense') {
  713. $where['plog_type'] = ['in', [7, 8, 9]];
  714. }
  715. $order = 'plog_id desc';
  716. $res = model('Plog')->listData($where, $order, $param['page'], $param['limit']);
  717. $this->assign('param',$param);
  718. $this->assign('list', $res['list']);
  719. $page_url = url('user/plog', ['filter' => $param['filter'], 'page' => 'PAGELINK']);
  720. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], $page_url);
  721. $this->assign('__PAGING__', $pages);
  722. return $this->fetch('user/plog');
  723. }
  724. public function plog_del()
  725. {
  726. $param = input();
  727. $ids = htmlspecialchars(urldecode(trim($param['ids'])));
  728. $type = $param['type'];
  729. $all = $param['all'];
  730. if (empty($ids) && empty($all)) {
  731. return json(['code' => 1001, 'msg' => lang('param_err')]);
  732. }
  733. $arr = [];
  734. $ids = explode(',', $ids);
  735. foreach ($ids as $k => $v) {
  736. $v = abs(intval($v));
  737. $arr[$v] = $v;
  738. }
  739. $where = [];
  740. $where['user_id'] = $GLOBALS['user']['user_id'];
  741. if ($all != '1') {
  742. $where['plog_id'] = array('in', implode(',', $arr));
  743. }
  744. $return = model('Plog')->delData($where);
  745. return json($return);
  746. }
  747. public function cash()
  748. {
  749. $param = input();
  750. if (Request()->isPost()) {
  751. $param['user_id'] = $GLOBALS['user']['user_id'];
  752. $res = model('Cash')->saveData($param);
  753. return json($res);
  754. }
  755. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  756. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  757. $where = [];
  758. $where['user_id'] = $GLOBALS['user']['user_id'];
  759. $order = 'cash_id desc';
  760. $res = model('Cash')->listData($where, $order, $param['page'], $param['limit']);
  761. $this->assign('param',$param);
  762. $this->assign('list', $res['list']);
  763. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/cash', ['page' => 'PAGELINK']));
  764. $this->assign('__PAGING__', $pages);
  765. return $this->fetch('user/cash');
  766. }
  767. public function cash_del()
  768. {
  769. $param = input();
  770. $ids = htmlspecialchars(urldecode(trim($param['ids'])));
  771. $type = $param['type'];
  772. $all = $param['all'];
  773. if (empty($ids) && empty($all)) {
  774. return json(['code' => 1001, 'msg' => lang('param_err')]);
  775. }
  776. $arr = [];
  777. $ids = explode(',', $ids);
  778. foreach ($ids as $k => $v) {
  779. $v = abs(intval($v));
  780. $arr[$v] = $v;
  781. }
  782. $where = [];
  783. $where['user_id'] = $GLOBALS['user']['user_id'];
  784. if ($all != '1') {
  785. $where['cash_id'] = array('in', implode(',', $arr));
  786. }
  787. $return = model('Cash')->delData($where);
  788. return json($return);
  789. }
  790. public function reward()
  791. {
  792. $param = input();
  793. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  794. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  795. $where = [];
  796. if($param['level']=='2'){
  797. $where['user_pid_2'] = ['eq',$GLOBALS['user']['user_id']];
  798. }
  799. elseif($param['level']=='3'){
  800. $where['user_pid_3'] = ['eq',$GLOBALS['user']['user_id']];
  801. }
  802. else{
  803. $where['user_pid'] = ['eq',$GLOBALS['user']['user_id']];
  804. }
  805. $order = 'user_id desc';
  806. $res = model('User')->listData($where, $order, $param['page'], $param['limit']);
  807. $this->assign('param',$param);
  808. $this->assign('list', $res['list']);
  809. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/reward', ['level'=>$param['level'], 'page' => 'PAGELINK']));
  810. $this->assign('__PAGING__', $pages);
  811. return $this->fetch('user/reward');
  812. }
  813. public function orders()
  814. {
  815. $param = input();
  816. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  817. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  818. $where = [];
  819. $where['o.user_id'] = $GLOBALS['user']['user_id'];
  820. $order = 'o.order_id desc';
  821. $res = model('Order')->listData($where, $order, $param['page'], $param['limit']);
  822. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/orders', ['page' => 'PAGELINK']));
  823. $this->assign('__PAGING__', $pages);
  824. $this->assign('param',$param);
  825. $this->assign('list', $res['list']);
  826. return $this->fetch('user/orders');
  827. }
  828. public function order_info()
  829. {
  830. $param = input();
  831. $where = [];
  832. $where['order_id'] = intval($param['order_id']);
  833. $res = model('Order')->infoData($where);
  834. if (request()->isAjax()) {
  835. return json($res);
  836. }
  837. $this->assign('param',$param);
  838. return $this->fetch('user/order_info');
  839. }
  840. public function cards()
  841. {
  842. $param = input();
  843. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  844. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  845. $where = [];
  846. $where['user_id'] = $GLOBALS['user']['user_id'];
  847. $where['card_use_status'] = 1;
  848. $order = 'card_id desc';
  849. $res = model('Card')->listData($where, $order, $param['page'], $param['limit']);
  850. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/cards', ['page' => 'PAGELINK']));
  851. $this->assign('__PAGING__', $pages);
  852. $this->assign('param',$param);
  853. $this->assign('list', $res['list']);
  854. return $this->fetch('user/cards');
  855. }
  856. public function comment()
  857. {
  858. $param = input();
  859. $this->assign('param',$param);
  860. return $this->fetch('user/comment');
  861. }
  862. public function gbook()
  863. {
  864. $param = input();
  865. $this->assign('param',$param);
  866. return $this->fetch('user/gbook');
  867. }
  868. /**
  869. * 邀请推广页面:展示邀请码、邀请链接及下线列表
  870. */
  871. public function invite()
  872. {
  873. $param = input();
  874. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  875. $param['limit'] = intval($param['limit']) < 1 ? 20 : intval($param['limit']);
  876. $user_id = $GLOBALS['user']['user_id'];
  877. $invite_code = $GLOBALS['user']['user_invite_code'];
  878. $base_url = $GLOBALS['http_type'] . $_SERVER['HTTP_HOST'];
  879. $reg_path = mac_url('user/reg');
  880. $invite_link_uid = $base_url . $reg_path . '?uid=' . $user_id;
  881. $invite_link_code = !empty($invite_code)
  882. ? $base_url . $reg_path . '?invite_code=' . $invite_code
  883. : '';
  884. $total = model('User')->where('user_pid', $user_id)->count();
  885. $invitees_raw = model('User')
  886. ->field('user_id,user_name,user_nick_name,user_invite_code,user_invite_count,user_reg_time')
  887. ->where('user_pid', $user_id)
  888. ->order('user_id desc')
  889. ->page($param['page'])
  890. ->limit($param['limit'])
  891. ->select();
  892. $invitees = is_array($invitees_raw)
  893. ? $invitees_raw
  894. : (is_object($invitees_raw) ? $invitees_raw->toArray() : []);
  895. if (!empty($invitees)) {
  896. $level1_ids = array_column($invitees, 'user_id');
  897. $sub_raw = model('User')
  898. ->field('user_id,user_name,user_nick_name,user_invite_count,user_reg_time,user_pid')
  899. ->where('user_pid', 'in', $level1_ids)
  900. ->order('user_id desc')
  901. ->select();
  902. $sub_list = is_array($sub_raw)
  903. ? $sub_raw
  904. : (is_object($sub_raw) ? $sub_raw->toArray() : []);
  905. $sub_map = [];
  906. foreach ($sub_list as $sub) {
  907. $sub_map[$sub['user_pid']][] = $sub;
  908. }
  909. foreach ($invitees as &$invitee) {
  910. $invitee['sub_invitees'] = isset($sub_map[$invitee['user_id']]) ? $sub_map[$invitee['user_id']] : [];
  911. $invitee['sub_count'] = count($invitee['sub_invitees']);
  912. }
  913. unset($invitee);
  914. }
  915. $this->assign('invite_code', $invite_code);
  916. $this->assign('invite_link_uid', $invite_link_uid);
  917. $this->assign('invite_link_code', $invite_link_code);
  918. $this->assign('total', intval($total));
  919. $this->assign('list', $invitees);
  920. $this->assign('param', $param);
  921. $pages = mac_page_param($total, $param['limit'], $param['page'], url('user/invite', ['page' => 'PAGELINK']));
  922. $this->assign('__PAGING__', $pages);
  923. return $this->fetch('user/invite');
  924. }
  925. public function visit()
  926. {
  927. $param = input();
  928. $res = model('User')->visit($param);
  929. $url = '/';
  930. if(!empty($param['url'])){
  931. $tempu = @parse_url($param['url']);
  932. if($_SERVER['HTTP_HOST'] == $tempu['host']){
  933. $url = $param['url'];
  934. }
  935. }
  936. $this->redirect($url);
  937. }
  938. }