Commit 0fd4dde9 by 赵增煜

限购bug修复

parent 898de112
...@@ -105,13 +105,17 @@ public function drugLimit(Request $request) ...@@ -105,13 +105,17 @@ public function drugLimit(Request $request)
->get(); ->get();
$drugCounts = []; $drugCounts = [];
foreach ($prescriptions as $prescription) { // 判断搜索出来的处方不为空
$drugs = json_decode($prescription->drugs, true); // Parse JSON data if ($prescriptions->count() > 0) {
foreach ($drugs as $drug) { foreach ($prescriptions as $prescription) {
$drugId = $drug['drug_id']; $drugs = json_decode($prescription->drug_info, true); // Parse JSON data
$drugCounts[$drugId] = ($drugCounts[$drugId] ?? 0) + $drug['num']; foreach ($drugs as $drug) {
$drugId = $drug['drug_id'];
$drugCounts[$drugId] = ($drugCounts[$drugId] ?? 0) + $drug['num'];
}
} }
} }
$purchaseCount = $drugCounts[$drug_id] ?? 0; $purchaseCount = $drugCounts[$drug_id] ?? 0;
// 计算获取剩余可买的次数 // 计算获取剩余可买的次数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment