123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace JinDouYun\Model\System;
- use JinDouYun\Controller\Common\CloudPrint;
- use JinDouYun\Model\Order\MOrder;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- /**
- * 单据打印小票
- * Class MReceiptService
- * @package JinDouYun\Model\System
- */
- class MReceipt
- {
- /**
- * @var integer 企业id
- */
- private $onlineEnterpriseId;
- /**
- * @var integer 用户id
- */
- private $onlineUserId;
- /**
- * @var CloudPrint 小票云打印
- */
- private $objCloudPrint;
- /**
- * MReceiptService constructor.
- * @param $onlineEnterpriseId
- * @param $onlineUserId
- */
- public function __construct($onlineEnterpriseId,$onlineUserId)
- {
- $this->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());
- }
- }
|