Files
MBTI_wang/api/app/common/service/ResumeUploadsAdminService.php
Ghost 513093a5e0 feat: 管理端用户详情展示企业简历上传;小程序资料与结果页配套
- 新增 ResumeUploadsAdminService,超管/企业用户详情返回 resumeUploads

- 管理端 UserDetailDialog 展示列表;小程序个人中心与多测评结果页文案/入口微调

Made-with: Cursor
2026-04-23 16:32:54 +08:00

106 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\service;
use think\facade\Db;
/**
* 管理后台用户详情企业版上传的简历文件mbti_enterprise_resume_uploads
*/
final class ResumeUploadsAdminService
{
/**
* @param int $wechatUserId wechat_users.id
* @param int|null $scopeEnterpriseId 非空时仅企业后台:该企业的记录;且包含「未写 enterpriseId 但用户已绑定该企业」的上传
* @return list<array{id:int, enterpriseId: int|null, enterpriseName: string, fileName: string, url: string, isDefault: bool, uploadedAt: int|null}>
*/
public static function listForWechatUser(int $wechatUserId, ?int $scopeEnterpriseId): array
{
if ($wechatUserId <= 0) {
return [];
}
try {
if ($scopeEnterpriseId !== null && (int) $scopeEnterpriseId > 0) {
$eid = (int) $scopeEnterpriseId;
$byE = Db::name('enterprise_resume_uploads')->alias('r')
->leftJoin('enterprises e', 'e.id = r.enterpriseId')
->where('r.userId', $wechatUserId)
->where('r.enterpriseId', $eid)
->field('r.id,r.enterpriseId,r.fileUrl,r.fileName,r.is_default,r.createdAt,e.name as enterpriseName')
->order('r.createdAt', 'desc')
->select()
->toArray();
$byNull = [];
$boundE = (int) (Db::name('wechat_users')->where('id', $wechatUserId)->value('enterpriseId') ?? 0);
if ($boundE === $eid) {
$byNull = Db::name('enterprise_resume_uploads')->alias('r')
->leftJoin('enterprises e', 'e.id = r.enterpriseId')
->where('r.userId', $wechatUserId)
->whereNull('r.enterpriseId')
->field('r.id,r.enterpriseId,r.fileUrl,r.fileName,r.is_default,r.createdAt,e.name as enterpriseName')
->order('r.createdAt', 'desc')
->select()
->toArray();
}
$rows = self::mergeRowsById($byE, $byNull);
} else {
$rows = Db::name('enterprise_resume_uploads')->alias('r')
->leftJoin('enterprises e', 'e.id = r.enterpriseId')
->where('r.userId', $wechatUserId)
->field('r.id,r.enterpriseId,r.fileUrl,r.fileName,r.is_default,r.createdAt,e.name as enterpriseName')
->order('r.createdAt', 'desc')
->select()
->toArray();
}
} catch (\Throwable $e) {
return [];
}
return self::mapRows($rows);
}
/**
* @param list<array> $a
* @param list<array> $b
* @return list<array>
*/
private static function mergeRowsById(array $a, array $b): array
{
$byId = [];
foreach (array_merge($a, $b) as $row) {
$id = (int) ($row['id'] ?? 0);
if ($id > 0) {
$byId[$id] = $row;
}
}
$out = array_values($byId);
usort($out, static function ($x, $y) {
$ax = (int) ($x['createdAt'] ?? 0);
$ay = (int) ($y['createdAt'] ?? 0);
return $ay <=> $ax;
});
return $out;
}
private static function mapRows(array $rows): array
{
$out = [];
foreach ($rows as $row) {
$ts = (int) ($row['createdAt'] ?? 0);
$out[] = [
'id' => (int) ($row['id'] ?? 0),
'enterpriseId' => isset($row['enterpriseId']) && $row['enterpriseId'] !== null && (int) $row['enterpriseId'] > 0
? (int) $row['enterpriseId'] : null,
'enterpriseName' => (string) ($row['enterpriseName'] ?? ''),
'fileName' => (string) ($row['fileName'] ?? ''),
'url' => (string) ($row['fileUrl'] ?? ''),
'isDefault' => (int) ($row['is_default'] ?? 0) === 1,
'uploadedAt' => $ts > 1000000000 ? $ts : null,
];
}
return $out;
}
}