WIN-2308041133\Administrator пре 1 дан
родитељ
комит
bf49a886a9
1 измењених фајлова са 223 додато и 223 уклоњено
  1. 223 223
      app/model/api/User.php

+ 223 - 223
app/model/api/User.php

@@ -423,265 +423,265 @@ class User extends BaseModel
     }
 
 
-    /**
-     * 获取小程序在职展示列表
-     * @return type
-     */
-    public function getNewApiWorkerList($post)
-    {
-        $post["pageSize"] = $post["pageSize"] > 20 ? 20 : (int)$post["pageSize"];
-        $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"];
-
-        // user 表的基础筛选条件
-        $where = [["u.work_type_id", ">", 0], ["u.status", "=", 1]];
-        if (!empty($post['work_type_id'])) {
-            $where[] = ["u.work_type_id", "=", $post['work_type_id']];
-        }
-
-        // info_audit 表的筛选条件(需要在获取 uid 时应用)
-        $infoAuditWhere = [["status", "=", 1], ["is_show", "=", 1]];
-        if ($post['servicePrice'] > 0) {
-            $infoAuditWhere[] = ["service_min_price", "<=", $post['servicePrice']];
-        }
-        if (!empty($post['timetype'])) {
-            $infoAuditWhere[] = ["service_type", "=", $post['timetype']];
-        }
-        if ($post['is_china'] != '') {
-            $infoAuditWhere[] = ["is_china", '=', $post['is_china']];
-        }
-        
-        // 城市查询条件优化:预先获取 cityIds
-        $cityIds = [];
-        if (!empty($post["service_area"]) && is_array($post["service_area"])) {
-            $cityModel = new CityModel();
-            $areaNames = [];
-            foreach ($post["service_area"] as $v) {
-                $stc = str_replace(['省', '市', '区', '县'], ['', '', '', ''], $v);
-                $str = str_replace(['辖'], ['市辖'], $stc);
-                $arr = explode(",", $str);
-                $areaNames[] = ["arr1" => $arr[1] ?? '', "arr2" => $arr[2] ?? '', "arr0" => $arr[0] ?? ''];
-            }
-            // 批量查询 city_ids
-            if (!empty($areaNames)) {
-                $cityIdMap = [];
-                foreach ($areaNames as $item) {
-                    if (!isset($cityIdMap[$item['arr1']])) {
-                        $id = $cityModel->where('merger_name', 'like', "%" . $item['arr1'] . "," . $item['arr2'])->value('id');
-                        if (!$id) {
-                            $id = $cityModel->where('merger_name', 'like', "%" . $item['arr0'] . "," . $item['arr1'])->value('id');
-                        }
-                        $cityIdMap[$item['arr1']] = $id;
-                    }
-                    if ($cityIdMap[$item['arr1']]) {
-                        $cityIds[] = $cityIdMap[$item['arr1']];
-                    }
-                }
-                $cityIds = array_unique($cityIds);
-            }
-        }
-
-        // 构建 info_audit 查询条件(用于获取符合条件的 uid)
-        $infoAuditQuery = (new \app\model\api\InfoAudit())->where($infoAuditWhere);
-        
-        // 城市筛选:使用 find_in_set
-        if (!empty($cityIds)) {
-            $infoAuditQuery->where(function ($query) use ($cityIds) {
-                $orWhere = '';
-                foreach ($cityIds as $idx => $cid) {
-                    if ($idx == 0) {
-                        $orWhere .= "FIND_IN_SET({$cid}, service_area)";
-                    } else {
-                        $orWhere .= " OR FIND_IN_SET({$cid}, service_area)";
-                    }
-                }
-                $query->whereRaw("({$orWhere})");
-            });
-        }
-        
-        // 直接在 info_audit 上筛选 uid(如果有 info_audit 筛选条件)
-        $hasInfoAuditFilter = $post['servicePrice'] > 0 || !empty($post['timetype']) || $post['is_china'] != '' || !empty($cityIds);
-        
-        if ($hasInfoAuditFilter) {
-            // 通过 info_audit 获取符合条件的 uid
-            $infoAuditUids = $infoAuditQuery->column('uid');
-            
-            if (empty($infoAuditUids)) {
-                return ["list" => [], "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => 0];
-            }
-            
-            // user 查询以此 uid 列表为基础
-            $userQuery = $this->alias("u")
-                ->where($where)
-                ->where('u.uid', 'in', $infoAuditUids);
-        } else {
-            // 没有 info_audit 筛选条件,直接查 user
-            $userQuery = $this->alias("u")
-                ->where($where)
-                ->whereRaw("EXISTS (SELECT 1 FROM info_audit ia WHERE ia.uid = u.uid AND ia.status = 1 AND ia.is_show = 1)");
-        }
-        
-        // 获取总数
-        $totalCount = $userQuery->count();
-        
-        // 分页查询
-        $data = [];
-        if ($totalCount > 0) {
-            $offset = ($post["page"] - 1) * $post["pageSize"];
-            $userList = $userQuery->order("u.uid", "desc")
-                ->limit($offset, $post["pageSize"])
-                ->column('u.uid');
-            
-            if (!empty($userList)) {
-                // 批量获取 info_audit 信息(带所有筛选条件)
-                $infoAuditQuery2 = (new \app\model\api\InfoAudit())->where($infoAuditWhere);
-                if (!empty($cityIds)) {
-                    $infoAuditQuery2->where(function ($query) use ($cityIds) {
-                        $orWhere = '';
-                        foreach ($cityIds as $idx => $cid) {
-                            $orWhere .= ($idx == 0 ? "" : " OR ") . "FIND_IN_SET({$cid}, service_area)";
-                        }
-                        $query->whereRaw("({$orWhere})");
-                    });
-                }
-                $infoAuditList = $infoAuditQuery2->where('uid', 'in', $userList)->select()->toArray();
-                
-                $infoAuditMap = [];
-                foreach ($infoAuditList as $item) {
-                    $infoAuditMap[$item['uid']] = $item;
-                }
-                
-                foreach ($userList as $uid) {
-                    $audit = $infoAuditMap[$uid] ?? [];
-                    $data[] = [
-                        'uid' => $uid,
-                        'show_template_id' => $audit['show_template_id'] ?? 0,
-                        'name' => $audit['name'] ?? '',
-                        'avatar' => $audit['avatar'] ?? '',
-                        'longitude' => $audit['longitude'] ?? 0,
-                        'latitude' => $audit['latitude'] ?? 0,
-                        'user_work_type_title' => ''
-                    ];
-                }
-            }
-        }
-        
-        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];
+//
+//        // user 表的基础筛选条件
+//        $where = [["u.work_type_id", ">", 0], ["u.status", "=", 1]];
 //        if (!empty($post['work_type_id'])) {
 //            $where[] = ["u.work_type_id", "=", $post['work_type_id']];
 //        }
+//
+//        // info_audit 表的筛选条件(需要在获取 uid 时应用)
+//        $infoAuditWhere = [["status", "=", 1], ["is_show", "=", 1]];
 //        if ($post['servicePrice'] > 0) {
-//            $where[] = ["a.service_min_price", "<=", $post['servicePrice']];
+//            $infoAuditWhere[] = ["service_min_price", "<=", $post['servicePrice']];
 //        }
 //        if (!empty($post['timetype'])) {
-//            $where[] = ["a.service_type", "=", $post['timetype']];
+//            $infoAuditWhere[] = ["service_type", "=", $post['timetype']];
 //        }
 //        if ($post['is_china'] != '') {
-//            $where[] = ["a.is_china", '=', $post['is_china']];
+//            $infoAuditWhere[] = ["is_china", '=', $post['is_china']];
 //        }
-//        $cityModel = new CityModel();
-//        $serviceAreaWhere = null;
+//
+//        // 城市查询条件优化:预先获取 cityIds
+//        $cityIds = [];
 //        if (!empty($post["service_area"]) && is_array($post["service_area"])) {
-//            $cityIds = [];
+//            $cityModel = new CityModel();
+//            $areaNames = [];
 //            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;
+//                $areaNames[] = ["arr1" => $arr[1] ?? '', "arr2" => $arr[2] ?? '', "arr0" => $arr[0] ?? ''];
 //            }
-//            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)');
+//            // 批量查询 city_ids
+//            if (!empty($areaNames)) {
+//                $cityIdMap = [];
+//                foreach ($areaNames as $item) {
+//                    if (!isset($cityIdMap[$item['arr1']])) {
+//                        $id = $cityModel->where('merger_name', 'like', "%" . $item['arr1'] . "," . $item['arr2'])->value('id');
+//                        if (!$id) {
+//                            $id = $cityModel->where('merger_name', 'like', "%" . $item['arr0'] . "," . $item['arr1'])->value('id');
+//                        }
+//                        $cityIdMap[$item['arr1']] = $id;
 //                    }
-//                };
+//                    if ($cityIdMap[$item['arr1']]) {
+//                        $cityIds[] = $cityIdMap[$item['arr1']];
+//                    }
+//                }
+//                $cityIds = array_unique($cityIds);
 //            }
 //        }
 //
-//        $totalModel = $this->alias("u")->leftJoin("info_audit a", "u.uid=a.uid")->where($where);
-//        if ($serviceAreaWhere) {
-//            $totalModel->where($serviceAreaWhere);
+//        // 构建 info_audit 查询条件(用于获取符合条件的 uid)
+//        $infoAuditQuery = (new \app\model\api\InfoAudit())->where($infoAuditWhere);
+//
+//        // 城市筛选:使用 find_in_set
+//        if (!empty($cityIds)) {
+//            $infoAuditQuery->where(function ($query) use ($cityIds) {
+//                $orWhere = '';
+//                foreach ($cityIds as $idx => $cid) {
+//                    if ($idx == 0) {
+//                        $orWhere .= "FIND_IN_SET({$cid}, service_area)";
+//                    } else {
+//                        $orWhere .= " OR FIND_IN_SET({$cid}, service_area)";
+//                    }
+//                }
+//                $query->whereRaw("({$orWhere})");
+//            });
 //        }
-//        $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);
+//
+//        // 直接在 info_audit 上筛选 uid(如果有 info_audit 筛选条件)
+//        $hasInfoAuditFilter = $post['servicePrice'] > 0 || !empty($post['timetype']) || $post['is_china'] != '' || !empty($cityIds);
+//
+//        if ($hasInfoAuditFilter) {
+//            // 通过 info_audit 获取符合条件的 uid
+//            $infoAuditUids = $infoAuditQuery->column('uid');
+//
+//            if (empty($infoAuditUids)) {
+//                return ["list" => [], "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => 0];
 //            }
-//            $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 */
+//            // user 查询以此 uid 列表为基础
+//            $userQuery = $this->alias("u")
+//                ->where($where)
+//                ->where('u.uid', 'in', $infoAuditUids);
+//        } else {
+//            // 没有 info_audit 筛选条件,直接查 user
+//            $userQuery = $this->alias("u")
+//                ->where($where)
+//                ->whereRaw("EXISTS (SELECT 1 FROM info_audit ia WHERE ia.uid = u.uid AND ia.status = 1 AND ia.is_show = 1)");
+//        }
+//
+//        // 获取总数
+//        $totalCount = $userQuery->count();
+//
+//        // 分页查询
+//        $data = [];
+//        if ($totalCount > 0) {
+//            $offset = ($post["page"] - 1) * $post["pageSize"];
+//            $userList = $userQuery->order("u.uid", "desc")
+//                ->limit($offset, $post["pageSize"])
+//                ->column('u.uid');
 //
-//                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($userList)) {
+//                // 批量获取 info_audit 信息(带所有筛选条件)
+//                $infoAuditQuery2 = (new \app\model\api\InfoAudit())->where($infoAuditWhere);
+//                if (!empty($cityIds)) {
+//                    $infoAuditQuery2->where(function ($query) use ($cityIds) {
+//                        $orWhere = '';
+//                        foreach ($cityIds as $idx => $cid) {
+//                            $orWhere .= ($idx == 0 ? "" : " OR ") . "FIND_IN_SET({$cid}, service_area)";
+//                        }
+//                        $query->whereRaw("({$orWhere})");
+//                    });
+//                }
+//                $infoAuditList = $infoAuditQuery2->where('uid', 'in', $userList)->select()->toArray();
+//
+//                $infoAuditMap = [];
+//                foreach ($infoAuditList as $item) {
+//                    $infoAuditMap[$item['uid']] = $item;
+//                }
+//
+//                foreach ($userList as $uid) {
+//                    $audit = $infoAuditMap[$uid] ?? [];
+//                    $data[] = [
+//                        'uid' => $uid,
+//                        'show_template_id' => $audit['show_template_id'] ?? 0,
+//                        'name' => $audit['name'] ?? '',
+//                        'avatar' => $audit['avatar'] ?? '',
+//                        'longitude' => $audit['longitude'] ?? 0,
+//                        'latitude' => $audit['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];
+    }
+
     /**
      * 获取从业人员列表
      * @param type $post