| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\api\model;
- use think\Model;
- class Store extends BaseModel
- {
- // 表名
- protected $name = 'store';
- static function SWKey($s_id)
- {
- return "store:w:update:{$s_id}";
- }
- public function fetch($city_code, $county_code, array $lng_lat, $search_text = null, $hot = false, $distance = false, $page = 1, $size = 10)
- {
- $where = [
- // 'city_code' => $city_code,
- 'status' => \E_BASE_STATUS::Normal,
- ];
- if ($county_code) {
- $where["county_code"] = $county_code;
- }
- $subQuery = $this->field("*,round(st_distance_sphere (point($lng_lat[0],$lng_lat[1]),point ( `lng`, `lat` ))) distance")
- ->where($where)
- ->where("lng IS NOT NULL")
- ->where("lat IS NOT NULL");
- if ($search_text)
- $subQuery->where("name", "like", "%$search_text%");
- $query = $this->table($subQuery->buildSql() . ' distance')
- ->where($where)
- ->where("lng IS NOT NULL")
- ->where("lat IS NOT NULL");
- if ($search_text)
- $query->where("name", "like", "%$search_text%");
- if ($hot)
- $query->where('hot', 1);
- return $query
- ->order('distance', 'ASC')
- ->page($page)
- ->paginate($size);
- }
- }
|