Receipt.Class.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace JinDouYun\Controller\Common;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Model\System\MReceipt;
  5. use Mall\Framework\Core\ErrorCode;
  6. /**
  7. * 小票打印
  8. * Class Receipt
  9. * @package JinDouYun\Controller\Common
  10. */
  11. class Receipt extends BaseController
  12. {
  13. /**
  14. * @var MReceipt
  15. */
  16. private $objMReceipt;
  17. /**
  18. * Receipt constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @param bool $checkToken
  22. * @param bool $getAreaCode
  23. */
  24. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true, $getAreaCode = false)
  25. {
  26. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode);
  27. $this->objMReceipt = new MReceipt($this->onlineEnterpriseId,$this->onlineUserId);
  28. }
  29. /**
  30. * 公共参数
  31. */
  32. public function commonFieldFilter()
  33. {
  34. $params = $this->request->getRawJson();
  35. if(empty($params)){
  36. $this->sendOutput('参数为空', ErrorCode::$paramError );
  37. }
  38. $data = [
  39. 'objectId' => isset($params['objectId']) ? $params['objectId'] : null,
  40. 'objectType' => isset($params['objectType']) ? $params['objectType'] : null
  41. ];
  42. foreach($data as $key => $value){
  43. if(empty($value)){
  44. parent::sendOutput($key.'参数错误', ErrorCode::$paramError );
  45. }
  46. }
  47. return $data;
  48. }
  49. /**
  50. * 打印小票
  51. * @throws \Exception
  52. */
  53. public function toPrint()
  54. {
  55. $data = self::commonFieldFilter();
  56. $result = $this->objMReceipt->toPrint($data['objectId'],$data['objectType']);
  57. if($result->isSuccess()){
  58. parent::sendOutput('操作成功');
  59. }
  60. parent::sendOutput($result->getData(), $result->getErrorCode());
  61. }
  62. }