['mer_name'], ]; } /** * @notes 商户列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @date 2024/04/27 11:26 */ public function lists(): array { $long=$this->request->get('long'); $lat=$this->request->get('lat'); $order=['mer_id' => 'desc']; if($long&&$lat){ $order=Db::raw("(2 * 6378.137 * ASIN( SQRT( POW( SIN( PI( ) * ( $long- `long` ) / 360 ), 2 ) + COS( PI( ) * $lat / 180 ) * COS( `lat` * PI( ) / 180 ) * POW( SIN( PI( ) * ( $lat- `lat` ) / 360 ), 2 ) ) ) ) ASC "); } return Merchant::where($this->searchWhere) ->field('mer_id,mer_name,long,lat,service_phone,mer_address') ->limit($this->limitOffset, $this->limitLength) ->order($order) ->select() ->each(function ($item) use($long,$lat){ if($long&&$lat){ $distance = getDistance($lat, $long, (float)$item['lat'], (float)$item['long']); if ($distance < 0.9) { $distance = max(bcmul($distance, 1000, 0), 1).'m'; if ($distance == '1m') { $distance = '100m以内'; } } else { $distance .= 'km'; } $item['distance']=$distance; }else{ $item['distance']=''; } }) ->toArray(); } /** * @notes 商户数量 * @return int * @date 2024/04/27 11:26 */ public function count(): int { return Merchant::where($this->searchWhere)->count(); } }