Merge branch '20260518-long'
This commit is contained in:
@@ -68,6 +68,7 @@ class AccountCostLists extends BaseAdminDataLists implements ListsSearchInterfac
|
||||
'total_amount' => round((float) $this->baseQuery()->sum('amount'), 2),
|
||||
'days_count' => (int) $this->baseQuery()->distinct(true)->count('cost_date'),
|
||||
'media_channel_options' => MediaChannelService::getOptions(),
|
||||
'media_channel_groups' => MediaChannelService::getOptionGroups(),
|
||||
'dept_options' => DeptLogic::getAllData(),
|
||||
'supports_dept_binding' => AccountCost::supportsDeptBinding(),
|
||||
'default_media_channel_code' => MediaChannelService::getDefaultCode(),
|
||||
|
||||
@@ -11,6 +11,50 @@ use think\db\Query;
|
||||
|
||||
class MediaChannelService
|
||||
{
|
||||
/**
|
||||
* 与业绩看板「渠道来源」相同的分组(按 source_group_name),不含客户数统计。
|
||||
*
|
||||
* @return array<int, array{
|
||||
* group_name: string,
|
||||
* channels: array<int, array{channel_code: string, channel_name: string}>
|
||||
* }>
|
||||
*/
|
||||
public static function getOptionGroups(): array
|
||||
{
|
||||
$rows = QywxMediaChannel::where('status', 1)
|
||||
->field('channel_code, channel_name, source_group_name')
|
||||
->order('source_group_name asc, id asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if ($rows === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$groups = [];
|
||||
foreach ($rows as $r) {
|
||||
$g = (string) (($r['source_group_name'] ?? '') !== '' ? $r['source_group_name'] : '其它');
|
||||
$groups[$g] ??= ['group_name' => $g, 'channels' => []];
|
||||
$groups[$g]['channels'][] = [
|
||||
'channel_code' => (string) ($r['channel_code'] ?? ''),
|
||||
'channel_name' => (string) ($r['channel_name'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
$sortedGroups = array_values($groups);
|
||||
usort($sortedGroups, static function (array $a, array $b): int {
|
||||
$aMedia = mb_strpos($a['group_name'], '自媒体') !== false ? 0 : 1;
|
||||
$bMedia = mb_strpos($b['group_name'], '自媒体') !== false ? 0 : 1;
|
||||
if ($aMedia !== $bMedia) {
|
||||
return $aMedia <=> $bMedia;
|
||||
}
|
||||
|
||||
return strcmp($a['group_name'], $b['group_name']);
|
||||
});
|
||||
|
||||
return $sortedGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array{code: string, name: string}>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user