feat(stats): 新增自录转化统计模块
支持后台用户手动录入个人业绩与账户消耗,独立计算转化指标,接入 DataScope 数据权限。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\logic\stats;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\stats\PersonalYeji;
|
||||
|
||||
class PersonalYejiLogic extends BaseLogic
|
||||
{
|
||||
use PersonalStatsScopeTrait;
|
||||
|
||||
public static function add(array $params, int $adminId, string $adminName): bool
|
||||
{
|
||||
try {
|
||||
$yejiDate = (string) $params['yeji_date'];
|
||||
$mediaSource = self::normalizeMediaSource((string) ($params['media_source'] ?? ''));
|
||||
if ($mediaSource === '') {
|
||||
self::setError('请填写自媒体来源');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self::isYejiDuplicate($adminId, $yejiDate, $mediaSource)) {
|
||||
self::setError('该日期下该自媒体来源的业绩已存在,请直接编辑');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
PersonalYeji::create([
|
||||
'yeji_date' => $yejiDate,
|
||||
'media_source' => $mediaSource,
|
||||
'add_fans_count' => (int) ($params['add_fans_count'] ?? 0),
|
||||
'total_open_count' => (int) ($params['total_open_count'] ?? 0),
|
||||
'unreplied_count' => (int) ($params['unreplied_count'] ?? 0),
|
||||
'paid_appointment_count' => (int) ($params['paid_appointment_count'] ?? 0),
|
||||
'free_appointment_count' => (int) ($params['free_appointment_count'] ?? 0),
|
||||
'interview_count' => (int) ($params['interview_count'] ?? 0),
|
||||
'order_amount' => round((float) ($params['order_amount'] ?? 0), 2),
|
||||
'completed_order_count' => (int) ($params['completed_order_count'] ?? 0),
|
||||
'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 = PersonalYeji::find($params['id']);
|
||||
if (!$model) {
|
||||
self::setError('记录不存在');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!self::assertRecordVisible($adminId, $adminInfo, (int) $model->creator_id)) {
|
||||
self::setError('无权操作该记录');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!self::canMutateRecord($adminId, $adminInfo, (int) $model->creator_id)) {
|
||||
self::setError('仅可编辑本人录入的业绩');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$model->add_fans_count = (int) ($params['add_fans_count'] ?? 0);
|
||||
$model->total_open_count = (int) ($params['total_open_count'] ?? 0);
|
||||
$model->unreplied_count = (int) ($params['unreplied_count'] ?? 0);
|
||||
$model->paid_appointment_count = (int) ($params['paid_appointment_count'] ?? 0);
|
||||
$model->free_appointment_count = (int) ($params['free_appointment_count'] ?? 0);
|
||||
$model->interview_count = (int) ($params['interview_count'] ?? 0);
|
||||
$model->order_amount = round((float) ($params['order_amount'] ?? 0), 2);
|
||||
$model->completed_order_count = (int) ($params['completed_order_count'] ?? 0);
|
||||
$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 = PersonalYeji::find($id);
|
||||
if (!$model) {
|
||||
self::setError('记录不存在');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!self::assertRecordVisible($adminId, $adminInfo, (int) $model->creator_id)) {
|
||||
self::setError('无权操作该记录');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!self::canMutateRecord($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 = PersonalYeji::find($id);
|
||||
if (!$model) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!self::assertRecordVisible($adminId, $adminInfo, (int) $model->creator_id)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $model->toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user