onlineEnterpriseId = $onlineEnterpriseId; $this->onlineUserId = $onlineUserId; $this->objCloudPrint = new CloudPrint(); } /** * @param int $id * @param int $type * @return ResultWrapper * @throws \Exception */ public function toPrint(int $id,int $type) { //1.单据信息 $objectInfo = self::objectInfo($id,$type); if (!$objectInfo->isSuccess()){ return ResultWrapper::fail($objectInfo->getData(),$objectInfo->getErrorCode()); } $objectInfo = $objectInfo->getData(); //2.转化格式封装数据 $pattern = (new MReceiptAdapter)->arrayToPattern($objectInfo,$type); //3.调用打印服务 $result = $this->objCloudPrint->sendMsg($pattern,$this->onlineEnterpriseId); if (!$result->isSuccess()){ file_put_contents('/www/wwwroot/logs/api.junhailan.com/MReceipt_error.log', date('Y-m-d H:i:s') . '错误原因: ' . $result->getData(). PHP_EOL, FILE_APPEND); return ResultWrapper::fail('打印失败,'.$result->getData(),ErrorCode::$paramError); } return ResultWrapper::success("操作成功"); } /** * 获取打印单据的信息 * @param int $id * @param int $type * @return ResultWrapper * @throws \Exception */ public function objectInfo(int $id,int $type) { $dbResult = false; switch ($type){ case StatusCode::$orderType['salesSlip']: //销售单 $objMOrder = new MOrder($this->onlineUserId,$this->onlineEnterpriseId); $dbResult = $objMOrder->getOrderInfoById($id); break; case StatusCode::$orderType['saleOrder']: //订单单 $objMOrder = new MOrder($this->onlineUserId,$this->onlineEnterpriseId); $dbResult = $objMOrder->getOrderInfoById($id); break; default: return ResultWrapper::fail("尚未完善。。。",ErrorCode::$paramError); break; } if (!$dbResult->isSuccess()){ return ResultWrapper::fail($dbResult->getData(),$dbResult->getErrorCode()); } return ResultWrapper::success($dbResult->getData()); } }