Index.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $zoom = (int)$this->request->get('zoom', $config['zoom']);
  39. $lng = (float)$this->request->get('lng');
  40. $lat = (float)$this->request->get('lat');
  41. $address = $this->request->get('address');
  42. $lng = $lng ?: $config['lng'];
  43. $lat = $lat ?: $config['lat'];
  44. $this->view->assign('zoom', $zoom);
  45. $this->view->assign('lng', $lng);
  46. $this->view->assign('lat', $lat);
  47. $this->view->assign('address', $address);
  48. $maptype = $config['maptype'];
  49. if (!isset($config[$maptype . 'key']) || !$config[$maptype . 'key']) {
  50. $this->error("请在配置中配置对应类型地图的密钥");
  51. }
  52. return $this->view->fetch('index/' . $maptype);
  53. }
  54. }