123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- /**
- * Created by PhpStorm.
- * User: phperstar
- * Date: 2020/6/17
- * Time: 4:07 PM
- */
- namespace JinDouYun\Controller\Common;
- use Jindouyun\Cache\EnterpriseCache;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Factory;
- use JinDouYun\Controller\BaseController;
- use Util\CloudPrint\Gainshca;
- use Util\CloudPrint\Feie;
- class CloudPrint extends BaseController
- {
- private $objEnterpriseCache;
- public function __construct($isCheckAcl = false, $isMustLogin = false, $checkToken = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
- }
- /**
- * 佳博打印机添加设备
- */
- public function adddev()
- {
- //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
- $gainshcaConfigData = self::getConfig();
- if(empty($gainshcaConfigData)){
- $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
- }
- $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
- $result = $objGainshca->adddev();
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 由于此方法在model层调用,所以传递一个企业id
- * @param $msgDetail
- * @param $onlineEnterpriseId
- */
- public function sendMsg($msgDetail,$onlineEnterpriseId)
- {
- $this->onlineEnterpriseId = $onlineEnterpriseId;
- //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
- $gainshcaConfigData = self::getConfig();
- if(empty($gainshcaConfigData)){
- $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
- }
- $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
- $result = $objGainshca->sendMsg($msgDetail);
- if ($result->isSuccess()) {
- return ResultWrapper::success('success');
- //parent::sendOutput($result->getData());
- } else {
- return ResultWrapper::fail($result->getData(),$result->getErrorCode());
- //parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 查询打印机设备
- * return deviceID设备id online在线状态(0离线1在线) status状态(1正常 2缺纸 3其他异常 4过热 5开盖 8暂停 9打印中) outtime最后一次离线时间 printnum累计打印次数
- * @param bool $deviceID //打印机id
- * @param bool $selectAll //是否查询所有打印机
- */
- public function getStatus($deviceID = false, $selectAll = false)
- {
- //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
- $gainshcaConfigData = self::getConfig();
- if(empty($gainshcaConfigData)){
- $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
- }
- $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
- $result = $objGainshca->getStatus($deviceID, $selectAll);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 设置打印机音量
- * @param $num
- */
- public function setVolume($num)
- {
- //$gainshcaConfigData = Factory::config()->getAppoint('cloudPrint','gainshca');
- $gainshcaConfigData = self::getConfig();
- if(empty($gainshcaConfigData)){
- $this->sendOutput('小程序配置项错误',ErrorCode::$configEroor);
- }
- $objGainshca = new Gainshca($gainshcaConfigData['memberCode'], $gainshcaConfigData['deviceID'], $gainshcaConfigData['apiKey']);
- $result = $objGainshca->setVolume($num);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取打印机配置项
- * @return array
- */
- public function getConfig()
- {
- $objEnterpriseCache = new EnterpriseCache();
- $cache = $objEnterpriseCache->getEnterpriseSetting($this->onlineEnterpriseId);
- if (empty($cache)){
- return [];
- }
- return [
- 'memberCode' => isset($cache['memberCode']) ? $cache['memberCode'] : '',
- 'deviceID' => isset($cache['deviceID']) ? $cache['deviceID'] : '',
- 'apiKey' => isset($cache['apiKey']) ? $cache['apiKey'] : '',
- ];
- }
- /**************************************飞鹅打印机 *******************************************/
- /**
- * 添加打印机
- */
- public function addFeieDev()
- {
- $objFeie = new Feie('930534909', '8gh4jctw');
- $result = $objFeie->adddev();
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 发送打印机信息
- * @param $params
- */
- public function feieSendMsg($params)
- {
- $objFeie = new Feie('930534909', '8gh4jctw');
- $result = $objFeie->sendMsg($params);
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|