CloudPrint.Class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: phperstar
  5. * Date: 2020/6/17
  6. * Time: 4:07 PM
  7. */
  8. namespace JinDouYun\Controller\Common;
  9. use Jindouyun\Cache\EnterpriseCache;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use Mall\Framework\Factory;
  13. use JinDouYun\Controller\BaseController;
  14. use Util\CloudPrint\Gainshca;
  15. use Util\CloudPrint\Feie;
  16. class CloudPrint extends BaseController
  17. {
  18. private $objEnterpriseCache;
  19. public function __construct($isCheckAcl = false, $isMustLogin = false, $checkToken = true)
  20. {
  21. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  22. }
  23. /**
  24. * 佳博打印机添加设备
  25. */
  26. public function adddev()
  27. {
  28. //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
  29. $gainshcaConfigData = self::getConfig();
  30. if(empty($gainshcaConfigData)){
  31. $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
  32. }
  33. $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
  34. $result = $objGainshca->adddev();
  35. if ($result->isSuccess()) {
  36. parent::sendOutput($result->getData());
  37. } else {
  38. parent::sendOutput($result->getData(), $result->getErrorCode());
  39. }
  40. }
  41. /**
  42. * 由于此方法在model层调用,所以传递一个企业id
  43. * @param $msgDetail
  44. * @param $onlineEnterpriseId
  45. */
  46. public function sendMsg($msgDetail,$onlineEnterpriseId)
  47. {
  48. $this->onlineEnterpriseId = $onlineEnterpriseId;
  49. //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
  50. $gainshcaConfigData = self::getConfig();
  51. if(empty($gainshcaConfigData)){
  52. $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
  53. }
  54. $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
  55. $result = $objGainshca->sendMsg($msgDetail);
  56. if ($result->isSuccess()) {
  57. return ResultWrapper::success('success');
  58. //parent::sendOutput($result->getData());
  59. } else {
  60. return ResultWrapper::fail($result->getData(),$result->getErrorCode());
  61. //parent::sendOutput($result->getData(), $result->getErrorCode());
  62. }
  63. }
  64. /**
  65. * 查询打印机设备
  66. * return deviceID设备id online在线状态(0离线1在线) status状态(1正常 2缺纸 3其他异常 4过热 5开盖 8暂停 9打印中) outtime最后一次离线时间 printnum累计打印次数
  67. * @param bool $deviceID //打印机id
  68. * @param bool $selectAll //是否查询所有打印机
  69. */
  70. public function getStatus($deviceID = false, $selectAll = false)
  71. {
  72. //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
  73. $gainshcaConfigData = self::getConfig();
  74. if(empty($gainshcaConfigData)){
  75. $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
  76. }
  77. $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
  78. $result = $objGainshca->getStatus($deviceID, $selectAll);
  79. if ($result->isSuccess()) {
  80. parent::sendOutput($result->getData());
  81. } else {
  82. parent::sendOutput($result->getData(), $result->getErrorCode());
  83. }
  84. }
  85. /**
  86. * 设置打印机音量
  87. * @param $num
  88. */
  89. public function setVolume($num)
  90. {
  91. //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
  92. $gainshcaConfigData = self::getConfig();
  93. if(empty($gainshcaConfigData)){
  94. $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
  95. }
  96. $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
  97. $result = $objGainshca->setVolume($num);
  98. if ($result->isSuccess()) {
  99. parent::sendOutput($result->getData());
  100. } else {
  101. parent::sendOutput($result->getData(), $result->getErrorCode());
  102. }
  103. }
  104. /**
  105. * 获取打印机配置项
  106. * @return array
  107. */
  108. public function getConfig()
  109. {
  110. $objEnterpriseCache = new EnterpriseCache();
  111. $cache = $objEnterpriseCache->getEnterpriseSetting($this->onlineEnterpriseId);
  112. if (empty($cache)){
  113. return [];
  114. }
  115. return [
  116. 'memberCode' => isset($cache['memberCode']) ? $cache['memberCode'] : '',
  117. 'deviceID' => isset($cache['deviceID']) ? $cache['deviceID'] : '',
  118. 'apiKey' => isset($cache['apiKey']) ? $cache['apiKey'] : '',
  119. ];
  120. }
  121. /**************************************飞鹅打印机 *******************************************/
  122. /**
  123. * 添加打印机
  124. */
  125. public function addFeieDev()
  126. {
  127. $objFeie = new Feie('930534909', '8gh4jctw');
  128. $result = $objFeie->adddev();
  129. if(!$result->isSuccess()){
  130. parent::sendOutput($result->getData());
  131. } else {
  132. parent::sendOutput($result->getData(), $result->getErrorCode());
  133. }
  134. }
  135. /**
  136. * 发送打印机信息
  137. * @param $params
  138. */
  139. public function feieSendMsg($params)
  140. {
  141. $objFeie = new Feie('930534909', '8gh4jctw');
  142. $result = $objFeie->sendMsg($params);
  143. if(!$result->isSuccess()){
  144. parent::sendOutput($result->getData());
  145. } else {
  146. parent::sendOutput($result->getData(), $result->getErrorCode());
  147. }
  148. }
  149. }