IndexController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\OrderService;
  6. use App\Services\Api\SupervisorsService;
  7. use App\Services\Common\AdService;
  8. use App\Services\Common\NoticeService;
  9. use App\Services\ConfigService;
  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. 'index_logo' => get_image_url(ConfigService::make()->getConfigByCode('index_logo')),
  33. 'app_name_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_name_logo')),
  34. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  35. 'bonus_desc' => format_content(ConfigService::make()->getConfigByCode('bonus_desc', '')),
  36. 'auth_desc' => format_content(ConfigService::make()->getConfigByCode('auth_desc', '')),
  37. 'bank_desc' => format_content(ConfigService::make()->getConfigByCode('bank_desc', '')),
  38. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  39. 'goods_disclaimer' => format_content(ConfigService::make()->getConfigByCode('goods_disclaimer', '')),
  40. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  41. 'bank_limit_num' => ConfigService::make()->getConfigByCode('bank_limit_num', 5),
  42. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  43. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  44. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  45. ];
  46. RedisService::set($cacheKey, $config, 3600);
  47. }
  48. return showJson(1010, true, $config);
  49. } catch (\Exception $exception) {
  50. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  51. return showJson(1046, false, $error);
  52. }
  53. }
  54. /**
  55. * 首页数据
  56. * @return array
  57. */
  58. public function data()
  59. {
  60. try {
  61. $data = [
  62. 'menus'=>[
  63. ['id'=>4,'name'=>'男神玩具','menu-icon'=>'','remark'=>'SELF-OPERATED PRODUCTS'],
  64. ['id'=>5,'name'=>'女神玩具','menu-icon'=>'','remark'=>'GODDESS TOY PRODUCTS'],
  65. ['id'=>6,'name'=>'私密养护','menu-icon'=>'','remark'=>'INTIMATE CARE PRODUCTS'],
  66. ['id'=>7,'name'=>'情趣服饰','menu-icon'=>'','remark'=>'EROTIC CLOTHING PRODUCTS'],
  67. ['id'=>8,'name'=>'SM房趣','menu-icon'=>'','remark'=>'SM HOUSE FUN PRODUCTS'],
  68. ['id'=>9,'name'=>'体感娃娃','menu-icon'=>'','remark'=>'HUG DOLL PRODUCTS'],
  69. ],
  70. // 轮播
  71. 'banners' => AdService::make()->getListByPosition(1), // 轮播
  72. 'config'=>[
  73. 'short_name' => ConfigService::make()->getConfigByCode('short_name'),
  74. 'index_logo' => get_image_url(ConfigService::make()->getConfigByCode('index_logo')),
  75. ]
  76. ];
  77. return showJson(1010, true, $data);
  78. } catch (\Exception $exception) {
  79. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  80. return showJson(1046, false, $error);
  81. }
  82. }
  83. /**
  84. * 订单公告
  85. * @return array
  86. */
  87. public function notices()
  88. {
  89. try {
  90. return showJson(1010, true, \App\Services\Api\NoticeService::make()->getDataList());
  91. } catch (\Exception $exception) {
  92. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  93. return showJson(1046, false, $error);
  94. }
  95. }
  96. /**
  97. * 验证更新
  98. * @return array
  99. */
  100. public function versionCheck()
  101. {
  102. $version = request()->post('version', '');
  103. $appSources = request()->post('app_sources', 'ios');
  104. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  105. if (getVersion($version) < getVersion($currentVersion)) {
  106. $data = [
  107. 'has_update' => true,
  108. 'app_version' => $currentVersion,
  109. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  110. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  111. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  112. 'auto_update' => false, // 是否APP内自动更新
  113. ];
  114. return showJson(1010, true, $data);
  115. } else {
  116. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  117. }
  118. }
  119. }