对账功能修改(修复历史遗留问题:中药对账没有按照贴数*克数计算)

This commit is contained in:
2025-04-07 10:31:51 +08:00
parent 601cabb393
commit 869431e982
3 changed files with 91 additions and 51 deletions

View File

@@ -801,11 +801,33 @@ class DoctorController extends BaseAdminController
['<>', 'refund_status', 3],
['=', 'is_pay', 1],
['<>', 'status', '4'],
])->andWhere($data)->andWhere($where)->select('sum(total_pay_price) as total_sale_price,sum(market_price+trans_expenses+process_price) as total_market_price')->asArray()->one();
// ])->andWhere($data)->andWhere($where)->select('sum(total_pay_price) as total_sale_price,sum(market_price+trans_expenses+process_price) as total_market_price')->asArray()->one();
])->andWhere($data)->andWhere($where)->select('total_pay_price,market_price,trans_expenses,process_price')->asArray()->all();
$totalPrice = 0;
$storeIncome = 0;
foreach ($total as $v) {
$totalPrice = bcadd($totalPrice, $v['total_pay_price'], 2);
// 将所有金额转换为字符串以确保高精度计算
$totalPayPrice = (string)$v['total_pay_price'];
$marketPrice = (string)$v['market_price'];
$transExpenses = (string)$v['trans_expenses'];
$processPrice = (string)$v['process_price'];
// 分步计算,提高可读性
$profit = bcsub($totalPayPrice, $marketPrice, 2); // 总支付价格减去市场价
$profit = bcsub($profit, $transExpenses, 2); // 再减去运输费用
$profit = bcsub($profit, $processPrice, 2); // 最后减去加工费用
// 累加到门诊收入
$storeIncome = bcadd($storeIncome, $profit, 2);
}
return [
'order_sale' => $total['total_sale_price'] ?? 0,
'store_income' => bcsub($total['total_sale_price'], $total['total_market_price'], 2),
'order_sale' => $totalPrice,
'store_income' => $storeIncome,
];
}
}