IndexController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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\OrderService;
  7. use App\Services\Api\SocialCircleService;
  8. use App\Services\Api\StoreService;
  9. use App\Services\Common\AdService;
  10. use App\Services\Common\NoticeService;
  11. use App\Services\ConfigService;
  12. use App\Services\RedisService;
  13. /**
  14. * 首页
  15. * Class IndexController
  16. * @package App\Http\Controllers\Api
  17. */
  18. class IndexController extends webApp
  19. {
  20. /**
  21. * 配置信息
  22. * @return array
  23. */
  24. public function config()
  25. {
  26. try {
  27. $appSources = request()->post('app_sources', 'ios');
  28. $cacheKey = "caches:config:app_{$appSources}";
  29. $config = RedisService::get($cacheKey);
  30. if (empty($config)) {
  31. $config = [
  32. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  33. 'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
  34. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  35. 'app_android_url' => ConfigService::make()->getConfigByCode('app_android_url'),
  36. 'alipay_open' => ConfigService::make()->getConfigByCode('alipay_open', 0),
  37. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  38. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  39. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  40. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  41. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  42. 'notices' => NoticeService::make()->getRecommandList(),
  43. ];
  44. RedisService::set($cacheKey, $config, 3600);
  45. }
  46. return showJson(1010, true, $config);
  47. } catch (\Exception $exception) {
  48. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  49. return showJson(1046, false, $error);
  50. }
  51. }
  52. /**
  53. * 首页数据
  54. * @return array
  55. */
  56. public function data()
  57. {
  58. try {
  59. $data = [
  60. // 轮播
  61. 'banners' => AdService::make()->getListByPosition(1),
  62. 'articles' => ArticleService::make()->getListByType(1),
  63. ];
  64. return showJson(1010, true, $data);
  65. } catch (\Exception $exception) {
  66. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  67. return showJson(1046, false, $error);
  68. }
  69. }
  70. /**
  71. * 主页店铺商品
  72. * @return array
  73. */
  74. public function storeGoods()
  75. {
  76. $params = request()->post();
  77. try {
  78. $params['user_id'] = $this->userId;
  79. $datas = StoreService::make()->getGoodsList($params);
  80. return showJson(StoreService::make()->getError(), true, $datas);
  81. } catch (\Exception $exception) {
  82. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  83. return showJson(1046, false, $error);
  84. }
  85. }
  86. /**
  87. * 验证更新
  88. * @return array
  89. */
  90. public function versionCheck()
  91. {
  92. $version = request()->post('version', '');
  93. $appSources = request()->post('app_sources', 'ios');
  94. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  95. if (getVersion($version) < getVersion($currentVersion)) {
  96. $data = [
  97. 'has_update' => true,
  98. 'app_version' => $currentVersion,
  99. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  100. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  101. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  102. 'auto_update' => false, // 是否APP内自动更新
  103. ];
  104. return showJson(1010, true, $data);
  105. } else {
  106. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  107. }
  108. }
  109. }