IndexController.php 6.3 KB

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