User.php 31 KB

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