iMerge branch 'master' of https://gitee.com/v_cms/zyt
This commit is contained in:
@@ -64,6 +64,7 @@
|
||||
<el-form-item label="时间范围">
|
||||
<el-radio-group v-model="queryParams.time_type" @change="handleTimeTypeChange">
|
||||
<el-radio-button label="today">今天</el-radio-button>
|
||||
<el-radio-button label="yesterday">昨天</el-radio-button>
|
||||
<el-radio-button label="week">最近7天</el-radio-button>
|
||||
<el-radio-button label="month">最近30天</el-radio-button>
|
||||
<el-radio-button label="custom">自定义</el-radio-button>
|
||||
@@ -353,6 +354,7 @@ const summaryCards: MetricCard[] = [
|
||||
{ key: 'interview_rate', label: '面诊率', type: 'percent' },
|
||||
{ key: 'receive_rate', label: '接诊率', type: 'percent' },
|
||||
{ key: 'interview_receive_rate', label: '面诊接诊率', type: 'percent' },
|
||||
{ key: 'business_order_amount', label: '业务订单额', type: 'money' },
|
||||
{ key: 'completed_order_amount', label: '诊单金额', type: 'money' },
|
||||
{ key: 'avg_unit_price', label: '平均单价', type: 'money' },
|
||||
{ key: 'account_cost', label: '账户消耗', type: 'money' },
|
||||
|
||||
@@ -147,6 +147,10 @@ class ConversionLogic
|
||||
$timeType = (string)($params['time_type'] ?? 'today');
|
||||
|
||||
switch ($timeType) {
|
||||
case 'yesterday':
|
||||
$startDate = date('Y-m-d', strtotime('-1 day'));
|
||||
$endDate = $startDate;
|
||||
break;
|
||||
case 'week':
|
||||
$startDate = date('Y-m-d', strtotime('-6 days'));
|
||||
$endDate = $today;
|
||||
@@ -302,6 +306,7 @@ class ConversionLogic
|
||||
'free_appointment_count' => 0,
|
||||
'appointment_total_count' => 0,
|
||||
'interview_count' => 0,
|
||||
'business_order_amount' => 0.0,
|
||||
'completed_order_amount' => 0.0,
|
||||
'completed_order_count' => 0,
|
||||
'account_cost' => 0.0,
|
||||
@@ -489,25 +494,25 @@ class ConversionLogic
|
||||
int $endTimestamp,
|
||||
?array $mediaChannel
|
||||
): void {
|
||||
$sourceExpr = $dimension === 'doctor' ? 'rx.creator_id' : 'rx.assistant_id';
|
||||
$query = Db::name('tcm_prescription_order')
|
||||
$completedSourceExpr = $dimension === 'doctor' ? 'rx.creator_id' : 'rx.assistant_id';
|
||||
$completedQuery = Db::name('tcm_prescription_order')
|
||||
->alias('po')
|
||||
->leftJoin('tcm_prescription rx', 'rx.id = po.prescription_id')
|
||||
->leftJoin('tcm_diagnosis dg', 'dg.id = po.diagnosis_id')
|
||||
->whereNull('po.delete_time')
|
||||
->where('po.payment_slip_audit_status', 1)
|
||||
->where('po.create_time', 'between', [$startTimestamp, $endTimestamp])
|
||||
->fieldRaw("{$sourceExpr} AS source_admin_id, SUM(CASE WHEN po.prescription_audit_status = 1 THEN 1 ELSE 0 END) AS order_count, SUM(CASE WHEN po.prescription_audit_status = 1 THEN po.amount ELSE 0 END) AS total_amount")
|
||||
->group($sourceExpr);
|
||||
->fieldRaw("{$completedSourceExpr} AS source_admin_id, SUM(CASE WHEN po.prescription_audit_status = 1 THEN 1 ELSE 0 END) AS order_count, SUM(CASE WHEN po.prescription_audit_status = 1 THEN po.amount ELSE 0 END) AS total_amount")
|
||||
->group($completedSourceExpr);
|
||||
|
||||
if ($mediaChannel !== null) {
|
||||
$query->leftJoin('qywx_external_contact q', 'q.external_userid = dg.external_userid');
|
||||
MediaChannelService::applyFollowUsersChannelFilter($query, 'q.follow_users', $mediaChannel);
|
||||
$completedQuery->leftJoin('qywx_external_contact q', 'q.external_userid = dg.external_userid');
|
||||
MediaChannelService::applyFollowUsersChannelFilter($completedQuery, 'q.follow_users', $mediaChannel);
|
||||
}
|
||||
|
||||
$rows = $query->select()->toArray();
|
||||
$completedRows = $completedQuery->select()->toArray();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
foreach ($completedRows as $row) {
|
||||
$sourceAdminId = (int)($row['source_admin_id'] ?? 0);
|
||||
|
||||
$mappedEntityIds = self::mapEntityIds($dimension, $sourceAdminId, $entityIds, $adminToDeptIds);
|
||||
@@ -523,6 +528,36 @@ class ConversionLogic
|
||||
$entities[$entityId]['completed_order_amount'] = round($entities[$entityId]['completed_order_amount'] + $amount, 2);
|
||||
}
|
||||
}
|
||||
|
||||
$businessSourceExpr = $dimension === 'doctor' ? 'po.creator_id' : 'dg.assistant_id';
|
||||
$businessQuery = Db::name('tcm_prescription_order')
|
||||
->alias('po')
|
||||
->leftJoin('tcm_diagnosis dg', 'dg.id = po.diagnosis_id')
|
||||
->whereNull('po.delete_time')
|
||||
->where('po.create_time', 'between', [$startTimestamp, $endTimestamp])
|
||||
->where('po.fulfillment_status', '<>', 4)
|
||||
->fieldRaw("{$businessSourceExpr} AS source_admin_id, SUM(po.amount) AS total_amount")
|
||||
->group($businessSourceExpr);
|
||||
|
||||
if ($mediaChannel !== null) {
|
||||
$businessQuery->leftJoin('qywx_external_contact q2', 'q2.external_userid = dg.external_userid');
|
||||
MediaChannelService::applyFollowUsersChannelFilter($businessQuery, 'q2.follow_users', $mediaChannel);
|
||||
}
|
||||
|
||||
$businessRows = $businessQuery->select()->toArray();
|
||||
|
||||
foreach ($businessRows as $row) {
|
||||
$sourceAdminId = (int)($row['source_admin_id'] ?? 0);
|
||||
$mappedEntityIds = self::mapEntityIds($dimension, $sourceAdminId, $entityIds, $adminToDeptIds);
|
||||
if ($mappedEntityIds === []) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$amount = round((float)($row['total_amount'] ?? 0), 2);
|
||||
foreach ($mappedEntityIds as $entityId) {
|
||||
$entities[$entityId]['business_order_amount'] = round($entities[$entityId]['business_order_amount'] + $amount, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -593,6 +628,7 @@ class ConversionLogic
|
||||
$addFansCount = (int)$entity['add_fans_count'];
|
||||
$totalOpenCount = (int)$entity['total_open_count'];
|
||||
$completedOrderCount = (int)$entity['completed_order_count'];
|
||||
$businessOrderAmount = round((float)$entity['business_order_amount'], 2);
|
||||
$completedOrderAmount = round((float)$entity['completed_order_amount'], 2);
|
||||
$accountCost = round((float)$entity['account_cost'], 2);
|
||||
$globalAccountCost = max($globalAccountCost, round((float)($entity['_global_account_cost'] ?? 0), 2));
|
||||
@@ -601,6 +637,7 @@ class ConversionLogic
|
||||
$entity['paid_appointment_count'] = $paidAppointmentCount;
|
||||
$entity['free_appointment_count'] = $freeAppointmentCount;
|
||||
$entity['appointment_total_count'] = $appointmentTotalCount;
|
||||
$entity['business_order_amount'] = $businessOrderAmount;
|
||||
$entity['completed_order_amount'] = $completedOrderAmount;
|
||||
$entity['account_cost'] = $effectiveAccountCost;
|
||||
$entity['paid_appointment_rate'] = self::percent($paidAppointmentCount, $addFansCount);
|
||||
@@ -682,6 +719,7 @@ class ConversionLogic
|
||||
$node['appointment_total_count'] += (int)$childNode['appointment_total_count'];
|
||||
$node['interview_count'] += (int)$childNode['interview_count'];
|
||||
$node['completed_order_count'] += (int)$childNode['completed_order_count'];
|
||||
$node['business_order_amount'] = round((float)$node['business_order_amount'] + (float)$childNode['business_order_amount'], 2);
|
||||
$node['completed_order_amount'] = round((float)$node['completed_order_amount'] + (float)$childNode['completed_order_amount'], 2);
|
||||
$node['account_cost'] = round((float)$node['account_cost'] + (float)$childNode['account_cost'], 2);
|
||||
}
|
||||
@@ -797,6 +835,7 @@ class ConversionLogic
|
||||
$addFansCount = (int)$node['add_fans_count'];
|
||||
$totalOpenCount = (int)$node['total_open_count'];
|
||||
$completedOrderCount = (int)$node['completed_order_count'];
|
||||
$businessOrderAmount = round((float)$node['business_order_amount'], 2);
|
||||
$completedOrderAmount = round((float)$node['completed_order_amount'], 2);
|
||||
$accountCost = round((float)$node['account_cost'], 2);
|
||||
$globalAccountCost = round((float)($node['_global_account_cost'] ?? 0), 2);
|
||||
@@ -805,6 +844,7 @@ class ConversionLogic
|
||||
$node['paid_appointment_count'] = $paidAppointmentCount;
|
||||
$node['free_appointment_count'] = $freeAppointmentCount;
|
||||
$node['appointment_total_count'] = $appointmentTotalCount;
|
||||
$node['business_order_amount'] = $businessOrderAmount;
|
||||
$node['completed_order_amount'] = $completedOrderAmount;
|
||||
$node['account_cost'] = $effectiveAccountCost;
|
||||
$node['paid_appointment_rate'] = self::percent($paidAppointmentCount, $addFansCount);
|
||||
@@ -838,6 +878,7 @@ class ConversionLogic
|
||||
'free_appointment_count' => 0,
|
||||
'appointment_total_count' => 0,
|
||||
'interview_count' => 0,
|
||||
'business_order_amount' => 0.0,
|
||||
'completed_order_amount' => 0.0,
|
||||
'completed_order_count' => 0,
|
||||
'account_cost' => 0.0,
|
||||
@@ -853,6 +894,7 @@ class ConversionLogic
|
||||
$summary['appointment_total_count'] += (int)$row['appointment_total_count'];
|
||||
$summary['interview_count'] += (int)$row['interview_count'];
|
||||
$summary['completed_order_count'] += (int)$row['completed_order_count'];
|
||||
$summary['business_order_amount'] = round($summary['business_order_amount'] + (float)($row['business_order_amount'] ?? 0), 2);
|
||||
$summary['completed_order_amount'] = round($summary['completed_order_amount'] + (float)$row['completed_order_amount'], 2);
|
||||
$globalAccountCost = max($globalAccountCost, round((float)($row['_global_account_cost'] ?? 0), 2));
|
||||
}
|
||||
@@ -883,6 +925,7 @@ class ConversionLogic
|
||||
|| (int)($row['appointment_total_count'] ?? 0) > 0
|
||||
|| (int)($row['interview_count'] ?? 0) > 0
|
||||
|| (int)($row['completed_order_count'] ?? 0) > 0
|
||||
|| (float)($row['business_order_amount'] ?? 0) > 0
|
||||
|| (float)($row['completed_order_amount'] ?? 0) > 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user