完整版V1 加入爬虫功能
This commit is contained in:
@@ -26,6 +26,7 @@ class Number extends Model
|
||||
'link_url_text',
|
||||
'status_text',
|
||||
'manual_manage_text',
|
||||
'platform_status_text',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -65,6 +66,18 @@ class Number extends Model
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getPlatformStatusList(): array
|
||||
{
|
||||
return [
|
||||
'online' => __('Platform status online'),
|
||||
'offline' => __('Platform status offline'),
|
||||
'unknown' => __('Platform status unknown'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分流链接
|
||||
*/
|
||||
@@ -94,17 +107,19 @@ class Number extends Model
|
||||
return $list[$type] ?? $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表展示用:仅显示分流链接码(非完整 URL)
|
||||
*/
|
||||
public function getLinkUrlTextAttr($value, $data): string
|
||||
{
|
||||
if ($value !== '' && $value !== null) {
|
||||
return (string) $value;
|
||||
if (isset($data['split_link']) && is_array($data['split_link'])) {
|
||||
return (string) ($data['split_link']['link_code'] ?? '');
|
||||
}
|
||||
$linkId = (int) ($data['split_link_id'] ?? 0);
|
||||
if ($linkId <= 0) {
|
||||
return '';
|
||||
}
|
||||
$code = Link::where('id', $linkId)->value('link_code');
|
||||
return self::buildLinkUrl((string) $code);
|
||||
return (string) Link::where('id', $linkId)->value('link_code');
|
||||
}
|
||||
|
||||
public function getStatusTextAttr($value, $data): string
|
||||
@@ -121,6 +136,13 @@ class Number extends Model
|
||||
return $list[$key] ?? $key;
|
||||
}
|
||||
|
||||
public function getPlatformStatusTextAttr($value, $data): string
|
||||
{
|
||||
$key = (string) ($data['platform_status'] ?? 'unknown');
|
||||
$list = $this->getPlatformStatusList();
|
||||
return $list[$key] ?? $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据链接码生成完整分流 URL
|
||||
*/
|
||||
|
||||
@@ -98,7 +98,8 @@ class Ticket extends Model
|
||||
*/
|
||||
public function splitLink()
|
||||
{
|
||||
return $this->belongsTo(Link::class, 'split_link_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
||||
// IN 预载入:避免 eagerlyType=0(JOIN) 与列表 field 子查询冲突导致 SQL 1064
|
||||
return $this->belongsTo(Link::class, 'split_link_id', 'id', [], 'LEFT')->setEagerlyType(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +127,7 @@ class Ticket extends Model
|
||||
$total = (int) ($data['ticket_total'] ?? 0);
|
||||
$complete = (int) ($data['complete_count'] ?? 0);
|
||||
if ($total <= 0) {
|
||||
return '—';
|
||||
return '0%';
|
||||
}
|
||||
$percent = round($complete / $total * 100, 2);
|
||||
return $percent . '%';
|
||||
|
||||
Reference in New Issue
Block a user