IndexController.php 4.5 KB

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