Company.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. class Company extends Api
  6. {
  7. protected $noNeedLogin = [];
  8. protected $noNeedRight = '*';
  9. protected $model = null;
  10. public function _initialize()
  11. {
  12. parent::_initialize();
  13. $this->model = Db::name('company');
  14. }
  15. /**
  16. * 列表
  17. * @return void
  18. */
  19. public function getList()
  20. {
  21. try {
  22. $lng = $this->request->param('lng','');
  23. $lat = $this->request->param('lat','');
  24. $field = 'id,name,image,contacts,mobile,full_address,longitude,latitude,is_open,open_hours';
  25. $where['status'] = 1;
  26. $result = $this->model->where($where)->field($field)->autopage()->select();
  27. if (!empty($result)) {
  28. foreach ($result as $key => &$value) {
  29. $value['distance'] = getDistance($lng, $lat, $value['longitude'], $value['latitude'], false, 2,true);
  30. }
  31. }
  32. $this->success('获取成功',$result);
  33. } catch (Exception $e) {
  34. $this->error($e->getMessage());
  35. }
  36. }
  37. }