\E_BASE_STATUS::Normal, 'type' => \E_SERVICE_TYPE::App, ]; if (!is_null($service_status)) { $where["online"] = $service_status; } $subQuery = $this->field("*,round(st_distance_sphere (point($lng_lat[0],$lng_lat[1]), point ( `lng`, `lat` ))) distance") ->where($where) ->where("status", "in", [\E_MASSAGER_STATUS::Hidden, \E_BASE_STATUS::Normal]) ->where("gender", "in", $gender); if ($search_text) $subQuery->where("name", "like", "%$search_text%"); $query = $this->table($subQuery->buildSql() . ' distance') ->where($where) ->where("gender", "in", $gender) ->where("distance", "<=", $distance * 1000); if ($service_id > 0) { $service = (new Service())->get($service_id); if ($service) { $query->where("level", $service["level"]); } // 获取线上技师 - 68元特惠价 必须在扫码10分钟内 登录app查看 只有当选择了服务的时候 才会去判断 该技师是否绑定了该门店 if ($service_id == 276) { if ($user_id) { $exist = RedisClient::of()->get("scan:qr:codes:" . $user_id); if ($exist) { $query->where("store_id", $exist); } } } } if ($level !== null && (int)$level === 0) { $query->where("level", $level); } if ($search_text) $query->where("name", "like", "%$search_text%"); if ($hot) $query->where('hot', 1); if ($free_travel) $query->where('free_travel', 1); $query->order("online", "desc"); switch ($sort) { case "weight": // 默认排序 $query->order("weight", "DESC"); break; case "distance": // 距离排序 $query->order('distance', 'ASC'); break; case "praise_rate": // 评价最高 $query->order('praise_rate', 'DESC'); break; case "order_count": //接单量优先 $query->order('order_count', 'DESC'); break; case "collect_count": // 人气最高 $query->order('collect_count', 'DESC'); break; case "new_people": // 新人推荐 $query->order('createtime', 'DESC'); break; } return $paginate = $query ->with(['store', 'nearly_two_days_orders']) ->page($page) ->paginate($size); } public function fetchStoreMassager($store_id, $service_id = null, $search_text = null, $hot = false, $gender = [\E_GENDER_TYPE::Man, \E_GENDER_TYPE::Woman], $page = 1, $size = 10) { $where = [ 'status' => \E_BASE_STATUS::Normal, // 'type' => \E_SERVICE_TYPE::Store, 'store_id' => $store_id, // "online" => 1, ]; $query = $this->where($where) ->where("gender", "in", $gender); // if ($service_id > 0) // $query->where("FIND_IN_SET($service_id, service_ids)"); // if ($search_text) // $query->where("name", "like", "%$search_text%"); // if ($hot) // $query->where('hot', 1); return $query ->with(['store', 'nearly_two_days_orders']) ->page($page) ->paginate($size); } public function fetchHiddenAndNormal($id, $with = ["store"]) { return $this->where([ 'ma_massager.id' => $id, ])->where("ma_massager.status", "in", [\E_MASSAGER_STATUS::Hidden, \E_MASSAGER_STATUS::Normal]) ->with($with) ->find(); } public function getMassager($id, $with = ["store"]) { return $this->where([ 'id' => $id, "status" => \E_MASSAGER_STATUS::Normal ])->with($with) ->find(); } public function store() { return $this->hasOne(Store::class, 'id', 'store_id'); } public function findByMobile($mobile) { return $this->where("mobile", $mobile) ->find(); } public function login($account, $password) { $m = $this->where([ "mobile" => $account, "password" => md5($password), ])->find(); if (!$m) return null; return self::fmtMassager($m); } public function findByUnionId($unionId) { return $this->where("union_id", $unionId)->find(); } public function nearlyTwoDaysOrders() { return $this->hasMany(Order::class, 'massager_id', 'id') ->where('service_end_date', '>=', date('Y-m-d H:i:s', time())) ->where('status', 'in', [ \E_ORDER_STATUS::Purchase, \E_ORDER_STATUS::Proceed, ]); } }