IndexController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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\VideoCommentService;
  8. use App\Services\Api\VideoService;
  9. use App\Services\ConfigService;
  10. use App\Services\RedisService;
  11. /**
  12. * 首页
  13. * @package App\Http\Controllers\Api
  14. */
  15. class IndexController extends webApp
  16. {
  17. /**
  18. * 视频推荐列表
  19. * @return array
  20. */
  21. public function videos()
  22. {
  23. try {
  24. $params = request()->post();
  25. $pageSize = request()->post('pageSize', 0);
  26. $params['is_recommend'] = 1;
  27. $datas = VideoService::make()->getIndexList($params, $pageSize,'', $this->userId);
  28. return showJson(1010, true, $datas);
  29. } catch (\Exception $exception){
  30. RedisService::set("caches:request:error_video_index", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  31. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  32. }
  33. }
  34. /**
  35. * 视频评论
  36. * @return array
  37. */
  38. public function videoComment()
  39. {
  40. try {
  41. $params = request()->post();
  42. $pageSize = request()->post('pageSize', 0);
  43. $datas = VideoCommentService::make()->getDataList($params, $pageSize,'', $this->userId);
  44. return showJson(1010, true, $datas);
  45. } catch (\Exception $exception){
  46. RedisService::set("caches:request:error_video_comment", ['error'=>$exception->getMessage(),'trace'=>$exception->getTrace()], 7200);
  47. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  48. }
  49. }
  50. /**
  51. * 配置信息
  52. * @return array
  53. */
  54. public function config()
  55. {
  56. try {
  57. $params = request()->all();
  58. $system = isset($params['system'])? json_decode($params['system'], true) : [];
  59. $appSources = isset($system['app_sources']) && $system['app_sources']? $system['app_sources'] : 'android';
  60. $cacheKey = "caches:config:app_{$appSources}";
  61. $config = RedisService::get($cacheKey);
  62. if (empty($config)) {
  63. $mealList = ConfigService::make()->getConfigByCode('recharge_xd_meals','');
  64. $mealList = $mealList? explode('|', $mealList) : [];
  65. $mealList = $mealList? $mealList : [10,20,50,100,200,500,1000];
  66. $meals = [];
  67. $xdPrice = (float)ConfigService::make()->getConfigByCode('xd_price',100);
  68. foreach($mealList as $item){
  69. $meals[] = [
  70. 'money'=> $item,
  71. 'usdt'=> moneyFormat($item/$xdPrice,2),
  72. ];
  73. }
  74. # 用户充值协议
  75. $locale = RedisService::get("caches:locale:lang_{$this->userId}");
  76. $locale = $locale? $locale : session('locale_lang');
  77. $rechargeAgree = ArticleService::make()->getInfo(3, $this->userId, true);
  78. $rechargeAgree = isset($rechargeAgree['content'])? $rechargeAgree['content'] : '';
  79. $withdrawAgree = ArticleService::make()->getInfo(5, $this->userId, true);
  80. $withdrawAgree = isset($withdrawAgree['content'])? $withdrawAgree['content'] : '';
  81. $minTransfer = (float)ConfigService::make()->getConfigByCode('min_transfer',0.1);
  82. $maxTransfer = (float)ConfigService::make()->getConfigByCode('max_transfer',100000);
  83. $transferFee = (float)ConfigService::make()->getConfigByCode('transfer_fee_rate',5);
  84. $withdrawFee = (float)ConfigService::make()->getConfigByCode('withdraw_fee_rate',5);
  85. $config = [
  86. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  87. 'app_logo' => ConfigService::make()->getConfigByCode('app_logo'),
  88. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  89. 'h5_url' => ConfigService::make()->getConfigByCode("h5_url"),
  90. 'chat_url' => ConfigService::make()->getConfigByCode("chat_url"),
  91. 'custom_phone' => ConfigService::make()->getConfigByCode('custom_phone'),
  92. 'custom_telegram' => ConfigService::make()->getConfigByCode('custom_telegram'),
  93. 'custom_email' => ConfigService::make()->getConfigByCode('custom_email'),
  94. 'open_h5' => (int)ConfigService::make()->getConfigByCode('open_h5',0),
  95. 'min_recharge' => (float)ConfigService::make()->getConfigByCode('min_recharge',0.1),
  96. 'min_transfer' => $minTransfer>0.1? moneyFormat($minTransfer,2) : 0.1,
  97. 'max_transfer' => $maxTransfer>0 && $maxTransfer<=100000? moneyFormat($maxTransfer,2) : 100000,
  98. 'transfer_fee_rate' => $transferFee>0 && $transferFee<100? moneyFormat($transferFee/100,2) : 0,
  99. 'withdraw_fee_rate' => $withdrawFee>0 && $withdrawFee<100? moneyFormat($withdrawFee/100,2) : 0,
  100. 'recharge_agree' => $rechargeAgree,
  101. 'withdraw_agree' => $withdrawAgree,
  102. 'xd_price' => $xdPrice,
  103. 'rechargeMeals'=> $meals,
  104. 'lang'=> $locale,
  105. ];
  106. RedisService::set($cacheKey, $config, 7200);
  107. }
  108. $config['app_sources'] = $appSources;
  109. $config['app_url'] = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  110. return showJson(1010, true, $config);
  111. } catch (\Exception $exception) {
  112. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  113. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  114. }
  115. }
  116. /**
  117. * 验证APP更新
  118. * @return array
  119. */
  120. public function versionCheck()
  121. {
  122. $system = request()->post('system',[]);
  123. $version = isset($system['version'])? $system['version'] : '1.3.20';
  124. $appSources = isset($system['app_sources'])? $system['app_sources'] : 'ios';
  125. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  126. if (getVersion($version) < getVersion($currentVersion)) {
  127. $data = [
  128. 'has_update' => true,
  129. 'app_version' => $currentVersion,
  130. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  131. 'update_notice' => ConfigService::make()->getConfigByCode('app_update_notice'),
  132. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  133. ];
  134. return showJson(1010, true, $data);
  135. } else {
  136. $appUrl = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  137. return showJson(1010, false, ['has_update' => false,'app_url'=>$appUrl, 'version' => $version]);
  138. }
  139. }
  140. /**
  141. * 币种
  142. * @return array
  143. */
  144. public function country()
  145. {
  146. $data = [
  147. ['code'=>'CNY','name'=>'人民币','country'=>'中国','locale'=>'zh-cn','mark'=>'¥','status'=>1],
  148. ['code'=>'MYR','name'=>'林吉特','country'=>'马来西亚','locale'=>'mal','mark'=>'RM','status'=>1],
  149. ['code'=>'VND','name'=>'越南盾','country'=>'越南','locale'=>'vie','mark'=>'₫','status'=>1],
  150. ['code'=>'THB','name'=>'泰铢','country'=>'泰国','locale'=>'tha','mark'=>'฿','status'=>1],
  151. ['code'=>'IDR','name'=>'卢比','country'=>'印度尼西亚','locale'=>'ind','mark'=>'R','status'=>1],
  152. ['code'=>'JAY','name'=>'日元','country'=>'日本','locale'=>'jap','mark'=>'¥','status'=>1],
  153. ['code'=>'KRW','name'=>'韩元','country'=>'韩国','locale'=>'sk','mark'=>'₩','status'=>1],
  154. ['code'=>'EUR','name'=>'欧元','country'=>'法国','locale'=>'fr','mark'=>'€','status'=>1],
  155. ['code'=>'USD','name'=>'美元','country'=>'美国','locale'=>'en','mark'=>'$','status'=>1],
  156. ];
  157. return showJson(1010, true, $data);
  158. }
  159. }