IndexController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. # 用户充值协议
  58. $rechargeAgree = ArticleService::make()->getInfo(1);
  59. $rechargeAgree = isset($rechargeAgree['content'])? htmlspecialchars_decode($rechargeAgree['content']) : '';
  60. $config = [
  61. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  62. 'app_logo' => ConfigService::make()->getConfigByCode('app_logo'),
  63. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  64. 'h5_url' => ConfigService::make()->getConfigByCode("h5_url"),
  65. 'chat_url' => ConfigService::make()->getConfigByCode("chat_url"),
  66. 'custom_phone' => ConfigService::make()->getConfigByCode('custom_phone'),
  67. 'custom_telegram' => ConfigService::make()->getConfigByCode('custom_telegram'),
  68. 'custom_email' => ConfigService::make()->getConfigByCode('custom_email'),
  69. 'open_h5' => (int)ConfigService::make()->getConfigByCode('open_h5',0),
  70. 'min_recharge' => (float)ConfigService::make()->getConfigByCode('min_recharge',0.1),
  71. 'recharge_agree' => $rechargeAgree,
  72. 'xd_price' => $xdPrice,
  73. 'rechargeMeals'=> $meals,
  74. ];
  75. RedisService::set($cacheKey, $config, 7200);
  76. }
  77. $config['app_sources'] = $appSources;
  78. $config['app_url'] = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  79. return showJson(1010, true, $config);
  80. } catch (\Exception $exception) {
  81. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  82. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  83. }
  84. }
  85. /**
  86. * 物流公司
  87. * @return array
  88. */
  89. public function express()
  90. {
  91. return showJson(1010, true, config('express'));
  92. }
  93. /**
  94. * 验证APP更新
  95. * @return array
  96. */
  97. public function versionCheck()
  98. {
  99. $system = request()->post('system',[]);
  100. $version = isset($system['version'])? $system['version'] : '1.3.20';
  101. $appSources = isset($system['app_sources'])? $system['app_sources'] : 'ios';
  102. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  103. if (getVersion($version) < getVersion($currentVersion)) {
  104. $data = [
  105. 'has_update' => true,
  106. 'app_version' => $currentVersion,
  107. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  108. 'update_notice' => ConfigService::make()->getConfigByCode('app_update_notice'),
  109. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  110. ];
  111. return showJson(1010, true, $data);
  112. } else {
  113. $appUrl = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  114. return showJson(1010, false, ['has_update' => false,'app_url'=>$appUrl, 'version' => $version]);
  115. }
  116. }
  117. /**
  118. * 直播参数
  119. * @return array
  120. */
  121. public function liveConfig()
  122. {
  123. $userId = request()->post('user_id', 0);
  124. $roomId = request()->post('room_id', 0);
  125. $refresh = request()->post('refresh', 0);
  126. return showJson(1010, true);
  127. }
  128. public function noticeCount()
  129. {
  130. $noticeUid = request()->post('id',0);
  131. $userId = request()->post('uid',0);
  132. $userType = request()->post('type',0);
  133. return message(1010, true, []);
  134. }
  135. /**
  136. * 验证视频通话剩余时长
  137. * @return array
  138. */
  139. public function checkChat()
  140. {
  141. $toUserId = request()->post('to_user_id', 0);
  142. $fromUserId = request()->post('from_user_id', 0);
  143. $type = request()->post('type', 2);
  144. $data = ImChatService::make()->checkChat($fromUserId, $toUserId, $type);
  145. $config = ConfigService::make()->getConfigByCode('chat_buy_time_money');
  146. $config = $config ? explode('/', $config) : [];
  147. $money = isset($config[0]) && $config[0] > 0 ? $config[0] : 10;
  148. $num = isset($config[1]) && $config[1] > 0 ? $config[1] : 5;
  149. $tips = "抱歉您的免费时长已经用完,请先余额支付【{$money}元】购买【{$num}分钟】聊天时长再使用视频聊天服务。";
  150. return message(1010, true, ['time' => $data, 'tips' => $tips]);
  151. }
  152. }