alias("m") ->field("m.*,u.nickname as i_nickname,u.uuid as i_uuid,t.name as i_tname,t.tuuid as i_tuuid,s.day_surplus_talk,s.day_surplus_video,s.time as surplus_time" . ",(select count(*) from table_user_friends as p where p.uid = m.uid) as friendsCount"//朋友数 . ",(select count(*) from table_user_attention as a where a.uid = m.uid) as attentionCount"//关注数 . ",(select count(*) from table_user_attention as f where f.i_uid = m.uid) as fasCount"//粉丝数 . ",(select count(*) from table_user_visitors as v where v.uid = m.uid) as visitorsCount"//访客数 . "") ->leftJoin("user u", "u.uid = m.i_uid") ->leftJoin("user_surplus s", "s.uid = m.uid and s.time = {$today}") ->leftJoin("tuser t", "t.tuid = m.i_tuid") ->when(!empty($where), function ($query) use ($where) { if (!empty($where['mobile'])) { $query->where('m.mobile', $where['mobile']); } if (!empty($where['nickname'])) { $query->whereLike('m.nickname', "%{$where['nickname']}%"); } if (is_numeric($where['levelid']) && in_array(strval($where['levelid']), ['0', '1', '2'])) { $query->where('m.levelid', intval($where['levelid'])); } if (is_numeric($where['is_certification']) && in_array(strval($where['is_certification']), ['0', '1', '2'])) { $query->where('m.is_certification', intval($where['is_certification'])); } if (is_numeric($where['is_goddess']) && in_array(strval($where['is_goddess']), ['0', '1', '2'])) { $query->where('m.is_goddess', intval($where['is_goddess'])); } if (!empty($where['address'])) { $query->whereLike('m.address', "%{$where['address']}%"); } if (!empty($where['now_address'])) { $query->whereLike('m.now_address', "%{$where['now_address']}%"); } if (!empty($where['i_uid'])) { $query->where('m.i_uid', $where['i_uid']); } if (!empty($where['i_tuid'])) { $query->where('m.i_tuid', $where['i_tuid']); } if (is_numeric($where["sex"]) && in_array(strval($where["sex"]), ["0", "1", "2"])) { $query->where('m.sex', $where["sex"]); } if (is_numeric($where["is_im"]) && in_array(strval($where["is_im"]), ["0", "1"])) { $query->where('m.is_im', $where["is_im"]); } if (is_numeric($where["is_online"]) && in_array(strval($where["is_online"]), ["0", "1"])) { $query->where('m.is_online', $where["is_online"]); } if (is_numeric($where["status"]) && in_array(strval($where["status"]), ["0", "1", "-1"])) { $query->where('m.status', $where["status"]); } if (!empty($where['uid'])) { $query->where('m.uid', $where['uid']); } if (!empty($where['uuid'])) { $query->where('m.uuid', $where['uuid']); } //注册时间 $startTime = ""; $endTime = ""; if (!empty($where['time']) && !empty($where['time'][0]) && !empty($where['time'][1])) { $startTime = strtotime($where['time'][0]); $endTime = strtotime($where['time'][1]); } if (!empty($startTime) && !empty($endTime)) { $query->whereBetween("m.regtime", "{$startTime},{$endTime}"); } }) ->order($desc) ->paginate(['list_rows' => $pageCount, 'page' => $page]) ->toArray(); return [$data['total'], $data['data']]; } /** * 保存数据 * @param $data * @param $admin_id * @return array */ public function saveUpdate($data, $admin_id) { try { self::beginTrans(); if (!is_numeric($data["levelid"]) || !in_array(strval($data["levelid"]), ["0", "1", "2"])) { unset($data["levelid"]); } if (empty($data["mobile"])) { unset($data["mobile"]); } else { if (!isMobile($data["mobile"])) { return [0, '请输入正确的手机号码']; } } if (empty($data["nickname"])) { unset($data["nickname"]); } if (empty($data["address"])) { unset($data["address"]); } if (empty($data["now_address"])) { unset($data["now_address"]); } if (!is_numeric($data["status"]) || !in_array(strval($data["status"]), ["0", "1", "-1"])) { unset($data["status"]); } if (!is_numeric($data["is_shield"]) || !in_array(strval($data["is_shield"]), ["0", "1"])) { unset($data["is_shield"]); } //密码 if (!empty($data['password'])) { $data['password'] = md5($data['password']); } else { unset($data["password"]); } if (empty($data["avatar"])) { unset($data["avatar"]); } if (!is_numeric($data["sex"]) || !in_array(strval($data["sex"]), ["0", "1", "2"])) { unset($data["sex"]); } //特殊设置 if (empty($data["msg_price"]) || !is_numeric($data["msg_price"])) { unset($data["msg_price"]); } if (empty($data["video_price"]) || !is_numeric($data["video_price"])) { unset($data["video_price"]); } if (empty($data["audio_price"]) || !is_numeric($data["audio_price"])) { unset($data["audio_price"]); } if (empty($data["phone_price"]) || !is_numeric($data["phone_price"])) { unset($data["phone_price"]); } if (empty($data["wx_price"]) || !is_numeric($data["wx_price"])) { unset($data["wx_price"]); } if (empty($data["qq_price"]) || !is_numeric($data["qq_price"])) { unset($data["qq_price"]); } //开关设置 if (!is_numeric($data["is_rank"]) || !in_array(strval($data["is_rank"]), ["0", "1"])) { unset($data["is_rank"]); } if (!is_numeric($data["is_gift"]) || !in_array(strval($data["is_gift"]), ["0", "1"])) { unset($data["is_gift"]); } if (!is_numeric($data["is_msg"]) || !in_array(strval($data["is_msg"]), ["0", "1"])) { unset($data["is_msg"]); } if (!is_numeric($data["is_video"]) || !in_array(strval($data["is_video"]), ["0", "1"])) { unset($data["is_video"]); } if (!is_numeric($data["is_audio"]) || !in_array(strval($data["is_audio"]), ["0", "1"])) { unset($data["is_audio"]); } //uid if (!empty($data['uid'])) { $uData = $this->where('uid', $data['uid'])->find()->toArray(); if (empty($uData)) { return [0, '会员不存在']; } if (!empty($data["mobile"])) { //判断手机是否重复 $count = $this ->where('mobile', $data['mobile']) ->where('uid', '<>', $data['uid']) ->count(); if ($count > 0) { return [0, '手机号码已经存在']; } } } else { $data['regtime'] = time(); } $this->saveModel($data); self::commitTrans(); return [1, '']; } catch (DbException $db) { self::rollbackTrans(); return [0, '操作失败1']; } catch (\Exception $e) { self::rollbackTrans(); return [0, '操作失败2']; } return [0, '操作失败']; } /** * 获取列表数据 * @param $page * @param $where * @param $pageCount * @param $desc */ public function getItem($uid) { $data = $this ->field("m.*,(select mobile from table_user where uid = m.i_uid) as i_name") ->alias("m") ->where('uid', $uid) ->select(); return $data; } /** * 获取小程序在职展示列表 * @return type */ public function getApiWorkerList($post) { $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (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']]; } $totalCount = $this->alias("u")->where($where)->count(); $data = null; if ($totalCount > 0) { $data = $this ->alias("u") ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit") ->leftJoin("info_audit a", "u.uid=a.uid") ->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(); if (!empty($data)) { $data = $data->toArray(); } $infoAuditDb = new InfoAudit(); foreach ($data as $k => $v) { $item = [ "name" => "", "avatar" => "", "age" => "", "service_project_ar" => [], "user_work_type_title" => "", "service_area_all" => [], "birthday" => "" ]; $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]); if (!empty($infoData)) { foreach ($item as $k2 => $v2) { $item[$k2] = $infoData[$k2]; } } $data[$k] = array_merge($v, $item); } } // $datatwo = []; // foreach($data as $v){ // if($v['is_show'] == 1){ // $datatwo[] = $v; // } // } $data = empty($data) ? [] : $data; return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]; } /** * 获取小程序在职展示列表 * @return type */ public function getGoodApiWorkerList($post) { $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"]; $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"]; $where = []; $where[] = ["u.work_type_id", ">", 0]; $where[] = ["u.show_temp_seq", ">", 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 ($post['is_china'] != '') { $where[] = ["a.is_china", '=', $post['is_china']]; } if (!empty($post['timetype'])) { $where[] = ["a.service_type", "=", $post['timetype']]; } $cityModel = new CityModel(); $totalModel = $this->alias("u")->leftJoin("info_audit a", "u.uid=a.uid")->where($where); if (!empty($post["service_area"]) && is_array($post["service_area"])) { $totalModel->where(function ($query) use ($post, $cityModel) { 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'); @file_put_contents('quanju.txt', $city_id. "-城市id\r\n", 8); $query->whereOr('find_in_set(' . $city_id . ',a.service_area)'); } }); } $totalCount = $totalModel->count(); $data = null; if ($totalCount > 0) { // Log::info('搜索条件:' . json_encode($where, JSON_UNESCAPED_UNICODE)); $dataModel = $this ->alias("u") ->field("u.uid,ut.show_template_id,a.ancestral_place,a.status as is_type_audit") ->leftJoin("info_audit a", "u.uid=a.uid") ->leftJoin("user_show_template ut", "ut.uid = u.uid and ut.is_default = 1")//默认模板 ->where($where)->where('ut.show_template_id',7); if (!empty($post["service_area"]) && is_array($post["service_area"])) { $dataModel->where(function ($query) use ($post, $cityModel) { 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'); @file_put_contents('quanju.txt', $city_id. "-城市id2222222\r\n", 8); $query->whereOr('find_in_set(' . $city_id . ',a.service_area)'); } }); } $data = $dataModel->order("u.show_temp_seq", "desc") ->order("u.uid", "desc") ->page($post["page"], $post["pageSize"]) ->select(); // Log::info('搜索语句:' . json_encode($this->getLastSql(), JSON_UNESCAPED_UNICODE)); if (!empty($data)) { $data = $data->toArray(); } $infoAuditDb = new InfoAudit(); foreach ($data as $k => $v) { $item = [ "name" => "", "avatar" => "", "age" => "", "service_project_ar" => [], "user_work_type_title" => "", "service_area_all" => [], "birthday" => "" ]; $infoData = $infoAuditDb->getItem(["status" => 1, "uid" => $v["uid"]]); if (!empty($infoData)) { foreach ($item as $k2 => $v2) { $item[$k2] = $infoData[$k2]; } } $data[$k] = array_merge($v, $item); } } // $datatwo = []; // foreach($data as $v){ // if($v['is_show'] == 1){ // $datatwo[] = $v; // } // } $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"]; // 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]; // 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 * @param type $field * @param type $is_admin */ public function getWorkerList($post, $field = "*", $is_admin = 0) { $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"]; $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"]; $where = []; $where[] = ["u.work_type_id", ">", 0]; //用户uid if (!empty($post['uid'])) { $where[] = ["u.uid", "=", $post['uid']]; } if (!empty($post['work_type_id'])) { $where[] = ["u.work_type_id", "=", $post['work_type_id']]; } //手机号码 if (!empty($post["mobile"])) { $where[] = ["u.mobile", "=", $post["mobile"]]; } //状态 if (isset($post["status"]) && in_array((string)$post["status"], ["0", "1", "-1"])) { $where[] = ["u.status", "=", (int)$post["status"]]; } //父级uid if (!empty($post["parent_uid"])) { $where[] = ["u.parent_uid", "=", $post["parent_uid"]]; } // if ($is_admin == 1) { $field = "u.*" . ",ut.show_template_id" . ",(select is_show from table_info_audit where uid = u.uid and status = 1 limit 1 ) as is_show" . ",p.nickname as p_nickname,p.mobile as p_mobile" . ",wt.title as work_type_title" . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount" . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit" . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit" . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount"; } $totalCount = $this->alias("u")->where($where)->count(); $data = null; if ($totalCount > 0) { $data = $this ->alias("u") ->field($field) ->leftJoin("user p", "p.uid = u.parent_uid") ->leftJoin("user_work_type wt", "wt.id = u.work_type_id")//职称 ->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(); // var_dump($this->getLastSql()); if (!empty($data)) { $data = $data->toArray(); } } $data = empty($data) ? [] : $data; $ShowTemplateDb = new ShowTemplate(); foreach ($data as $k => $v) { if (!empty($v["regtime"])) { $data[$k]["regtime"] = date("Y-m-d H:i:s", $v["regtime"]); } if (!empty($v["parent_time"])) { $data[$k]["parent_time"] = date("Y-m-d H:i:s", $v["parent_time"]); } } // $datatwo = []; // foreach($data as $v){ // if($v['is_show'] == 1){ // $datatwo[] = $v; // } // } return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]; } /** * 前端获取用户列表 * @param type $post * @param type $field * @return type */ public function getDataList($post, $field = "*", $is_admin = 0) { $post["pageSize"] = $post["pageSize"] > 50 ? 50 : (int)$post["pageSize"]; $post["page"] = $post["page"] <= 0 ? 1 : (int)$post["page"]; $where = []; //用户uid if (!empty($post['uid'])) { $where[] = ["u.uid", "=", $post['uid']]; } //状态 if (isset($post["status"]) && in_array((string)$post["status"], ["0", "1", "-1"])) { $where[] = ["u.status", "=", (int)$post["status"]]; } //昵称 if (!empty($post["nickname"])) { $where[] = ["u.nickname", "like", "%{$post["nickname"]}%"]; } //手机号码 if (!empty($post["mobile"])) { $where[] = ["u.mobile", "=", $post["mobile"]]; } //父级uid if (!empty($post["parent_uid"])) { $where[] = ["u.parent_uid", "=", $post["parent_uid"]]; } //注册时间 if (!empty($post['time']) && !empty($post['time'][0]) && !empty($post['time'][1])) { $startTime = strtotime($post['time'][0]); $endTime = strtotime($post['time'][1]); $where[] = ["u.regtime", "between", "{$startTime},{$endTime}"]; } if ($is_admin == 1) { $field = "u.*" . ",p.nickname as p_nickname,p.mobile as p_mobile" . ",wt.title as work_type_title" . ",(select count(*) from table_user_show_template where uid = u.uid) as showTempCount" . ",(select count(*) from table_info_audit where uid = u.uid and status = 1) as is_info_audit" . ",(select count(*) from table_type_audit where uid = u.uid and status = 1) as is_type_audit" . ",(select count(*) from table_user where parent_uid = u.uid) as branchCount"; } $totalCount = $this->alias("u")->where($where)->count(); $data = null; if ($totalCount > 0) { $data = $this ->alias("u") ->field($field) ->leftJoin("user p", "p.uid = u.parent_uid") ->leftJoin("user_work_type wt", "wt.id = u.work_type_id")//职称 ->where($where) ->order("u.uid", "desc") ->page($post["page"], $post["pageSize"]) ->select(); if (!empty($data)) { $data = $data->toArray(); } } $data = empty($data) ? [] : $data; foreach ($data as $k => $v) { if (!empty($v["regtime"])) { $data[$k]["regtime"] = date("Y-m-d H:i:s", $v["regtime"]); } if (!empty($v["parent_time"])) { $data[$k]["parent_time"] = date("Y-m-d H:i:s", $v["parent_time"]); } } return ["list" => $data, "pageSize" => $post["pageSize"], "page" => $post["page"], "totalCount" => $totalCount]; } }