IndexController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. $exchangePrice = (float)ConfigService::make()->getConfigByCode('score_exchange_xd_rate',100);
  69. foreach($mealList as $item){
  70. $meals[] = [
  71. 'money'=> $item,
  72. 'usdt'=> moneyFormat($item/$xdPrice,2),
  73. ];
  74. }
  75. # 用户充值协议
  76. $locale = RedisService::get("caches:locale:lang_{$this->userId}");
  77. $locale = $locale? $locale : session('locale_lang');
  78. $rechargeAgree = ArticleService::make()->getInfo(3, $this->userId, true);
  79. $rechargeAgree = isset($rechargeAgree['content'])? $rechargeAgree['content'] : '';
  80. $withdrawAgree = ArticleService::make()->getInfo(5, $this->userId, true);
  81. $withdrawAgree = isset($withdrawAgree['content'])? $withdrawAgree['content'] : '';
  82. $minTransfer = (float)ConfigService::make()->getConfigByCode('min_transfer',0.1);
  83. $maxTransfer = (float)ConfigService::make()->getConfigByCode('max_transfer',100000);
  84. $transferFee = (float)ConfigService::make()->getConfigByCode('transfer_fee_rate',0);
  85. $withdrawFee = (float)ConfigService::make()->getConfigByCode('withdraw_fee_rate',0);
  86. $exchangeFee = (float)ConfigService::make()->getConfigByCode('exchange_fee_rate',0);
  87. $accounts = [];
  88. $wxpayRealname = ConfigService::make()->getConfigByCode('recharge_wxpay_realname','');
  89. $wxpayQrcode = ConfigService::make()->getConfigByCode('recharge_wxpay_qrcode', '');
  90. if($wxpayRealname && $wxpayQrcode){
  91. $accounts['wxpay'] = [
  92. 'realname' => $wxpayRealname,
  93. 'qrcode'=> get_image_url($wxpayQrcode),
  94. ];
  95. }
  96. $alipayRealname = ConfigService::make()->getConfigByCode('recharge_alipay_realname','');
  97. $alipayQrcode = ConfigService::make()->getConfigByCode('recharge_alipay_qrcode', '');
  98. if($alipayRealname && $alipayQrcode){
  99. $accounts['alipay'] = [
  100. 'realname' => $alipayRealname,
  101. 'qrcode'=> get_image_url($alipayQrcode),
  102. ];
  103. }
  104. $bankRealname = ConfigService::make()->getConfigByCode('recharge_bank_realname','');
  105. $bankName = ConfigService::make()->getConfigByCode('recharge_bank_name','');
  106. $bankCard = ConfigService::make()->getConfigByCode('recharge_bank_card', '');
  107. $bankBranch = ConfigService::make()->getConfigByCode('recharge_bank_branch', '');
  108. if($bankRealname && $bankName && $bankCard){
  109. $accounts['bank_account'] = [
  110. 'realname' => $bankRealname,
  111. 'bank_name' => $bankName,
  112. 'bank_card' => $bankCard,
  113. 'bank_branch'=> $bankBranch,
  114. ];
  115. }
  116. $usdtPrice = RedisService::get("caches:wallets:usdt_rate");
  117. if ($usdtPrice <= 0) {
  118. $usdtCnyPrice = ConfigService::make()->getConfigByCode('usdt_cny_price', 7.2);
  119. $usdtPrice = $usdtCnyPrice > 0 && $usdtCnyPrice < 100 ? $usdtCnyPrice : 0;
  120. }
  121. $config = [
  122. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  123. 'app_logo' => ConfigService::make()->getConfigByCode('app_logo'),
  124. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  125. 'h5_url' => ConfigService::make()->getConfigByCode("h5_url"),
  126. 'chat_url' => ConfigService::make()->getConfigByCode("chat_url"),
  127. 'chat_api_url' => ConfigService::make()->getConfigByCode("chat_api_url"),
  128. 'custom_phone' => ConfigService::make()->getConfigByCode('custom_phone'),
  129. 'custom_telegram' => ConfigService::make()->getConfigByCode('custom_telegram'),
  130. 'custom_email' => ConfigService::make()->getConfigByCode('custom_email'),
  131. 'open_h5' => (int)ConfigService::make()->getConfigByCode('open_h5',0),
  132. 'min_recharge' => (float)ConfigService::make()->getConfigByCode('min_recharge',0.1),
  133. 'min_transfer' => $minTransfer>0.1? moneyFormat($minTransfer,2) : 0.1,
  134. 'max_transfer' => $maxTransfer>0 && $maxTransfer<=100000? moneyFormat($maxTransfer,2) : 100000,
  135. 'transfer_fee_rate' => $transferFee>0 && $transferFee<100? moneyFormat($transferFee/100,2) : 0,
  136. 'withdraw_fee_rate' => $withdrawFee>0 && $withdrawFee<100? moneyFormat($withdrawFee/100,2) : 0,
  137. 'exchange_fee' => $exchangeFee>0 && $exchangeFee<100? moneyFormat($exchangeFee,3) : 0,
  138. 'recharge_agree' => $rechargeAgree,
  139. 'withdraw_agree' => $withdrawAgree,
  140. 'xd_price' => $xdPrice,
  141. 'usdt_price' => $usdtPrice,
  142. 'exchange_price' => $exchangePrice,
  143. 'rechargeMeals'=> $meals,
  144. 'accounts'=> $accounts,
  145. 'payments' => [
  146. [
  147. 'icon' => get_image_url('/images/pay/icon_usdt.png'),
  148. 'name' => 'USDT',
  149. 'status' => ConfigService::make()->getConfigByCode('usdt_open',1),
  150. 'code' => 20,
  151. "color"=> '#14ECCC',
  152. ],
  153. [
  154. 'icon' => get_image_url('/images/pay/icon_wxpay.png'),
  155. 'name' => '微信',
  156. 'status' => ConfigService::make()->getConfigByCode('wechat_open',1),
  157. 'code' => 30,
  158. "color"=> '#666',
  159. ],
  160. [
  161. 'icon' => get_image_url('/images/pay/icon_alipay.png'),
  162. 'name' => '支付宝',
  163. 'status' => ConfigService::make()->getConfigByCode('alipay_open',1),
  164. 'code' => 40,
  165. "color"=> '#666',
  166. ],
  167. [
  168. 'icon' => get_image_url('/images/pay/icon_bank.png'),
  169. 'name' => '银行卡',
  170. 'status' => ConfigService::make()->getConfigByCode('bank_open',1),
  171. 'code' => 50,
  172. "color"=> '#666',
  173. ],
  174. ],
  175. 'lang'=> $locale,
  176. ];
  177. RedisService::set($cacheKey, $config, 7200);
  178. }
  179. $config['app_sources'] = $appSources;
  180. $config['ios_plist'] = get_image_url('/app/');
  181. $config['app_logo'] = get_image_url($config['app_logo']);
  182. $config['app_url'] = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  183. return showJson(1010, true, $config);
  184. } catch (\Exception $exception) {
  185. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  186. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  187. }
  188. }
  189. /**
  190. * APP配置信息
  191. * @return array
  192. */
  193. public function appData()
  194. {
  195. try {
  196. $params = request()->all();
  197. $system = isset($params['system'])? json_decode($params['system'], true) : [];
  198. $appSources = isset($system['app_sources']) && $system['app_sources']? $system['app_sources'] : 'android';
  199. $cacheKey = "caches:config:app_data_{$appSources}";
  200. $config = RedisService::get($cacheKey);
  201. if (empty($config)) {
  202. $locale = RedisService::get("caches:locale:lang_{$this->userId}");
  203. $locale = $locale? $locale : session('locale_lang');
  204. $updateNotice = ConfigService::make()->getConfigByCode('app_update_notice');
  205. $updateNotice = $updateNotice? str_replace("\n","</br>", $updateNotice):'';
  206. $config = [
  207. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  208. 'app_logo' => ConfigService::make()->getConfigByCode('app_logo'),
  209. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  210. 'app_update_notice' => $updateNotice,
  211. 'h5_url' => ConfigService::make()->getConfigByCode("h5_url"),
  212. 'custom_phone' => ConfigService::make()->getConfigByCode('custom_phone'),
  213. 'custom_telegram' => ConfigService::make()->getConfigByCode('custom_telegram'),
  214. 'custom_email' => ConfigService::make()->getConfigByCode('custom_email'),
  215. 'lang'=> $locale,
  216. ];
  217. RedisService::set($cacheKey, $config, 7200);
  218. }
  219. $config['app_sources'] = $appSources;
  220. $config['app_logo'] = get_image_url($config['app_logo']);
  221. $config['app_url'] = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  222. return showJson(1010, true, $config);
  223. } catch (\Exception $exception) {
  224. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  225. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  226. }
  227. }
  228. /**
  229. * 验证APP更新
  230. * @return array
  231. */
  232. public function versionCheck()
  233. {
  234. $system = request()->post('system',[]);
  235. $version = request()->post('version', '1.3.20');
  236. $appSources = isset($system['app_sources'])? $system['app_sources'] : 'ios';
  237. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  238. // var_dump(getVersion($version),getVersion($currentVersion));
  239. if (getVersion($version) < getVersion($currentVersion)) {
  240. $data = [
  241. 'has_update' => true,
  242. 'app_version' => $currentVersion,
  243. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  244. 'update_notice' => ConfigService::make()->getConfigByCode('app_update_notice'),
  245. 'app_url' => ConfigService::make()->getConfigByCode("app_url"),
  246. 'is_force' => ConfigService::make()->getConfigByCode("is_force",0),
  247. 'app_hot_wget_url' => ConfigService::make()->getConfigByCode("app_hot_wget_url"),
  248. 'app_download_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  249. ];
  250. return showJson(1010, true, $data);
  251. } else {
  252. $wgetUrl = ConfigService::make()->getConfigByCode("app_hot_wget_url");
  253. $appUrl = ConfigService::make()->getConfigByCode("app_url");
  254. $isForce = ConfigService::make()->getConfigByCode("is_force",0);
  255. $appDownloadUrl = ConfigService::make()->getConfigByCode("app_{$appSources}_url");
  256. return showJson(1010, false, ['has_update' => false,'is_force'=>$isForce,'app_url'=>$appUrl,'app_hot_wget_url'=>$wgetUrl,'app_download_url'=>$appDownloadUrl, 'version' => $version]);
  257. }
  258. }
  259. /**
  260. * 币种
  261. * @return array
  262. */
  263. public function country()
  264. {
  265. $data = [
  266. ['code'=>'CNY','name'=>'人民币','country'=>'中国','locale'=>'zh-cn','mark'=>'¥','status'=>1],
  267. ['code'=>'MYR','name'=>'林吉特','country'=>'马来西亚','locale'=>'mal','mark'=>'RM','status'=>1],
  268. ['code'=>'VND','name'=>'越南盾','country'=>'越南','locale'=>'vie','mark'=>'₫','status'=>1],
  269. ['code'=>'THB','name'=>'泰铢','country'=>'泰国','locale'=>'tha','mark'=>'฿','status'=>1],
  270. ['code'=>'IDR','name'=>'卢比','country'=>'印度尼西亚','locale'=>'ind','mark'=>'R','status'=>1],
  271. ['code'=>'JAY','name'=>'日元','country'=>'日本','locale'=>'jap','mark'=>'¥','status'=>1],
  272. ['code'=>'KRW','name'=>'韩元','country'=>'韩国','locale'=>'sk','mark'=>'₩','status'=>1],
  273. ['code'=>'EUR','name'=>'欧元','country'=>'法国','locale'=>'fr','mark'=>'€','status'=>1],
  274. ['code'=>'USD','name'=>'美元','country'=>'美国','locale'=>'en','mark'=>'$','status'=>1],
  275. ];
  276. return showJson(1010, true, $data);
  277. }
  278. }