|
|
@@ -431,9 +431,9 @@ class User extends BaseModel
|
|
|
{
|
|
|
$post["pageSize"] = $post["pageSize"] > 20 ? 20 : (int)$post["pageSize"];
|
|
|
$post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
|
|
|
- $where = [];
|
|
|
- $where[] = ["u.work_type_id", ">", 0];
|
|
|
- $where[] = ["u.status", "=", 1];
|
|
|
+
|
|
|
+ // 构建基础条件
|
|
|
+ $where = [["u.work_type_id", ">", 0], ["u.status", "=", 1]];
|
|
|
if (!empty($post['work_type_id'])) {
|
|
|
$where[] = ["u.work_type_id", "=", $post['work_type_id']];
|
|
|
}
|
|
|
@@ -446,10 +446,12 @@ class User extends BaseModel
|
|
|
if ($post['is_china'] != '') {
|
|
|
$where[] = ["a.is_china", '=', $post['is_china']];
|
|
|
}
|
|
|
- $cityModel = new CityModel();
|
|
|
+
|
|
|
+ // 城市查询条件
|
|
|
$serviceAreaWhere = null;
|
|
|
if (!empty($post["service_area"]) && is_array($post["service_area"])) {
|
|
|
$cityIds = [];
|
|
|
+ $cityModel = new CityModel();
|
|
|
foreach ($post["service_area"] as $v) {
|
|
|
$stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
|
|
|
$str = str_replace(['辖'], ['市辖'], $stc);
|
|
|
@@ -459,84 +461,166 @@ class User extends BaseModel
|
|
|
if ($city_id) $cityIds[] = $city_id;
|
|
|
}
|
|
|
if (!empty($cityIds)) {
|
|
|
- $cityIdStr = implode(',', $cityIds);
|
|
|
- $serviceAreaWhere = function ($query) use ($cityIdStr) {
|
|
|
- foreach (explode(',', $cityIdStr) as $cid) {
|
|
|
+ $serviceAreaWhere = function ($query) use ($cityIds) {
|
|
|
+ foreach ($cityIds as $cid) {
|
|
|
$query->whereOr('find_in_set(' . intval($cid) . ',a.service_area)');
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $totalModel = $this->alias("u")->leftJoin("info_audit a", "u.uid=a.uid")->where($where);
|
|
|
+ // 构建查询(不设置 field,用默认查所有,减少解析开销)
|
|
|
+ $query = $this
|
|
|
+ ->alias("u")
|
|
|
+ ->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")
|
|
|
+ ->where($where);
|
|
|
if ($serviceAreaWhere) {
|
|
|
- $totalModel->where($serviceAreaWhere);
|
|
|
- }
|
|
|
- $totalCount = $totalModel->count();
|
|
|
- $data = null;
|
|
|
+ $query->where($serviceAreaWhere);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取总数
|
|
|
+ $totalCount = $query->count();
|
|
|
+
|
|
|
+ // 分页查询
|
|
|
+ $data = [];
|
|
|
if ($totalCount > 0) {
|
|
|
- $dataModel = $this
|
|
|
- ->alias("u")
|
|
|
- ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit,a.name,a.avatar,a.birthday,a.service_project,IFNULL(u.longitude,0) as longitude,IFNULL(u.latitude,0) as latitude")
|
|
|
- ->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")
|
|
|
- ->where($where);
|
|
|
- if ($serviceAreaWhere) {
|
|
|
- $dataModel->where($serviceAreaWhere);
|
|
|
- }
|
|
|
- $data = $dataModel->order("u.uid", "desc")
|
|
|
- ->page($post["page"], $post["pageSize"])
|
|
|
+ $offset = ($post["page"] - 1) * $post["pageSize"];
|
|
|
+ $result = $query->order("u.uid", "desc")
|
|
|
+ ->limit($offset, $post["pageSize"])
|
|
|
->select();
|
|
|
- if (!empty($data)) {
|
|
|
- $data = $data->toArray();
|
|
|
-
|
|
|
- // /* 注释掉 service_project_ar 查询 start */
|
|
|
- // // 一次性获取所有 service_project 的详情
|
|
|
- // $allProjectIds = [];
|
|
|
- // foreach ($data as $v) {
|
|
|
- // if (!empty($v['service_project'])) {
|
|
|
- // $projectIds = is_array($v['service_project']) ? $v['service_project'] : explode(',', $v['service_project']);
|
|
|
- // $allProjectIds = array_merge($allProjectIds, $projectIds);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // $projectMap = [];
|
|
|
- // if (!empty($allProjectIds)) {
|
|
|
- // $allProjectIds = array_unique(array_map('intval', $allProjectIds));
|
|
|
- // $projectList = (new ServiceTypeModel())->where('id', 'in', $allProjectIds)->select()->toArray();
|
|
|
- // foreach ($projectList as $p) {
|
|
|
- // $projectMap[$p['id']] = $p;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // /* 注释掉 service_project_ar 查询 end */
|
|
|
-
|
|
|
- foreach ($data as $k => $v) {
|
|
|
- $data[$k]['name'] = $v['name'] ?? '';
|
|
|
- $data[$k]['avatar'] = $v['avatar'] ?? '';
|
|
|
- // age 通过 birthday 计算得出
|
|
|
- $data[$k]['age'] = !empty($v['birthday']) ? (intval(date('Y')) - intval(date('Y', $v['birthday']))) : '';
|
|
|
- $data[$k]['birthday'] = !empty($v['birthday']) ? date('Y-m-d', $v['birthday']) : '';
|
|
|
- $data[$k]['longitude'] = $v['longitude'] ?? 0;
|
|
|
- $data[$k]['latitude'] = $v['latitude'] ?? 0;
|
|
|
- $data[$k]['service_project_ar'] = [];
|
|
|
- // /* 注释掉 service_project 匹配逻辑 start */
|
|
|
- // if (!empty($v['service_project'])) {
|
|
|
- // $projectIds = is_array($v['service_project']) ? $v['service_project'] : explode(',', $v['service_project']);
|
|
|
- // foreach ($projectIds as $pid) {
|
|
|
- // if (isset($projectMap[$pid])) {
|
|
|
- // $data[$k]['service_project_ar'][] = $projectMap[$pid];
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
- // /* 注释掉 service_project 匹配逻辑 end */
|
|
|
- $data[$k]['user_work_type_title'] = '';
|
|
|
- $data[$k]['service_area_all'] = [];
|
|
|
+ if (!empty($result)) {
|
|
|
+ $result = $result->toArray();
|
|
|
+ foreach ($result as $v) {
|
|
|
+ $data[] = [
|
|
|
+ 'uid' => $v['uid'],
|
|
|
+ 'show_template_id' => $v['show_template_id'] ?? 0,
|
|
|
+ 'name' => $v['name'] ?? '',
|
|
|
+ 'avatar' => $v['avatar'] ?? '',
|
|
|
+ 'longitude' => $v['longitude'] ?? 0,
|
|
|
+ 'latitude' => $v['latitude'] ?? 0,
|
|
|
+ 'user_work_type_title' => ''
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- $data = empty($data) ? [] : $data;
|
|
|
+
|
|
|
return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
|
|
|
}
|
|
|
|
|
|
+// /**
|
|
|
+// * 获取小程序在职展示列表 备份
|
|
|
+// * @return type
|
|
|
+// */
|
|
|
+// public function getNewApiWorkerList($post)
|
|
|
+// {
|
|
|
+// $post["pageSize"] = $post["pageSize"] > 20 ? 20 : (int)$post["pageSize"];
|
|
|
+// $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
|
|
|
+// $where = [];
|
|
|
+// $where[] = ["u.work_type_id", ">", 0];
|
|
|
+// $where[] = ["u.status", "=", 1];
|
|
|
+// if (!empty($post['work_type_id'])) {
|
|
|
+// $where[] = ["u.work_type_id", "=", $post['work_type_id']];
|
|
|
+// }
|
|
|
+// if ($post['servicePrice'] > 0) {
|
|
|
+// $where[] = ["a.service_min_price", "<=", $post['servicePrice']];
|
|
|
+// }
|
|
|
+// if (!empty($post['timetype'])) {
|
|
|
+// $where[] = ["a.service_type", "=", $post['timetype']];
|
|
|
+// }
|
|
|
+// if ($post['is_china'] != '') {
|
|
|
+// $where[] = ["a.is_china", '=', $post['is_china']];
|
|
|
+// }
|
|
|
+// $cityModel = new CityModel();
|
|
|
+// $serviceAreaWhere = null;
|
|
|
+// if (!empty($post["service_area"]) && is_array($post["service_area"])) {
|
|
|
+// $cityIds = [];
|
|
|
+// foreach ($post["service_area"] as $v) {
|
|
|
+// $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
|
|
|
+// $str = str_replace(['辖'], ['市辖'], $stc);
|
|
|
+// $arr = explode(",", $str);
|
|
|
+// $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[1] . "," . $arr[2])->value('id');
|
|
|
+// if (!$city_id) $city_id = $cityModel->where('merger_name', 'like', "%" . $arr[0] . "," . $arr[1])->value('id');
|
|
|
+// if ($city_id) $cityIds[] = $city_id;
|
|
|
+// }
|
|
|
+// if (!empty($cityIds)) {
|
|
|
+// $cityIdStr = implode(',', $cityIds);
|
|
|
+// $serviceAreaWhere = function ($query) use ($cityIdStr) {
|
|
|
+// foreach (explode(',', $cityIdStr) as $cid) {
|
|
|
+// $query->whereOr('find_in_set(' . intval($cid) . ',a.service_area)');
|
|
|
+// }
|
|
|
+// };
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// $totalModel = $this->alias("u")->leftJoin("info_audit a", "u.uid=a.uid")->where($where);
|
|
|
+// if ($serviceAreaWhere) {
|
|
|
+// $totalModel->where($serviceAreaWhere);
|
|
|
+// }
|
|
|
+// $totalCount = $totalModel->count();
|
|
|
+// $data = null;
|
|
|
+// if ($totalCount > 0) {
|
|
|
+// $dataModel = $this
|
|
|
+// ->alias("u")
|
|
|
+// ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit,a.name,a.avatar,a.birthday,a.service_project,IFNULL(u.longitude,0) as longitude,IFNULL(u.latitude,0) as latitude")
|
|
|
+// ->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")
|
|
|
+// ->where($where);
|
|
|
+// if ($serviceAreaWhere) {
|
|
|
+// $dataModel->where($serviceAreaWhere);
|
|
|
+// }
|
|
|
+// $data = $dataModel->order("u.uid", "desc")
|
|
|
+// ->page($post["page"], $post["pageSize"])
|
|
|
+// ->select();
|
|
|
+// if (!empty($data)) {
|
|
|
+// $data = $data->toArray();
|
|
|
+//
|
|
|
+// // /* 注释掉 service_project_ar 查询 start */
|
|
|
+// // // 一次性获取所有 service_project 的详情
|
|
|
+// // $allProjectIds = [];
|
|
|
+// // foreach ($data as $v) {
|
|
|
+// // if (!empty($v['service_project'])) {
|
|
|
+// // $projectIds = is_array($v['service_project']) ? $v['service_project'] : explode(',', $v['service_project']);
|
|
|
+// // $allProjectIds = array_merge($allProjectIds, $projectIds);
|
|
|
+// // }
|
|
|
+// // }
|
|
|
+// // $projectMap = [];
|
|
|
+// // if (!empty($allProjectIds)) {
|
|
|
+// // $allProjectIds = array_unique(array_map('intval', $allProjectIds));
|
|
|
+// // $projectList = (new ServiceTypeModel())->where('id', 'in', $allProjectIds)->select()->toArray();
|
|
|
+// // foreach ($projectList as $p) {
|
|
|
+// // $projectMap[$p['id']] = $p;
|
|
|
+// // }
|
|
|
+// // }
|
|
|
+// // /* 注释掉 service_project_ar 查询 end */
|
|
|
+//
|
|
|
+// foreach ($data as $k => $v) {
|
|
|
+// $data[$k]['name'] = $v['name'] ?? '';
|
|
|
+// $data[$k]['avatar'] = $v['avatar'] ?? '';
|
|
|
+// // age 通过 birthday 计算得出
|
|
|
+// $data[$k]['age'] = !empty($v['birthday']) ? (intval(date('Y')) - intval(date('Y', $v['birthday']))) : '';
|
|
|
+// $data[$k]['birthday'] = !empty($v['birthday']) ? date('Y-m-d', $v['birthday']) : '';
|
|
|
+// $data[$k]['longitude'] = $v['longitude'] ?? 0;
|
|
|
+// $data[$k]['latitude'] = $v['latitude'] ?? 0;
|
|
|
+// $data[$k]['service_project_ar'] = [];
|
|
|
+// // /* 注释掉 service_project 匹配逻辑 start */
|
|
|
+// // if (!empty($v['service_project'])) {
|
|
|
+// // $projectIds = is_array($v['service_project']) ? $v['service_project'] : explode(',', $v['service_project']);
|
|
|
+// // foreach ($projectIds as $pid) {
|
|
|
+// // if (isset($projectMap[$pid])) {
|
|
|
+// // $data[$k]['service_project_ar'][] = $projectMap[$pid];
|
|
|
+// // }
|
|
|
+// // }
|
|
|
+// // }
|
|
|
+// // /* 注释掉 service_project 匹配逻辑 end */
|
|
|
+// $data[$k]['user_work_type_title'] = '';
|
|
|
+// $data[$k]['service_area_all'] = [];
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// $data = empty($data) ? [] : $data;
|
|
|
+// return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 获取从业人员列表
|