debug
This commit is contained in:
@@ -22,10 +22,8 @@ class PersonalAccountCostLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
$conflict = self::findCostConflict($costDate, $mediaSource);
|
||||
if ($conflict['conflict']) {
|
||||
$by = $conflict['creator_name'] !== '' ? '(录入人:' . $conflict['creator_name'] . ')' : '';
|
||||
self::setError('该日期下该渠道的账户消耗已存在' . $by . ',请直接编辑该记录,避免重复汇总');
|
||||
if (self::isCostDuplicate($adminId, $costDate, $mediaSource)) {
|
||||
self::setError('您在该日期下已录入过该渠道的账户消耗,请直接编辑');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,8 @@ class PersonalYejiLogic extends BaseLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
$conflict = self::findYejiConflict($yejiDate, $mediaSource);
|
||||
if ($conflict['conflict']) {
|
||||
$by = $conflict['creator_name'] !== '' ? '(录入人:' . $conflict['creator_name'] . ')' : '';
|
||||
self::setError('该日期下该渠道的业绩已存在' . $by . ',请直接编辑该记录,避免重复汇总');
|
||||
if (self::isYejiDuplicate($adminId, $yejiDate, $mediaSource)) {
|
||||
self::setError('您在该日期下已录入过该渠道的业绩,请直接编辑');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user