getActiveSheet()->toArray()); // foreach ($spreadsheet->getActiveSheet()->getRowIterator() as $row) { // foreach ($row->getCellIterator() as $cell) { // if (!$cell->getValue()) { // 跳过空白单元格 // continue; // } // echo 'Cell ' . $cell->getColumn() . $cell->getRow() . ' = ' . $cell->getValue() . '
'; // } // } // 获取活动工作表 $worksheet = $spreadsheet->getActiveSheet(); // 遍历每一行 foreach ($worksheet->getRowIterator() as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(FALSE); // 这里设置为迭代所有单元格,包括空单元格 // 遍历每列 $rowData = []; foreach ($cellIterator as $cell) { $rowData[] = $cell->getValue(); } // 输出当前行数据 echo implode(", ", $rowData) . "\n"; } // // 加载Excel文件 // $spreadsheet = IOFactory::load($filePath); // // // 获取活动工作表 // $worksheet = $spreadsheet->getActiveSheet(); // // // 遍历每一行 // foreach ($worksheet->getRowIterator() as $row) { // $cellIterator = $row->getCellIterator(); // $cellIterator->setIterateOnlyExistingCells(FALSE); // 这里设置为迭代所有单元格,包括空单元格 // // // 遍历每列 // $rowData = []; // foreach ($cellIterator as $cell) { // $rowData[] = $cell->getValue(); // } // // // 输出当前行数据 // echo implode(", ", $rowData) . "\n"; // } } public function actionList() { $where = []; $get = Yii::$app->request->get(); $export = 1; $search = $get['search'] ?? ''; $where['shopId'] = 23580; $ghsId = $get['ghsId'] ?? 0; if (!empty($ghsId)) { $where['ghsId'] = $ghsId; } if (!empty($search)) { if (is_numeric($search) && strlen($search) == 4) { $where['orderSn'] = ['like', $search]; } else { $where['ghsName'] = ['like', $search]; } } $name = $get['name'] ?? ''; if (!empty($name)) { $re = strstr($name, 'PH'); if (!empty($re)) { $where['orderSn'] = $name; } else { $where['ghsName'] = ['like', $name]; } } $searchTime = 'custom'; $startTime = '2024-07-01'; $endTime = '2024-07-31'; $period = dateUtil::formatTime($searchTime, $startTime, $endTime); $where['entryTime'] = ['between', [$period['startTime'], $period['endTime']]]; $cgStaffId = $get['cgStaffId'] ?? 0; if (!empty($cgStaffId)) { $where['cgStaffId'] = $cgStaffId; } if ($export == 1) { ini_set('memory_limit', '2045M'); set_time_limit(0); if (isset($where['entryTime']) == false) { util::fail('请选时间段'); } $start = $where['entryTime'][1][0]; $end = $where['entryTime'][1][1]; $monthTime = bcmul(31, 86400); $startArea = strtotime($start); $endArea = strtotime($end); $diff = bcsub($endArea, $startArea); if ($diff > $monthTime) { util::fail('最长可导出一个月'); } } $data = PurchaseOrderClass::getOrderList($where); if ($export == 1) { $this->exportOrderData($data, 23390); util::stop(''); } //状态统计,很慢,暂时隐藏 //$statData = PurchaseOrderClass::statNum($this->shopId); $statData = [ 'allNum' => 0, 'unPayNum' => 0, 'unSendNum' => 0, 'sendingNum' => 0, 'finishNum' => 0, ]; $data = array_merge($data, $statData); echo "
";
        print_r($data);
        util::stop('');
    }


    public function exportOrderData($respond, $mainId)
    {
        $orderList = $respond['list'] ?? [];
        if (empty($orderList)) {
            util::fail('没有数据需要导出');
        }
        $orderSnList = array_column($orderList, 'orderSn');
        $orderItemData = PurchaseOrderItemClass::getAllByCondition(['orderSn' => ['in', $orderSnList]], null, '*');
        $orderItemList = [];
        if (!empty($orderItemData)) {
            foreach ($orderItemData as $itemInfo) {
                $orderSn = $itemInfo['orderSn'] ?? '';
                $orderItemList[$orderSn][] = $itemInfo;
            }
        }
        $totalActPrice = 0;
        $totalTkPrice = 0;
        $totalOnlyTkPrice = 0;
        $totalOrderPrice = 0;
        foreach ($orderList as $key => $orderInfo) {
            $orderSn = $orderInfo['orderSn'] ?? '';
            $status = $orderInfo['status'] ?? 0;
            $entryTime = $orderInfo['entryTime'] ?? '';
            //增加项
            $actPrice = $orderInfo['actPrice'] ?? 0;
            $tkPrice = $orderInfo['tkPrice'] ?? 0;
            $orderPrice = $orderInfo['orderPrice'] ?? 0;
            $discountAmount = $orderInfo['discountAmount'] ?? 0;
            $packingCharge = $orderInfo['packingCharge'] ?? 0;
            $shortCharge = $orderInfo['shortCharge'] ?? 0;
            $longCharge = $orderInfo['longCharge'] ?? 0;
            $pickCharge = $orderInfo['pickCharge'] ?? 0;
            $localCharge = $orderInfo['localCharge'] ?? 0;
            if ($status != 4) {
                unset($orderList[$key]);
                continue;
            }
            //增加项
            if ($actPrice <= 0) {
                unset($orderList[$key]);
                continue;
            }

            if ($discountAmount > 0 || $packingCharge > 0 || $shortCharge > 0 || $longCharge > 0 || $pickCharge > 0 || $localCharge > 0) {
                echo $orderSn . ' ' . $discountAmount . ' ' . $packingCharge . ' ' . $shortCharge . ' ' . $longCharge . ' ' . $pickCharge . ' ' . $localCharge . "
\n"; } $totalActPrice = bcadd($totalActPrice, $actPrice, 2); $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2); $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2); $itemList = $orderItemList[$orderSn] ?? []; $orderList[$key]['itemList'] = $itemList; //增加项 if ($tkPrice > 0) { $refundList = CgRefundClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true); if (!empty($refundList)) { foreach ($refundList as $refundInfo) { if (isset($refundInfo->refundType) && $refundInfo->refundType == 2) { $refundPrice = $refundInfo->refundPrice ?? 0; $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2); } } } } $currentItemPrice = 0; if (!empty($itemList)) { foreach ($itemList as $itemData) { $bigPrice = $itemData['bigPrice'] ?? 0; $itemNum = $itemData['itemNum'] ?? 0; $total = bcmul($bigPrice, $itemNum, 2); $currentItemPrice = bcadd($currentItemPrice, $total, 2); } } $add1 = bcadd($currentItemPrice, $packingCharge, 2); $add2 = bcadd($add1, $shortCharge, 2); $add3 = bcadd($add2, $longCharge, 2); $last = bcsub($add3, $tkPrice, 2); // if (floatval($last) != floatval($actPrice)) { // echo $currentItemPrice . ' 优惠:' . $discountAmount . ' 打包:' . $packingCharge . ' 短途:' . $shortCharge . ' 长途:' . $longCharge . ' 提:' . $pickCharge . ' 本:' . $localCharge . ' 实:' . $actPrice . $entryTime . "
\n"; // echo $orderSn . " 不同
\n"; // die; // } } echo "
";
        echo '订单金额:' . $totalOrderPrice . ' 实际金额:' . $totalActPrice . ' 退款金额:' . $totalTkPrice . ' 仅退款:' . $totalOnlyTkPrice;
    }

}