This commit is contained in:
2026-05-22 16:45:28 +08:00
parent e4f181e4fe
commit 003810114b
6 changed files with 83 additions and 39 deletions
@@ -200,43 +200,32 @@ trait PersonalStatsScopeTrait
}
/**
* 同一天 + 同一渠道全局唯一(不录入人):避免重复汇总
* 命中时返回首个已存在记录的录入人姓名,便于前端提示。
*
* @return array{conflict: bool, creator_name: string}
* 同一录入人 + 同一天 + 同一渠道唯一(不录入人可同日同渠道各录一条)
*/
protected static function findYejiConflict(string $yejiDate, string $mediaSource, int $excludeId = 0): array
protected static function isYejiDuplicate(int $creatorId, string $yejiDate, string $mediaSource, int $excludeId = 0): bool
{
$query = PersonalYeji::where('yeji_date', $yejiDate)
$query = PersonalYeji::where('creator_id', $creatorId)
->where('yeji_date', $yejiDate)
->where('media_source', $mediaSource);
if ($excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
$row = $query->field('id, creator_name')->find();
if (!$row) {
return ['conflict' => false, 'creator_name' => ''];
}
return ['conflict' => true, 'creator_name' => (string) ($row['creator_name'] ?? '')];
return $query->count() > 0;
}
/**
* 同一天 + 同一渠道全局唯一(不录入人):避免重复汇总
*
* @return array{conflict: bool, creator_name: string}
* 同一录入人 + 同一天 + 同一渠道唯一(不录入人可同日同渠道各录一条)
*/
protected static function findCostConflict(string $costDate, string $mediaSource, int $excludeId = 0): array
protected static function isCostDuplicate(int $creatorId, string $costDate, string $mediaSource, int $excludeId = 0): bool
{
$query = PersonalAccountCost::where('cost_date', $costDate)
$query = PersonalAccountCost::where('creator_id', $creatorId)
->where('cost_date', $costDate)
->where('media_source', $mediaSource);
if ($excludeId > 0) {
$query->where('id', '<>', $excludeId);
}
$row = $query->field('id, creator_name')->find();
if (!$row) {
return ['conflict' => false, 'creator_name' => ''];
}
return ['conflict' => true, 'creator_name' => (string) ($row['creator_name'] ?? '')];
return $query->count() > 0;
}
}