IndexController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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\SupervisorsService;
  8. use App\Services\Common\AdService;
  9. use App\Services\Common\NoticeService;
  10. use App\Services\ConfigService;
  11. use App\Services\RedisService;
  12. /**
  13. * 首页
  14. * Class IndexController
  15. * @package App\Http\Controllers\Api
  16. */
  17. class IndexController extends webApp
  18. {
  19. /**
  20. * 配置信息
  21. * @return array
  22. */
  23. public function config()
  24. {
  25. try {
  26. $appSources = request()->post('app_sources', 'ios');
  27. $cacheKey = "caches:config:app_{$appSources}";
  28. $config = RedisService::get($cacheKey);
  29. if (empty($config)) {
  30. $config = [
  31. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  32. 'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
  33. 'index_logo' => get_image_url(ConfigService::make()->getConfigByCode('index_logo')),
  34. 'app_name_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_name_logo')),
  35. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  36. 'bonus_desc' => format_content(ConfigService::make()->getConfigByCode('bonus_desc', '')),
  37. 'auth_desc' => format_content(ConfigService::make()->getConfigByCode('auth_desc', '')),
  38. 'bank_desc' => format_content(ConfigService::make()->getConfigByCode('bank_desc', '')),
  39. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  40. 'goods_disclaimer' => format_content(ConfigService::make()->getConfigByCode('goods_disclaimer', '')),
  41. 'social_open' => ConfigService::make()->getConfigByCode('social_open', 0),
  42. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  43. 'bank_limit_num' => ConfigService::make()->getConfigByCode('bank_limit_num', 5),
  44. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  45. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  46. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  47. ];
  48. RedisService::set($cacheKey, $config, 3600);
  49. }
  50. return showJson(1010, true, $config);
  51. } catch (\Exception $exception) {
  52. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  53. return showJson(1046, false, $error);
  54. }
  55. }
  56. /**
  57. * 首页数据
  58. * @return array
  59. */
  60. public function data()
  61. {
  62. try {
  63. $data = [
  64. 'menus'=>[
  65. ['id'=>4,'name'=>'男神玩具','remark'=>'MALE GOD PRODUCTS'],
  66. ['id'=>5,'name'=>'女神玩具','remark'=>'GODDESS TOY PRODUCTS'],
  67. ['id'=>6,'name'=>'私密养护','remark'=>'INTIMATE CARE PRODUCTS'],
  68. ['id'=>7,'name'=>'情趣服饰','remark'=>'EROTIC CLOTHING PRODUCTS'],
  69. ['id'=>8,'name'=>'SM房趣','remark'=>'SM HOUSE FUN PRODUCTS'],
  70. ['id'=>9,'name'=>'体感娃娃','remark'=>'HUG DOLL PRODUCTS'],
  71. ],
  72. // 轮播
  73. 'banners' => AdService::make()->getListByPosition(1), // 轮播
  74. 'goods1' => GoodsService::make()->getListByZoneType(2), // 限定商品
  75. 'goods2' => GoodsService::make()->getListByZoneType(3), // 优选商品
  76. 'config'=>[
  77. 'short_name' => ConfigService::make()->getConfigByCode('short_name'),
  78. 'index_logo' => get_image_url(ConfigService::make()->getConfigByCode('index_logo')),
  79. 'shop_tips' => htmlspecialchars_decode(ConfigService::make()->getConfigByCode('shop_tips')),
  80. ]
  81. ];
  82. return showJson(1010, true, $data);
  83. } catch (\Exception $exception) {
  84. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  85. return showJson(1046, false, $error);
  86. }
  87. }
  88. /**
  89. * 订单公告
  90. * @return array
  91. */
  92. public function notices()
  93. {
  94. try {
  95. return showJson(1010, true, \App\Services\Api\NoticeService::make()->getDataList());
  96. } catch (\Exception $exception) {
  97. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  98. return showJson(1046, false, $error);
  99. }
  100. }
  101. /**
  102. * 验证更新
  103. * @return array
  104. */
  105. public function versionCheck()
  106. {
  107. $version = request()->post('version', '');
  108. $appSources = request()->post('app_sources', 'ios');
  109. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  110. if (getVersion($version) < getVersion($currentVersion)) {
  111. $data = [
  112. 'has_update' => true,
  113. 'app_version' => $currentVersion,
  114. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  115. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  116. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  117. 'auto_update' => false, // 是否APP内自动更新
  118. ];
  119. return showJson(1010, true, $data);
  120. } else {
  121. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  122. }
  123. }
  124. }