|
|
@@ -429,7 +429,6 @@ class User extends BaseModel
|
|
|
*/
|
|
|
public function getNewApiWorkerList($post)
|
|
|
{
|
|
|
- $startTime = microtime(true);
|
|
|
$post["pageSize"] = $post["pageSize"] > 20 ? 20 : (int)$post["pageSize"];
|
|
|
$post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
|
|
|
$where = [];
|
|
|
@@ -447,46 +446,94 @@ class User extends BaseModel
|
|
|
if ($post['is_china'] != '') {
|
|
|
$where[] = ["a.is_china", '=', $post['is_china']];
|
|
|
}
|
|
|
-
|
|
|
- // 简化查询:先只查 user 表获取 uid,再关联其他表
|
|
|
- $userIds = $this->where('work_type_id', '>', 0)
|
|
|
- ->where('status', 1)
|
|
|
- ->column('uid');
|
|
|
- $totalCount = count($userIds);
|
|
|
-
|
|
|
+ $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) {
|
|
|
- $data = $this
|
|
|
+ $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('u.uid', 'in', $userIds)
|
|
|
- ->where($where)
|
|
|
- ->order("u.uid", "desc")
|
|
|
+ ->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;
|
|
|
-
|
|
|
- $costTime = round(microtime(true) - $startTime, 3);
|
|
|
- Log::info("getNewApiWorkerList 耗时: {$costTime}s, 总数: {$totalCount}");
|
|
|
-
|
|
|
return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount];
|
|
|
}
|
|
|
|