request->get(); $where = ['mainId' => $this->mainId]; $searchTime = !empty($get['searchTime']) ? $get['searchTime'] : 'today'; $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true); $start = $period['startTime']; $end = $period['endTime']; $startDate = date("Y-m-d 00:00:00", strtotime($start)); $endDate = date("Y-m-d 23:59:59", strtotime($end)); $where['payTime'] = ['between', [$startDate, $endDate]]; if (!empty($get['ghsId'])) { $where['ghsId'] = $get['ghsId']; } $showGhsParam = $get['showGhsParam'] ?? 0; $ghsProduct = []; if ($showGhsParam == 1) { $ghsId = $get['ghsId'] ?? 0; $ghs = GhsClass::getById($ghsId, true); if (!empty($ghs)) { $ghsMainId = $ghs->mainId ?? 0; $ghsProduct = ProductClass::getAllByCondition(['mainId' => $ghsMainId, 'delStatus' => 0], null, 'id,name,itemId', 'itemId'); } } $list = PurchaseItemClass::getAllByCondition($where, null, '*'); if (empty($list)) { util::success(['list' => $list]); } $ids = array_column($list, 'productId'); $ids = array_unique(array_filter($ids)); $productInfo = ProductClass::getByIds($ids, null, 'id'); $stat = []; $totalNum = 0; $totalAmount = 0; foreach ($list as $key => $val) { $productId = $val['productId'] ?? 0; $ptItemId = $val['itemId'] ?? 0; $xhUnitType = $val['xhUnitType'] ?? 0; $xhUnitPrice = $val['xhUnitPrice'] ?? 0; $ratio = $val['ratio'] ?? 20; $beforeNum = bcsub($val['xhNum'], $val['refundNum'], 2); if ($xhUnitType == 0) { $num = $beforeNum; } else { $num = bcdiv($beforeNum, $ratio, 2); } $amount = bcmul($num, $xhUnitPrice, 2); $totalNum = bcadd($totalNum, $num, 2); $totalAmount = bcadd($totalAmount, $amount, 2); $myCurrentInfo = $productInfo[$productId] ?? []; if ($showGhsParam == 1) { $myGhsItem = $ghsProduct[$ptItemId] ?? []; $name = $myGhsItem['name'] ?? '未找到'; $py = $myGhsItem['py'] ?? ''; } else { $name = $myCurrentInfo['name'] ?? ''; $py = $myCurrentInfo['py'] ?? ''; } $stat[$productId]['productId'] = $productId; $stat[$productId]['name'] = $name; $stat[$productId]['py'] = $py; if (isset($stat[$productId]['num'])) { $stat[$productId]['num'] = bcadd($stat[$productId]['num'], $num, 2); } else { $stat[$productId]['num'] = $num; } if (isset($stat[$productId]['amount'])) { $stat[$productId]['amount'] = bcadd($stat[$productId]['amount'], $amount, 2); } else { $stat[$productId]['amount'] = $amount; } } $stat = arrayUtil::arraySort($stat, 'num'); $totalNum = floatval($totalNum); $totalAmount = floatval($totalAmount); util::success(['list' => $stat, 'totalNum' => $totalNum, 'totalAmount' => $totalAmount]); } }