User.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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('未登录', 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' => '收费收据需单独记录'];
  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:$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' => '参数错误']);
  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' => '您已经购买过此条数据,无需再次支付,请刷新页面重试']);
  135. }
  136. if ($data['ulog_points'] > $GLOBALS['user']['user_points']) {
  137. return json(['code' => 2002, 'msg' => '对不起,查看此页面数据需要[' . $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' => '对不起,更新用户积分信息失败,请刷新重试!']);
  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('参数错误');
  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('参数错误');
  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' => '已经绑定该账号']);
  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' => '绑定成功']);
  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('同步信息注册失败,请联系管理员');
  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('获取第三方用户信息失败,请重试');
  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'] = '注册成功,' . $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 ($GLOBALS['config']['user']['portrait_status'] == 0) {
  350. return json(['code' => 0, 'msg' => '未开启自定义头像功能!']);
  351. }
  352. $file = request()->file('file');
  353. if (empty($file)) {
  354. return json(['code' => 0, 'msg' => '未找到上传的文件(原因:表单名可能错误,默认表单名“file”)!']);
  355. }
  356. if ($file->getMime() == 'text/x-php') {
  357. return json(['code' => 0, 'msg' => '禁止上传php,html文件!']);
  358. }
  359. $upload_image_ext = 'jpg,png,gif';
  360. if ($file->checkExt($upload_image_ext)) {
  361. $type = 'image';
  362. } else {
  363. return json(['code' => 0, 'msg' => '非系统允许的上传格式!']);
  364. }
  365. $uniq = $GLOBALS['user']['user_id'] % 10;
  366. // 上传附件路径
  367. $_upload_path = ROOT_PATH . 'upload' . '/user/' . $uniq . '/';
  368. // 附件访问路径
  369. $_save_path = 'upload' . '/user/' . $uniq . '/';
  370. $_save_name = $GLOBALS['user']['user_id'] . '.jpg';
  371. if (!file_exists($_save_path)) {
  372. mac_mkdirss($_save_path);
  373. }
  374. $upfile = $file->move($_upload_path, $_save_name);
  375. if (!is_file($_upload_path . $_save_name)) {
  376. return json(['code' => 0, 'msg' => '文件上传失败!']);
  377. }
  378. $file = $_save_path . str_replace('\\', '/', $_save_name);
  379. $config = [
  380. 'thumb_type' => 6,
  381. 'thumb_size' => $GLOBALS['config']['user']['portrait_size'],
  382. ];
  383. $new_thumb = $GLOBALS['user']['user_id'] . '.jpg';
  384. $new_file = $_save_path . $new_thumb;
  385. try {
  386. $image = \think\Image::open('./' . $file);
  387. $t_size = explode('x', strtolower($GLOBALS['config']['user']['portrait_size']));
  388. if (!isset($t_size[1])) {
  389. $t_size[1] = $t_size[0];
  390. }
  391. $res = $image->thumb($t_size[0], $t_size[1], 6)->save('./' . $new_file);
  392. $update = [];
  393. $update['user_portrait'] = $new_file;
  394. $where = [];
  395. $where['user_id'] = $GLOBALS['user']['user_id'];
  396. $res = model('User')->where($where)->update($update);
  397. if ($res === false) {
  398. return json(['code' => 0, 'msg' => '更新会员头像信息失败!']);
  399. }
  400. return json(['code' => 1, 'msg' => 'ok', 'file' => '' . MAC_PATH . $new_file . '?' . mt_rand(1, 9999)]);
  401. } catch (\Exception $e) {
  402. return json(['code' => 0, 'msg' => '生成缩放头像图片文件失败!']);
  403. }
  404. }
  405. public function findpass()
  406. {
  407. $param = input();
  408. if (Request()->isPost()) {
  409. $res = model('User')->findpass($param);
  410. return json($res);
  411. }
  412. $this->assign('param',$param);
  413. return $this->fetch('user/findpass');
  414. }
  415. public function findpass_msg()
  416. {
  417. $param = input();
  418. if (Request()->isPost()) {
  419. $res = model('User')->findpass_msg($param);
  420. return json($res);
  421. }
  422. $param['ac_text'] = $param['ac'] == 'phone' ? '手机' : '邮箱';
  423. $this->assign('param', $param);
  424. return $this->fetch('user/findpass_msg');
  425. }
  426. public function findpass_reset()
  427. {
  428. if (Request()->isPost()) {
  429. $param = input();
  430. $res = model('User')->findpass_reset($param);
  431. return json($res);
  432. }
  433. }
  434. public function buy()
  435. {
  436. $param = input();
  437. if (Request()->isPost()) {
  438. $flag = input('param.flag');
  439. if ($flag == 'card') {
  440. $card_no = htmlspecialchars(urldecode(trim($param['card_no'])));
  441. $card_pwd = htmlspecialchars(urldecode(trim($param['card_pwd'])));
  442. $res = model('Card')->useData($card_no, $card_pwd, $GLOBALS['user']);
  443. return json($res);
  444. } else {
  445. $price = input('param.price');
  446. if (empty($price)) {
  447. return json(['code' => 1001, 'msg' => '参数错误']);
  448. }
  449. if ($price < $GLOBALS['config']['pay']['min']) {
  450. return json(['code' => 1002, 'msg' => '最小充值金额不能低于' . $GLOBALS['config']['pay']['min'] . '元']);
  451. }
  452. $data = [];
  453. $data['user_id'] = $GLOBALS['user']['user_id'];
  454. $data['order_code'] = 'PAY' . mac_get_uniqid_code();
  455. $data['order_price'] = $price;
  456. $data['order_time'] = time();
  457. $data['order_points'] = intval($GLOBALS['config']['pay']['scale'] * $price);
  458. $res = model('Order')->saveData($data);
  459. $res['data'] = $data;
  460. return json($res);
  461. }
  462. }
  463. $this->assign('param',$param);
  464. $this->assign('config', $GLOBALS['config']['pay']);
  465. return $this->fetch('user/buy');
  466. }
  467. public function pay()
  468. {
  469. $param = input();
  470. $order_code = htmlspecialchars(urldecode(trim($param['order_code'])));
  471. $where = [];
  472. $where['order_code'] = $order_code;
  473. $where['user_id'] = $GLOBALS['user']['user_id'];
  474. $res = model('Order')->infoData($where);
  475. if ($res['code'] > 1) {
  476. return $this->error($res['msg']);
  477. }
  478. $this->assign('param',$param);
  479. $this->assign('config', $GLOBALS['config']['pay']);
  480. $this->assign('info', $res['info']);
  481. $extends = mac_extends_list('pay');
  482. $this->assign('extends',$extends);
  483. $this->assign('ext_list',$extends['ext_list']);
  484. return $this->fetch('user/pay');
  485. }
  486. public function gopay()
  487. {
  488. $param = input();
  489. $order_code = htmlspecialchars(urldecode(trim($param['order_code'])));
  490. $order_id = intval((trim($param['order_id'])));
  491. $payment = strtolower(htmlspecialchars(urldecode(trim($param['payment']))));
  492. if (empty($order_code) && empty($order_id) && empty($payment)) {
  493. return $this->error('参数错误');
  494. }
  495. if ($GLOBALS['config']['pay'][$payment]['appid'] == '') {
  496. return $this->error('该支付选项未开启');
  497. }
  498. //核实订单
  499. $where['order_id'] = $order_id;
  500. $where['order_code'] = $order_code;
  501. $where['user_id'] = $GLOBALS['user']['user_id'];
  502. $res = model('Order')->infoData($where);
  503. if ($res['code'] > 1) {
  504. return $this->error('获取单据失败');
  505. }
  506. if ($res['info']['order_status'] == 1) {
  507. return $this->error('该单据已支付完成');
  508. }
  509. $this->assign('order', $res['info']);
  510. //跳转到相应页面
  511. $this->assign('param',$param);
  512. $cp = 'app\\common\\extend\\pay\\' . ucfirst($payment);
  513. if (class_exists($cp)) {
  514. $c = new $cp;
  515. $payment_res = $c->submit($this->user, $res['info'], $param);
  516. }
  517. //$payment_res = model('Pay' . $payment)->submit($this->user, $res['info'], $param);
  518. if ($payment == 'weixin') {
  519. $this->assign('payment', $payment_res);
  520. return $this->fetch('user/payment_weixin');
  521. }
  522. }
  523. public function qrcode()
  524. {
  525. ob_end_clean();
  526. header('Content-Type:image/png;');
  527. $param = input();
  528. $data = $param['data'];
  529. if(substr($data, 0, 6) == "weixin") {
  530. QRcode::png($data,false,QR_ECLEVEL_L,10);
  531. }
  532. else{
  533. return $this->error('参数错误');
  534. }
  535. }
  536. public function upgrade()
  537. {
  538. $param = input();
  539. if (Request()->isPost()) {
  540. $res = model('User')->upgrade($param);
  541. return json($res);
  542. }
  543. $group_list = model('Group')->getCache();
  544. $this->assign('group_list', $group_list);
  545. $this->assign('param',$param);
  546. return $this->fetch('user/upgrade');
  547. }
  548. public function popedom()
  549. {
  550. $type_tree = model('Type')->getCache('type_tree');
  551. $this->assign('type_tree', $type_tree);
  552. $n = 1;
  553. $ids = [1 => '列表页', 2 => '内容页', 3 => '播放页', 4 => '下载页', '5' => '试看'];
  554. foreach ($type_tree as $k1 => $v1) {
  555. unset($type_tree[$k1]['type_extend']);
  556. foreach ($ids as $a => $b) {
  557. $n++;
  558. if ($v1['type_mid'] == 2 && $a > 2) {
  559. break;
  560. }
  561. $type_tree[$k1]['popedom'][$b] = model('User')->popedom($v1['type_id'], $a, $GLOBALS['user']['group_id']);
  562. }
  563. foreach ($v1['child'] as $k2 => $v2) {
  564. unset($type_tree[$k1]['child'][$k2]['type_extend']);
  565. foreach ($ids as $a => $b) {
  566. $n++;
  567. if ($v2['type_mid'] == 2 && $a > 2) {
  568. break;
  569. }
  570. $type_tree[$k1]['child'][$k2]['popedom'][$b] = model('User')->popedom($v2['type_id'], $a, $GLOBALS['user']['group_id']);
  571. }
  572. }
  573. }
  574. $this->assign('type_tree', $type_tree);
  575. return $this->fetch('user/popedom');
  576. }
  577. public function plays()
  578. {
  579. $param = input();
  580. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  581. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  582. $where = [];
  583. $where['user_id'] = $GLOBALS['user']['user_id'];
  584. $where['ulog_mid'] = 1;
  585. $where['ulog_type'] = 4;
  586. $order = 'ulog_time desc';
  587. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  588. $this->assign('param',$param);
  589. $this->assign('list', $res['list']);
  590. $this->assign('title', '我的点播');
  591. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/plays', ['page' => 'PAGELINK']));
  592. $this->assign('__PAGING__', $pages);
  593. return $this->fetch('user/plays');
  594. }
  595. public function downs()
  596. {
  597. $param = input();
  598. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  599. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  600. $where = [];
  601. $where['user_id'] = $GLOBALS['user']['user_id'];
  602. $where['ulog_mid'] = 1;
  603. $where['ulog_type'] = 5;
  604. $order = 'ulog_time desc';
  605. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  606. $this->assign('param',$param);
  607. $this->assign('list', $res['list']);
  608. $this->assign('title', '我的下载');
  609. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/downs', ['page' => 'PAGELINK']));
  610. $this->assign('__PAGING__', $pages);
  611. return $this->fetch('user/downs');
  612. }
  613. public function favs()
  614. {
  615. $param = input();
  616. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  617. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  618. $where = [];
  619. $where['user_id'] = $GLOBALS['user']['user_id'];
  620. if(in_array($param['mid'],['1','2','3','8'])){
  621. $where['ulog_mid'] = $param['mid'];
  622. }
  623. $where['ulog_type'] = 2;
  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. $this->assign('title', '我的收藏');
  629. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/favs', ['page' => 'PAGELINK']));
  630. $this->assign('__PAGING__', $pages);
  631. return $this->fetch('user/favs');
  632. }
  633. public function ulog()
  634. {
  635. $param = input();
  636. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  637. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  638. $where = [];
  639. $where['user_id'] = $GLOBALS['user']['user_id'];
  640. if(in_array($param['mid'],['1','2','3','8'])){
  641. $where['ulog_mid'] = $param['mid'];
  642. }
  643. if(in_array($param['type'],['1','2','3','4','5'])){
  644. $where['ulog_type'] = $param['type'];
  645. }
  646. $order = 'ulog_time desc';
  647. $res = model('Ulog')->listData($where, $order, $param['page'], $param['limit']);
  648. $this->assign('param',$param);
  649. $this->assign('list', $res['list']);
  650. $this->assign('title', '我的记录');
  651. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/ulog', ['page' => 'PAGELINK']));
  652. $this->assign('__PAGING__', $pages);
  653. return $this->fetch('user/ulog');
  654. }
  655. public function ulog_del()
  656. {
  657. $param = input();
  658. $ids = htmlspecialchars(urldecode(trim($param['ids'])));
  659. $type = $param['type'];
  660. $all = $param['all'];
  661. if (!in_array($type, array('1', '2', '3', '4', '5'))) {
  662. return json(['code' => 1001, 'msg' => '参数错误']);
  663. }
  664. if (empty($ids) && empty($all)) {
  665. return json(['code' => 1001, 'msg' => '参数错误']);
  666. }
  667. $arr = [];
  668. $ids = explode(',', $ids);
  669. foreach ($ids as $k => $v) {
  670. $v = intval(abs($v));
  671. $arr[$v] = $v;
  672. }
  673. $where = [];
  674. $where['user_id'] = $GLOBALS['user']['user_id'];
  675. $where['ulog_type'] = $type;
  676. if ($all != '1') {
  677. $where['ulog_id'] = array('in', implode(',', $arr));
  678. }
  679. $return = model('Ulog')->delData($where);
  680. return json($return);
  681. }
  682. public function plog()
  683. {
  684. $param = input();
  685. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  686. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  687. $where = [];
  688. $where['user_id'] = $GLOBALS['user']['user_id'];
  689. $order = 'plog_id desc';
  690. $res = model('Plog')->listData($where, $order, $param['page'], $param['limit']);
  691. $this->assign('param',$param);
  692. $this->assign('list', $res['list']);
  693. $this->assign('title', '积分记录');
  694. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/plog', ['page' => 'PAGELINK']));
  695. $this->assign('__PAGING__', $pages);
  696. return $this->fetch('user/plog');
  697. }
  698. public function plog_del()
  699. {
  700. $param = input();
  701. $ids = htmlspecialchars(urldecode(trim($param['ids'])));
  702. $type = $param['type'];
  703. $all = $param['all'];
  704. if (empty($ids) && empty($all)) {
  705. return json(['code' => 1001, 'msg' => '参数错误']);
  706. }
  707. $arr = [];
  708. $ids = explode(',', $ids);
  709. foreach ($ids as $k => $v) {
  710. $v = intval(abs($v));
  711. $arr[$v] = $v;
  712. }
  713. $where = [];
  714. $where['user_id'] = $GLOBALS['user']['user_id'];
  715. if ($all != '1') {
  716. $where['plog_id'] = array('in', implode(',', $arr));
  717. }
  718. $return = model('Plog')->delData($where);
  719. return json($return);
  720. }
  721. public function cash()
  722. {
  723. $param = input();
  724. if (Request()->isPost()) {
  725. $param['user_id'] = $GLOBALS['user']['user_id'];
  726. $res = model('Cash')->saveData($param);
  727. return json($res);
  728. }
  729. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  730. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  731. $where = [];
  732. $where['user_id'] = $GLOBALS['user']['user_id'];
  733. $order = 'cash_id desc';
  734. $res = model('Cash')->listData($where, $order, $param['page'], $param['limit']);
  735. $this->assign('param',$param);
  736. $this->assign('list', $res['list']);
  737. $this->assign('title', '提现记录');
  738. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/cash', ['page' => 'PAGELINK']));
  739. $this->assign('__PAGING__', $pages);
  740. return $this->fetch('user/cash');
  741. }
  742. public function cash_del()
  743. {
  744. $param = input();
  745. $ids = htmlspecialchars(urldecode(trim($param['ids'])));
  746. $type = $param['type'];
  747. $all = $param['all'];
  748. if (empty($ids) && empty($all)) {
  749. return json(['code' => 1001, 'msg' => '参数错误']);
  750. }
  751. $arr = [];
  752. $ids = explode(',', $ids);
  753. foreach ($ids as $k => $v) {
  754. $v = intval(abs($v));
  755. $arr[$v] = $v;
  756. }
  757. $where = [];
  758. $where['user_id'] = $GLOBALS['user']['user_id'];
  759. if ($all != '1') {
  760. $where['cash_id'] = array('in', implode(',', $arr));
  761. }
  762. $return = model('Cash')->delData($where);
  763. return json($return);
  764. }
  765. public function reward()
  766. {
  767. $param = input();
  768. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  769. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  770. $where = [];
  771. if($param['level']=='2'){
  772. $where['user_pid_2'] = ['eq',$GLOBALS['user']['user_id']];
  773. }
  774. elseif($param['level']=='3'){
  775. $where['user_pid_3'] = ['eq',$GLOBALS['user']['user_id']];
  776. }
  777. else{
  778. $where['user_pid'] = ['eq',$GLOBALS['user']['user_id']];
  779. }
  780. $order = 'user_id desc';
  781. $res = model('User')->listData($where, $order, $param['page'], $param['limit']);
  782. $this->assign('param',$param);
  783. $this->assign('list', $res['list']);
  784. $this->assign('title', '提现记录');
  785. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/plog', ['page' => 'PAGELINK']));
  786. $this->assign('__PAGING__', $pages);
  787. return $this->fetch('user/reward');
  788. }
  789. public function orders()
  790. {
  791. $param = input();
  792. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  793. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  794. $where = [];
  795. $where['o.user_id'] = $GLOBALS['user']['user_id'];
  796. $order = 'o.order_id desc';
  797. $res = model('Order')->listData($where, $order, $param['page'], $param['limit']);
  798. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/orders', ['page' => 'PAGELINK']));
  799. $this->assign('__PAGING__', $pages);
  800. $this->assign('param',$param);
  801. $this->assign('list', $res['list']);
  802. return $this->fetch('user/orders');
  803. }
  804. public function order_info()
  805. {
  806. $param = input();
  807. $where = [];
  808. $where['order_id'] = intval($param['order_id']);
  809. $res = model('Order')->infoData($where);
  810. if (request()->isAjax()) {
  811. return json($res);
  812. }
  813. $this->assign('param',$param);
  814. return $this->fetch('user/order_info');
  815. }
  816. public function cards()
  817. {
  818. $param = input();
  819. $param['page'] = intval($param['page']) < 1 ? 1 : intval($param['page']);
  820. $param['limit'] = intval($param['limit']) < 20 ? 20 : intval($param['limit']);
  821. $where = [];
  822. $where['user_id'] = $GLOBALS['user']['user_id'];
  823. $where['card_use_status'] = 1;
  824. $order = 'card_id desc';
  825. $res = model('Card')->listData($where, $order, $param['page'], $param['limit']);
  826. $pages = mac_page_param($res['total'], $param['limit'], $param['page'], url('user/cards', ['page' => 'PAGELINK']));
  827. $this->assign('__PAGING__', $pages);
  828. $this->assign('param',$param);
  829. $this->assign('list', $res['list']);
  830. return $this->fetch('user/cards');
  831. }
  832. public function comment()
  833. {
  834. $param = input();
  835. $this->assign('param',$param);
  836. return $this->fetch('user/comment');
  837. }
  838. public function gbook()
  839. {
  840. $param = input();
  841. $this->assign('param',$param);
  842. return $this->fetch('user/gbook');
  843. }
  844. public function visit()
  845. {
  846. $param = input();
  847. $res = model('User')->visit($param);
  848. $url = '/';
  849. if(!empty($param['url'])){
  850. $tempu = @parse_url($param['url']);
  851. if($_SERVER['HTTP_HOST'] == $tempu['host']){
  852. $url = $param['url'];
  853. }
  854. }
  855. $this->redirect($url);
  856. }
  857. }