IndexController.php 5.6 KB

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