| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Services\Api\ArticleService;
- use App\Services\Api\CourseService;
- use App\Services\Common\AdService;
- use App\Services\Common\InstitutionService;
- 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'),
- 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 1),
- 'vip_buy_desc' => format_content(ConfigService::make()->getConfigByCode('vip_buy_desc', '')),
- 'custom_name' => ConfigService::make()->getConfigByCode('custom_name', ''),
- 'custom_desc' => format_content(ConfigService::make()->getConfigByCode('custom_desc', '')),
- 'video_vip_tips' => format_content(ConfigService::make()->getConfigByCode('video_vip_tips', '')),
- 'errors' => config('platform.errors'),
- ];
- RedisService::set($cacheKey, $config, 3600);
- }
- return showJson(1010, true, $config);
- } catch (\Exception $exception) {
- RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
- return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
- }
- }
- /**
- * 首页数据
- * @return array
- */
- public function data()
- {
- $data = [
- // 菜单
- 'menuList' => config('platform.menuList'),
- // 公告
- 'notices' => NoticeService::make()->getRecommandList(),
- // 资讯
- 'articles' => ArticleService::make()->getIndexList(1),
- // 轮播
- 'banners' => AdService::make()->getListByPosition(1),
- // 线上课程
- 'courses' => [
- CourseService::make()->getListByType(1),
- CourseService::make()->getListByType(2),
- ],
- ];
- return showJson(1010, true, $data);
- }
- /**
- * 院校列表
- * @return array
- */
- public function institutions()
- {
- $params = request()->all();
- $pageSize = isset($params['pageSize']) && $params['pageSize']? intval($params['pageSize']) : 20;
- $data = InstitutionService::make()->getDataList($params, $pageSize);
- return showJson(1010, true, $data);
- }
- /**
- * 验证更新
- * @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]);
- }
- }
- }
|