123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <?php
- /**
- * Created by PhpStorm.
- * User: lts
- * Date: 2019-04-01
- * Time: 17:29
- */
- namespace app\clientappapi\controller;
- use app\common\controller\ClientApi;
- //use app\common\model\Config;
- use app\common\service\ClientuserService;
- use app\main\constants\ClientApiConstants;
- use app\main\constants\ErrorCodeConstants;
- use app\main\service\ClientAppService;
- use function PHPSTORM_META\elementType;
- use think\Exception;
- use think\Config;
- class Boot extends ClientApi
- {
- /**
- * 启动接口
- */
- public function splash()
- {
- $result = [];
- if (isset($this->params['fun'])) {
- $funs = explode(',', $this->params['fun']);
- if (in_array('f1', $funs)) {
- $this->checkParamRequired('code');
- $result['f1'] = $this->_register($this->params['code']);
- }
- if (in_array('f2', $funs)) {
- $bookIds = [];
- $defaultBookIdsResult = ClientAppService::instance()->getDefaultBookIds();
- if ($defaultBookIdsResult->code == ErrorCodeConstants::SUCCESS) {
- foreach ($defaultBookIdsResult->data as $bookId) {
- $bookIds[$bookId] = '';
- }
- }
- $booksInfoResult = ClientAppService::instance()->userReadBooksInfo($bookIds, $this->userInfo);
- if ($booksInfoResult->code != ErrorCodeConstants::SUCCESS) {
- $this->error($booksInfoResult->msg, $booksInfoResult->code);
- }
- $result['f2'] = $booksInfoResult->data['bookList'];
- }
- if (in_array('f0', $funs)) {
- $result['f0'] = $this->_baseInfo();
- }
- }
- $this->success('', $result);
- }
- /**
- * 基础信息
- * @return array
- * @throws Exception
- */
- private function _baseInfo()
- {
- $webHost = Config::get("site.client_web_host");
- $result = [
- 'urls' => [
- 'url_book_store' => $webHost . '/clientweb/index',
- //'url_user_account' => $webHost . '/clientweb/user/account',
- //'url_user_vip' => $webHost . '/clientweb/myvip/index',
- //'url_user_record' => $webHost .'/clientweb/user/recent',
- //'url_user_mark' => $webHost . '/clientweb/checkin/index',
- 'url_search' => $webHost . '/clientweb/index/search',
- //'url_book_detail' => $webHost . '/clientweb/book/info?book_id=',
- //'url_recharge' => $webHost . '/clientweb/recharge/pay',
- //'url_account_safe' => $webHost . '/clientweb/bindphone/bind',
- //'url_login' => $webHost . '/clientweb/bindphone/register',
- 'url_user_mark' => $webHost . '/clientweb/user/signPersist',
- 'url_popup_temp' => $webHost . '/clientweb/index/popuptemp',
- 'url_bind_popup' => $webHost . '/clientweb/index/bindpopup',
- 'url_vip_popup' => $webHost . '/clientweb/index/vippopup',
- 'url_codeshow' => $webHost . '/clientweb/user/codeshow',
- 'url_syxy' => $webHost . '/clientweb/aboutus/syxy',
- 'url_ysxy' => $webHost . '/clientweb/aboutus/ysxy',
- ],
- 'custom_tel' => Config::get('site.app_custom_tel') ?? '',
- ];
- $userId = null;
- if (!empty($this->userInfo)) {
- $result['user_info'] = ClientuserService::instance()->packageUserInfo($this->userInfo);
- }
- return $result;
- }
- /**
- * 用户通过注册码注册,注册成功后将用户信息写入userInfo全局变量
- * @param $code
- * @return array
- */
- private function _register($code)
- {
- try {
- $userResult = ClientAppService::instance()->userRegister($code);
- if ($userResult->code == ErrorCodeConstants::SUCCESS) {
- $this->userInfo = $userResult->data;
- $result = [
- 'r_code' => ClientApiConstants::CLIENT_API_CODE_SUCCESS,
- 'r_msg' => '',
- 'user_info' => ClientuserService::instance()->packageUserInfo($this->userInfo),
- ];
- } else {
- $result = [
- 'r_code' => $userResult->code,
- 'r_msg' => $userResult->msg,
- ];
- }
- return $result;
- } catch (\Exception $e) {
- $result = [
- 'r_code' => $e->getCode(),
- 'r_msg' => $e->getMessage(),
- ];
- return $result;
- }
- }
- /**
- * @throws \Exception
- */
- public function clientconfig()
- {
- $result = [];
- $this->checkParamRequired('fun');
- $funs = explode(',', $this->params['fun']);
- if (in_array('loading', $funs)) {
- $loading = [];
- $loadingResult = ClientAppService::instance()->getClientConfigLoading($this->userInfo, $this->aCommon['p']);
- if ($loadingResult->code == ErrorCodeConstants::SUCCESS) {
- $loading[] = $loadingResult->data;
- }
- $result['loading'] = $loading;
- }
- if (in_array('book_shelf', $funs)) {
- $bookShelf = [];
- $bookShelfResult = ClientAppService::instance()->getClientConfigBookShelf($this->userInfo,
- $this->aCommon['p']);
- if ($bookShelfResult->code == ErrorCodeConstants::SUCCESS) {
- $bookShelf = $bookShelfResult->data;
- }
- $result['book_shelf'] = $bookShelf;
- }
- $this->info($result);
- }
- /**
- * 弹窗运营位配置
- * @throws \Exception
- */
- public function clientconfigalert()
- {
- $this->checkParamRequired('position');
- $strPosition = $this->params['position'];
- $aPosition = explode(',', $strPosition);
- $result = [];
- $webHost = Config::get("site.client_web_host");
- foreach ($aPosition as $position) {
- $resultClientConfig = ClientAppService::instance()->getClientConfigAlert($this->userInfo,
- $this->aCommon['p'], $position);
- $resultItem = new \ArrayObject(array());
- if ($resultClientConfig->code == ErrorCodeConstants::SUCCESS) {
- $clientConfig = $resultClientConfig->data;
- $resultItem = [
- 'image_url' => '',
- 'uri' => sprintf('%s/clientweb/index/popuptemp?id=%s', $webHost, $clientConfig['id']),
- 'delay_time' => 0,
- 'start_time' => strtotime($clientConfig['start_time']),
- 'end_time' => strtotime($clientConfig['end_time']),
- ];
- } elseif ($resultClientConfig->code == ErrorCodeConstants::RESULT_EMPTY) {
- } else {
- throw new Exception($resultClientConfig->msg);
- }
- switch ($position) {
- case 1:
- $result['book_shelf'] = $resultItem;
- break;
- case 2:
- $result['user_centre'] = $resultItem;
- break;
- case 3:
- $result['book_city'] = $resultItem;
- break;
- default:
- break;
- }
- }
- $this->info($result);
- }
- /**
- * 插件列表接口
- */
- public function plugin()
- {
- $packageName = $this->aCommon['pkna'];
- $pluginResult = ClientAppService::instance()->getPlugin($packageName);
- if ($pluginResult->code == ErrorCodeConstants::SUCCESS) {
- $result = [
- 'ttsPlugin' => [
- 'isEnable' => $pluginResult->data['status'],
- ],
- ];
- if ($pluginResult->data['status'] == '1') {
- $voiceTypeList[] = ['fileName' => $pluginResult->data['boy_voice_title'], 'index' => 1];
- $voiceTypeList[] = ['fileName' => $pluginResult->data['girl_voice_title'], 'index' => 0];
- $voiceTypeList[] = ['fileName' => $pluginResult->data['male_anchor_title'], 'index' => 2];
- $voiceTypeList[] = ['fileName' => $pluginResult->data['child_anchor_title'], 'index' => 3];
- $ttsInfo = [
- 'version' => $pluginResult->data['version'],
- 'zipUrl' => $pluginResult->data['voice_file'],
- 'baseFileName' => $pluginResult->data['basic_title'],
- 'appId' => $pluginResult->data['appid'],
- 'appKey' => $pluginResult->data['apikey'],
- 'secretKey' => $pluginResult->data['servretkey'],
- ];
- $ttsInfo['voiceTypeList'] = $voiceTypeList;
- $result['ttsPlugin']['ttsInfo'] = $ttsInfo;
- }
- $this->success('', $result);
- } else {
- $this->error($pluginResult->msg);
- }
- }
- public function getappversion()
- {
- $webHost = Config::get("site.client_web_host");
- $versionName = $this->aCommon['vn'];
- $appVersionResult = ClientAppService::instance()->getAppVersion($versionName);
- if ($appVersionResult->code == ErrorCodeConstants::SUCCESS) {
- $info = $appVersionResult->data;
- $result = [
- 'update_version' => $info['version_name'],
- 'download_url' => $webHost . $info['apk_url'],
- 'is_new_version' => 1,
- 'introduction' => $info['content'],
- 'must_update' => $info['type'],
- 'version_size' => $info['size'],
- ];
- $this->info($result);
- } elseif ($appVersionResult->code == ErrorCodeConstants::RESULT_EMPTY) {
- $this->info(['is_new_version' => 2]);
- }
- }
- }
|