IndexController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Helpers\Jwt;
  4. use App\Http\Validator\MemberValidator;
  5. use App\Services\Api\AdService;
  6. use App\Services\Api\MemberService;
  7. use App\Services\ChatMessageService;
  8. use App\Services\Common\TradeOrderService;
  9. use App\Services\ConfigService;
  10. use App\Services\EmailService;
  11. use App\Services\RedisService;
  12. use App\Services\SmsService;
  13. use App\Services\UsdtWalletService;
  14. /**
  15. * 会员控制器基类
  16. * Class IndexController
  17. * @package App\Http\Controllers
  18. */
  19. class IndexController extends webApp
  20. {
  21. /**
  22. * 首页数据
  23. * @return array
  24. */
  25. public function index(int $userId=0)
  26. {
  27. // 语言默认同步更新
  28. $locale = request()->post('locale');
  29. if($locale){
  30. RedisService::set("stores:locale:lang_{$this->userId}", $locale, 24 * 3600);
  31. session(['locale_lang'=>$locale]);
  32. app()->setLocale($locale);
  33. }
  34. // 广告幻灯片
  35. $banners = [
  36. 'top'=> AdService::make()->getList(1, 6),
  37. 'middle'=> AdService::make()->getList(2, 1),
  38. ];
  39. // 交易参数
  40. $trade = ConfigService::make()->getConfigByGroup(5);
  41. $counts = TradeOrderService::make()->getRateByTime(0,24);
  42. $trade = [
  43. 'buy_price'=> isset($trade['usdt_buy_price']['value'])? floatval($trade['usdt_buy_price']['value']) : '0.00',
  44. 'sell_price'=> isset($trade['usdt_sell_price']['value'])? floatval($trade['usdt_sell_price']['value']) : '0.00',
  45. 'total'=> TradeOrderService::make()->getCompleteTotalByTime(24),
  46. 'count'=> TradeOrderService::make()->getCompleteCountByTime(24),
  47. 'rate'=> isset($counts['rate'])? $counts['rate'] : '0.00',
  48. ];
  49. $notices = [];
  50. return message(1010, true, compact('banners','trade','notices'));
  51. }
  52. /**
  53. * 获取实时交易数据
  54. * @return array
  55. */
  56. public function trade()
  57. {
  58. // 交易参数
  59. $trade = ConfigService::make()->getConfigByGroup(5);
  60. $trade = [
  61. 'buy_price'=> isset($trade['usdt_buy_price']['value'])? floatval($trade['usdt_buy_price']['value']) : '0.00',
  62. 'sell_price'=> isset($trade['usdt_sell_price']['value'])? floatval($trade['usdt_sell_price']['value']) : '0.00',
  63. 'total'=> rand(100000,999999)+(rand(10,50)/100),
  64. 'count'=> rand(1000,9999),
  65. 'rate'=> rand(10,90)+(rand(10,50)/100),
  66. ];
  67. return message(1010, true, compact('trade'));
  68. }
  69. /**
  70. * 获取平台交易参数配置
  71. * @return array
  72. */
  73. public function config()
  74. {
  75. // 交易参数
  76. $type = request()->post('type', 1);
  77. if($type == 1){
  78. $trade = ConfigService::make()->getConfigOptionByGroup(5);
  79. }else if ($type == 2){
  80. $trade = ConfigService::make()->getConfigOptionByGroup(6);
  81. }else if ($type == 3){
  82. $trade1 = ConfigService::make()->getConfigOptionByGroup(7);
  83. $trade2 = ConfigService::make()->getConfigOptionByGroup(8);
  84. $trade = [
  85. 'confirm'=> array_values($trade1),
  86. 'tips'=> array_values($trade2),
  87. 'platform'=> ConfigService::make()->getConfigOptionByGroup(1)
  88. ];
  89. }
  90. return message(1010, true, compact('trade'));
  91. }
  92. /**
  93. * 未读消息数量
  94. * @return array
  95. */
  96. public function chatCount()
  97. {
  98. $userId = request()->post('user_id', 0);
  99. $userId = $userId? $userId : $this->userId;
  100. $count = ChatMessageService::make()->getUnReadCount($userId);
  101. return message(1002, true, $count);
  102. }
  103. }