IndexController.php 5.8 KB

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