IndexController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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'])? $params['system'] : [];
  32. $appSources = isset($system['app_sources']) && $system['app_sources']? $system['app_sources'] : 'ios';
  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. 'custom_phone' => ConfigService::make()->getConfigByCode('custom_phone'),
  42. 'custom_telegram' => ConfigService::make()->getConfigByCode('custom_telegram'),
  43. 'custom_email' => ConfigService::make()->getConfigByCode('custom_email'),
  44. 'open_h5' => ConfigService::make()->getConfigByCode('open_h5',0),
  45. ];
  46. RedisService::set($cacheKey, $config, 7200);
  47. }
  48. $config['app_sources'] = $appSources;
  49. $config['app_url'] = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  50. return showJson(1010, true, $config);
  51. } catch (\Exception $exception) {
  52. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  53. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  54. }
  55. }
  56. /**
  57. * 物流公司
  58. * @return array
  59. */
  60. public function express()
  61. {
  62. return showJson(1010, true, config('express'));
  63. }
  64. /**
  65. * 验证APP更新
  66. * @return array
  67. */
  68. public function versionCheck()
  69. {
  70. $system = request()->post('system',[]);
  71. $version = isset($system['version'])? $system['version'] : '1.3.20';
  72. $appSources = isset($system['app_sources'])? $system['app_sources'] : 'ios';
  73. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  74. if (getVersion($version) < getVersion($currentVersion)) {
  75. $data = [
  76. 'has_update' => true,
  77. 'app_version' => $currentVersion,
  78. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  79. 'update_notice' => ConfigService::make()->getConfigByCode('app_update_notice'),
  80. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  81. ];
  82. return showJson(1010, true, $data);
  83. } else {
  84. $appUrl = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  85. return showJson(1010, false, ['has_update' => false,'app_url'=>$appUrl, 'version' => $version]);
  86. }
  87. }
  88. /**
  89. * 直播参数
  90. * @return array
  91. */
  92. public function liveConfig()
  93. {
  94. $userId = request()->post('user_id', 0);
  95. $roomId = request()->post('room_id', 0);
  96. $refresh = request()->post('refresh', 0);
  97. return showJson(1010, true);
  98. }
  99. public function noticeCount()
  100. {
  101. $noticeUid = request()->post('id',0);
  102. $userId = request()->post('uid',0);
  103. $userType = request()->post('type',0);
  104. return message(1010, true, []);
  105. }
  106. /**
  107. * 验证视频通话剩余时长
  108. * @return array
  109. */
  110. public function checkChat()
  111. {
  112. $toUserId = request()->post('to_user_id', 0);
  113. $fromUserId = request()->post('from_user_id', 0);
  114. $type = request()->post('type', 2);
  115. $data = ImChatService::make()->checkChat($fromUserId, $toUserId, $type);
  116. $config = ConfigService::make()->getConfigByCode('chat_buy_time_money');
  117. $config = $config ? explode('/', $config) : [];
  118. $money = isset($config[0]) && $config[0] > 0 ? $config[0] : 10;
  119. $num = isset($config[1]) && $config[1] > 0 ? $config[1] : 5;
  120. $tips = "抱歉您的免费时长已经用完,请先余额支付【{$money}元】购买【{$num}分钟】聊天时长再使用视频聊天服务。";
  121. return message(1010, true, ['time' => $data, 'tips' => $tips]);
  122. }
  123. }