IndexController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\CarCategoryService;
  6. use App\Services\Api\FreightCategoryService;
  7. use App\Services\Api\FreightPackageService;
  8. use App\Services\Api\GoodsService;
  9. use App\Services\Api\MemberBankService;
  10. use App\Services\Api\NoticeService;
  11. use App\Services\Api\OrderService;
  12. use App\Services\Common\AdService;
  13. use App\Services\Common\CarBrandService;
  14. use App\Services\ConfigService;
  15. use App\Services\RedisService;
  16. /**
  17. * 首页
  18. * Class IndexController
  19. * @package App\Http\Controllers\Api
  20. */
  21. class IndexController extends webApp
  22. {
  23. /**
  24. * 配置信息
  25. * @return array
  26. */
  27. public function config()
  28. {
  29. try {
  30. $appSources = request()->post('app_sources','ios');
  31. $cacheKey = "caches:config:app_{$appSources}";
  32. $config = RedisService::get($cacheKey);
  33. if(empty($config)){
  34. $config = [
  35. 'app_name'=> ConfigService::make()->getConfigByCode('app_name'),
  36. 'app_logo'=> get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
  37. 'app_version'=> ConfigService::make()->getConfigByCode('app_version'),
  38. ];
  39. RedisService::set($cacheKey, $config, 7200);
  40. }
  41. return showJson(1010, true, $config);
  42. } catch (\Exception $exception){
  43. RedisService::set("caches:request:error_config", ['trace'=>$exception->getTrace()], 7200);
  44. return showJson(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
  45. }
  46. }
  47. /**
  48. * 首页数据
  49. * @return array
  50. */
  51. public function data()
  52. {
  53. $historyGoods = OrderService::make()->getHistoryGoods($this->userId);
  54. $proGoodsList = GoodsService::make()->getDataList(['is_discount'=>1,'type'=>2]);
  55. $data = [
  56. // 首页轮播
  57. 'banners'=> AdService::make()->getListByPosition(1),
  58. // 历史购买商品
  59. 'historyGoods'=> isset($historyGoods['list'])? $historyGoods['list'] : [],
  60. // 促销商品
  61. 'proGoodsList'=> isset($proGoodsList['list'])? $proGoodsList['list'] : [],
  62. 'userId'=> $this->userId
  63. ];
  64. return showJson(1010, true, $data);
  65. }
  66. /**
  67. * 其他广告
  68. * @return array
  69. */
  70. public function banner()
  71. {
  72. $params = request()->all();
  73. $position = isset($params['position'])? intval($params['position']) : 0;
  74. $num = isset($params['num']) && $params['num']? intval($params['num']) : 6;
  75. $data = AdService::make()->getListByPosition($position,$num);
  76. return showJson(1010, true, $data);
  77. }
  78. /**
  79. * 验证更新
  80. * @return array
  81. */
  82. public function versionCheck()
  83. {
  84. $version = request()->post('version','');
  85. $appSources = request()->post('app_sources','ios');
  86. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  87. if(getVersion($version) < getVersion($currentVersion)){
  88. $data = [
  89. 'has_update'=> true,
  90. 'app_version'=> $currentVersion,
  91. 'app_name'=> ConfigService::make()->getConfigByCode('app_name'),
  92. 'app_url'=> ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  93. 'is_force'=> ConfigService::make()->getConfigByCode("app_force_update"),
  94. 'auto_update'=> false, // 是否APP内自动更新
  95. ];
  96. return showJson(1010, true, $data);
  97. }else{
  98. return showJson(1010, false, ['has_update'=>false,'version'=> $version]);
  99. }
  100. }
  101. }