request->param(); // 数据校验 $valid = $this->validate($param, [ 'lng' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'], 'lat' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'], 'page' => 'require', ],[ 'lng.require' => '缺少经度参数', 'lng.regex' => '经度参数有误', 'lat.require' => '缺少维度参数', 'lat.regex' => '维度参数有误' ]); // 错误 if (true !== $valid){ return $this->ApiJson(-1,$valid); } $limit = 10; // 经纬度升序 $lists = model('Stores') ->fieldRaw("* , TRUNCATE(( 6371 * acos ( cos ( radians(".$param['lat'].") ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(".$param['lng'].") ) + sin ( radians(".$param['lat'].") ) * sin( radians( latitude ) ) ) ), 2) AS distance") ->having('distance < 20') ->order(['distance' => 'ASC']) ->where(['status' => 1,'type'=> $param['type']]) ->limit((($param['page'] - 1) * $limit) . "," . $limit) ->select(); return $this->ApiJson(0,'', $lists); } /** * 获取门店详情 * * @url /store/:id * @param $id * * @return \think\response\Json * @throws \Lettered\Support\Exceptions\EvidentException */ public function getStoreById($id) { (new IDMustBePositiveInt())->valid(); $info = model('Stores')::get($id); if (!$info){ return $this->ApiJson(-1,'此门店不存在或已被禁封!'); } return $this->ApiJson(0,'', $info); } }