plugins.action.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class pluginsModule extends baseModule
  3. {
  4. public function __construct()
  5. {
  6. parent::__construct();
  7. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/GamesRedisService.php');
  8. }
  9. /**
  10. * 检查是否登录
  11. * @return int
  12. */
  13. protected static function getUserId()
  14. {
  15. $user_id = intval($GLOBALS['user_info']['id']);
  16. if (!$user_id) {
  17. api_ajax_return(array(
  18. 'status' => 0,
  19. 'error' => '未登录',
  20. ));
  21. }
  22. return $user_id;
  23. }
  24. /**
  25. * 插件列表(暂时只有游戏)
  26. */
  27. public function init()
  28. {
  29. $user_id = self::getUserId();
  30. $table = DB_PREFIX . 'games';
  31. $count = $GLOBALS['db']->getOne("SELECT count(1) as count FROM $table");
  32. $list = array();
  33. if ($count) {
  34. $field = '`id`,`name`,`image`,`principal`';
  35. $list = $GLOBALS['db']->getALL("SELECT $field FROM $table");
  36. $table = DB_PREFIX . 'video';
  37. $video = $GLOBALS['db']->getRow("SELECT `id` FROM $table WHERE user_id=" . $user_id . " and live_in=1");
  38. $game_id = 0;
  39. if ($video['id']) {
  40. fanwe_require(APP_ROOT_PATH . 'mapi/lib/redis/VideoRedisService.php');
  41. $video_redis = new VideoRedisService();
  42. $redis = new GamesRedisService();
  43. $last_game = $video_redis->getOne_db($video['id'], 'game_log_id');
  44. if ($last_game) {
  45. $last_game = $redis->get($last_game, 'game_id,create_time,long_time');
  46. if (NOW_TIME < $last_game['create_time'] + $last_game['long_time']) {
  47. $game_id = $last_game['game_id'];
  48. }
  49. }
  50. }
  51. foreach ($list as $key => $value) {
  52. $list[$key]['is_active'] = intval($value['id'] == $game_id);
  53. $list[$key]['image'] = get_abs_img_root($value['image']);
  54. }
  55. }
  56. api_ajax_return(array(
  57. 'status' => 1,
  58. 'rs_count' => $count,
  59. 'list' => $list,
  60. ));
  61. }
  62. }