| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Services\Common\AdService;
- use App\Services\Common\NoticeService;
- use App\Services\ConfigService;
- use App\Services\RedisService;
- /**
- * 首页
- * Class IndexController
- * @package App\Http\Controllers\Api
- */
- class IndexController extends webApp
- {
- /**
- * 配置信息
- * @return array
- */
- public function config()
- {
- try {
- $appSources = request()->post('app_sources', 'ios');
- $cacheKey = "caches:config:app_{$appSources}";
- $config = RedisService::get($cacheKey);
- if (empty($config)) {
- $config = [
- 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
- 'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
- 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
- 'app_android_url' => ConfigService::make()->getConfigByCode('app_android_url'),
- 'alipay_open' => ConfigService::make()->getConfigByCode('alipay_open', 0),
- 'agent_apply_desc' => ConfigService::make()->getConfigByCode('agent_apply_desc', ''),
- 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
- 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
- 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
- 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
- 'notices' => NoticeService::make()->getRecommandList(),
- ];
- RedisService::set($cacheKey, $config, 3600);
- }
- return showJson(1010, true, $config);
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 首页数据
- * @return array
- */
- public function data()
- {
- try {
- $data = [
- // 公告
- 'notices' => NoticeService::make()->getRecommandList(),
- // 轮播
- 'banners' => AdService::make()->getListByPosition(1),
- ];
- return showJson(1010, true, $data);
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 验证更新
- * @return array
- */
- public function versionCheck()
- {
- $version = request()->post('version', '');
- $appSources = request()->post('app_sources', 'ios');
- $currentVersion = ConfigService::make()->getConfigByCode('app_version');
- if (getVersion($version) < getVersion($currentVersion)) {
- $data = [
- 'has_update' => true,
- 'app_version' => $currentVersion,
- 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
- 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
- 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
- 'auto_update' => false, // 是否APP内自动更新
- ];
- return showJson(1010, true, $data);
- } else {
- return showJson(1010, false, ['has_update' => false, 'version' => $version]);
- }
- }
- }
|