更新
This commit is contained in:
@@ -82,7 +82,7 @@ class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$where[] = ['patient_id', 'in', function ($query) {
|
||||
$query->table('zyt_tcm_diagnosis')
|
||||
->whereNull('delete_time')
|
||||
->where('patient_name|patient_phone', 'like', '%' . $this->params['patient_keyword'] . '%')
|
||||
->where('patient_name|phone', 'like', '%' . $this->params['patient_keyword'] . '%')
|
||||
->field('id');
|
||||
}];
|
||||
}
|
||||
@@ -128,7 +128,7 @@ class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
$where[] = ['patient_id', 'in', function ($query) {
|
||||
$query->table('zyt_tcm_diagnosis')
|
||||
->whereNull('delete_time')
|
||||
->where('patient_name|patient_phone', 'like', '%' . $this->params['patient_keyword'] . '%')
|
||||
->where('patient_name|phone', 'like', '%' . $this->params['patient_keyword'] . '%')
|
||||
->field('id');
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ namespace app\adminapi\lists\tcm;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
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\tcm\PrescriptionOrder;
|
||||
use app\common\model\tcm\PrescriptionOrderPayOrder;
|
||||
|
||||
class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
||||
{
|
||||
public function setSearch(): array
|
||||
{
|
||||
@@ -38,18 +40,115 @@ class PrescriptionOrderLists extends BaseAdminDataLists implements ListsSearchIn
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$poIds = array_values(array_filter(array_map('intval', array_column($lists, 'id'))));
|
||||
$paidSumByPo = [];
|
||||
if ($poIds !== []) {
|
||||
$links = PrescriptionOrderPayOrder::whereIn('prescription_order_id', $poIds)
|
||||
->field(['prescription_order_id', 'pay_order_id'])
|
||||
->select()
|
||||
->toArray();
|
||||
$byPo = [];
|
||||
foreach ($links as $l) {
|
||||
$poid = (int) ($l['prescription_order_id'] ?? 0);
|
||||
$oid = (int) ($l['pay_order_id'] ?? 0);
|
||||
if ($poid > 0 && $oid > 0) {
|
||||
$byPo[$poid][] = $oid;
|
||||
}
|
||||
}
|
||||
$allOids = [];
|
||||
foreach ($byPo as $oids) {
|
||||
$allOids = array_merge($allOids, $oids);
|
||||
}
|
||||
$allOids = array_values(array_unique($allOids));
|
||||
$amountByOid = [];
|
||||
if ($allOids !== []) {
|
||||
$amountByOid = Order::whereIn('id', $allOids)->whereNull('delete_time')->column('amount', 'id');
|
||||
}
|
||||
foreach ($poIds as $pid) {
|
||||
$s = 0.0;
|
||||
foreach ($byPo[$pid] ?? [] as $oid) {
|
||||
$s += (float) ($amountByOid[$oid] ?? 0);
|
||||
}
|
||||
$paidSumByPo[$pid] = round($s, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取创建人姓名
|
||||
$creatorIds = array_values(array_unique(array_filter(array_map('intval', array_column($lists, 'creator_id')))));
|
||||
$creatorNames = [];
|
||||
if ($creatorIds !== []) {
|
||||
$creatorNames = \app\common\model\auth\Admin::whereIn('id', $creatorIds)->column('name', 'id');
|
||||
}
|
||||
|
||||
// 获取处方ID对应的开方人姓名
|
||||
$prescriptionIds = array_values(array_unique(array_filter(array_map('intval', array_column($lists, 'prescription_id')))));
|
||||
$prescriptionCreators = [];
|
||||
if ($prescriptionIds !== []) {
|
||||
$prescriptions = \app\common\model\tcm\Prescription::whereIn('id', $prescriptionIds)
|
||||
->whereNull('delete_time')
|
||||
->field(['id', 'creator_id', 'doctor_name'])
|
||||
->select()
|
||||
->toArray();
|
||||
$doctorIds = [];
|
||||
foreach ($prescriptions as $rx) {
|
||||
$rxId = (int) ($rx['id'] ?? 0);
|
||||
$doctorId = (int) ($rx['creator_id'] ?? 0);
|
||||
$doctorName = (string) ($rx['doctor_name'] ?? '');
|
||||
if ($rxId > 0) {
|
||||
$prescriptionCreators[$rxId] = [
|
||||
'doctor_id' => $doctorId,
|
||||
'doctor_name' => $doctorName
|
||||
];
|
||||
if ($doctorId > 0) {
|
||||
$doctorIds[] = $doctorId;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果 doctor_name 为空,从 Admin 表获取
|
||||
$doctorIds = array_values(array_unique($doctorIds));
|
||||
if ($doctorIds !== []) {
|
||||
$doctorNamesFromAdmin = \app\common\model\auth\Admin::whereIn('id', $doctorIds)->column('name', 'id');
|
||||
foreach ($prescriptionCreators as &$pc) {
|
||||
if (empty($pc['doctor_name']) && $pc['doctor_id'] > 0) {
|
||||
$pc['doctor_name'] = $doctorNamesFromAdmin[$pc['doctor_id']] ?? '';
|
||||
}
|
||||
}
|
||||
unset($pc);
|
||||
}
|
||||
}
|
||||
|
||||
$depMin = PrescriptionOrderLogic::depositMinAmount();
|
||||
foreach ($lists as &$item) {
|
||||
PrescriptionOrderLogic::maskInternalCostIfNeeded($item, $this->adminInfo);
|
||||
$pid = (int) ($item['id'] ?? 0);
|
||||
$item['linked_pay_order_count'] = (int) PrescriptionOrderPayOrder::where(
|
||||
'prescription_order_id',
|
||||
(int) ($item['id'] ?? 0)
|
||||
$pid
|
||||
)->count();
|
||||
$item['linked_pay_paid_total'] = $paidSumByPo[$pid] ?? 0.0;
|
||||
$item['deposit_min_amount'] = $depMin;
|
||||
|
||||
// 添加创建人姓名
|
||||
$creatorId = (int) ($item['creator_id'] ?? 0);
|
||||
$item['creator_name'] = $creatorId > 0 ? ($creatorNames[$creatorId] ?? '') : '';
|
||||
|
||||
// 添加开方人姓名
|
||||
$rxId = (int) ($item['prescription_id'] ?? 0);
|
||||
$item['doctor_name'] = $rxId > 0 ? ($prescriptionCreators[$rxId]['doctor_name'] ?? '') : '';
|
||||
}
|
||||
unset($item);
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
public function extend(): array
|
||||
{
|
||||
return [
|
||||
'deposit_min_amount' => PrescriptionOrderLogic::depositMinAmount(),
|
||||
];
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
$query = PrescriptionOrder::where($this->searchWhere)->whereNull('delete_time');
|
||||
|
||||
Reference in New Issue
Block a user