|
@@ -329,6 +329,10 @@ class User extends BaseModel
|
|
|
|| $post['is_china'] !== ''
|
|
|| $post['is_china'] !== ''
|
|
|
|| (!empty($post["service_area"]) && is_array($post["service_area"]));
|
|
|| (!empty($post["service_area"]) && is_array($post["service_area"]));
|
|
|
|
|
|
|
|
|
|
+ // 判断是否传了经纬度(用于按距离排序)
|
|
|
|
|
+ $hasLocation = !empty($post['longitude']) && !empty($post['latitude'])
|
|
|
|
|
+ && is_numeric($post['longitude']) && is_numeric($post['latitude']);
|
|
|
|
|
+
|
|
|
$where = [];
|
|
$where = [];
|
|
|
$where[] = ["u.work_type_id", ">", 0];
|
|
$where[] = ["u.work_type_id", ">", 0];
|
|
|
$where[] = ["u.status", "=", 1];
|
|
$where[] = ["u.status", "=", 1];
|
|
@@ -336,6 +340,15 @@ class User extends BaseModel
|
|
|
$where[] = ["u.work_type_id", "=", $post['work_type_id']];
|
|
$where[] = ["u.work_type_id", "=", $post['work_type_id']];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 距离计算 SQL 字段
|
|
|
|
|
+ $distanceField = "";
|
|
|
|
|
+ if ($hasLocation) {
|
|
|
|
|
+ $lng = floatval($post['longitude']);
|
|
|
|
|
+ $lat = floatval($post['latitude']);
|
|
|
|
|
+ // 使用 MySQL 球面距离公式计算距离(单位:公里)
|
|
|
|
|
+ $distanceField = ", (6371 * acos(cos(radians({$lat})) * cos(radians(u.latitude)) * cos(radians(u.longitude) - radians({$lng})) + sin(radians({$lat})) * sin(radians(u.latitude)))) AS distance";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if ($hasNewCondition) {
|
|
if ($hasNewCondition) {
|
|
|
// 使用新搜索条件的逻辑
|
|
// 使用新搜索条件的逻辑
|
|
|
if ($post['servicePrice'] > 0) {
|
|
if ($post['servicePrice'] > 0) {
|
|
@@ -380,17 +393,23 @@ class User extends BaseModel
|
|
|
if ($totalCount > 0) {
|
|
if ($totalCount > 0) {
|
|
|
$dataModel = $this
|
|
$dataModel = $this
|
|
|
->alias("u")
|
|
->alias("u")
|
|
|
- ->field("u.uid,IFNULL(u.longitude,0) as longitude,IFNULL(u.latitude,0) as latitude,ut.show_template_id,a.ancestral_place,a.status as is_type_audit,a.name,a.avatar,a.birthday,a.service_project")
|
|
|
|
|
|
|
+ ->field("u.uid,IFNULL(u.longitude,0) as longitude,IFNULL(u.latitude,0) as latitude,ut.show_template_id,a.ancestral_place,a.status as is_type_audit,a.name,a.avatar,a.birthday,a.service_project" . $distanceField)
|
|
|
->leftJoin("info_audit a", "u.uid=a.uid and a.status = 1 and a.is_show = 1")
|
|
->leftJoin("info_audit a", "u.uid=a.uid and a.status = 1 and a.is_show = 1")
|
|
|
->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")
|
|
->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")
|
|
|
->where($where);
|
|
->where($where);
|
|
|
if ($serviceAreaWhere) {
|
|
if ($serviceAreaWhere) {
|
|
|
$dataModel->where($serviceAreaWhere);
|
|
$dataModel->where($serviceAreaWhere);
|
|
|
}
|
|
}
|
|
|
- $data = $dataModel->order("u.show_temp_seq", "desc")
|
|
|
|
|
- ->order("u.uid", "desc")
|
|
|
|
|
- ->page($post["page"], $post["pageSize"])
|
|
|
|
|
- ->select();
|
|
|
|
|
|
|
+ if ($hasLocation) {
|
|
|
|
|
+ $data = $dataModel->order("distance", "asc")
|
|
|
|
|
+ ->page($post["page"], $post["pageSize"])
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $data = $dataModel->order("u.show_temp_seq", "desc")
|
|
|
|
|
+ ->order("u.uid", "desc")
|
|
|
|
|
+ ->page($post["page"], $post["pageSize"])
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ }
|
|
|
if (!empty($data)) {
|
|
if (!empty($data)) {
|
|
|
$data = $data->toArray();
|
|
$data = $data->toArray();
|
|
|
$infoAuditDb = new InfoAudit();
|
|
$infoAuditDb = new InfoAudit();
|
|
@@ -419,16 +438,22 @@ class User extends BaseModel
|
|
|
$totalCount = $this->alias("u")->where($where)->count();
|
|
$totalCount = $this->alias("u")->where($where)->count();
|
|
|
$data = null;
|
|
$data = null;
|
|
|
if ($totalCount > 0) {
|
|
if ($totalCount > 0) {
|
|
|
- $data = $this
|
|
|
|
|
|
|
+ $dataModel = $this
|
|
|
->alias("u")
|
|
->alias("u")
|
|
|
- ->field("u.uid,IFNULL(u.longitude,0) as longitude,IFNULL(u.latitude,0) as latitude,ut.show_template_id,a.ancestral_place,a.status as is_type_audit")
|
|
|
|
|
|
|
+ ->field("u.uid,IFNULL(u.longitude,0) as longitude,IFNULL(u.latitude,0) as latitude,ut.show_template_id,a.ancestral_place,a.status as is_type_audit" . $distanceField)
|
|
|
->leftJoin("info_audit a", "u.uid=a.uid")
|
|
->leftJoin("info_audit a", "u.uid=a.uid")
|
|
|
->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")
|
|
->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")
|
|
|
- ->where($where)
|
|
|
|
|
- ->order("u.show_temp_seq", "desc")
|
|
|
|
|
- ->order("u.uid", "desc")
|
|
|
|
|
- ->page($post["page"], $post["pageSize"])
|
|
|
|
|
- ->select();
|
|
|
|
|
|
|
+ ->where($where);
|
|
|
|
|
+ if ($hasLocation) {
|
|
|
|
|
+ $data = $dataModel->order("distance", "asc")
|
|
|
|
|
+ ->page($post["page"], $post["pageSize"])
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $data = $dataModel->order("u.show_temp_seq", "desc")
|
|
|
|
|
+ ->order("u.uid", "desc")
|
|
|
|
|
+ ->page($post["page"], $post["pageSize"])
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ }
|
|
|
if (!empty($data)) {
|
|
if (!empty($data)) {
|
|
|
$data = $data->toArray();
|
|
$data = $data->toArray();
|
|
|
}
|
|
}
|