| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Services\Api\CartService;
- use App\Services\Api\GoodsService;
- use App\Services\Api\OrderService;
- use App\Services\Api\SocialCircleService;
- use App\Services\Api\StoreService;
- 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)) {
- $socialOpen = ConfigService::make()->getConfigByCode('social_open', 0);
- $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' => format_content(ConfigService::make()->getConfigByCode('agent_apply_desc', '')),
- 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
- 'recharge_desc_1' => format_content(ConfigService::make()->getConfigByCode('recharge_desc_1', '')),
- 'recharge_desc_2' => format_content(ConfigService::make()->getConfigByCode('recharge_desc_2', '')),
- 'recharge_desc_3' => format_content(ConfigService::make()->getConfigByCode('recharge_desc_3', '')),
- 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
- 'pay_recharge_open' => ConfigService::make()->getConfigByCode('pay_recharge_open', 0),
- 'hide_social_menu' => ConfigService::make()->getConfigByCode('hide_social_menu', 0),
- 'social_open' => $socialOpen,
- '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);
- }
- }
- /**
- * 菜单
- * @param int $socialOpen
- * @return array[]
- */
- public function getMenus($socialOpen=-1)
- {
- $socialOpen = $socialOpen>=0?$socialOpen:ConfigService::make()->getConfigByCode('social_open', 0);
- return [
- [
- "name" => '首页',
- "code" => 'home',
- "icon" => 'home',
- "status"=> 1,
- "page" => '/pages/index/index'
- ], [
- "name" => '客服',
- "code" => 'custom',
- "icon" => 'custom',
- "status"=> 1,
- ], [
- "name" => '',
- "code" => 'social',
- "icon" => 'social',
- "status"=> $socialOpen?1:0,
- "page" => '/pages/social/index'
- ], [
- "name" => '购物车',
- "code" => 'cart',
- "icon" => 'cart',
- "badge" => OrderService::make()->getCountByStatus($this->userId,1),
- "status"=> 1,
- "page" => '/pages/cart/index'
- ], [
- "name" => '我的',
- "code" => 'mine',
- "icon" => 'mine',
- "status"=> 1,
- "page" => '/pages/mine/index'
- ]
- ];
- }
- /**
- * 首页数据
- * @return array
- */
- public function data()
- {
- try {
- $params = request()->all();
- $type = isset($params['type']) && $params['type'] ? $params['type'] : 1;
- $position = isset($params['position']) && $params['position'] ? $params['position'] : 1;
- $data = [
- // 轮播
- 'banners' => AdService::make()->getListByPosition($position),
- ];
- if ($type == 2) {
- $data['hide_social_menu'] = ConfigService::make()->getConfigByCode('hide_social_menu', 0);
- $data['socials'] = SocialCircleService::make()->getIndexList();
- } else {
- $data['notices'] = NoticeService::make()->getRecommandList();
- $data['cates'] = GoodsService::make()->getCategoryList();
- $params['user_id'] = $this->userId;
- $data['stores'] = StoreService::make()->getGoodsList($params);
- $data['social_open'] = ConfigService::make()->getConfigByCode('social_open', 0);
- $data['cart_count'] = CartService::make()->getCount($this->userId);
- $data['pay_recharge_open'] = ConfigService::make()->getConfigByCode('pay_recharge_open', 0);
- }
- return showJson(1010, true, $data);
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 主页店铺商品
- * @return array
- */
- public function storeGoods()
- {
- $params = request()->post();
- try {
- $params['user_id'] = $this->userId;
- $datas = StoreService::make()->getGoodsList($params);
- return showJson(StoreService::make()->getError(), true, $datas);
- } 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]);
- }
- }
- }
|