更新
This commit is contained in:
@@ -5,11 +5,13 @@ declare(strict_types=1);
|
||||
namespace app\adminapi\lists\tcm;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\adminapi\logic\dept\DeptLogic;
|
||||
use app\adminapi\logic\tcm\PrescriptionOrderLogic;
|
||||
use app\common\lists\ListsExtendInterface;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\Order;
|
||||
use app\common\model\tcm\Diagnosis;
|
||||
use app\common\model\auth\AdminDept;
|
||||
use app\common\model\tcm\Prescription;
|
||||
use app\common\model\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
@@ -276,31 +278,48 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$s = $this->computeListStatsForExtend();
|
||||
|
||||
return [
|
||||
'deposit_min_amount' => PrescriptionOrderLogic::depositMinAmount(),
|
||||
'gancao_scm_enabled' => GancaoScmRecipelService::isConfigured(),
|
||||
'stats_order_amount' => $s['order_amount'],
|
||||
'stats_linked_pay_amount' => $s['linked_pay_amount'],
|
||||
'stats_time_start' => $s['label_start'],
|
||||
'stats_time_end' => $s['label_end'],
|
||||
'deposit_min_amount' => PrescriptionOrderLogic::depositMinAmount(),
|
||||
'gancao_scm_enabled' => GancaoScmRecipelService::isConfigured(),
|
||||
'stats_order_amount' => $s['order_amount'],
|
||||
'stats_order_amount_not_cancelled' => $s['order_amount_not_cancelled'],
|
||||
'stats_order_amount_cancelled' => $s['order_amount_cancelled'],
|
||||
'stats_linked_pay_amount' => $s['linked_pay_amount'],
|
||||
'stats_linked_pay_amount_not_cancelled' => $s['linked_pay_amount_not_cancelled'],
|
||||
'stats_linked_pay_amount_cancelled' => $s['linked_pay_amount_cancelled'],
|
||||
'stats_time_start' => $s['label_start'],
|
||||
'stats_time_end' => $s['label_end'],
|
||||
/** 统计口径:all=支付审核白名单全量;assistant=医助仅诊单协助业绩;restricted=与列表同域 */
|
||||
'stats_scope' => $s['scope'],
|
||||
'stats_scope' => $s['scope'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{order_amount: float, linked_pay_amount: float, label_start: string, label_end: string, scope: string}
|
||||
* 关联实付按业务订单 id 列表汇总
|
||||
*
|
||||
* @param array<int> $poIds
|
||||
*/
|
||||
private function sumLinkedPayForPrescriptionOrderIds(array $poIds): float
|
||||
{
|
||||
if ($poIds === []) {
|
||||
return 0.0;
|
||||
}
|
||||
$sum = (float) PrescriptionOrderPayOrder::alias('l')
|
||||
->join('order o', 'l.pay_order_id = o.id')
|
||||
->whereIn('l.prescription_order_id', $poIds)
|
||||
->whereNull('o.delete_time')
|
||||
->sum('o.amount');
|
||||
|
||||
return round($sum, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{order_amount: float, order_amount_not_cancelled: float, order_amount_cancelled: float, linked_pay_amount: float, linked_pay_amount_not_cancelled: float, linked_pay_amount_cancelled: float, label_start: string, label_end: string, scope: string}
|
||||
*/
|
||||
private function computeListStatsForExtend(): array
|
||||
{
|
||||
[$t0, $t1, $l0, $l1] = $this->resolveStatsTimeWindow();
|
||||
if ($t0 <= 0 || $t1 <= 0) {
|
||||
return [
|
||||
'order_amount' => 0.0,
|
||||
'linked_pay_amount' => 0.0,
|
||||
'label_start' => '',
|
||||
'label_end' => '',
|
||||
'scope' => 'restricted',
|
||||
];
|
||||
return $this->statsZeroPayload();
|
||||
}
|
||||
if ($t1 < $t0) {
|
||||
$tmp = $t0;
|
||||
@@ -309,29 +328,69 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
}
|
||||
|
||||
$q = $this->buildBaseQueryForStats()->whereBetween('create_time', [$t0, $t1]);
|
||||
$orderAmount = round((float) (clone $q)->sum('amount'), 2);
|
||||
$ids = (clone $q)->column('id');
|
||||
$ids = array_values(array_filter(array_map('intval', $ids), static function (int $id): bool {
|
||||
$orderTotal = round((float) (clone $q)->sum('amount'), 2);
|
||||
$orderCancelled = round((float) (clone $q)->where('fulfillment_status', 4)->sum('amount'), 2);
|
||||
$orderNotCancelled = round($orderTotal - $orderCancelled, 2);
|
||||
|
||||
$idsAll = (clone $q)->column('id');
|
||||
$idsAll = array_values(array_filter(array_map('intval', $idsAll), static function (int $id): bool {
|
||||
return $id > 0;
|
||||
}));
|
||||
if ($ids === []) {
|
||||
return $this->statsExtendPayload($orderAmount, 0.0, $l0, $l1);
|
||||
if ($idsAll === []) {
|
||||
return $this->statsExtendPayload(
|
||||
$orderTotal,
|
||||
$orderNotCancelled,
|
||||
$orderCancelled,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
$l0,
|
||||
$l1
|
||||
);
|
||||
}
|
||||
$sumPaid = (float) PrescriptionOrderPayOrder::alias('l')
|
||||
->join('order o', 'l.pay_order_id = o.id')
|
||||
->whereIn('l.prescription_order_id', $ids)
|
||||
->whereNull('o.delete_time')
|
||||
->sum('o.amount');
|
||||
$sumPaid = round($sumPaid, 2);
|
||||
$idsCancel = (clone $q)->where('fulfillment_status', 4)->column('id');
|
||||
$idsCancel = array_values(array_filter(array_map('intval', $idsCancel), static function (int $id): bool {
|
||||
return $id > 0;
|
||||
}));
|
||||
$idsNotCancelled = array_values(array_diff($idsAll, $idsCancel));
|
||||
|
||||
return $this->statsExtendPayload($orderAmount, $sumPaid, $l0, $l1);
|
||||
$linkedTotal = $this->sumLinkedPayForPrescriptionOrderIds($idsAll);
|
||||
$linkedNotCancelled = $this->sumLinkedPayForPrescriptionOrderIds($idsNotCancelled);
|
||||
$linkedCancelled = $this->sumLinkedPayForPrescriptionOrderIds($idsCancel);
|
||||
|
||||
return $this->statsExtendPayload(
|
||||
$orderTotal,
|
||||
$orderNotCancelled,
|
||||
$orderCancelled,
|
||||
$linkedTotal,
|
||||
$linkedNotCancelled,
|
||||
$linkedCancelled,
|
||||
$l0,
|
||||
$l1
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{order_amount: float, linked_pay_amount: float, label_start: string, label_end: string, scope: string}
|
||||
* @return array{order_amount: float, order_amount_not_cancelled: float, order_amount_cancelled: float, linked_pay_amount: float, linked_pay_amount_not_cancelled: float, linked_pay_amount_cancelled: float, label_start: string, label_end: string, scope: string}
|
||||
*/
|
||||
private function statsExtendPayload(float $orderAmount, float $linked, string $l0, string $l1): array
|
||||
private function statsZeroPayload(): array
|
||||
{
|
||||
return $this->statsExtendPayload(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, '', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{order_amount: float, order_amount_not_cancelled: float, order_amount_cancelled: float, linked_pay_amount: float, linked_pay_amount_not_cancelled: float, linked_pay_amount_cancelled: float, label_start: string, label_end: string, scope: string}
|
||||
*/
|
||||
private function statsExtendPayload(
|
||||
float $orderTotal,
|
||||
float $orderNotCancelled,
|
||||
float $orderCancelled,
|
||||
float $linkedTotal,
|
||||
float $linkedNotCancelled,
|
||||
float $linkedCancelled,
|
||||
string $l0,
|
||||
string $l1
|
||||
): array {
|
||||
$scope = 'restricted';
|
||||
if (PrescriptionOrderLogic::canViewOrderListStatsAllScope($this->adminInfo)) {
|
||||
$scope = 'all';
|
||||
@@ -343,11 +402,15 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
}
|
||||
|
||||
return [
|
||||
'order_amount' => $orderAmount,
|
||||
'linked_pay_amount' => $linked,
|
||||
'label_start' => $l0,
|
||||
'label_end' => $l1,
|
||||
'scope' => $scope,
|
||||
'order_amount' => $orderTotal,
|
||||
'order_amount_not_cancelled' => $orderNotCancelled,
|
||||
'order_amount_cancelled' => $orderCancelled,
|
||||
'linked_pay_amount' => $linkedTotal,
|
||||
'linked_pay_amount_not_cancelled' => $linkedNotCancelled,
|
||||
'linked_pay_amount_cancelled' => $linkedCancelled,
|
||||
'label_start' => $l0,
|
||||
'label_end' => $l1,
|
||||
'scope' => $scope,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -376,6 +439,26 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$query->whereExists("SELECT 1 FROM {$diagTbl} dg WHERE dg.id = {$poTbl}.diagnosis_id AND dg.delete_time IS NULL AND dg.assistant_id = {$assistantId}");
|
||||
}
|
||||
|
||||
if (isset($this->params['assistant_dept_id']) && $this->params['assistant_dept_id'] !== '' && (int) $this->params['assistant_dept_id'] > 0) {
|
||||
$rootDeptId = (int) $this->params['assistant_dept_id'];
|
||||
$deptIds = DeptLogic::getSelfAndDescendantIds($rootDeptId);
|
||||
$deptIds = array_values(array_filter(array_map('intval', $deptIds), static function (int $id): bool {
|
||||
return $id > 0;
|
||||
}));
|
||||
if ($deptIds === []) {
|
||||
$query->whereRaw('0 = 1');
|
||||
|
||||
return;
|
||||
}
|
||||
$inList = implode(',', $deptIds);
|
||||
$diagTbl = (new Diagnosis())->getTable();
|
||||
$adTbl = (new AdminDept())->getTable();
|
||||
$query->whereExists(
|
||||
"SELECT 1 FROM `{$adTbl}` ad INNER JOIN `{$diagTbl}` dg ON ad.admin_id = dg.assistant_id AND dg.delete_time IS NULL "
|
||||
. "WHERE dg.id = `{$poTbl}`.`diagnosis_id` AND ad.dept_id IN ({$inList})"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user