'未确认', self::SEND_TYPE_NO => '自取', self::SEND_TYPE_MYSELF => '商家配送', self::SEND_TYPE_THIRD => '快递配送', ]; //待付款 const PAY_STATUS_UN_PAY = 0; //已付款 const PAY_STATUS_HAS_PAY = 1; const SEND_STATUS_UNSEND = 0; //未发货 const SEND_STATUS_SENDING = 1; //已发货(配送中) const SEND_STATUS_COMPLETED = 2; //已送达 const SEND_STATUS_CANCEL = 3; //取消 //订单总流程数 const TOTAL_FLOW = 3; //清算方式 //欠款 const CLEAR_DEBT = 1; //已付款 const CLEAR_HAS_GATHERING = 2; //没有欠款 const DEBT_NO = 0; //欠款 const DEBT_YES = 1; //正常订单 const REFUND_NO = 1; //已退款订单 const REFUND_YES = 2; public static $refundMap = [ self::REFUND_NO => '', self::REFUND_YES => '有退款', ]; public static function printMyWlList($shop, $beginTime, $endTime) { $end = strtotime($endTime); $begin = strtotime($beginTime); $different = $end - $begin; if ($different > 172800) { util::fail('最多可打印2天订单'); } $mainId = $shop->mainId; $orderList = OrderClass::getAllByCondition(['mainId' => $mainId, 'payTime' => ['between', [$beginTime, $endTime]], 'payStatus' => 1], 'id asc', '*', null, true); if (empty($orderList)) { util::fail('没有订单需要打印'); } $ids = []; foreach ($orderList as $order) { $customId = $order->customId; $ids[] = $customId; } $ids = array_unique(array_filter($ids)); $customList = CustomClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,mainId,shortName,mobile,wlName', 'id'); $myList = []; foreach ($orderList as $order) { $customId = $order->customId; $custom = $customList[$customId] ?? []; $sendNum = $order->sendNum; $customMobile = $order->customMobile; $shortName = $custom['shortName'] ?? ''; $wlName = $custom['wlName'] ?? ''; $myList[] = ['sendNum' => $sendNum, 'customMobile' => $customMobile, 'shortName' => $shortName, 'wlName' => $wlName]; } $myList = arrayUtil::arraySort($myList, 'customMobile'); $size = 50; $arr = array_chunk($myList, $size); $totalPage = count($arr); foreach ($arr as $key => $sonList) { $content = ''; if ($totalPage > 1) { $currentPage = bcadd($key, 1); $content .= "第{$currentPage}页,共{$totalPage}页
"; } $content .= '
'; $content .= '--------------------------------
'; if (!empty($sonList)) { foreach ($sonList as $info) { $sendNum = $info['sendNum']; $customMobile = $info['customMobile']; $shortName = $info['shortName']; $wlName = $info['wlName']; $content .= '' . $sendNum . ' ' . $shortName . '
'; $content .= '
'; $content .= '' . $customMobile . ' ' . $wlName . '
'; $content .= '--------------------------------
'; } } $content .= '
'; $shopId = $shop->id; $ext = ShopExtClass::getByCondition(['shopId' => $shopId]); $printSn = $ext['printSn'] ?? ''; if (empty($printSn)) { util::fail('没有设置打印机'); } $p = new printUtil($printSn); $p->printMsg($content, $shop); } } public static function exportOrderData($respond, $mainId) { $orderList = $respond['list'] ?? []; if (empty($orderList)) { util::fail('没有数据需要导出'); } $orderSnList = array_column($orderList, 'orderSn'); $orderItemData = OrderItemClass::getAllByCondition(['orderSn' => ['in', $orderSnList]], null, '*'); $orderItemList = []; if (!empty($orderItemData)) { foreach ($orderItemData as $itemInfo) { $orderSn = $itemInfo['orderSn'] ?? ''; $orderItemList[$orderSn][] = $itemInfo; } } foreach ($orderList as $key => $orderInfo) { $book = $orderInfo['book'] ?? 0; $actPrice = $orderInfo['actPrice'] ?? 0; $status = $orderInfo['status'] ?? 0; if ($book == 1 && $status == 2) { //预订单待发货的不算收入 unset($orderList[$key]); continue; } if ($status == 1 || $status == 5) { unset($orderList[$key]); continue; } if ($actPrice <= 0) { unset($orderList[$key]); continue; } $orderSn = $orderInfo['orderSn'] ?? ''; $itemList = $orderItemList[$orderSn] ?? []; $orderList[$key]['itemList'] = $itemList; } $classList = ItemClassClass::getAllByCondition(['mainId' => $mainId], null, '*', 'id'); $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/"); require_once($phpExcelFile . 'Classes/PHPExcel.php'); $objPHPExcel = new \PHPExcel(); $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Document") ->setSubject("Office 2007 XLSX Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("file"); $ghsTitle = '供货商'; $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle); $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7); $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5); $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0); $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', '订单号'); $objPHPExcel->getActiveSheet()->setCellValue('B1', '创建时间'); $objPHPExcel->getActiveSheet()->setCellValue('C1', '账单日期'); $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单金额'); $objPHPExcel->getActiveSheet()->setCellValue('E1', '退款金额'); $objPHPExcel->getActiveSheet()->setCellValue('F1', '实际金额'); $objPHPExcel->getActiveSheet()->setCellValue('G1', '客户'); $objPHPExcel->getActiveSheet()->setCellValue('H1', '客户手机号'); $objPHPExcel->getActiveSheet()->setCellValue('I1', '在线支付'); $objPHPExcel->getActiveSheet()->setCellValue('J1', '结清状态'); $objPHPExcel->getActiveSheet()->setCellValue('K1', '已优惠'); $objPHPExcel->getActiveSheet()->setCellValue('L1', '备注'); $objPHPExcel->getActiveSheet()->setCellValue('M1', '开单人'); $objPHPExcel->getActiveSheet()->setCellValue('N1', '花材Id'); $objPHPExcel->getActiveSheet()->setCellValue('O1', '花材名称'); $objPHPExcel->getActiveSheet()->setCellValue('P1', '单价'); $objPHPExcel->getActiveSheet()->setCellValue('Q1', '数量'); $objPHPExcel->getActiveSheet()->setCellValue('R1', '已退数量'); $objPHPExcel->getActiveSheet()->setCellValue('S1', '金额'); $objPHPExcel->getActiveSheet()->setCellValue('T1', '分类'); $objPHPExcel->getActiveSheet()->setCellValue('U1', '备注'); $objPHPExcel->getActiveSheet()->setCellValue('V1', '成本'); //设置宽度 $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(16); $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(18); $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(18); //加粗 $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('K1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('L1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('M1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('N1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('O1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('P1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('Q1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('R1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('S1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('T1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('U1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('V1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('M1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('O1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('P1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('Q1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('R1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('S1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('T1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('U1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('V1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('K1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('L1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('M1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('N1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('O1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('P1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('Q1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('R1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('S1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('T1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('U1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('V1')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER); $baseRow = 2; $x = 0; foreach ($orderList as $key => $orderData) { $currentList = $orderData['itemList'] ?? []; if (!empty($currentList)) { foreach ($currentList as $k => $orderInfo) { $i = $baseRow + $x; $x++; $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $orderData['orderSn']); $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $orderData['addTime']); $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $orderData['payTime']); $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $orderData['orderPrice']); $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $orderData['tkPrice']); $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $orderData['actPrice']); $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $orderData['customName']); $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $orderData['customMobile']); $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $orderData['onlinePay'] == 1 ? '否' : '是'); $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $orderData['debt'] == 1 ? '未结清' : '已结清'); $objPHPExcel->getActiveSheet()->setCellValue('K' . $i, $orderData['discountAmount']); $objPHPExcel->getActiveSheet()->setCellValue('L' . $i, $orderData['remark']); $objPHPExcel->getActiveSheet()->setCellValue('M' . $i, $orderData['shopAdminName']); $objPHPExcel->getActiveSheet()->setCellValue('N' . $i, $orderInfo['productId']); $objPHPExcel->getActiveSheet()->setCellValue('O' . $i, $orderInfo['name']); $objPHPExcel->getActiveSheet()->setCellValue('P' . $i, $orderInfo['xhUnitPrice']); $remainNum = bcsub($orderInfo['xhNum'], $orderInfo['refundNum']); $price = bcmul($remainNum, $orderInfo['xhUnitPrice'], 2); $objPHPExcel->getActiveSheet()->setCellValue('Q' . $i, $remainNum); $objPHPExcel->getActiveSheet()->setCellValue('R' . $i, $orderInfo['refundNum']); $objPHPExcel->getActiveSheet()->setCellValue('S' . $i, $price); $classId = $orderInfo['classId'] ?? 0; $className = isset($classList[$classId]) && isset($classList[$classId]['name']) ? $classList[$classId]['name'] : ''; $objPHPExcel->getActiveSheet()->setCellValue('T' . $i, $className); $objPHPExcel->getActiveSheet()->setCellValue('U' . $i, $orderInfo['remark']); $objPHPExcel->getActiveSheet()->setCellValue('V' . $i, $orderInfo['cost']); //居左 $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('J' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('K' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('L' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('M' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('N' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('O' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('P' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('Q' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('R' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('S' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('T' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('V' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); } } } $fileName = '订单明细-' . time(); $objPHPExcel->getActiveSheet()->setTitle($fileName); $objPHPExcel->setActiveSheetIndex(0); $dir = './priceTable/' . $mainId; if (file_exists($dir) == false) { mkdir($dir, 0777, true); } $date = $fileName; $file = $date . '.xls'; $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); if (file_exists($dir . '/' . $file)) { unlink($dir . '/' . $file); } $objWriter->save($dir . '/' . $file); $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file; util::success(['file' => $fileUrl, 'shortFile' => $file]); } public static function hasSend($order, $params = []) { $order->status = 3; $order->save(); $cgId = $order->purchaseId ?? 0; $cg = PurchaseClass::getById($cgId, true); if (empty($cg)) { util::fail('没有找到采购信息'); } $cg->status = 3; $cg->save(); } public static function confirmReach($order, $params = []) { $cgId = $order->purchaseId ?? 0; $cg = PurchaseClass::getById($cgId, true); if (empty($cg)) { util::fail('没有找到采购信息'); } $customId = $order->customId ?? 0; $custom = CustomClass::getById($customId, true); if (empty($custom)) { util::fail('没有找到客户信息,编号:' . $customId); } $shopId = $custom->shopId ?? 0; $customShop = ShopClass::getById($shopId, true); if (empty($customShop)) { util::fail('没有找到客户的门店'); } //订单如果没有发货则先发货 if ($order->status == 2) { $staffId = $params['staffId'] ?? 0; $staffName = $params['staffName'] ?? ''; $notice = $params['notice'] ?? true; $element = ['staffId' => $staffId, 'staffName' => $staffName, 'notice' => $notice]; self::orderSend($order, $element, true); $cg = PurchaseClass::getById($cgId, true); } // 构建“冲销”函数的参数 -- 变动前的花材存库数据 $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId"); $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组 $oldStocks = []; foreach ($productIds as $productId) { $product = ProductClass::getById($productId, true); $oldStocks[$productId] = $product; } PurchaseClass::takeToPutIn($cg); $shop = ShopClass::getLockById($shopId); if (empty($shop)) { util::fail('没有找到门店14'); } $adminId = $shop->adminId; $mainId = $shop->mainId; PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $mainId, '系统'); } //订单发货主方法 ssh 20231119 public static function orderSend($order, $params, $allowRepeat = false) { self::orderFh($order, $params, $allowRepeat); $cgId = $order->purchaseId ?? 0; $cgInfo = PurchaseClass::getById($cgId, true); if (empty($cgInfo)) { util::fail('没有找到采购信息'); } $notice = $params['notice'] ?? true; // 兼容处理,实现控制是否发发货通知 PurchaseClass::orderFh($cgInfo, $params, $allowRepeat, $notice); } //取消发货 ssh 20250917 public static function cancelOrderSend($order, $params) { $order->status = 2; $order->save(); $cgId = $order->purchaseId ?? 0; $cgInfo = PurchaseClass::getById($cgId, true); if (empty($cgInfo)) { util::fail('没有找到采购信息'); } PurchaseClass::cancelFh($cgInfo, $params); } //订单发货子方法 ssh 20231119 public static function orderFh($order, $params, $allowRepeat = false) { if ($order->status == 3) { if (!$allowRepeat) { util::fail('订单已发货'); } else { return true; } } $fhType = $params['fhType'] ?? 0; if (!is_numeric($fhType)) { util::fail('请选择发货类型'); } if ($fhType == 1) { $fhWl = $params['fhWl'] ?? ''; $fhWlNo = $params['fhWlNo'] ?? ''; if (empty($fhWl)) { util::fail('请填写物流名称'); } if (empty($fhWlNo)) { util::fail('请填写物流编号'); } $order->fhWl = $fhWl; $order->fhWlNo = $fhWlNo; } $order->fhType = $fhType; $order->status = 3; $order->fhTime = date("Y-m-d H:i:s"); $staffId = $params['staffId'] ?? 0; $staffName = $params['staffName'] ?? ''; $order->sendStaffId = $staffId; $order->sendStaffName = $staffName; $order->save(); } public static function arrival($order, $data) { if ($order->stockChange == 1) { util::fail('您已操作过了'); } $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0; $packCost = isset($data['packCost']) && is_numeric($data['packCost']) ? $data['packCost'] : 0; $order->sendCost = $sendCost; $order->packCost = $packCost; $order->save(); $sjId = $order->sjId ?? 0; $shopId = $order->shopId ?? 0; $mainId = $order->mainId ?? 0; //product [{"productId":"3674","num":0,"price":1}] $product = $data['product'] ?? ''; if (empty($product)) { util::fail('没有花材?'); } $ids = []; $format = []; foreach ($product as $val) { $productId = $val['productId'] ?? 0; $ids[] = $productId; $format[$productId] = $val; } $info = ProductClass::getByIds($ids, null, 'id'); $orderSn = $order->orderSn ?? ''; $customName = $order->customName ?? ''; $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); if (empty($list)) { util::fail('没有找到订单的花材'); } $itemPrice = 0; $weight = 0; foreach ($list as $key => $val) { $productId = $val->productId ?? 0; $num = $format[$productId]['num'] ?? 0; $unitPrice = $format[$productId]['price'] ?? 0; $price = bcmul($unitPrice, $num, 2); $name = $val->name ?? ''; $xhUnitName = $val->xhUnitName ?? ''; $xhPreNum = $val->xhPreNum ?? 0; if ($unitPrice <= 0) { util::fail('花材金额需要大于0'); } if ($num > $xhPreNum) { //util::fail($name . "数量不能超过{$xhPreNum}{$xhUnitName}"); } $val->cost = $unitPrice; $val->unitPrice = $unitPrice; $val->price = $price; $val->bigNum = $num; $val->num = $num; $val->xhNum = $num; $val->xhUnitPrice = $unitPrice; $val->xhPrice = $price; $val->save(); if ($val->xhPreNum > $num) { //客户下单退货数增加 $subNum = bcsub($val->xhPreNum, $num); StatKhCgClass::ghsBookOrderRefundNum($order, $subNum); //花材销量榜减少 StatItemClass::ghsBookOrderRefundNum($order, $val, $subNum); } $itemPrice = bcadd($itemPrice, $price, 2); $productWeight = $info[$productId]['weight'] ?? 0; $currentWeight = bcmul($productWeight, $num, 2); $weight = bcadd($currentWeight, $weight, 2); //减少库存 $unitType = $val->xhUnitType ?? 0; $bigNum = 0; $smallNum = 0; if ($unitType == dict::getDict('unitType', 'big')) { $bigNum = $num; $itemNum = $num; } else { $smallNum = $num; $itemNum = bcdiv($num, $val->ratio, 2); } $checkStock = true; $stockInfo = ProductClass::decreaseStock($productId, $bigNum, $smallNum, $checkStock); $recordData = []; $recordData['sjId'] = $sjId; $recordData['shopId'] = $shopId; $recordData['mainId'] = $mainId; $recordData['itemId'] = $val->itemId; $recordData['itemNum'] = $itemNum; $recordData['oldStock'] = $stockInfo['oldStock']; $recordData['newStock'] = $stockInfo['newStock']; $recordData['productId'] = $productId; $recordData['orderSn'] = $orderSn; $recordData['relateName'] = $customName; $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs'); StockRecordClass::addSellStockOrderRecord($recordData); } $order->itemPrice = $itemPrice; $sendCost = $order->sendCost ?? 0; $currentPrice = bcadd($itemPrice, $sendCost, 2); $packCost = $order->packCost ?? 0; $currentPrice = bcadd($currentPrice, $packCost, 2); $shopId = $order->shopId ?? 0; $shop = ShopClass::getLockById($shopId); if (empty($shop)) { util::fail('没有找到门店6'); } $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息4'); } $main->unSendOrder -= 1; $main->finishOrder += 1; $main->save(); $kiloFee = $shop->kiloFee ?? 0; $miniKilo = $shop->miniKilo ?? 0; $calcWeight = $weight > $miniKilo ? $weight : $miniKilo; $allKiloFee = bcmul($calcWeight, $kiloFee, 2); $currentPrice = bcadd($currentPrice, $allKiloFee, 2); $order->prePrice = $currentPrice; $order->orderPrice = $currentPrice; $order->actPrice = $currentPrice; $order->realPrice = $currentPrice; $order->stockChange = 1; $order->save(); $bookPrice = $order->bookPrice ?? 0; $mainId = $shop->mainId ?? 0; $sjId = $shop->sjId ?? 0; $customId = $order->customId ?? 0; $relateOrderSn = $order->orderSn ?? ''; $shopAdminId = $data['shopAdminId'] ?? 0; $shopAdminName = $data['shopAdminName'] ?? ''; $refund = null; if ($bookPrice != $currentPrice) { if ($bookPrice > $currentPrice) { $refundPrice = bcsub($bookPrice, $currentPrice, 2); $order->refundPrice = $refundPrice; $order->tkPrice = bcadd($order->tkPrice, $refundPrice, 2); $order->refund = self::REFUND_YES; $order->refundLog = 1; $order->save(); $orderSn = orderSn::getGhsRefundSn(); $book = 1; $refundData = [ 'mainId' => $mainId, 'shopId' => $shopId, 'sjId' => $sjId, 'customId' => $customId, 'orderSn' => $orderSn, 'relateOrderSn' => $relateOrderSn, 'book' => $book, 'status' => RefundOrderClass::STATUS_COMPLETE, 'shopAdminId' => $shopAdminId, 'shopAdminName' => $shopAdminName, 'refundPrice' => $refundPrice, 'refundType' => RefundOrderClass::REFUND_TYPE_MONEY, ]; //退款 $refund = RefundOrderClass::add($refundData, true); //余额减少 ShopClass::ghsBookOrderRefundReduceBalance($main, $shop, $refund, $refundPrice); //总支出增加 $currentTotalExpend = bcadd($main->totalExpend, $refundPrice, 2); $main->totalExpend = $currentTotalExpend; $totalRefund = bcadd($main->totalRefund, $refundPrice, 2); $main->totalRefund = $totalRefund; $main->save(); //支出流水 $thisType = dict::getDict('capitalType', 'ghsBookRefund', 'id'); $sjId = $order->sjId ?? 0; $event = "预订单多付退给{$customName}"; $capitalData = [ 'capitalType' => $thisType, 'io' => 0, 'totalExpend' => $currentTotalExpend, 'payWay' => 0, 'amount' => $refundPrice, 'sjId' => $sjId, 'shopId' => $shopId, 'event' => $event, 'mainId' => $mainId, ]; ShopCapitalClass::addCapital($capitalData); //支出统计 StatOutClass::updateOrInsert($main, $shop, $refundPrice); //退款统计 $payWay = $order->payWay ?? 0; StatRefundClass::replace($main, $shop, $payWay, $refundPrice); //供货商预订单退款给客户,客户采购金额减少 StatKhCgClass::ghsBookOrderChange(false, $order, $refundPrice); } else { //欠款 $currentDebt = bcsub($currentPrice, $bookPrice, 2); $order->debtPrice = $currentDebt; $order->remainDebtPrice = $currentDebt; $order->debt = OrderClass::DEBT_YES; $order->save(); $currentTotalIncome = bcadd($main->totalIncome, $currentDebt, 2); $main->totalIncome = $currentTotalIncome; $main->save(); $payWay = dict::getDict('payWay', 'debtPay'); $pair = \bizGhs\custom\services\GhsRechargeSettleService::lockAccountPair(['id' => $customId]); $custom = $pair['custom']; $ghs = $pair['ghs']; if (empty($custom)) { util::fail('没有找到客户'); } CustomClass::cgDebtAmountAdd($custom, $order, true, $ghs); //收入增加 StatIncomeClass::updateOrInsert($main, $shop, $currentDebt); //收入流水增加 $orderId = $order->id; $capitalType = dict::getDict('capitalType', 'ghsBookOrderGetBack', 'id'); $shopAdminId = $order->shopAdminId ?? 0; $shopAdminName = $order->shopAdminName ?? ''; $event = "预订单 {$orderSn} 差价补款"; $mainId = $shop->mainId ?? 0; $sjId = $order->sjId ?? 0; $shopId = $order->shopId ?? 0; $capital = [ 'capitalType' => $capitalType, 'relateId' => $orderId, 'io' => 1, 'amount' => $currentDebt, 'totalIncome' => $currentTotalIncome, 'payWay' => $payWay, 'event' => $event, 'mainId' => $mainId, 'sjId' => $sjId, 'shopId' => $shopId, 'shopAdminId' => $shopAdminId, 'shopAdminName' => $shopAdminName, ]; ShopCapitalClass::addCapital($capital); //各渠道收入金额统计 StatKdClass::replace($shop, $currentDebt, $payWay); //每天销售收入统计 StatSaleClass::replace($main, $shop, $currentDebt); //预订单,客户补款给供货商,客户采购金额增加 StatKhCgClass::ghsBookOrderChange(true, $order, $currentDebt); } } return ['kiloFee' => $kiloFee, 'refund' => $refund, 'miniKilo' => $miniKilo]; } //添加订单 ssh 2019.12.5 public static function addOrder($data, $custom = []) { $shopId = $data['shopId'] ?? 0; $mainId = $data['mainId'] ?? 0; $ghsId = $data['ghsId'] ?? 0; $customId = $data['customId'] ?? 0; $distId = $custom['distId'] ?? 0; $data['customDistId'] = $distId; $snData = ['shopId' => $shopId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'customId' => $customId]; $orderSn = orderSn::getGhsOrderSn($snData); $data['orderSn'] = $orderSn; $data['payStatus'] = self::PAY_STATUS_UN_PAY; $data['customId'] = !empty($data['customId']) ? $data['customId'] : 0; $live = $data['live'] ?? 1; $currentShopId = $data['shopId'] ?? 0; $shop = ShopClass::getLockById($currentShopId); if (empty($shop)) { util::fail('没有找到门店7'); } $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息5'); } //花材 $product = $data['product']; $book = $data['book'] ?? 0; $stockMayChange = true; $data['stockChange'] = 1; if ($book == 1) { $stockMayChange = false; $data['stockChange'] = 0; } //花店向虚拟批发店采购的,批发店没有的花材需要补充 if ($live == 0) { $product = \bizHd\product\classes\ProductClass::hdToggleGhs($product, $shop); } $customShopAdminId = $data['customShopAdminId'] ?? 0; $moreParams = ['book' => $book, 'customShopAdminId' => $customShopAdminId, 'custom' => $custom]; $respond = OrderItemClass::replaceItem($orderSn, $product, $data, $stockMayChange, $moreParams); $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0; $data['sendCost'] = $sendCost; $data['bigNum'] = $respond['bigNum'] ?? 0; $data['smallNum'] = $respond['smallNum'] ?? 0; $data['itemNum'] = $respond['totalItemNum'] ?? 0; //这个字段记录每个花材满多少扎减掉的金额,并汇总金额,区别于整单满减的 $cutAmount。保存起来应该是在哪里有用,$totalReachDiscount在这边不影响actPrice,估计因为取花材的价格里::getFinalPrice()已经使用了优惠后的价格,有多处,关键词 reachDiscountPrice_explain ssh 20260116 $data['reachDiscountPrice'] = $respond['totalReachDiscount'] ?? 0; //记录订单的总成本 $totalCost = $respond['totalCost'] ?? 0; $packCost = $data['packCost'] ?? 0; $totalCost = bcadd($totalCost, $packCost, 2); $totalCost = bcadd($totalCost, $sendCost, 2); $data['totalCost'] = $totalCost; $data['remainCost'] = $totalCost; //默认订单要打单 $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need'); $weight = $respond['weight'] ?? 0; $data['weight'] = $weight; $itemPrice = $respond['price'] ?? 0; $data['itemPrice'] = $itemPrice; $currentPrice = bcadd($itemPrice, $sendCost, 2); $packCost = isset($data['packCost']) && $data['packCost'] > 0 ? $data['packCost'] : 0; $currentPrice = bcadd($currentPrice, $packCost, 2); //预订单需要增加服务费 if ($book == 1) { $kiloFee = $shop->kiloFee ?? 0; $miniKilo = $shop->miniKilo ?? 0; $calcWeight = max($weight, $miniKilo); $allKiloFee = bcmul($calcWeight, $kiloFee, 2); $currentPrice = bcadd($currentPrice, $allKiloFee, 2); $data['allKiloFee'] = $allKiloFee; $data['kiloFee'] = $kiloFee; $data['miniKilo'] = $miniKilo; } $data['prePrice'] = $currentPrice; $actPrice = $currentPrice; //商家自己开单时 if (isset($data['modifyPrice'])) { $modifyPrice = $data['modifyPrice'] ?? 0; if ($modifyPrice <= 0) { util::fail('收款金额必须大于0'); } if ($modifyPrice > $currentPrice) { //人工和资材费用 $data['labourCost'] = bcsub($modifyPrice, $currentPrice, 2); } if ($modifyPrice < $currentPrice) { //优惠金额 $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2); $data['discountType'] = dict::getDict('discountType', 'discount'); } $actPrice = $modifyPrice; if ($book == 1) { $actPrice = 0; } } else { //客户自己下单才有整单满减,门店帮忙开单没有,,多个地方要同步修改,关键词 meet_amount_num_reduce if ($book == 0) { $meetNum = $shop->meetNum ?? 0; $meetAmount = $shop->meetAmount ?? 0; $cutOption = $shop->cutAmount ?? 0; $cutStyle = $shop->cutStyle ?? 0; if ($cutStyle == 0) { $cutAmount = $cutOption; } else { $miniOption = bcsub(1, $cutOption, 2); $cutAmount = bcmul($actPrice, $miniOption, 2); } if ($cutAmount > 0 && $meetNum > 0 && $meetAmount > 0) { if (isset($data['bigNum']) && $data['bigNum'] >= $meetNum && isset($data['itemPrice']) && $data['itemPrice'] >= $meetAmount) { if ($cutAmount < $actPrice) { $actPrice = bcsub($actPrice, $cutAmount, 2); $data['orderReachDiscountPrice'] = $cutAmount; } else { noticeUtil::push('订单金额不足满减金额,customId:' . $customId, '15280215347'); } } } } } //如果有设置指定客户涨价百分之几,然后又设置了涨价的幅度。【这个功能主要用于客户不收他运费,门店不赚钱,收他运费客户不乐意,所以把运费加到花材里】,多处同步修改,关键词 rise_percent_rang if (isset($data['itemPrice'])) { if (isset($data['orderReachDiscountPrice'])) { $originActPrice = bcadd($actPrice, $data['orderReachDiscountPrice'], 2); } else { $originActPrice = $actPrice; } if ($originActPrice >= $data['itemPrice']) { if (isset($custom['risePercent']) && $custom['risePercent'] > 0) { if (isset($custom['riseRange']) && $custom['riseRange'] > 0) { $risePercent = $custom['risePercent']; $riseRange = $custom['riseRange']; // 计算涨价金额:涨价后金额 * (涨价百分比 / (100 + 涨价百分比)) $riseAmount = bcmul($data['itemPrice'], bcdiv($risePercent, bcadd(100, $risePercent, 0), 4), 2); if ($riseAmount > $riseRange) { //应该退回的金额 $backAmount = bcsub($riseAmount, $riseRange, 2); $actPrice = bcsub($actPrice, $backAmount, 2); if (isset($data['orderReachDiscountPrice'])) { if ($data['orderReachDiscountPrice'] < $backAmount) { //前面整单满减的,就不减了,所以这里面加回来 $actPrice = bcadd($actPrice, $data['orderReachDiscountPrice'], 2); //改成减多加钱里面的 $data['orderReachDiscountPrice'] = $backAmount; } } else { $data['orderReachDiscountPrice'] = $backAmount; } } } } } } //客户采购时使用红包时 if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'hb')) { $discountAmount = $data['discountAmount'] ?? 0; $currentDiscountPrice = bcsub($currentPrice, $discountAmount, 2); $actPrice = $currentDiscountPrice; } $data['actPrice'] = $actPrice; $data['bookPrice'] = $actPrice; $data['orderPrice'] = $actPrice; $data['realPrice'] = $actPrice; $data['sendTimeWant'] = isset($data['sendTimeWant']) && !empty($data['sendTimeWant']) ? $data['sendTimeWant'] : date("Y-m-d"); //订单有效期 $validTime = dict::getDict('order_pay_has_time'); $current = time() + $validTime; $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current); $data['status'] = self::ORDER_STATUS_UN_PAY; $main->totalOrder += 1; $main->unPayOrder += 1; $main->save(); //将当天日期+花店每天的总订单数作为编号,批发的加个0作为前缀,跟零售的编号这样来区分 $data['sendNum'] = '0' . date("j") . StatOrderCountClass::addOrder($shop, $main); //订单有效期 $currentTime = time(); $validTime = dict::getDict('order_pay_has_time'); $current = $currentTime + $validTime; $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current); if ($book == 1) { $fiveTime = bcmul(86400, 5); $bookDeadline = bcadd($currentTime, $fiveTime); $data['deadline'] = date("Y-m-d H:i:s", $bookDeadline); } //订单自动记为欠款单时间 $localConfirmTime = dict::getDict('local_gys_kd_auto_set_debt_time'); $currentSet = $currentTime + $localConfirmTime; $data['autoSetTime'] = $data['autoSetTime'] ?? date("Y-m-d H:i:s", $currentSet); $data['salt'] = $data['salt'] ?? stringUtil::charsShuffleLowerCase(10); $return = self::add($data, true); return $return; } //修改订单 ssh 2019.12.5 public static function updateOrder($order, $data) { $sjId = $order->sjId ?? 0; $orderSn = $order->orderSn ?? 0; $currentShopId = $order->shopId ?? 0; $data['payStatus'] = self::PAY_STATUS_UN_PAY; //花材列表 $product = $data['product']; //删除花材再添加 OrderItemClass::deleteByCondition(['orderSn' => $orderSn]); $respond = OrderItemClass::replaceItem($orderSn, $product, $data); $sendCost = isset($data['sendCost']) && is_numeric($data['sendCost']) ? $data['sendCost'] : 0; $data['sendCost'] = $sendCost; $data['bigNum'] = $respond['bigNum'] ?? 0; $data['smallNum'] = $respond['smallNum'] ?? 0; $price = $respond['price'] ?? 0; $currentPrice = bcadd($price, $sendCost, 2); $data['prePrice'] = $currentPrice; if (isset($data['modifyPrice'])) { //商家打折,修改金额 $modifyPrice = $data['modifyPrice'] ?? 0; if ($modifyPrice > $currentPrice) { util::fail('实收金额大于订单总金额'); } if ($modifyPrice < $currentPrice) { $data['discountAmount'] = bcsub($currentPrice, $modifyPrice, 2); $data['discountType'] = dict::getDict('discountType', 'discount'); $currentPrice = $modifyPrice; } } $data['actPrice'] = $currentPrice; $data['realPrice'] = $currentPrice; //如果有平台补贴 if (isset($data['discountType']) && $data['discountType'] == dict::getDict('discountType', 'usePtCoupon')) { $discountAmount = $data['discountAmount'] ?? 0; $data['realPrice'] = bcsub($currentPrice, $discountAmount, 2); } $data['sendTime'] = isset($data['sendTime']) && !empty($data['sendTime']) ? $data['sendTime'] : '0000-00-00 00:00:00'; //订单有效期 $validTime = dict::getDict('order_pay_has_time'); $current = time() + $validTime; $data['deadline'] = $data['deadline'] ?? date("Y-m-d H:i:s", $current); $data['status'] = self::ORDER_STATUS_UN_PAY; //计算总重量(kg) $weight = 0; $productMapData = ProductClass::getProductMapData($product); foreach ($product as $key => $val) { $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']); $productId = $val['productId']; $weight = bcadd($w, $weight, 2); $checkStock = true; $stockInfo = ProductClass::decreaseStock($val['productId'], $val['bigNum'], $val['smallNum'], $checkStock); //记录库存流水 $recordData = []; $recordData['sjId'] = $sjId; $recordData['shopId'] = $currentShopId; $recordData['itemId'] = $productMapData[$productId]['itemId'] ?? 0; $ratio = $productMapData[$productId]['ratio'] ?? 0; $recordData['itemNum'] = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio); $recordData['oldStock'] = $stockInfo['oldStock']; $recordData['newStock'] = $stockInfo['newStock']; $recordData['productId'] = $productId; $recordData['orderSn'] = $orderSn; StockRecordClass::addSellStockOrderRecord($recordData); } $data['weight'] = $weight; $current = time() + 300; $data['deadline'] = isset($data['deadline']) ? $data['deadline'] : date("Y-m-d H:i:s", $current); //修改订单暂时不打印 $data['needPrint'] = $data['needPrint'] ?? dict::getDict('needPrint', 'need'); $orderId = $order->id ?? 0; self::updateById($orderId, $data); $return = self::getLockById($orderId); //门店总订单数+1 $shop = ShopClass::getLockById($currentShopId); if (empty($shop)) { util::fail('没有找到门店8'); } $shop->unPayOrder += 1; $shop->cancelOrder -= 1; $shop->save(); return $return; } //根据订单编号查询 ssh 2021.19 public static function getByOrderSn($orderSn, $returnObj = false) { return self::getByCondition(['orderSn' => $orderSn], $returnObj); } //根据编号列表查订单 public static function getOrderInfoBySnList($snList) { $list = self::getAllByCondition(['orderSn' => ['in', $snList]], null, '*', 'orderSn'); $list = self::groupOrder($list, true, false, false, true); return $list; } //显示操作按钮 public static function getShowButton($showButton, $isList, $order) { if ($showButton == false) { return []; } $print = ['type' => 'print', 'show' => 1, 'disable' => 0, 'name' => '打印']; $modifyProduct = ['type' => 'modifyProduct', 'show' => 0, 'disable' => 0, 'name' => '修改花材']; $confirm = ['type' => 'confirm', 'show' => 0, 'disable' => 1, 'name' => '确认']; $cancel = ['type' => 'cancel', 'show' => 0, 'disable' => 0, 'name' => '取消']; $arrival = ['type' => 'arrival', 'show' => 0, 'disable' => 0, 'name' => '确认发货']; if ($isList) { //订单列表页显示的按钮 $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货']; $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取']; if ($order['status'] == self::ORDER_STATUS_UN_PAY) { //待确认订单,打印和修改花材按钮可以使用 $send['disable'] = 1; $selfGet['disable'] = 1; $print['disable'] = 0; $confirm['disable'] = 0; } if ($order['status'] == self::ORDER_STATUS_UN_SEND) { //待配送订单,改花材按钮不可点,自取可点 $selfGet['disable'] = 0; } //自取订单发货按钮置灰 if ($order['sendType'] == self::SEND_TYPE_NO) { $send['disable'] = 1; } //取消订单置灰 if ($order['status'] == self::ORDER_STATUS_CANCEL) { $send['disable'] = 1; $selfGet['disable'] = 1; $print['disable'] = 1; } if ($order['status'] == self::ORDER_STATUS_COMPLETE) { $send['name'] = '发货记录'; } return [$send, $selfGet, $print, $confirm]; } else { //订单详情页显示的按钮 if (isset($order['book']) && $order['book'] == 1 && isset($order['stockChange']) && $order['stockChange'] == 0) { if ($order['status'] == self::ORDER_STATUS_UN_SEND) { $arrival['show'] = 1; } } //待确认订单显示延期付和已付款 if ($order['status'] == self::ORDER_STATUS_UN_PAY) { $debtPay = ['type' => 'debtPay', 'show' => 0, 'disable' => 0, 'name' => '延期收款']; $hasPay = ['type' => 'hasPay', 'show' => 0, 'disable' => 0, 'name' => '欠款']; $confirm['disable'] = 0; return [$print, $debtPay, $hasPay, $confirm, $cancel, $arrival]; } //待配送订单显示打印、发货和自取 if ($order['status'] == self::ORDER_STATUS_UN_SEND) { $selfGet = ['type' => 'selfGet', 'show' => 0, 'disable' => 1, 'name' => '自取']; $send = ['type' => 'send', 'show' => 0, 'disable' => 1, 'name' => '发货']; if ($order['hasItem'] == 2) { return [$print, $selfGet, $send, $arrival]; } $selfGet['disable'] = 0; $send['disable'] = 0; return [$print, $selfGet, $send, $arrival]; } //配送中显示按钮 if ($order['status'] == self::ORDER_STATUS_SENDING) { $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货']; return [$print, $send, $arrival]; } //完成 if ($order['status'] == self::ORDER_STATUS_COMPLETE) { $send = ['type' => 'send', 'show' => 0, 'disable' => 0, 'name' => '发货记录']; //自取订单不显示发货按钮 if ($order['sendType'] == self::SEND_TYPE_NO) { $send['show'] = 0; } return [$print, $send, $arrival]; } //取消订单置灰 if ($order['status'] == self::ORDER_STATUS_CANCEL) { $selfGet['disable'] = 1; $send['disable'] = 1; $print['disable'] = 1; return [$modifyProduct, $arrival]; } return []; } } //显示进度 ssh 2021.3.1 public static function getShowProgress($showProgress, $order) { if ($showProgress == false) { return []; } $create = ['name' => '创建', 'complete' => 1]; $unConfirm = ['name' => '待确认', 'complete' => 0]; if ($order['status'] > 0) { $unConfirm['complete'] = 1; } $out = ['name' => '出库', 'complete' => 0]; if ($order['status'] > 1) { $out['complete'] = 1; } return [$create, $unConfirm, $out]; } //退款等需要使用原来的订单花材结构 public static function getOriginalShowItem($showItem, $order) { if ($showItem == false) { return ['list' => [], 'itemStat' => []]; } $orderSn = $order['orderSn']; $list = OrderItemClass::getOrderItem($orderSn); $totalPrice = 0; $totalBigNum = 0; $totalSmallNum = 0; $kind = 0; $itemStat = []; if (!empty($list)) { $ids = array_column($list, 'productId'); $ids = array_filter(array_unique($ids)); $productInfo = ProductClass::getByIds($ids, null, 'id'); foreach ($list as $key => $val) { $productId = $val['productId'] ?? 0; $currentInfo = $productInfo[$productId]; $currentPrice = $productInfo[$productId]['price'] ?? 0; $unitPrice = isset($val['xhUnitPrice']) ? floatval($val['xhUnitPrice']) : 0; $list[$key]['currentHdPrice'] = $unitPrice; //原有售价 $list[$key]['itemSalePrice'] = floatval($currentPrice); //自己填的价格 $list[$key]['itemModifyPrice'] = $unitPrice; $list[$key]['property'] = ''; $list[$key]['cost'] = $currentInfo['cost'] ?? 0; $list[$key]['stock'] = $currentInfo['stock'] ? floatval($currentInfo['stock']) : 0; $price = $val['price']; $totalPrice = stringUtil::calcAdd($totalPrice, $price); $kind++; $currentBigNum = $val['bigNum'] ?? 0; $currentSmallNum = $val['smallNum'] ?? 0; $currentGiveNum = $val['giveNum'] ?? 0; $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum); $totalBigNum = bcadd($totalBigNum, $currentGiveNum); $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum); } $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice]; } return ['list' => $list, 'itemStat' => $itemStat]; } public static function getShowItem($showItem, $order) { if ($showItem == false) { return ['list' => [], 'itemStat' => []]; } $orderSn = $order['orderSn']; $list = OrderItemClass::getOrderItem($orderSn); $totalPrice = 0; $totalBigNum = 0; $totalSmallNum = 0; $kind = 0; $itemStat = []; //小菊增加部分 $xjAddList = []; if (!empty($list)) { foreach ($list as $key => $val) { $price = $val['price']; $totalPrice = stringUtil::calcAdd($totalPrice, $price); $kind++; $currentBigNum = $val['bigNum']; $currentSmallNum = $val['smallNum']; $unitType = $val['xhUnitType'] ?? 0; $refundNum = $val['refundNum'] ?? 0; if ($unitType == 0) { $currentBigNum = bcsub($currentBigNum, $refundNum); } else { $currentSmallNum = bcsub($currentSmallNum, $refundNum); } $totalBigNum = stringUtil::calcAdd($totalBigNum, $currentBigNum); $totalSmallNum = stringUtil::calcAdd($totalSmallNum, $currentSmallNum); //赠送数量 $giveNum = $val['giveNum'] ?? 0; $totalBigNum = bcadd($totalBigNum, $giveNum); $list[$key]['property'] = ''; //小菊 if (isset($val['variety']) && $val['variety'] == 1) { $currentItemId = $val['id'] ?? 0; $xjList = OrderXjClass::getAllByCondition(['itemId' => $currentItemId], null, '*'); if (!empty($xjList)) { //选了有颜色的小菊才把原小菊删除不显示出来!!! unset($list[$key]); foreach ($xjList as $xjKey => $xj) { $xjBase = $val; $num = $xj['num'] ?? 0; $price = $xj['price'] ?? 0; $name = $xj['name'] ?? ''; $cover = $xj['cover'] ?? ''; if ($num > 0) { $bigTotalPrice = bcmul($price, $num, 2); $xjBase['cover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; $xjBase['bigCover'] = imgUtil::groupImg($cover) . "?x-oss-process=image/resize,m_fill,h_700,w_700"; $xjBase['unitPrice'] = $price; $xjBase['price'] = floatval($bigTotalPrice); $xjBase['num'] = floatval($num); $xjBase['bigNum'] = floatval($num); $xjBase['name'] = $name; $xjBase['property'] = ''; $xjBase['userPrice'] = $bigTotalPrice; $xjBase['xhNum'] = floatval($num); $xjBase['xhPreNum'] = floatval($num); $xjBase['xhPrice'] = floatval($bigTotalPrice); $xjAddList[] = $xjBase; } } } } } if (!empty($xjAddList)) { $list = array_merge($list, $xjAddList); } $itemStat = ['kind' => $kind, 'bigNum' => $totalBigNum, 'smallNun' => $totalSmallNum, 'totalPrice' => $totalPrice]; } return ['list' => $list, 'itemStat' => $itemStat]; } /** * 列表分享:批量附加采购单 salt,仅查 purchase 表 id,salt */ public static function attachCgSaltForList($list) { if (empty($list)) { return $list; } $purchaseIds = array_unique(array_filter(array_column($list, 'purchaseId'))); $cgSaltMap = []; if (!empty($purchaseIds)) { $cgList = PurchaseClass::getByIds($purchaseIds, null, 'id', 'id,salt'); foreach ($cgList as $cg) { $cgId = $cg['id'] ?? 0; if (!empty($cgId)) { $cgSaltMap[$cgId] = $cg['salt'] ?? ''; } } } foreach ($list as $key => $val) { $purchaseId = $val['purchaseId'] ?? 0; $list[$key]['cgSalt'] = !empty($purchaseId) ? ($cgSaltMap[$purchaseId] ?? '') : ''; } return $list; } //订单列表 ssh 2021.1.19 public static function getOrderList($where) { $data = self::getList('*', $where, 'addTime DESC'); $data['totalActPrice'] = 0; $data['totalTkPrice'] = 0; if (!empty($data['list'])) { $distIds = array_unique(array_filter(array_column($data['list'], 'customDistId'))); $distMap = []; if (!empty($distIds)) { $distMap = DistClass::getByIds($distIds, null, 'id'); } foreach ($data['list'] as $key => $val) { $customDistId = intval($val['customDistId'] ?? 0); $data['list'][$key]['customDistName'] = $customDistId > 0 && isset($distMap[$customDistId]) ? ($distMap[$customDistId]['name'] ?? '') : ''; //同个人同地址当天订单数 $sameNum = $val['mergeNum']; if ($sameNum > 0) { $mergeId = $val['mergeId'] ?? 0; if (!empty($mergeId)) { $mergeList = OrderMergeClass::getAllByCondition(['mergeId' => $mergeId], null, 'orderId'); $ids = array_column($mergeList, 'orderId'); $sameTimeIds = implode(',', $ids); $data['list'][$key]['sameTimeIds'] = $sameTimeIds; $data['list'][$key]['mergeStatus'] = '已经使用新版本'; } } else { $sameTimeIds = $val['sameTimeIds'] ?? ''; if (!empty($sameTimeIds)) { $sameIds = explode(',', $sameTimeIds); $sameNum = count($sameIds); } } $data['list'][$key]['sameTimeIdsNum'] = $sameNum; $data['list'][$key]['customAvatarUrl'] = imgUtil::groupImg(''); } $data['list'] = self::attachCgSaltForList($data['list']); } return $data; } //按片区排列的订单列表 public static function getDistOrderList($where) { /** @var Order $model */ $model = self::getActiveRecord(); $query = $model->conditionQuery($where) ->alias('o') ->leftJoin(['c' => Custom::tableName()], 'c.id = o.customId') ->select(['o.id', 'o.mainId', 'o.customId', 'o.customName', 'o.customAvatar', 'o.fullAddress', 'o.remark', 'c.name', 'c.mobile', 'c.distId', 'distId' => 'c.distId']); // $clone = clone $query; // $count = intval($clone->count('o.id')); $orderList = $query ->orderBy(['c.distId' => SORT_ASC, 'o.addTime' => SORT_DESC]) // ->offset($offset)->limit($pageSize) ->asArray() ->all(); $distIds = array_unique(array_filter(array_column($orderList, 'distId'))); $distMap = []; if (!empty($distIds)) { $distMap = DistClass::getByIds($distIds, null, 'id'); } $grouped = []; foreach ($orderList as $orderInfo) { $distId = intval($orderInfo['distId']); if (!isset($grouped[$distId]) && isset($distMap[$distId])) { $grouped[$distId] = [ 'distId' => $distId, 'distName' => $distMap[$distId]['name'], 'list' => [], ]; } $grouped[$distId]['list'][$orderInfo['customId']][] = $orderInfo; } return [ 'list' => array_values($grouped), ]; } //整合订单员工和供货商等信息 ssh 2021.1.19 //$isList 是否列表页 public static function groupOrder($list, $showButton = false, $showItem = false, $showExpress = false, $isList = false) { if (empty($list)) { return $list; } $adminIds = array_unique(array_filter(array_column($list, 'adminId'))); $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id'); //退款需要显示原有的花材结构,不显示小菊的多颜色 $getOriginalItem = Yii::$app->request->get('getOriginalItem', 0); $getOriginalItem2 = Yii::$app->request->post('getOriginalItem', 0); $customIds = array_column($list, 'customId'); $customIds = array_unique(array_filter($customIds)); $customInfoList = CustomClass::getByIds($customIds, null, 'id'); foreach ($list as $key => $val) { $adminId = $val['adminId'] ?? 0; $list[$key]['adminName'] = $adminInfo[$adminId]['name'] ?? ''; $list[$key]['customAddress'] = $val['fullAddress'] ?? ''; //显示列表页的操作按钮 $list[$key]['buttonList'] = self::getShowButton($showButton, $isList, $val); //为了列表页的打印按钮能用,列表也强制显示花材 $showItem = true; if ($getOriginalItem == 1 || $getOriginalItem2 == 1) { $showItemData = self::getOriginalShowItem($showItem, $val); } else { $showItemData = self::getShowItem($showItem, $val); } $list[$key]['product'] = $showItemData['list']; $list[$key]['productStat'] = $showItemData['itemStat']; $showResetItem = 0; //待付款订单显示改花材按钮 if ($val['status'] == self::PAY_STATUS_UN_PAY) { $showResetItem = 1; } $list[$key]['showResetItem'] = $showResetItem; //获取配送进展 $expressProgress = ''; if ($val['sendType'] == 4) { $expressInfo = OrderExpressClass::getByCondition(['orderSn' => $val['orderSn']]); if ($expressInfo) { $expressProgress = ['progressName' => OrderExpressClass::$statusMap[$expressInfo['status']] ?? '']; } } $list[$key]['sendTypeName'] = self::$sendTypeMap[$val['sendType']] ?? '未知'; $list[$key]['expressProgress'] = $expressProgress; $list[$key]['customAvatarUrl'] = imgUtil::groupImg($val['customAvatar']); $list[$key]['customName'] = !empty($val['customId']) ? $val['customName'] : '散客'; $customId = $val['customId'] ?? ''; $balance = $customInfoList[$customId]['balance'] ?? 0.00; $debtAmount = $balance < 0 ? abs($balance) : 0; //打印数据组合 $printData = self::getPrintData($val, $debtAmount, $showItemData); $list[$key]['printData'] = json_encode($printData); $list[$key]['debtAmount'] = $debtAmount; $list[$key]['customShopId'] = $customInfoList[$customId]['shopId'] ?? 0; //计算利润 $actPrice = $val['actPrice'] ?? 0; $remainCost = $val['remainCost'] ?? 0; $profit = bcsub($actPrice, $remainCost, 2); $profit = floatval($profit); $list[$key]['profit'] = $profit; } return self::attachCgSaltForList($list); } public static function printGroup($current, $content, $showPrice = 1, $fontSizeType = 0) { //58mm的机器,一行打印16个汉字,32个字母 $productPrice = $current['price'] ?? ''; $unitPrice = $current['unitPrice'] ?? ''; $name = $current['name'] ?? ''; if (floatval($unitPrice) == 0.01) { $name = $name . '(送)'; } $productNum = $current['num'] ?? ''; $itemNum = $current['itemNum'] ?? 0; $refundNum = $current['refundNum'] ?? 0; $unitName = $current['unitName'] ?? '扎'; $remark = $current['remark'] ?? ''; $ratioType = $current['ratioType'] === null ? -1 : intval($current['ratioType']); $ratio = $current['ratio']; $lastNum = bcsub($itemNum, $refundNum); if (!empty($remark)) { $show = $lastNum . $unitName . ' ' . $name . "【" . $remark . "】"; } else { $show = $lastNum . $unitName . ' ' . $name; } if ($fontSizeType == 1) { $content .= '' . $show . '
'; } else { $content .= '' . $show . '
'; } if ($refundNum > 0) { $content .= '(买' . $itemNum . $unitName . ' 退' . $refundNum . $unitName . ')
'; } if ($showPrice == 1) { if (floatval($unitPrice) == 0.01) { $content .= $productNum . ' = ' . $productPrice . '元 赠送价
'; } else { $content .= $productNum . ' = ' . $productPrice . '元 ' . ($ratioType == 0 ? $ratio . '支装' : ($ratioType == 1 ? '若干支装' : '')) . '
'; } } else { $content .= ' ' . ($ratioType == 0 ? $ratio . '支装' : ($ratioType == 1 ? '若干支装' : '')) . '
'; } $content .= '--------------------------------
'; return $content; } //合并打印订单 ssh 20230929 public static function mergePrintOrder($ids, $mainId) { $all = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true); if (empty($all)) { util::fail('没有找到订单'); } $snList = []; $sendNumList = []; $remarkList = []; foreach ($all as $info) { if ($info->mainId != $mainId) { util::fail('不是你的订单'); } $orderSn = $info->orderSn; if ($info->payStatus == 1) { $snList[] = $orderSn; $orderInfo = $info; $sendNumList[] = $info->sendNum; if (!empty($info->remark)) { $remarkList[] = $info->remark; } } } $sendNumString = ''; if (!empty($sendNumList)) { $sendNumString = implode(',', $sendNumList); } $remarkString = ''; if (!empty($remarkList)) { $remarkString = implode(',', $remarkList); } $allItem = OrderItemClass::getAllByCondition(['orderSn' => ['in', $snList]], null, '*'); if (empty($allItem)) { util::fail('没有花材信息'); } $new = []; foreach ($allItem as $currentItem) { $unitType = $currentItem['xhPreUnitType'] ?? 1; $productId = $currentItem['productId'] ?? 0; if ($unitType == 0 && $productId > 0) { if (isset($new[$productId])) { $xhNum = $currentItem['xhNum'] ?? 0; $refundNum = $currentItem['refundNum'] ?? 0; $giveNum = $currentItem['giveNum'] ?? 0; $new[$productId]['xhNum'] = bcadd($new[$productId]['xhNum'], $xhNum); $new[$productId]['refundNum'] = bcadd($new[$productId]['refundNum'], $refundNum); $new[$productId]['giveNum'] = bcadd($new[$productId]['giveNum'], $giveNum); $remark = $currentItem['remark'] ?? ''; if (!empty($remark)) { $new[$productId]['remark'] = $remark; } } else { $new[$productId] = $currentItem; } } } $showPrice = 1; $customId = $orderInfo->customId ?? 0; $c = CustomClass::getById($customId); $debtAmount = $c['debtAmount'] ?? 0.00; $shopId = $orderInfo->shopId ?? 0; $shop = ShopClass::getById($shopId, true); if (empty($shop)) { util::fail('打印失败,没有找到门店9'); } $sjId = $shop->sjId ?? 0; $fontSizeType = $shop->fontSize ?? 0; $telephone = $shop->telephone ?? ''; $sj = SjClass::getById($sjId, true); $sjName = $sj->name ?? ''; $shopName = $shop->shopName ?? ''; $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; $fromType = $orderInfo->fromType ?? dict::getDict('fromType', 'shop'); $fromTypeMap = dict::getDict('fromTypeMap'); $fromTypeName = $fromTypeMap[$fromType] ?? '门店'; $content = "" . $currentName . ""; $content .= "销售单

"; $content .= '' . $sendNumString . ' ' . $fromTypeName . '
'; $content .= '--------------------------------
'; //快捷开单不需要打印买家信息 if ($customId != $shop->skCustomId) { $content .= '买家信息:

'; $content .= '' . $orderInfo->customName . '
'; $content .= '' . $orderInfo->customMobile . '
'; if (isset($orderInfo->address) && !empty($orderInfo->address)) { $content .= $orderInfo->fullAddress; if (isset($orderInfo->showAddress) && !empty($orderInfo->showAddress)) { $content .= '(' . $orderInfo->showAddress . ')
'; } else { $content .= '
'; } } } if (isset($orderInfo->book) && $orderInfo->book == 1) { $content .= '预订单
'; } if (isset($orderInfo->presell) && $orderInfo->presell == 1) { $content .= '预售单
'; } if (isset($shop->pfLevel) && $shop->pfLevel == 1) { if (isset($orderInfo->transType)) { $sendName = '同城配送'; if ($orderInfo->transType == 0) { $sendName = '德邦物流'; } if ($orderInfo->transType == 1) { $sendName = '顺丰物流'; } if ($orderInfo->transType == 2) { $sendName = '冷链物流'; } if ($orderInfo->transType == 3) { $sendName = '航空物流'; } if ($orderInfo->transType == 4) { $sendName = '同城配送'; } if ($orderInfo->transType == 5) { $sendName = '到店自取'; } $content .= '
' . $sendName . '
'; } } else { if (isset($orderInfo->sendType)) { $sendName = '送货上门'; if ($orderInfo->sendType == 1) { $sendName = '到店自取'; } if ($orderInfo->sendType == 2) { $sendName = '跑腿送'; } if ($orderInfo->sendType == 3) { $wlName = $orderInfo['wlName'] ?? '未填物流'; $sendName = $wlName; } if ($orderInfo->sendType == 4) { $sendName = '发快递'; } $content .= '
' . $sendName . '
'; } } if (!empty($remarkString)) { $content .= '
'; $content .= '备注:
'; $content .= '' . $remarkString . '
'; } $content .= '
'; $content .= '商品 数量/单价 金额
'; $content .= '--------------------------------
'; $totalNum = 0; $refundTotalNum = 0; foreach ($new as $current) { //58mm的机器,一行打印16个汉字,32个字母 $productPrice = $current['xhUnitPrice'] ?? ''; $name = $current['name'] ?? ''; if (floatval($productPrice) == 0.01) { $name = $name . '(送)'; } $giveNum = $current['giveNum'] ?? 0; $refundNum = $current['refundNum'] ?? 0; $productNum = $current['xhNum'] ?? ''; $unitName = $current['xhUnitName'] ?? '扎'; $remark = $current['remark'] ?? ''; $totalNum = bcadd($totalNum, $giveNum); $refundTotalNum = bcadd($refundTotalNum, $refundNum); $lastNum = bcadd($productNum, $giveNum); $lastNum = bcsub($lastNum, $refundNum); $show = $name . ' ' . $lastNum . $unitName; if (!empty($remark)) { $show .= "【{$remark}】"; } $hint = ''; if ($refundNum > 0 || $giveNum > 0) { $hint .= '(买' . $productNum . $unitName; } if ($refundNum > 0) { $hint .= ' 退' . $refundNum . $unitName; if ($giveNum <= 0) { $hint .= ')'; } } if ($giveNum > 0) { $hint .= ' 送' . $giveNum . $unitName . ')'; } $content .= '' . $show . '
'; if (!empty($hint)) { $content .= $hint . '
'; } $content .= '--------------------------------
'; $totalNum = bcadd($totalNum, $productNum); } $content .= '********************************
'; $kindNum = count($new); $remainNum = bcsub($totalNum, $refundTotalNum); $content .= "共{$kindNum}种"; $content .= ",{$remainNum}扎"; $content .= ""; $content .= '********************************

'; $ext = ShopExtClass::getByCondition(['shopId' => $shopId]); $printSn = $ext['printSn'] ?? ''; if (!empty($printSn)) { $p = new printUtil($printSn); $p->printMsg($content, $shop); } foreach ($all as $info) { if ($info->payStatus == 1) { $info->printNum += 1; $info->printStatus = 2; $info->save(); } } } //超出数量的打印 sssh 20240605 public static function onlinePrintOver($showItem, $orderInfo, $currentName, $shop) { $itemList = $showItem['list']; $orderSn = $orderInfo->orderSn ?? ''; $arr = array_chunk($itemList, 40); $totalPage = count($arr); foreach ($arr as $key => $itemList) { $content = ''; $content .= "{$currentName}
"; $content .= "销售单

"; $content .= '' . $orderSn . '

'; //快捷开单不需要打印买家信息 if ($orderInfo->customId != $shop->skCustomId) { $content .= '买家信息:

'; $content .= '' . $orderInfo->customName . '
'; $content .= '' . $orderInfo->customMobile . '
'; if (isset($orderInfo['address']) && !empty($orderInfo['address'])) { $content .= $orderInfo->fullAddress; if (isset($orderInfo['showAddress']) && !empty($orderInfo['showAddress']) && $orderInfo->fullAddress != $orderInfo['showAddress']) { $content .= '(' . $orderInfo['showAddress'] . ')

'; } else { $content .= '

'; } } } if ($totalPage > 1) { $currentPage = bcadd($key, 1); $content .= "第{$currentPage}页,共{$totalPage}页
"; } $content .= '
'; $content .= '商品 数量
'; $content .= '--------------------------------
'; if (isset($itemList) && !empty($itemList)) { foreach ($itemList as $info) { $name = $info['name'] ?? ''; $num = $info['xhNum'] ?? 0; $refundNum = $info['refundNum'] ?? 0; $lastNum = bcsub($num, $refundNum); $unitName = $info['xhUnitName'] ?? ''; $show = $name . ' ' . $lastNum . $unitName; $content .= '' . $show . '
'; $content .= '--------------------------------
'; } } $kindNum = $showItem['itemStat']['kind'] ?? 0; $bigNum = $showItem['itemStat']['bigNum'] ?? 0; $smallNun = $showItem['itemStat']['smallNun'] ?? 0; $content .= '********************************
'; $content .= "共{$kindNum}种"; $content .= " 数量:"; if ($bigNum > 0) { $content .= "{$bigNum}"; } if ($smallNun > 0) { $content .= "{$smallNun}"; } $content .= ""; $content .= '********************************

'; $content .= '
'; $content .= '
'; $shopId = $shop->id; $ext = ShopExtClass::getByCondition(['shopId' => $shopId]); $printSn = $ext['printSn'] ?? ''; if (!empty($printSn)) { $p = new printUtil($printSn); $p->printMsg($content, $shop); } } } //云打印 ssh 20210709 public static function onlinePrint($orderInfo, $showPrice = 1) { if (getenv('YII_ENV') == 'production') { //淮北花语集、丽子鲜花,客户线上下单不显示价格,门店开单显示价格 if ($orderInfo->shopId == 1527 || $orderInfo->mainId == 52291) { if (!empty($orderInfo->customShopAdminId)) { $showPrice = 0; } } //源花汇小票不带价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 62382) { $showPrice = 0; } //三明易批花非洲菊 不带价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 10536) { $showPrice = 0; } //义乌我要花 不带价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 83694) { $showPrice = 0; } //衡阳昕得鲜花批发,线上下单,不显示价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 85744) { if (!empty($orderInfo->customShopAdminId)) { $showPrice = 0; } } //清流美朵花业线上下单不显示价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 99641) { if (!empty($orderInfo->customShopAdminId)) { $showPrice = 0; } } //北京花篮子,线上下单,不显示价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 10735) { if (!empty($orderInfo->customShopAdminId)) { $showPrice = 0; } } //美婷鲜花批发,线上下单,不显示价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 73125) { if (!empty($orderInfo->customShopAdminId)) { $showPrice = 0; } } //淄博花超鲜花小票不带价格 if (isset($orderInfo->mainId) && $orderInfo->mainId == 16293) { $showPrice = 0; } } else { if (isset($orderInfo->mainId) && $orderInfo->mainId == 644) { //$showPrice = 0; } } if (isset($orderInfo['actPrice']) && $orderInfo['actPrice'] == 0 && $orderInfo['book'] == 0) { //全额退款了,也要能打小票 //util::fail('已全额退款,不能打小票'); } $showItem = OrderClass::getShowItem(true, $orderInfo); $customId = $orderInfo['customId'] ?? 0; $c = CustomClass::getById($customId); $balance = $c['balance'] ?? 0.00; $debtAmount = $balance < 0 ? abs($balance) : 0; $orderSn = $orderInfo['orderSn'] ?? ''; $shopId = $orderInfo['shopId'] ?? 0; $shop = ShopClass::getById($shopId, true); if (empty($shop)) { util::fail('打印失败,没有找到门店10'); } $sjId = $shop->sjId ?? 0; $fontSizeType = $shop->fontSize ?? 0; $telephone = $shop->telephone ?? ''; $telephone2 = $shop->telephone2 ?? ''; $sj = SjClass::getById($sjId, true); $sjName = $sj->name ?? ''; $shopName = $shop->shopName ?? ''; $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true); $printSn = $ext->printSn ?? ''; /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/ $orderMainId = $orderInfo['mainId'] ?? 0; if (getenv('YII_ENV') == 'production') { //东莞我要花不要自动打印标准,mainId=2644,已经去掉了 $map = [65726, 58, 25119, 28500, 1294, 12925, 83694]; } else { $map = [828,644]; } if (in_array($orderMainId, $map)) { self::printLogisticsLabel($orderInfo, $shop, $ext); } /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/ // $itemList = $showItem['list'] ?? []; // if (count($itemList) > 40) { // //超出数量的打印 // self::onlinePrintOver($showItem, $orderInfo, $currentName, $shop); // return true; // } $fromType = $orderInfo['fromType'] ?? dict::getDict('fromType', 'shop'); $fromTypeMap = dict::getDict('fromTypeMap'); $fromTypeName = $fromTypeMap[$fromType] ?? '门店'; $content = "" . $currentName . ""; $content .= "销售单

"; $respond = self::getPrintData($orderInfo, $debtAmount, $showItem); $content .= '' . $respond['sendNum'] . ' ' . $fromTypeName . '
'; $content .= '--------------------------------
'; //快捷开单不需要打印买家信息 if ($customId != $shop->skCustomId) { $content .= '买家信息:

'; $content .= '' . $respond['custom']['customName'] . '
'; if (isset($orderInfo->mainId) && $orderInfo->mainId == 62382) { //三明易批花非洲菊,比较特殊,不要带客户手机号 $content .= ''; } else { $content .= '' . $respond['custom']['customMobile'] . '
'; } if (isset($orderInfo['address']) && !empty($orderInfo['address'])) { $content .= $respond['custom']['fullAddress']; if (isset($orderInfo['showAddress']) && !empty($orderInfo['showAddress']) && $orderInfo['showAddress'] != $respond['custom']['fullAddress']) { $content .= '(' . $orderInfo['showAddress'] . ')
'; } else { $content .= '
'; } } } $payDate = date("Y-m-d", strtotime($orderInfo['payTime'])); $sendTimWant = $orderInfo['sendTimeWant'] ?? ''; if ($payDate != $sendTimWant) { $content .= '

'; $content .= '********************************
'; $content .= '注意! 送货时间
'; $content .= '【' . $orderInfo['sendTimeWant'] . '】'; $content .= '********************************


'; } if (isset($orderInfo['book']) && $orderInfo['book'] == 1) { $content .= '预订单
'; } if (isset($orderInfo['presell']) && $orderInfo['presell'] == 1) { $content .= '预售单
'; } if (isset($shop->pfLevel) && $shop->pfLevel == 1) { if (isset($orderInfo['transType'])) { $sendName = '同城配送'; if ($orderInfo['transType'] == 0) { $sendName = '德邦物流'; } if ($orderInfo['transType'] == 1) { $sendName = '顺丰物流'; } if ($orderInfo['transType'] == 2) { $sendName = '冷链物流'; } if ($orderInfo['transType'] == 3) { $sendName = '航空物流'; } if ($orderInfo['transType'] == 4) { $sendName = '同城配送'; } if ($orderInfo['transType'] == 5) { $sendName = '到店自取'; } $content .= '
' . $sendName . '
'; } } else { if (isset($orderInfo['sendType'])) { $sendName = '送货上门'; if ($orderInfo['sendType'] == 1) { $sendName = '到店自取'; } if ($orderInfo['sendType'] == 2) { $sendName = '跑腿送'; } if ($orderInfo['sendType'] == 3) { $wlName = $orderInfo['wlName'] ?? '未填物流'; $sendName = $wlName; } if ($orderInfo['sendType'] == 4) { $sendName = '发快递'; } $content .= '
' . $sendName . '
'; } } if (isset($respond['remark']) && !empty($respond['remark'])) { $content .= '
'; $content .= '备注:
'; $content .= '' . $respond['remark'] . '
'; } $content .= '
'; $content .= '商品 数量/单价 金额
'; $content .= '--------------------------------
'; if (isset($respond['product']) && !empty($respond['product'])) { foreach ($respond['product'] as $current) { $content = self::printGroup($current, $content, $showPrice, $fontSizeType); } } if (isset($respond['give']) && !empty($respond['give'])) { $content .= '
【赠送】
'; foreach ($respond['give'] as $current) { //58mm的机器,一行打印16个汉字,32个字母 $name = $current['name'] ?? ''; $count = $current['count'] ?? ''; if ($fontSizeType == 1) { $content .= '' . $name . ' ' . $count . '
'; } else { $content .= '' . $name . ' ' . $count . '
'; } $content .= '--------------------------------
'; } } $kindNum = $showItem['itemStat']['kind'] ?? 0; $bigNum = $showItem['itemStat']['bigNum'] ?? 0; $smallNun = $showItem['itemStat']['smallNun'] ?? 0; $content .= '********************************
'; $content .= "共{$kindNum}种 "; if ($bigNum > 0) { $content .= "{$bigNum}扎"; } if ($smallNun > 0) { $content .= "{$smallNun}支"; } $content .= ""; $content .= '********************************

'; if ($showPrice == 1) { if (isset($orderInfo['itemPrice']) && $orderInfo['itemPrice'] > 0) { $content .= '商品金额:' . floatval($orderInfo['itemPrice']) . '
'; } if (isset($respond['sendCost']) && $respond['sendCost'] > 0) { $content .= '跑腿费:' . floatval($respond['sendCost']) . '
'; } if (isset($orderInfo['packCost']) && $orderInfo['packCost'] > 0) { $content .= ' 打包费:' . floatval($orderInfo['packCost']) . '
'; } $content .= '合计金额:' . floatval($respond['prePrice']) . '
'; if (isset($respond['discountAmount']) && !empty($respond['discountAmount']) && $respond['discountAmount'] > 0) { $content .= '优惠扣除:-' . floatval($respond['discountAmount']) . '
'; } if (isset($orderInfo['book']) && $orderInfo['book'] == 1) { $content .= '预付金额:' . floatval($orderInfo['bookPrice']) . '
'; } if (isset($orderInfo['tkPrice']) && $orderInfo['tkPrice'] > 0) { $content .= '退款金额:' . floatval($orderInfo['tkPrice']) . '
'; } $content .= '金额:' . floatval($respond['realPrice']) . '
'; if (isset($respond['debt']) && $respond['debt'] == 1) { $content .= '实付金额:0
'; } else { $content .= '实付金额:' . floatval($respond['realPrice']) . '
'; } if ($debtAmount > 0) { $content .= '累计待结:' . floatval($debtAmount) . '
'; } $content .= '--------------------------------
'; } $getInfo = self::getById($orderInfo['id']); if (!empty($telephone)) { $content .= '联系电话:' . $telephone . '
'; } if (!empty($telephone2)) { $content .= '联系电话2:' . $telephone2 . '
'; } $content .= '订单日期:' . date("Y-m-d H:i", strtotime($getInfo['addTime'])) . '
'; $content .= '订单编号:' . $respond['orderSn'] . '
'; if (isset($orderInfo['shopAdminId']) && !empty($orderInfo['shopAdminId'])) { $content .= '本单由员工(' . $orderInfo['shopAdminName'] . ')开单
'; } else { $content .= '本单由客户(' . $orderInfo['customShopAdminName'] . ')下单
'; } $content .= "
"; $content .= "
"; $content .= "
"; if (!empty($printSn)) { $p = new printUtil($printSn); // onlinePrint 每次打印均写入飞鹅打印日志缓存 $logMeta = [ 'writeLog' => true, 'mainId' => intval($orderInfo['mainId'] ?? 0), 'orderId' => intval($orderInfo['id'] ?? 0), 'orderSn' => (string)$orderSn, 'printSn' => (string)$printSn, ]; $p->printMsg($content, $shop, $orderSn, $logMeta); } } //打印数据 ssh 20210702 public static function getPrintData($val, $debtAmount, $showItem) { $giveList = []; $printProduct = []; if (isset($showItem['list']) && !empty($showItem['list'])) { foreach ($showItem['list'] as $itemKey => $itemVal) { $bigNum = $itemVal['bigNum'] ?? 0; $bigUnitPrice = $itemVal['unitPrice'] ?? 0; $smallUnitPrice = $itemVal['smallUnitPrice'] ?? 0; $smallNum = $itemVal['smallNum'] ?? 0; $giveNum = $itemVal['giveNum'] ?? 0; $xhUnitName = $itemVal['xhUnitName'] ?? '扎'; $refundNum = $itemVal['refundNum'] ?? 0; $remark = $itemVal['remark'] ?? ''; if ($bigNum > 0) { $bigTotalPrice = bcmul($bigUnitPrice, $bigNum, 2); $printProduct[] = [ 'name' => $itemVal['name'] ?? '', 'num' => floatval($bigNum) . $xhUnitName . ' * ' . floatval($bigUnitPrice) . '元', 'count' => floatval($bigNum) . $xhUnitName, 'price' => floatval($bigTotalPrice), 'unitPrice' => floatval($bigUnitPrice), 'refundNum' => $refundNum, 'unitName' => $xhUnitName, 'itemNum' => $bigNum, 'remark' => $remark, 'ratioType' => $itemVal['ratioType'], 'ratio' => $itemVal['ratio'] ]; } if ($smallNum > 0) { $smallTotalPrice = bcmul($smallUnitPrice, $smallNum, 2); $printProduct[] = [ 'name' => $itemVal['name'] ?? '', 'num' => floatval($smallNum) . '支 * ' . floatval($smallUnitPrice) . '元', 'count' => floatval($smallNum) . '支', 'price' => floatval($smallTotalPrice), 'unitPrice' => floatval($smallUnitPrice), 'refundNum' => $refundNum, 'unitName' => '支', 'itemNum' => $smallNum, 'remark' => $remark, ]; } if ($giveNum > 0) { $giveList[] = [ 'name' => $itemVal['name'] ?? '', 'num' => floatval($giveNum) . $xhUnitName . ' * 0元', 'count' => floatval($giveNum) . $xhUnitName, 'price' => 0, 'unitPrice' => 0, 'unitName' => $xhUnitName, 'itemNum' => $giveNum, 'remark' => $remark, ]; } } } $sendNum = $val['sendNum'] ?? ''; $relateOrderSn = $val['orderSn'] ?? ''; $refundList = []; $refundData = RefundOrderClass::getAllByCondition(['relateOrderSn' => $relateOrderSn], null, '*', null, true); if (!empty($refundData)) { foreach ($refundData as $refund) { $refundOrderSn = $refund->orderSn ?? ''; $refundProductList = RefundOrderItemClass::getAllByCondition(['orderSn' => $refundOrderSn], null, '*'); if (!empty($refundProductList)) { foreach ($refundProductList as $currentRefund) { $num = $currentRefund['xhNum'] ?? 0; $unitName = $currentRefund['xhUnitName'] ?? ''; $unitPrice = $currentRefund['xhUnitPrice'] ?? 0; $currentPrice = bcmul($unitPrice, $num, 2); $refundList[] = [ 'name' => $currentRefund['name'] ?? '', 'num' => floatval($num) . $unitName . '*' . floatval($unitPrice), 'count' => floatval($num) . $unitName, 'price' => floatval($currentPrice), ]; } } } } $printData = [ 'address' => '', 'sendCost' => $val['sendCost'] ?? '0.00', 'prePrice' => $val['prePrice'] ?? '0.00', 'discountAmount' => $val['discountAmount'] ?? '0.00', 'realPrice' => $val['realPrice'] ?? '0.00', 'refundPrice' => $val['refundPrice'] ?? '0.00', 'debt' => $val['debt'] ?? 0, 'orderSn' => $val['orderSn'] ?? '', 'date' => $val['addTime'] ?? '', 'remark' => $val['remark'] ?? '', 'custom' => [ 'customName' => $val['customName'] ?? '', 'customMobile' => $val['customMobile'] ?? '', 'fullAddress' => $val['fullAddress'] ?? '', ], 'product' => $printProduct, 'refund' => $refundList, 'sendNum' => $sendNum, 'debtAmount' => $debtAmount, 'give' => $giveList, ]; return $printData; } //订单的验证 ssh 2021.3.2 public static function valid($info, $shopId) { if (empty($info)) { util::fail('没有找到订单'); } if (isset($info['shopId']) && $info['shopId'] == $shopId) { return true; } util::fail('无法操作的订单'); } //快递送 ssh 2021.3.16 public static function thirdSend($order, $expressInfo) { if ($order->status == self::ORDER_STATUS_UN_PAY) { util::fail('订单未付款'); } if ($order->status != self::ORDER_STATUS_UN_SEND) { util::fail('不是待配送状态'); } $id = $order->id; $expressId = $expressInfo['expressId'] ?? 1; $expressName = $expressInfo['deliveryName'] ?? '达达'; $expressRemark = $expressInfo['remark'] ?? ''; $order->status = self::ORDER_STATUS_SENDING; $order->sendType = self::SEND_TYPE_THIRD; $order->expressId = $expressId; $order->save(); $shopId = $order->shopId; $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one(); if (empty($shop)) { util::fail('没有找到门店11'); } $shop->unSendOrder -= 1; $shop->sendingOrder += 1; $shop->save(); $express = OrderExpressClass::getByCondition(['orderId' => $id]); if (!empty($express)) { util::fail('已经发过了'); } //达达 $dadaRes = DadaExpressServices::addOrder($order, $expressRemark); $orderSn = $order->orderSn; $sjId = $order->sjId ?? 0; /* $getInfo = ExpressClass::getExpressInfo($expressId); $hour = $expressInfo['sendTime'] ?? '12:00'; $sendCost = 12; $distance = 5; $sendTime = strtotime(date("Y-m-d ") . $hour); OrderSendClass::thirdSend($order); */ $sendTime = $order->sendTime; if ($sendTime == '0000-00-00 00:00:00') { $sendTime = time(); } else { $sendTime = strtotime($order->sendTime); } $expData = [ 'orderId' => $id, 'orderSn' => $orderSn, 'sjId' => $sjId, 'expressId' => $expressId, 'sendTime' => $sendTime, 'cost' => $dadaRes['fee'], 'distance' => $dadaRes['distance'], 'status' => 1, 'expressName' => $expressName, 'remark' => $expressRemark, ]; OrderExpressClass::addExpress($expData); OrderSendClass::thirdSend($order); $respond = [ 'expressName' => $expressName, 'expressId' => $expressId, 'distance' => $dadaRes['distance'], 'cost' => $dadaRes['fee'], 'status' => 2, 'tip' => 0, ]; //采购单变成已发货 $purchaseId = $order->purchaseId ?? 0; PurchaseClass::sending($purchaseId); return $respond; } //本店送 ssh 2021.1.24 public static function selfSend($info) { if ($info->status == self::ORDER_STATUS_UN_PAY) { util::fail('订单未付款'); } if ($info->status != self::ORDER_STATUS_UN_SEND) { util::fail('不是待配送状态'); } $info->status = self::ORDER_STATUS_SENDING; $info->sendType = self::SEND_TYPE_MYSELF; $info->save(); $shopId = $info->shopId; $shop = Shop::findBySql('select * from ' . Shop::tableName() . ' where id = :id for update', ['id' => $shopId])->one(); if (empty($shop)) { util::fail('没有找到门店12'); } $shop->unSendOrder -= 1; $shop->sendingOrder += 1; $shop->save(); OrderSendClass::selfSend($info); //采购单变成已发货 $purchaseId = $info->purchaseId ?? 0; PurchaseClass::sending($purchaseId); } //订单完成 ssh 2020.3.12 public static function complete($order, $shop) { $order->status = OrderClass::ORDER_STATUS_COMPLETE; $order->currentFlow = self::TOTAL_FLOW; $order->totalFlow = self::TOTAL_FLOW; $order->save(); $shop->finishOrder += 1; $shop->sendingOrder -= 1; $shop->save(); return $order; } //修改订单表的配送信息 lqh 2021.3.28 public static function updateCustomExpressInfo($id, $expressAddInfo) { $data = [ 'province' => $expressAddInfo['province'], 'city' => $expressAddInfo['city'], 'address' => $expressAddInfo['address'], 'floor' => $expressAddInfo['floor'], 'fullAddress' => $expressAddInfo['city'] . $expressAddInfo['address'] . $expressAddInfo['floor'], 'lat' => $expressAddInfo['lat'], 'long' => $expressAddInfo['long'], 'sendTime' => $expressAddInfo['sendTime'], ]; return self::updateById($id, $data); } //最客户最近的订单 ssh 2021.5.4 public static function getCustomOrder($id, $limit = 10, $order = null, $with = null) { $where = ['customId' => $id, 'payStatus' => 1]; return self::getLimitList('*', $where, $limit, $order, $with); } //销售单取消 ssh 2021.5.14 public static function cancel($id) { $order = self::getLockById($id); if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) { util::fail("销售单{$id}不是待付款状态,无法取消"); } $order->status = self::ORDER_STATUS_CANCEL; $order->cancelTime = date("Y-m-d H:i:s"); $order->save(); $shopId = $order->shopId; $shop = ShopClass::getLockById($shopId); if (empty($shop)) { util::fail('没有找到门店13'); } $mainId = $shop->mainId ?? 0; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有main信息6'); } $main->unPayOrder -= 1; $main->cancelOrder += 1; $main->save(); if ($order->book != 1) { //非预订单库存回滚 $orderItem = OrderItemClass::getOrderItem($order->orderSn); foreach ($orderItem as $v) { $stockInfo = ProductClass::addStockByItemNum($v['productId'], $v['num']); ProductClass::tryRecoverLimitBuyWhenStockRollbackFromZero($v['productId'], $stockInfo['oldStock']); $recordData = []; $recordData['sjId'] = $order->sjId; $recordData['shopId'] = $shopId; //增加中央ID $recordData['mainId'] = ProductClass::getMainIdByProductId($v['productId']); $recordData['itemId'] = $v['itemId'] ?? 0; $recordData['itemNum'] = $v['num']; $recordData['oldStock'] = $stockInfo['oldStock']; $recordData['newStock'] = $stockInfo['newStock']; $recordData['productId'] = $v['productId']; $recordData['orderSn'] = $order->orderSn; $recordData['relateName'] = $order->customName ?? ''; $recordData['ptStyle'] = dict::getDict('ptStyle', 'ghs'); StockRecordClass::addSellStockOrderCancelRecord($recordData); //如果有限购数量占用,也需要清除 $customId = $order->customId ?? 0; $num = floor($v['num']); ProductClass::baseClearLimitBuy($v['productId'], $customId, $num); } } return $order; } //新订单入队列 ssh 20211012 public static function newOrderAddQueue($order) { $shopId = $order->shopId ?? 0; if (empty($shopId)) { return false; } $id = $order->id ?? 0; if (empty($id)) { return false; } $newOrderKey = 'ghsNewOrder_' . $shopId; Yii::$app->redis->executeCommand('LPUSH', [$newOrderKey, $id]); } public static function createImgOrder($order, $shop, $staff, $all) { $staffName = $order->shopAdminName ?? ''; $shopName = $shop->shopName ?? ''; $sjName = $shop->merchantName ?? ''; $fullSjName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; $customName = $order->customName ?? ''; $customId = $order->customId ?? 0; $custom = CustomClass::getById($customId, true); $debtAmount = $custom->debtAmount ?? 0; $mainId = $order->mainId ?? 0; $dir = Yii::getAlias('@app/web/html/' . $mainId . '/'); if (!file_exists($dir)) { //检查是否有该文件夹,如果没有就创建,并给予最高权限 mkdir($dir, 0700, true); } $payTime = $order->payTime ?? ''; $currentDate = date("Y-m-d", strtotime($payTime)); $sameTimeIds = $order->sameTimeIds; $sameIds = []; if (!empty($sameTimeIds)) { $sameIds = explode(',', $sameTimeIds); } $sameNum = count($sameIds); if ($all == 1 && $sameNum > 1) { $orderList = OrderClass::getAllByCondition(['id' => ['in', $sameIds]], null, '*'); if (empty($orderList)) { return ['imgFile' => '']; } $itemList = []; $remainDebtPrice = 0; $actPrice = 0; $tkPrice = 0; foreach ($orderList as $currentOrder) { $orderSn = $currentOrder['orderSn'] ?? ''; $remainDebtPrice = bcadd($currentOrder['remainDebtPrice'], $remainDebtPrice, 2); $actPrice = bcadd($currentOrder['actPrice'], $actPrice, 2); $tkPrice = bcadd($tkPrice, $currentOrder['tkPrice'], 2); $itemData = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null); if (!empty($itemData)) { foreach ($itemData as $singleItem) { $productId = $singleItem['productId'] ?? 0; $unitPrice = $singleItem['xhUnitPrice'] ?? 0; $unitPrice = floatval($unitPrice); $xhNum = $singleItem['xhNum'] ?? 0; $refundNum = $singleItem['refundNum'] ?? 0; if (isset($itemList[$productId . '_' . $unitPrice])) { $currentInfo = $itemList[$productId . '_' . $unitPrice]; $thisNum = bcadd($currentInfo['xhNum'], $xhNum); $thisRefundNum = bcadd($currentInfo['refundNum'], $refundNum); $itemList[$productId . '_' . $unitPrice]['xhNum'] = $thisNum; $itemList[$productId . '_' . $unitPrice]['refundNum'] = $thisRefundNum; } else { $itemList[$productId . '_' . $unitPrice] = $singleItem; } } } } $itemList = array_values($itemList); $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2); $tkString = ''; if ($tkPrice > 0) { $tkString = "已退款:{$tkPrice}"; } } else { $orderSn = $order->orderSn ?? ''; $remainDebtPrice = $order->remainDebtPrice ?? 0; $beforeDebtPrice = bcsub($debtAmount, $remainDebtPrice, 2); $actPrice = $order->actPrice ?? 0; $tkPrice = $order->tkPrice ?? 0; $tkString = ''; if ($tkPrice > 0) { $tkString = "已退款:{$tkPrice}"; } $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], 'id asc', '*', null); } if (empty($itemList)) { return ['imgFile' => '']; } $balance = $custom->balance ?? 0; $balanceContent = ''; if ($balance > 0 && $balance > $debtAmount) { if ($debtAmount > 0 && $balance > $debtAmount) { $remainBalance = bcsub($balance, $debtAmount, 2); $balanceContent = '余额:' . $balance . ',最终余额:' . $remainBalance . ''; } else { $balanceContent = '余额:' . $balance . ''; } } if ($debtAmount >= $balance) { $debtAmount = bcsub($debtAmount, $balance, 2); } if ($beforeDebtPrice >= $balance) { $beforeDebtPrice = bcsub($beforeDebtPrice, $balance, 2); } $totalNum = 0; $totalAmount = 0; foreach ($itemList as $item) { $xhNum = $item['xhNum'] ?? 0; $refundNum = $item['refundNum'] ?? 0; $realNum = bcsub($xhNum, $refundNum); $unitPrice = $item['xhUnitPrice'] ?? 0; $amount = bcmul($realNum, $unitPrice, 2); $totalNum = bcadd($totalNum, $realNum); $totalAmount = bcadd($totalAmount, $amount, 2); } $totalAmount = floatval($totalAmount); $itemList[] = ['xhNum' => $totalNum, 'totalAmount' => $totalAmount,]; $content = << XL; $total = count($itemList); $pageSize = 14; $totalPage = ceil($total / $pageSize); for ($page = 1; $page <= $totalPage; $page++) { $start = ($page - 1) * $pageSize; $currentList = array_slice($itemList, $start, $pageSize); if (!empty($currentList)) { $tableList = ''; foreach ($currentList as $key => $item) { $index = bcadd($key, $start); $index++; $name = $item['name'] ?? ''; $num = $item['xhNum']; $refundNum = $item['refundNum'] ?? 0; $realNum = bcsub($num, $refundNum); $bigUnit = $item['xhUnitName'] ?? ''; $unitPrice = $item['xhUnitPrice'] ?? 0; $unitPrice = floatval($unitPrice); $amount = bcmul($realNum, $unitPrice, 2); $amount = floatval($amount); if ($name == '') { $index = '合计'; $amount = $item['totalAmount'] ?? 0; } $remark = $item['remark'] ?? ''; $tableList .= ""; $tableList .= "{$index}"; $tableList .= "{$name}"; $tableList .= "{$realNum}"; $tableList .= "{$bigUnit}"; $tableList .= "{$unitPrice}"; $tableList .= "{$amount}"; $tableList .= "{$remark}"; $tableList .= ""; } $content .= <<
{$fullSjName}
销售单
单据日期:{$currentDate} 开单:{$staffName} 客户:{$customName} 编号:{$orderSn}
{$tableList}
编号 名称 数量 单位 单价 金额 备注
{$tkString} 本单:{$actPrice} 上次欠款:{$beforeDebtPrice} 待付欠款:{$debtAmount} {$balanceContent}
请在收到货后12小时以内验货,超12小时概不负责!
XL; } } $content .= << XL; $file = $dir . $orderSn . '.html'; $imgFile = $dir . $orderSn . '.png'; if (file_exists($file)) { unlink($file); } if (file_exists($imgFile)) { unlink($imgFile); } file_put_contents($file, $content); $con = new Converter(null, [ "fmt" => "png", "in" => $file, "out" => $imgFile, ]); $con->convert(); return ['imgFile' => $imgFile]; } //应收统计下载 ssh 20240530 public static function exportAccountList($list, $mainId) { $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/"); require_once($phpExcelFile . 'Classes/PHPExcel.php'); $objPHPExcel = new \PHPExcel(); $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Document") ->setSubject("Office 2007 XLSX Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("file"); $ghsTitle = '供货商'; $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle); $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7); $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5); $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0); $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID'); $objPHPExcel->getActiveSheet()->setCellValue('B1', '名称'); $objPHPExcel->getActiveSheet()->setCellValue('C1', '金额'); $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数'); //设置宽度 $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20); //加粗 $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $baseRow = 2; foreach ($list as $key => $custom) { $i = $baseRow + $key; $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']); $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']); $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['amount']); $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']); //居左 $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); } $fileName = '应收统计-' . date("m-d"); $objPHPExcel->getActiveSheet()->setTitle($fileName); $objPHPExcel->setActiveSheetIndex(0); $dir = './priceTable/' . $mainId; if (file_exists($dir) == false) { mkdir($dir, 0777, true); } $date = $fileName; $file = $date . '.xls'; $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); if (file_exists($dir . '/' . $file)) { unlink($dir . '/' . $file); } $objWriter->save($dir . '/' . $file); $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file; util::success(['file' => $fileUrl, 'shortFile' => $file]); } //应收统计下载 ssh 20240530 public static function exportPastList($list, $mainId) { $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/"); require_once($phpExcelFile . 'Classes/PHPExcel.php'); $objPHPExcel = new \PHPExcel(); $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Document") ->setSubject("Office 2007 XLSX Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("file"); $ghsTitle = '供货商'; $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle); $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7); $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5); $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0); $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID'); $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户'); $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号'); $objPHPExcel->getActiveSheet()->setCellValue('D1', '欠款金额'); //设置宽度 $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(25); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20); //加粗 $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $baseRow = 2; foreach ($list as $key => $custom) { $i = $baseRow + $key; $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']); $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']); $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']); $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['currentDebAmount']); //居左 $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); } $fileName = '历史应收-' . date("m-d"); $objPHPExcel->getActiveSheet()->setTitle($fileName); $objPHPExcel->setActiveSheetIndex(0); $dir = './priceTable/' . $mainId; if (file_exists($dir) == false) { mkdir($dir, 0777, true); } $date = $fileName; $file = $date . '.xls'; $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); if (file_exists($dir . '/' . $file)) { unlink($dir . '/' . $file); } $objWriter->save($dir . '/' . $file); $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file; util::success(['file' => $fileUrl, 'shortFile' => $file]); } public static function exportYj($list, $mainId) { $phpExcelFile = Yii::getAlias("@vendor/phpoffice/phpexcel/"); require_once($phpExcelFile . 'Classes/PHPExcel.php'); $objPHPExcel = new \PHPExcel(); $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Document") ->setSubject("Office 2007 XLSX Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("file"); $ghsTitle = '供货商'; $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader(date('n月j日') . " " . $ghsTitle); $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(0.7); $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.5); $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0); $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader(0.1); $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID'); $objPHPExcel->getActiveSheet()->setCellValue('B1', '客户'); $objPHPExcel->getActiveSheet()->setCellValue('C1', '手机号'); $objPHPExcel->getActiveSheet()->setCellValue('D1', '订单数'); $objPHPExcel->getActiveSheet()->setCellValue('E1', '订单金额'); $objPHPExcel->getActiveSheet()->setCellValue('F1', '退款金额'); $objPHPExcel->getActiveSheet()->setCellValue('G1', '实际金额'); $objPHPExcel->getActiveSheet()->setCellValue('H1', '纸箱费'); $objPHPExcel->getActiveSheet()->setCellValue('I1', '打包费'); $objPHPExcel->getActiveSheet()->setCellValue('J1', '运费'); //设置宽度 $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20); //加粗 $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('B1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('C1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('D1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('E1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('F1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('G1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('H1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('I1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('J1')->getFont()->setSize(9)->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('E1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('G1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('H1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('I1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('J1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $baseRow = 2; foreach ($list as $key => $custom) { $i = $baseRow + $key; $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $custom['id']); $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $custom['name']); $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, $custom['mobile']); $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $custom['num']); $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $custom['orderPrice']); $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, $custom['tkPrice']); $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, $custom['actPrice']); $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $custom['carton']); $objPHPExcel->getActiveSheet()->setCellValue('I' . $i, $custom['pack']); $objPHPExcel->getActiveSheet()->setCellValue('J' . $i, $custom['freight']); //居左 $objPHPExcel->getActiveSheet()->getStyle('A' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('B' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('C' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('D' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('E' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('F' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('G' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('H' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('I' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('J' . $i)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); } $fileName = '客户业绩-' . date("m-d"); $objPHPExcel->getActiveSheet()->setTitle($fileName); $objPHPExcel->setActiveSheetIndex(0); $dir = './priceTable/' . $mainId; if (file_exists($dir) == false) { mkdir($dir, 0777, true); } $date = $fileName; $file = $date . '.xls'; $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); if (file_exists($dir . '/' . $file)) { unlink($dir . '/' . $file); } $objWriter->save($dir . '/' . $file); $fileUrl = Yii::$app->params['ghsHost'] . '/priceTable/' . $mainId . '/' . $file; util::success(['file' => $fileUrl, 'shortFile' => $file]); } public static function printLogisticsLabel($order, $shop, $ext) { /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/ $orderMainId = $order->mainId; if (getenv('YII_ENV') == 'production') { $map = [65726, 58, 25119, 28500, 1294, 12925, 2644, 10652, 2084, 89473, 83694]; } else { $map = [828,644]; } /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/ $customId = $order->customId ?? 0; $custom = CustomClass::getById($customId, true); if (empty($custom)) { if (!in_array($orderMainId, $map)) { util::fail('没有找到客户'); } else { return false; } } $shortName = $custom->shortName ?? '未命名'; $shortName = stringUtil::subStringUtf8($shortName, 5); $customMobile = $order->customMobile ?? ''; if (empty($customMobile)) { if (!in_array($orderMainId, $map)) { util::fail('客户手机号无效'); } else { return false; } } //东莞我要花 手机后四号变星号 if (in_array((int)$orderMainId, [2644, 10652, 89473], true)) { $customMobile = preg_replace('/(.{4})$/u', '****', trim($customMobile)); } $customName = $order->customName ?? ''; $remark = $order->remark ?? ''; $shortRemark = stringUtil::subStringUtf8($remark, 8); $wlName = $custom->wlName ?? ''; if (empty($wlName)) { $wlName = $shortRemark; } $distId = $custom->distId ?? ''; $dist = DistClass::getById($distId, true); $distName = $dist->name ?? '未分区'; $address = $order->address ?? ''; $floor = $order->floor ?? ''; $fullAddress = $address . $floor; $showAddress = $order->showAddress ?? ''; $shopName = $shop->shopName ?? ''; $sjName = $shop->merchantName; $currentName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; $telephone = $shop->telephone ?? ''; $wlLabelSn = $ext->wlLabelSn ?? ''; if (empty($wlLabelSn)) { if (!in_array($orderMainId, $map)) { util::fail('请绑定物流标签机'); } else { return false; } } $p = new printUtil($wlLabelSn); if (!in_array($orderMainId, $map)) { $p->times = 1; //安庆三叶鲜花批发,比较特殊 if ($orderMainId == 2071) { $content = '' . $shortName . ''; $content .= '地址'; $content .= '' . $customMobile . ''; $content .= '号码'; $content .= '' . $wlName . ''; $content .= '物流'; $content .= '' . $currentName . ' ' . $telephone . ''; } else { $content = '' . $shortName . ''; $content .= '地址'; $content .= '' . $customMobile . ''; $content .= '号码'; $content .= '' . $wlName . ''; $content .= '物流'; $content .= '' . $currentName . ' ' . $telephone . ''; } } else { /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/ $sameTimeIds = $order->sameTimeIds; $num = 1; if (!empty($sameTimeIds)) { $ids = explode(',', $sameTimeIds); if (!empty($ids)) { $num = count($ids); } } if ($num > 1) { $customName = $customName . ' 共' . $num . '单'; } $itemNum = $order->itemNum ?? 0; $itemNum = floatval($itemNum); $payTime = $order->payTime ?? ''; $payDate = date('m-d H:i', strtotime($payTime)); $content = '' . $customName . ''; // 地址超过15个字,字体大小(w和h)变小一级(由 w="2" h="2" 变为 w="1" h="1") $addressLen = mb_strlen($fullAddress, 'UTF-8'); $fontScale = '2'; $content .= '' . $fullAddress . ''; if(!empty($showAddress)){ $content .= '' . $showAddress . ''; } $content .= '' . $customMobile . ' ' . $itemNum . '扎'; $content .= '' . $distName . ' ' . $payDate . ''; /**************************如果是好多花的云仓还要再打一下标签纸,多处要同步修改,关键词 hdh_yc *****************************/ } $p->printLabelMsg($content); if (is_object($order) && method_exists($order, 'save')) { $order->printWlNum = intval($order->printWlNum ?? 0) + 1; $order->save(); } return true; } //打印花材的物流标 ssh 20260507 public static function printItemLabel($order, $shop, $ext, $product, $num, $boxNum, $orderItem) { $customId = $order->customId ?? 0; $custom = CustomClass::getById($customId, true); $customMobile = $order->customMobile ?? ''; $customName = $order->customName ?? ''; $remark = $order->remark ?? ''; $shortRemark = stringUtil::subStringUtf8($remark, 8); $wlName = $custom->wlName ?? ''; if (empty($wlName)) { $wlName = $shortRemark; } $distId = $custom->distId ?? ''; $dist = DistClass::getById($distId, true); $distName = $dist->name ?? '未分区'; $address = $order->address ?? ''; $floor = $order->floor ?? ''; $fullAddress = $address . $floor; $wlLabelSn = $ext->wlLabelSn ?? ''; if (empty($wlLabelSn)) { util::fail('请绑定物流标签机'); } $p = new printUtil($wlLabelSn); $p->times = $num; $sameTimeIds = $order->sameTimeIds; $num = 1; if (!empty($sameTimeIds)) { $ids = explode(',', $sameTimeIds); if (!empty($ids)) { $num = count($ids); } } if ($num > 1) { $customName = $customName . ' ' . $num . '单'; } $remark = ''; if (!empty($orderItem->remark)) { $remark .= $orderItem->remark; } if (!empty($order->remark)) { if (!empty($remark)) { $remark .= ' ' . $order->remark; } else { $remark .= $order->remark; } } $productName = $product->name ?? ''; $content = '' . $productName . ' 装箱数:' . $boxNum . ''; $content .= '————————————————————'; $content .= '客户:' . $customName . ''; $content .= '地址:' . $fullAddress . ''; $content .= '电话:' . $customMobile . ''; $content .= '备注:' . $remark . ''; $p->printLabelMsg($content); return true; } //更新客户同一天的订单 $update 0 添加 1 修改 public static function updateMergeOrder($order, $update = 0) { $date = substr($order->payTime, 0, 10); $customId = $order->customId ?? 0; $mainId = $order->mainId ?? 0; $orderId = $order->id ?? 0; //找到当前订单客户的账单日期为 $date 的所有订单 $startTime = $date . ' 00:00:00'; $endTime = $date . ' 23:59:59'; $dayOrders = self::getAllByCondition([ 'mainId' => $mainId, 'customId' => $customId, 'payTime' => ['between', [$startTime, $endTime]] ], 'id ASC', 'id'); if (empty($dayOrders)) { return false; } $ids = array_column($dayOrders, 'id'); $count = count($ids); if ($update == 0) { if ($count <= 1) { //新增,如果当天只有一个订单,不需要操作 return false; } $hasMerge = OrderMergeSnClass::getByCondition(['customId' => $customId, 'mergeDate' => $date], true); if (!empty($hasMerge)) { $hasMergeId = $hasMerge->id ?? 0; $order->mergeId = $hasMergeId; $order->save(); OrderMergeClass::add(['mergeId' => $hasMergeId, 'orderId' => $orderId, 'mergeDate' => $date, 'customId' => $customId, 'mainId' => $mainId]); self::syncOrderMergeNumForMergeId($hasMergeId); PurchaseClass::syncMergeRelationByOrderIds([$orderId]); } else { self::rebuildOrderMergeGroupForDay($ids, $date, $customId, $mainId); } } else { //修改账单日:订单 payTime 已在调用方改为新日 $date $oldMergeId = (int)($order->mergeId ?? 0); if ($oldMergeId > 0) { $oldMergeSn = OrderMergeSnClass::getById($oldMergeId, true); if (empty($oldMergeSn)) { // 订单仍挂着 mergeId,但主档已不存在,避免后续报错并清理脏数据 $order->mergeId = 0; $order->mergeNum = 0; $order->save(); } else { $oldDate = $oldMergeSn->mergeDate ?? ''; if ($oldDate == $date) { //合并组账单日与当前一致,无需调整 return false; } $oldMergeList = OrderMergeClass::getAllByCondition(['mergeId' => $oldMergeId], null, '*', null, true); if (count($oldMergeList) <= 2) { //合并组内至多 2 单:整组 dissolve(与原先「只剩一单合并无意义」一致) $oldMergeSn->delete(); $del = []; foreach ($oldMergeList as $mergeRow) { $del[] = $mergeRow->orderId; $mergeRow->delete(); } self::updateByIds($del, ['mergeId' => 0, 'mergeNum' => 0]); } else { $order->mergeId = 0; $order->mergeNum = 0; $order->save(); OrderMergeClass::deleteByCondition(['mergeId' => $oldMergeId, 'orderId' => $orderId]); self::syncOrderMergeNumForMergeId($oldMergeId); } } } $hasNewMerge = OrderMergeSnClass::getByCondition(['customId' => $customId, 'mergeDate' => $date], true); if (!empty($hasNewMerge)) { $newMergeId = $hasNewMerge->id ?? 0; $order->mergeId = $newMergeId; $order->save(); OrderMergeClass::add(['mergeId' => $newMergeId, 'orderId' => $orderId, 'mergeDate' => $date, 'customId' => $customId, 'mainId' => $mainId]); self::syncOrderMergeNumForMergeId($newMergeId); PurchaseClass::syncMergeRelationByOrderIds([$orderId]); } else { self::rebuildOrderMergeGroupForDay($ids, $date, $customId, $mainId); } } return true; } /** * 指定客户、某日多单:新建合并主档,回写订单 mergeId,并批量写入 xhGhsOrderMerge。 * * @param int[] $ids 当日同客户订单 id 列表 */ private static function rebuildOrderMergeGroupForDay(array $ids, $date, $customId, $mainId) { $mergeData = ['mergeDate' => $date, 'customId' => $customId, 'mainId' => $mainId]; $mergeId = orderSn::getGhsOrderMergeId($mergeData); $mergeNum = count($ids); self::updateByIds($ids, ['mergeId' => $mergeId, 'mergeNum' => $mergeNum]); $addData = []; foreach ($ids as $currentId) { $addData[] = ['mergeId' => $mergeId, 'orderId' => $currentId, 'mergeDate' => $date, 'customId' => $customId, 'mainId' => $mainId]; } OrderMergeClass::batchAdd($addData); PurchaseClass::syncMergeRelationByOrderIds($ids); } /** 按 xhGhsOrderMerge 明细数量,回写该合并组内所有订单的 mergeNum */ private static function syncOrderMergeNumForMergeId($mergeId) { $mergeId = (int)$mergeId; if ($mergeId <= 0) { return; } $rows = OrderMergeClass::getAllByCondition(['mergeId' => $mergeId], null, 'orderId', null, true); $mergeNum = count($rows); if ($mergeNum === 0) { return; } $orderIds = []; foreach ($rows as $row) { $orderIds[] = (int)(is_object($row) ? ($row->orderId ?? 0) : ($row['orderId'] ?? 0)); } $orderIds = array_values(array_filter($orderIds)); if (!empty($orderIds)) { self::updateByIds($orderIds, ['mergeNum' => $mergeNum]); } } // 更新同天内的所有订单的 sameTimeIds public static function updateSameTimeIds($order, $date) { $id = $order->id ?? 0; $customId = $order->customId ?? 0; $mainId = $order->mainId ?? 0; $oldSameTimeIds = $order->sameTimeIds ?? ''; //找到当前订单客户的账单日期为 $date 的所有订单,然后更新同天内的所有订单的 sameTimeIds(加此次要改变的订单的订单号$id) $startTime = $date . ' 00:00:00'; $endTime = $date . ' 23:59:59'; $dayOrders = self::getAllByCondition([ 'mainId' => $mainId, 'customId' => $customId, 'payTime' => ['between', [$startTime, $endTime]] ], 'id ASC', 'id, sameTimeIds'); $ids = []; if (!empty($dayOrders)) { $ids = array_column($dayOrders, 'id'); } // 确保当前订单ID在列表中 if (!in_array($id, $ids)) { $ids[] = $id; } // 排序并去重 sort($ids); $ids = array_unique($ids); // 限制最多 90 单,避免 someTimeIds 过长(兼容原先业务逻辑限制) if (count($ids) > 90) { $ids = array_slice($ids, 0, 90); } $sameTimeIdsStr = implode(',', $ids); // 更新所有相关订单 if (!empty($ids) && in_array($id, $ids)) { self::updateByIds($ids, ['sameTimeIds' => $sameTimeIdsStr]); } //从原先同天内的订单中删除此次要改变的订单的订单号$id if (!empty($oldSameTimeIds) && $oldSameTimeIds != $sameTimeIdsStr) { $oldSameTimeIdsArr = explode(',', $oldSameTimeIds); if (in_array($id, $oldSameTimeIdsArr)) { $oldSameTimeIdsArr = array_diff($oldSameTimeIdsArr, [$id]); $oldSameTimeIdsStr = implode(',', $oldSameTimeIdsArr); if (!empty($oldSameTimeIdsArr)) { self::updateByIds($oldSameTimeIdsArr, ['sameTimeIds' => $oldSameTimeIdsStr]); } } } //noticeUtil::push("orderIds = {$sameTimeIdsStr}, sameTimeIdsStr: {$sameTimeIdsStr}"); } }