IndexController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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\MpService;
  10. use App\Services\RedisService;
  11. /**
  12. * 首页
  13. * Class IndexController
  14. * @package App\Http\Controllers\Api
  15. */
  16. class IndexController extends webApp
  17. {
  18. /**
  19. * 配置信息
  20. * @return array
  21. */
  22. public function config()
  23. {
  24. try {
  25. $appSources = request()->post('app_sources', 'ios');
  26. $cacheKey = "caches:config:app_{$appSources}";
  27. $config = RedisService::get($cacheKey);
  28. if (empty($config)) {
  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' => ConfigService::make()->getConfigByCode('deposit_money'),
  35. 'deposit_desc' => format_content(ConfigService::make()->getConfigByCode('deposit_desc', '')),
  36. 'deposit_refund_desc' => format_content(ConfigService::make()->getConfigByCode('deposit_refund_desc', '')),
  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. 'kfUrl' => ConfigService::make()->getConfigByCode('wechat_kf_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,[], true);
  61. $confirmStatus = isset($userInfo['confirm_status'])? $userInfo['confirm_status'] : 0;
  62. $pickerStatus = isset($userInfo['picker_status'])? $userInfo['picker_status'] : 0;
  63. if($confirmStatus != 1 || $pickerStatus!= 1){
  64. return message(2043, false,[],405);
  65. }
  66. $data = [
  67. // 线上课程
  68. 'courses' => [],
  69. 'articles'=>[]
  70. ];
  71. return showJson(1010, true, $data);
  72. }
  73. /**
  74. * 验证更新
  75. * @return array
  76. */
  77. public function versionCheck()
  78. {
  79. $version = request()->post('version', '');
  80. $appSources = request()->post('app_sources', 'ios');
  81. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  82. if (getVersion($version) < getVersion($currentVersion)) {
  83. $data = [
  84. 'has_update' => true,
  85. 'app_version' => $currentVersion,
  86. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  87. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  88. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  89. 'auto_update' => false, // 是否APP内自动更新
  90. ];
  91. return showJson(1010, true, $data);
  92. } else {
  93. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  94. }
  95. }
  96. }