IndexController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ArticleService;
  5. use App\Services\Api\GoodsService;
  6. use App\Services\Api\ImChatService;
  7. use App\Services\ConfigService;
  8. use App\Services\RedisService;
  9. /**
  10. * 首页
  11. * @package App\Http\Controllers\Api
  12. */
  13. class IndexController extends webApp
  14. {
  15. /**
  16. * 视频推荐列表
  17. * @return array
  18. */
  19. public function videoList()
  20. {
  21. return showJson(1010, true, []);
  22. }
  23. /**
  24. * 配置信息
  25. * @return array
  26. */
  27. public function config()
  28. {
  29. try {
  30. $params = request()->all();
  31. $system = isset($params['system'])? json_decode($params['system'], true) : [];
  32. $appSources = isset($system['app_sources']) && $system['app_sources']? $system['app_sources'] : 'android';
  33. $cacheKey = "caches:config:app_{$appSources}";
  34. $config = RedisService::get($cacheKey);
  35. if (empty($config)) {
  36. $config = [
  37. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  38. 'app_logo' => ConfigService::make()->getConfigByCode('app_logo'),
  39. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  40. 'h5_url' => ConfigService::make()->getConfigByCode("h5_url"),
  41. 'chat_url' => ConfigService::make()->getConfigByCode("chat_url"),
  42. 'custom_phone' => ConfigService::make()->getConfigByCode('custom_phone'),
  43. 'custom_telegram' => ConfigService::make()->getConfigByCode('custom_telegram'),
  44. 'custom_email' => ConfigService::make()->getConfigByCode('custom_email'),
  45. 'open_h5' => (int)ConfigService::make()->getConfigByCode('open_h5',0),
  46. ];
  47. RedisService::set($cacheKey, $config, 7200);
  48. }
  49. $config['app_sources'] = $appSources;
  50. $config['app_url'] = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  51. return showJson(1010, true, $config);
  52. } catch (\Exception $exception) {
  53. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  54. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  55. }
  56. }
  57. /**
  58. * 物流公司
  59. * @return array
  60. */
  61. public function express()
  62. {
  63. return showJson(1010, true, config('express'));
  64. }
  65. /**
  66. * 验证APP更新
  67. * @return array
  68. */
  69. public function versionCheck()
  70. {
  71. $system = request()->post('system',[]);
  72. $version = isset($system['version'])? $system['version'] : '1.3.20';
  73. $appSources = isset($system['app_sources'])? $system['app_sources'] : 'ios';
  74. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  75. if (getVersion($version) < getVersion($currentVersion)) {
  76. $data = [
  77. 'has_update' => true,
  78. 'app_version' => $currentVersion,
  79. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  80. 'update_notice' => ConfigService::make()->getConfigByCode('app_update_notice'),
  81. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  82. ];
  83. return showJson(1010, true, $data);
  84. } else {
  85. $appUrl = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  86. return showJson(1010, false, ['has_update' => false,'app_url'=>$appUrl, 'version' => $version]);
  87. }
  88. }
  89. /**
  90. * 直播参数
  91. * @return array
  92. */
  93. public function liveConfig()
  94. {
  95. $userId = request()->post('user_id', 0);
  96. $roomId = request()->post('room_id', 0);
  97. $refresh = request()->post('refresh', 0);
  98. return showJson(1010, true);
  99. }
  100. public function noticeCount()
  101. {
  102. $noticeUid = request()->post('id',0);
  103. $userId = request()->post('uid',0);
  104. $userType = request()->post('type',0);
  105. return message(1010, true, []);
  106. }
  107. /**
  108. * 验证视频通话剩余时长
  109. * @return array
  110. */
  111. public function checkChat()
  112. {
  113. $toUserId = request()->post('to_user_id', 0);
  114. $fromUserId = request()->post('from_user_id', 0);
  115. $type = request()->post('type', 2);
  116. $data = ImChatService::make()->checkChat($fromUserId, $toUserId, $type);
  117. $config = ConfigService::make()->getConfigByCode('chat_buy_time_money');
  118. $config = $config ? explode('/', $config) : [];
  119. $money = isset($config[0]) && $config[0] > 0 ? $config[0] : 10;
  120. $num = isset($config[1]) && $config[1] > 0 ? $config[1] : 5;
  121. $tips = "抱歉您的免费时长已经用完,请先余额支付【{$money}元】购买【{$num}分钟】聊天时长再使用视频聊天服务。";
  122. return message(1010, true, ['time' => $data, 'tips' => $tips]);
  123. }
  124. }