Index.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace addons\address\controller;
  3. use think\addons\Controller;
  4. use think\Config;
  5. use think\Hook;
  6. class Index extends Controller
  7. {
  8. // 首页
  9. public function index()
  10. {
  11. // 语言检测
  12. $lang = $this->request->langset();
  13. $lang = preg_match("/^([a-zA-Z\-_]{2,10})\$/i", $lang) ? $lang : 'zh-cn';
  14. $site = Config::get("site");
  15. // 配置信息
  16. $config = [
  17. 'site' => array_intersect_key($site, array_flip(['name', 'cdnurl', 'version', 'timezone', 'languages'])),
  18. 'upload' => null,
  19. 'modulename' => 'addons',
  20. 'controllername' => 'index',
  21. 'actionname' => 'index',
  22. 'jsname' => 'addons/address',
  23. 'moduleurl' => '',
  24. 'language' => $lang
  25. ];
  26. $config = array_merge($config, Config::get("view_replace_str"));
  27. // 配置信息后
  28. Hook::listen("config_init", $config);
  29. // 加载当前控制器语言包
  30. $this->view->assign('site', $site);
  31. $this->view->assign('config', $config);
  32. return $this->view->fetch();
  33. }
  34. // 选择地址
  35. public function select()
  36. {
  37. $config = get_addon_config('address');
  38. $lng = $this->request->get('lng');
  39. $lat = $this->request->get('lat');
  40. $lng = $lng ? $lng : $config['lng'];
  41. $lat = $lat ? $lat : $config['lat'];
  42. $this->view->assign('lng', $lng);
  43. $this->view->assign('lat', $lat);
  44. $maptype = $config['maptype'];
  45. if (!isset($config[$maptype . 'key']) || !$config[$maptype . 'key']) {
  46. $this->error("请在配置中配置对应类型地图的密钥");
  47. }
  48. return $this->view->fetch('index/' . $maptype);
  49. }
  50. }