ConfigService.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\sys;
  12. use app\service\admin\site\SiteService;
  13. use app\service\core\channel\CoreH5Service;
  14. use app\service\core\sys\CoreConfigService;
  15. use app\service\core\sys\CoreSysConfigService;
  16. use core\base\BaseAdminService;
  17. use core\exception\AdminException;
  18. /**
  19. * 配置服务层
  20. * Class ConfigService
  21. * @package app\service\core\sys
  22. */
  23. class ConfigService extends BaseAdminService
  24. {
  25. //系统配置文件
  26. public $core_config_service;
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. $this->core_config_service = new CoreConfigService();
  31. }
  32. /**
  33. * 获取版权信息(网站整体,不按照站点设置)
  34. * @return array|mixed
  35. */
  36. public function getCopyright()
  37. {
  38. return ( new CoreSysConfigService() )->getCopyright($this->request->defaultSiteId());
  39. }
  40. /**
  41. * 设置版权信息(整体设置,不按照站点)
  42. * @param array $value
  43. * @return bool
  44. */
  45. public function setCopyright(array $value)
  46. {
  47. $data = [
  48. 'icp' => $value[ 'icp' ],
  49. 'gov_record' => $value[ 'gov_record' ],
  50. 'gov_url' => $value[ 'gov_url' ],
  51. 'market_supervision_url' => $value[ 'market_supervision_url' ],
  52. 'logo' => $value[ 'logo' ],
  53. 'company_name' => $value[ 'company_name' ],
  54. 'copyright_link' => $value[ 'copyright_link' ],
  55. 'copyright_desc' => $value[ 'copyright_desc' ]
  56. ];
  57. return $this->core_config_service->setConfig($this->request->defaultSiteId(), 'COPYRIGHT', $data);
  58. }
  59. /**
  60. * 获取网站信息
  61. * @return array
  62. */
  63. public function getWebSite()
  64. {
  65. return ( new SiteService() )->getInfo($this->site_id);
  66. }
  67. /**
  68. * 设置网站信息
  69. * @return bool
  70. */
  71. public function setWebSite($data)
  72. {
  73. return ( new SiteService() )->edit($this->site_id, $data);
  74. }
  75. /**
  76. * 获取前端域名
  77. * @return array|string[]
  78. */
  79. public function getSceneDomain()
  80. {
  81. return ( new CoreSysConfigService() )->getSceneDomain($this->site_id);
  82. }
  83. /**
  84. * 获取服务信息
  85. * @return array|mixed
  86. */
  87. public function getService()
  88. {
  89. $info = ( new CoreConfigService() )->getConfig($this->request->defaultSiteId(), 'SERVICE_INFO');
  90. if (empty($info)) {
  91. $info = [];
  92. $info[ 'value' ] = [
  93. 'wechat_code' => '',
  94. 'enterprise_wechat' => '',
  95. 'tel' => '',
  96. ];
  97. }
  98. return $info[ 'value' ];
  99. }
  100. /**
  101. * 设置服务信息
  102. * @param array $value
  103. * @return bool
  104. */
  105. public function setService(array $value)
  106. {
  107. $data = [
  108. "wechat_code" => $value[ 'wechat_code' ],
  109. "enterprise_wechat" => $value[ 'enterprise_wechat' ],
  110. "tel" => $value[ 'tel' ]
  111. ];
  112. return $this->core_config_service->setConfig($this->request->defaultSiteId(), 'SERVICE_INFO', $data);
  113. }
  114. /**
  115. * 设置地图key
  116. * @param array $value
  117. * @return bool
  118. */
  119. public function setMap(array $value)
  120. {
  121. $data = [
  122. 'key' => $value[ 'key' ],
  123. 'is_open' => $value[ 'is_open' ], // 是否开启定位
  124. 'valid_time' => $value[ 'valid_time' ] // 定位有效期/分钟,过期后将重新获取定位信息,0为不过期
  125. ];
  126. ( new CoreH5Service() )->mapKeyChange($value[ 'key' ]);
  127. return $this->core_config_service->setConfig($this->request->defaultSiteId(), 'MAPKEY', $data);
  128. }
  129. /**
  130. * 获取地图key
  131. */
  132. public function getMap()
  133. {
  134. $info = ( new CoreConfigService() )->getConfig($this->request->defaultSiteId(), 'MAPKEY');
  135. if (empty($info)) {
  136. $info = [];
  137. $info[ 'value' ] = [
  138. 'key' => 'IZQBZ-3UHEU-WTCVD-2464U-I5N4V-ZFFU3',
  139. 'is_open' => 1, // 是否开启定位
  140. 'valid_time' => 5 // 定位有效期/分钟,过期后将重新获取定位信息,0为不过期
  141. ];
  142. }
  143. $info[ 'value' ][ 'is_open' ] = $info[ 'value' ][ 'is_open' ] ?? 1;
  144. $info[ 'value' ][ 'valid_time' ] = $info[ 'value' ][ 'valid_time' ] ?? 5;
  145. return $info[ 'value' ];
  146. }
  147. /**
  148. * 获取站点主页配置
  149. * @return mixed|string[]
  150. */
  151. public function getSiteIndexConfig()
  152. {
  153. $config = ( new CoreConfigService() )->getConfig($this->request->defaultSiteId(), "site_index");
  154. if (empty($config)) {
  155. $config[ 'value' ] = [
  156. 'view_path' => 'index/site_index'
  157. ];
  158. } else {
  159. $result = event("SiteIndex");
  160. $index_list = [];
  161. foreach ($result as $v) {
  162. $index_list = empty($index_list) ? $v : array_merge($index_list, $v);
  163. }
  164. $tag = 0;
  165. $view_path = $config[ 'value' ][ 'view_path' ];
  166. foreach ($index_list as $v) {
  167. $v_view_path = $v[ 'view_path' ] ?? '';
  168. if ($view_path == $v_view_path) {
  169. $tag = 1;
  170. break;
  171. }
  172. }
  173. if ($tag == 0) {
  174. $config[ 'value' ] = [
  175. 'view_path' => 'index/site_index'
  176. ];
  177. }
  178. }
  179. return $config[ 'value' ][ 'view_path' ];
  180. }
  181. /**
  182. * 站点主页配置
  183. * @param $data
  184. * @return true
  185. */
  186. public function setSiteIndexConfig($data)
  187. {
  188. $config = [
  189. 'view_path' => $data[ 'view_path' ],
  190. ];
  191. //检测是否路劲一个异常
  192. $index_list = $this->getSiteIndexList();
  193. $check_tag = 0;
  194. foreach ($index_list as $v) {
  195. if ($v[ 'view_path' ] == $data[ 'view_path' ]) {
  196. $check_tag = 1;
  197. }
  198. }
  199. if ($check_tag == 0) throw new AdminException('SITE_INDEX_VIEW_PATH_NOT_EXIST');
  200. ( new CoreConfigService() )->setConfig($this->request->defaultSiteId(), "site_index", $config);
  201. return true;
  202. }
  203. /**
  204. * 获取站点配置的首页列表
  205. * @return array
  206. */
  207. public function getSiteIndexList()
  208. {
  209. $result = event("SiteIndex");
  210. $index_list = [];
  211. foreach ($result as $v) {
  212. $index_list = empty($index_list) ? $v : array_merge($index_list, $v);
  213. }
  214. $view_path = $this->getSiteIndexConfig();
  215. foreach ($index_list as $k => $v) {
  216. $v_view_path = $v[ 'view_path' ] ?? '';
  217. $index_list[ $k ][ 'is_use' ] = ( $v_view_path == $view_path ) ? 1 : 0;
  218. }
  219. return $index_list;
  220. }
  221. /**
  222. * 设置站点快捷菜单
  223. * @param $data
  224. * @return bool
  225. */
  226. public function setShortcutMenu($data)
  227. {
  228. ( new CoreConfigService() )->setConfig($this->request->defaultSiteId(), 'shortcut_menu', $data);
  229. return true;
  230. }
  231. /**
  232. * 获取站点快捷菜单
  233. * @return array|mixed
  234. */
  235. public function getShortcutMenu()
  236. {
  237. $config = ( new CoreConfigService() )->getConfig($this->request->defaultSiteId(), 'shortcut_menu');
  238. $menu = $config[ 'value' ] ?? [];
  239. if (!empty($menu)) {
  240. $menu_service = new MenuService();
  241. foreach ($menu as $k => &$v) {
  242. $menu_key = $v[ 'menu_key' ] ?? '';
  243. if ($menu_key != '') {
  244. $item_router_path = $menu_service->getFullRouterPath($menu_key);
  245. if (empty($item_router_path)) {
  246. unset($v[ $k ]);
  247. } else {
  248. $v[ 'router_path' ] = $item_router_path;
  249. }
  250. }
  251. }
  252. }
  253. return $menu;
  254. }
  255. /**
  256. * 获取平台主页配置
  257. * @return mixed|string[]
  258. */
  259. public function getAdminIndexConfig()
  260. {
  261. $result = event("AdminIndex");
  262. if (empty($result)) {
  263. return 'index/index';
  264. } else {
  265. return $result[ 0 ][ 0 ][ 'view_path' ];
  266. }
  267. // $config = (new CoreConfigService())->getConfig($this->site_id, "admin_index");
  268. /* if(empty($config['value']))
  269. {
  270. }else{
  271. $result = event("AdminIndex");
  272. $index_list = [];
  273. foreach ($result as $v)
  274. {
  275. $index_list = empty($index_list) ? $v: array_merge($index_list, $v);
  276. }
  277. $tag = 0;
  278. $view_path = $config['value']['view_path'];
  279. foreach ($index_list as $v)
  280. {
  281. $v_view_path = $v['view_path'] ?? '';
  282. if($view_path == $v_view_path)
  283. {
  284. $tag = 1;
  285. break;
  286. }
  287. }
  288. if($tag == 0)
  289. {
  290. $config['value'] = [
  291. 'view_path' => 'index/index'
  292. ];
  293. }
  294. }
  295. return $config['value']['view_path'];*/
  296. }
  297. /**
  298. * 站点主页配置
  299. * @param $data
  300. * @return true
  301. */
  302. public function setAdminIndexConfig($data)
  303. {
  304. $config = [
  305. 'view_path' => $data[ 'view_path' ],
  306. ];
  307. //检测是否路劲一个异常
  308. $index_list = $this->getAdminIndexList();
  309. $check_tag = 0;
  310. foreach ($index_list as $v) {
  311. if ($v[ 'view_path' ] == $data[ 'view_path' ]) {
  312. $check_tag = 1;
  313. }
  314. }
  315. if ($check_tag == 0) throw new AdminException('ADMIN_INDEX_VIEW_PATH_NOT_EXIST');
  316. ( new CoreConfigService() )->setConfig($this->request->defaultSiteId(), "admin_index", $config);
  317. return true;
  318. }
  319. /**
  320. * 获取站点配置的首页列表
  321. * @return array
  322. */
  323. public function getAdminIndexList()
  324. {
  325. $result = event("AdminIndex");
  326. $index_list = [];
  327. foreach ($result as $v) {
  328. $index_list = empty($index_list) ? $v : array_merge($index_list, $v);
  329. }
  330. $view_path = $this->getAdminIndexConfig();
  331. foreach ($index_list as $k => $v) {
  332. $v_view_path = $v[ 'view_path' ] ?? '';
  333. $index_list[ $k ][ 'is_use' ] = ( $v_view_path == $view_path ) ? 1 : 0;
  334. }
  335. return $index_list;
  336. }
  337. /**
  338. * 获取手机端首页列表
  339. * @param $data
  340. * @return array
  341. */
  342. public function getWapIndexList($data = [])
  343. {
  344. return ( new CoreSysConfigService() )->getWapIndexList($data);
  345. }
  346. /**
  347. * 获取开发者key
  348. * @return array
  349. */
  350. public function getDeveloperToken()
  351. {
  352. return ( new CoreConfigService() )->getConfigValue($this->request->defaultSiteId(), "DEVELOPER_TOKEN");
  353. }
  354. /**
  355. * 设置开发者key
  356. * @param array $data
  357. * @return bool
  358. */
  359. public function setDeveloperToken(array $data)
  360. {
  361. return ( new CoreConfigService() )->setConfig($this->request->defaultSiteId(), "DEVELOPER_TOKEN", $data);
  362. }
  363. }