Boot.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: lts
  5. * Date: 2019-04-01
  6. * Time: 17:29
  7. */
  8. namespace app\clientappapi\controller;
  9. use app\common\controller\ClientApi;
  10. //use app\common\model\Config;
  11. use app\common\service\ClientuserService;
  12. use app\main\constants\ClientApiConstants;
  13. use app\main\constants\ErrorCodeConstants;
  14. use app\main\service\ClientAppService;
  15. use function PHPSTORM_META\elementType;
  16. use think\Exception;
  17. use think\Config;
  18. class Boot extends ClientApi
  19. {
  20. /**
  21. * 启动接口
  22. */
  23. public function splash()
  24. {
  25. $result = [];
  26. if (isset($this->params['fun'])) {
  27. $funs = explode(',', $this->params['fun']);
  28. if (in_array('f1', $funs)) {
  29. $this->checkParamRequired('code');
  30. $result['f1'] = $this->_register($this->params['code']);
  31. }
  32. if (in_array('f2', $funs)) {
  33. $bookIds = [];
  34. $defaultBookIdsResult = ClientAppService::instance()->getDefaultBookIds();
  35. if ($defaultBookIdsResult->code == ErrorCodeConstants::SUCCESS) {
  36. foreach ($defaultBookIdsResult->data as $bookId) {
  37. $bookIds[$bookId] = '';
  38. }
  39. }
  40. $booksInfoResult = ClientAppService::instance()->userReadBooksInfo($bookIds, $this->userInfo);
  41. if ($booksInfoResult->code != ErrorCodeConstants::SUCCESS) {
  42. $this->error($booksInfoResult->msg, $booksInfoResult->code);
  43. }
  44. $result['f2'] = $booksInfoResult->data['bookList'];
  45. }
  46. if (in_array('f0', $funs)) {
  47. $result['f0'] = $this->_baseInfo();
  48. }
  49. }
  50. $this->success('', $result);
  51. }
  52. /**
  53. * 基础信息
  54. * @return array
  55. * @throws Exception
  56. */
  57. private function _baseInfo()
  58. {
  59. $webHost = Config::get("site.client_web_host");
  60. $result = [
  61. 'urls' => [
  62. 'url_book_store' => $webHost . '/clientweb/index',
  63. //'url_user_account' => $webHost . '/clientweb/user/account',
  64. //'url_user_vip' => $webHost . '/clientweb/myvip/index',
  65. //'url_user_record' => $webHost .'/clientweb/user/recent',
  66. //'url_user_mark' => $webHost . '/clientweb/checkin/index',
  67. 'url_search' => $webHost . '/clientweb/index/search',
  68. //'url_book_detail' => $webHost . '/clientweb/book/info?book_id=',
  69. //'url_recharge' => $webHost . '/clientweb/recharge/pay',
  70. //'url_account_safe' => $webHost . '/clientweb/bindphone/bind',
  71. //'url_login' => $webHost . '/clientweb/bindphone/register',
  72. 'url_user_mark' => $webHost . '/clientweb/user/signPersist',
  73. 'url_popup_temp' => $webHost . '/clientweb/index/popuptemp',
  74. 'url_bind_popup' => $webHost . '/clientweb/index/bindpopup',
  75. 'url_vip_popup' => $webHost . '/clientweb/index/vippopup',
  76. 'url_codeshow' => $webHost . '/clientweb/user/codeshow',
  77. 'url_syxy' => $webHost . '/clientweb/aboutus/syxy',
  78. 'url_ysxy' => $webHost . '/clientweb/aboutus/ysxy',
  79. ],
  80. 'custom_tel' => Config::get('site.app_custom_tel') ?? '',
  81. ];
  82. $userId = null;
  83. if (!empty($this->userInfo)) {
  84. $result['user_info'] = ClientuserService::instance()->packageUserInfo($this->userInfo);
  85. }
  86. return $result;
  87. }
  88. /**
  89. * 用户通过注册码注册,注册成功后将用户信息写入userInfo全局变量
  90. * @param $code
  91. * @return array
  92. */
  93. private function _register($code)
  94. {
  95. try {
  96. $userResult = ClientAppService::instance()->userRegister($code);
  97. if ($userResult->code == ErrorCodeConstants::SUCCESS) {
  98. $this->userInfo = $userResult->data;
  99. $result = [
  100. 'r_code' => ClientApiConstants::CLIENT_API_CODE_SUCCESS,
  101. 'r_msg' => '',
  102. 'user_info' => ClientuserService::instance()->packageUserInfo($this->userInfo),
  103. ];
  104. } else {
  105. $result = [
  106. 'r_code' => $userResult->code,
  107. 'r_msg' => $userResult->msg,
  108. ];
  109. }
  110. return $result;
  111. } catch (\Exception $e) {
  112. $result = [
  113. 'r_code' => $e->getCode(),
  114. 'r_msg' => $e->getMessage(),
  115. ];
  116. return $result;
  117. }
  118. }
  119. /**
  120. * @throws \Exception
  121. */
  122. public function clientconfig()
  123. {
  124. $result = [];
  125. $this->checkParamRequired('fun');
  126. $funs = explode(',', $this->params['fun']);
  127. if (in_array('loading', $funs)) {
  128. $loading = [];
  129. $loadingResult = ClientAppService::instance()->getClientConfigLoading($this->userInfo, $this->aCommon['p']);
  130. if ($loadingResult->code == ErrorCodeConstants::SUCCESS) {
  131. $loading[] = $loadingResult->data;
  132. }
  133. $result['loading'] = $loading;
  134. }
  135. if (in_array('book_shelf', $funs)) {
  136. $bookShelf = [];
  137. $bookShelfResult = ClientAppService::instance()->getClientConfigBookShelf($this->userInfo,
  138. $this->aCommon['p']);
  139. if ($bookShelfResult->code == ErrorCodeConstants::SUCCESS) {
  140. $bookShelf = $bookShelfResult->data;
  141. }
  142. $result['book_shelf'] = $bookShelf;
  143. }
  144. $this->info($result);
  145. }
  146. /**
  147. * 弹窗运营位配置
  148. * @throws \Exception
  149. */
  150. public function clientconfigalert()
  151. {
  152. $this->checkParamRequired('position');
  153. $strPosition = $this->params['position'];
  154. $aPosition = explode(',', $strPosition);
  155. $result = [];
  156. $webHost = Config::get("site.client_web_host");
  157. foreach ($aPosition as $position) {
  158. $resultClientConfig = ClientAppService::instance()->getClientConfigAlert($this->userInfo,
  159. $this->aCommon['p'], $position);
  160. $resultItem = new \ArrayObject(array());
  161. if ($resultClientConfig->code == ErrorCodeConstants::SUCCESS) {
  162. $clientConfig = $resultClientConfig->data;
  163. $resultItem = [
  164. 'image_url' => '',
  165. 'uri' => sprintf('%s/clientweb/index/popuptemp?id=%s', $webHost, $clientConfig['id']),
  166. 'delay_time' => 0,
  167. 'start_time' => strtotime($clientConfig['start_time']),
  168. 'end_time' => strtotime($clientConfig['end_time']),
  169. ];
  170. } elseif ($resultClientConfig->code == ErrorCodeConstants::RESULT_EMPTY) {
  171. } else {
  172. throw new Exception($resultClientConfig->msg);
  173. }
  174. switch ($position) {
  175. case 1:
  176. $result['book_shelf'] = $resultItem;
  177. break;
  178. case 2:
  179. $result['user_centre'] = $resultItem;
  180. break;
  181. case 3:
  182. $result['book_city'] = $resultItem;
  183. break;
  184. default:
  185. break;
  186. }
  187. }
  188. $this->info($result);
  189. }
  190. /**
  191. * 插件列表接口
  192. */
  193. public function plugin()
  194. {
  195. $packageName = $this->aCommon['pkna'];
  196. $pluginResult = ClientAppService::instance()->getPlugin($packageName);
  197. if ($pluginResult->code == ErrorCodeConstants::SUCCESS) {
  198. $result = [
  199. 'ttsPlugin' => [
  200. 'isEnable' => $pluginResult->data['status'],
  201. ],
  202. ];
  203. if ($pluginResult->data['status'] == '1') {
  204. $voiceTypeList[] = ['fileName' => $pluginResult->data['boy_voice_title'], 'index' => 1];
  205. $voiceTypeList[] = ['fileName' => $pluginResult->data['girl_voice_title'], 'index' => 0];
  206. $voiceTypeList[] = ['fileName' => $pluginResult->data['male_anchor_title'], 'index' => 2];
  207. $voiceTypeList[] = ['fileName' => $pluginResult->data['child_anchor_title'], 'index' => 3];
  208. $ttsInfo = [
  209. 'version' => $pluginResult->data['version'],
  210. 'zipUrl' => $pluginResult->data['voice_file'],
  211. 'baseFileName' => $pluginResult->data['basic_title'],
  212. 'appId' => $pluginResult->data['appid'],
  213. 'appKey' => $pluginResult->data['apikey'],
  214. 'secretKey' => $pluginResult->data['servretkey'],
  215. ];
  216. $ttsInfo['voiceTypeList'] = $voiceTypeList;
  217. $result['ttsPlugin']['ttsInfo'] = $ttsInfo;
  218. }
  219. $this->success('', $result);
  220. } else {
  221. $this->error($pluginResult->msg);
  222. }
  223. }
  224. public function getappversion()
  225. {
  226. $webHost = Config::get("site.client_web_host");
  227. $versionName = $this->aCommon['vn'];
  228. $appVersionResult = ClientAppService::instance()->getAppVersion($versionName);
  229. if ($appVersionResult->code == ErrorCodeConstants::SUCCESS) {
  230. $info = $appVersionResult->data;
  231. $result = [
  232. 'update_version' => $info['version_name'],
  233. 'download_url' => $webHost . $info['apk_url'],
  234. 'is_new_version' => 1,
  235. 'introduction' => $info['content'],
  236. 'must_update' => $info['type'],
  237. 'version_size' => $info['size'],
  238. ];
  239. $this->info($result);
  240. } elseif ($appVersionResult->code == ErrorCodeConstants::RESULT_EMPTY) {
  241. $this->info(['is_new_version' => 2]);
  242. }
  243. }
  244. }