12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- class Company extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = '*';
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = Db::name('company');
- }
- /**
- * 列表
- * @return void
- */
- public function getList()
- {
- try {
- $lng = $this->request->param('lng','');
- $lat = $this->request->param('lat','');
- $field = 'id,name,image,contacts,mobile,full_address,longitude,latitude,is_open,open_hours';
- $where['status'] = 1;
- $result = $this->model->where($where)->field($field)->autopage()->select();
- if (!empty($result)) {
- foreach ($result as $key => &$value) {
- $value['distance'] = getDistance($lng, $lat, $value['longitude'], $value['latitude'], false, 2,true);
- }
- }
- $this->success('获取成功',$result);
- } catch (Exception $e) {
- $this->error($e->getMessage());
- }
- }
- }
|