Files
zyt/server/app/adminapi/logic/stats/PersonalAccountCostLogic.php
T
longandCursor e4f181e4fe fix(stats/self_input): 渠道字典、财务脱敏与同日同渠道全局唯一
自媒体来源改推广渠道字典;非白名单隐藏账户消耗/ROI;部门展示完整路径;业绩与消耗按日期+渠道全局去重。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-22 12:02:12 +08:00

123 lines
3.6 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
declare(strict_types=1);
namespace app\adminapi\logic\stats;
use app\common\logic\BaseLogic;
use app\common\model\stats\PersonalAccountCost;
class PersonalAccountCostLogic extends BaseLogic
{
use PersonalStatsScopeTrait;
public static function add(array $params, int $adminId, string $adminName): bool
{
try {
$costDate = (string) $params['cost_date'];
$mediaSource = self::normalizeMediaSource((string) ($params['media_source'] ?? ''));
if ($mediaSource === '') {
self::setError('请填写自媒体来源');
return false;
}
$conflict = self::findCostConflict($costDate, $mediaSource);
if ($conflict['conflict']) {
$by = $conflict['creator_name'] !== '' ? '(录入人:' . $conflict['creator_name'] . '' : '';
self::setError('该日期下该渠道的账户消耗已存在' . $by . ',请直接编辑该记录,避免重复汇总');
return false;
}
PersonalAccountCost::create([
'cost_date' => $costDate,
'media_source' => $mediaSource,
'amount' => round((float) ($params['amount'] ?? 0), 2),
'remark' => (string) ($params['remark'] ?? ''),
'creator_id' => $adminId,
'creator_name' => $adminName,
'updater_id' => $adminId,
'updater_name' => $adminName,
'dept_id' => self::resolvePrimaryDeptId($adminId),
]);
return true;
} catch (\Throwable $e) {
self::setError($e->getMessage());
return false;
}
}
public static function edit(array $params, int $adminId, string $adminName, array $adminInfo): bool
{
try {
$model = PersonalAccountCost::find($params['id']);
if (!$model) {
self::setError('记录不存在');
return false;
}
if (!self::assertRecordVisible($adminId, $adminInfo, (int) $model->creator_id)) {
self::setError('无权操作该记录');
return false;
}
$model->amount = round((float) ($params['amount'] ?? 0), 2);
$model->remark = (string) ($params['remark'] ?? '');
$model->updater_id = $adminId;
$model->updater_name = $adminName;
$model->save();
return true;
} catch (\Throwable $e) {
self::setError($e->getMessage());
return false;
}
}
public static function delete(int $id, int $adminId, array $adminInfo): bool
{
try {
$model = PersonalAccountCost::find($id);
if (!$model) {
self::setError('记录不存在');
return false;
}
if (!self::assertRecordVisible($adminId, $adminInfo, (int) $model->creator_id)) {
self::setError('无权操作该记录');
return false;
}
$model->delete();
return true;
} catch (\Throwable $e) {
self::setError($e->getMessage());
return false;
}
}
public static function detail(int $id, int $adminId, array $adminInfo): array
{
$model = PersonalAccountCost::find($id);
if (!$model) {
return [];
}
if (!self::assertRecordVisible($adminId, $adminInfo, (int) $model->creator_id)) {
return [];
}
return $model->toArray();
}
}