IndexController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\AccountService;
  5. use App\Services\Api\MemberService;
  6. use App\Services\Api\OrderService;
  7. use App\Services\Common\NoticeService;
  8. use App\Services\ConfigService;
  9. use App\Services\RedisService;
  10. /**
  11. * 首页
  12. * Class IndexController
  13. * @package App\Http\Controllers\Api
  14. */
  15. class IndexController extends webApp
  16. {
  17. /**
  18. * 配置信息
  19. * @return array
  20. */
  21. public function config()
  22. {
  23. try {
  24. $appSources = request()->post('app_sources', 'ios');
  25. $cacheKey = "caches:config:app_{$appSources}";
  26. $config = RedisService::get($cacheKey);
  27. if (empty($config)) {
  28. $depositConfig = ConfigService::make()->getConfigByGroup(5);
  29. $config = [
  30. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  31. 'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
  32. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  33. 'app_android_url' => ConfigService::make()->getConfigByCode('app_android_url'),
  34. 'deposit_money' => isset($depositConfig['deposit_money']['value'])? floatval($depositConfig['deposit_money']['value']) : 0,
  35. 'deposit_desc' => isset($depositConfig['deposit_desc']['value'])? format_content($depositConfig['deposit_desc']['value']) : '',
  36. 'deposit_refund_desc' => isset($depositConfig['deposit_refund_desc']['value'])? format_content($depositConfig['deposit_refund_desc']['value']) : '',
  37. 'alipay_open' => ConfigService::make()->getConfigByCode('alipay_open', 1),
  38. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 1),
  39. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 1),
  40. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  41. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  42. 'imchat_url' => ConfigService::make()->getConfigByCode('imchat_url', ''),
  43. 'img_compress'=> ConfigService::make()->getConfigByCode('preview_img_compress', ''),
  44. 'notices' => NoticeService::make()->getRecommandList(),
  45. ];
  46. RedisService::set($cacheKey, $config, 3600);
  47. }
  48. return showJson(1010, true, $config);
  49. } catch (\Exception $exception) {
  50. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  51. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  52. }
  53. }
  54. /**
  55. * 首页数据
  56. * @return array
  57. */
  58. public function data()
  59. {
  60. $userInfo = MemberService::make()->getInfo($this->userId);
  61. $confirmStatus = isset($userInfo['confirm_status'])? $userInfo['confirm_status'] : 0;
  62. $pickerStatus = isset($userInfo['picker_status'])? $userInfo['picker_status'] : 0;
  63. if($confirmStatus != 1){
  64. return message(2043, false,[],405);
  65. }
  66. if($pickerStatus!= 1){
  67. return message(2063, false,[],406);
  68. }
  69. $data = [
  70. // 首页数据
  71. 'counts' => [
  72. 'dayIncome' => AccountService::make()->getTotalByDay($this->userId, 1),
  73. 'dayOrder' => OrderService::make()->getCountByDay($this->userId, 3),
  74. ],
  75. ];
  76. return showJson(1010, true, $data);
  77. }
  78. /**
  79. * 验证更新
  80. * @return array
  81. */
  82. public function versionCheck()
  83. {
  84. $version = request()->post('version', '');
  85. $appSources = request()->post('app_sources', 'ios');
  86. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  87. if (getVersion($version) < getVersion($currentVersion)) {
  88. $data = [
  89. 'has_update' => true,
  90. 'app_version' => $currentVersion,
  91. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  92. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  93. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  94. 'auto_update' => false, // 是否APP内自动更新
  95. ];
  96. return showJson(1010, true, $data);
  97. } else {
  98. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  99. }
  100. }
  101. }