102 lines
2.6 KiB
PHP
102 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Admin\Catering\Option;
|
|
|
|
use App\Cache\Redis\Admin\PrinterCache;
|
|
use App\Constants\Admin\CateringCode;
|
|
use App\Exception\ErrException;
|
|
use App\Model\OrderOptionCateringLog;
|
|
use App\Service\Admin\Catering\CateringBaseService;
|
|
use App\Service\Admin\Catering\Print\PrintOrderFactory;
|
|
use App\Service\ServiceTrait\Admin\Catering\PrintTrait;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class PrintService extends CateringBaseService
|
|
{
|
|
/**
|
|
* @var PrinterCache
|
|
*/
|
|
#[Inject]
|
|
protected PrinterCache $printerCache;
|
|
|
|
/**
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$type = (int)$this->request->input('type');
|
|
$res = match ($type) {
|
|
CateringCode::OPTION_PRINT_YLY => $this->printerCache->getYlyPrinter(),
|
|
CateringCode::OPTION_PRINT_CODING => $this->printerCache->getOtherPrinter(),
|
|
default => throw new ErrException('参数错误')
|
|
};
|
|
|
|
return $this->return->success('success', ['list' => $res]);
|
|
}
|
|
|
|
use PrintTrait;
|
|
|
|
/**
|
|
* @var OrderOptionCateringLog
|
|
*/
|
|
#[Inject]
|
|
protected OrderOptionCateringLog $orderOptionCateringLogModel;
|
|
|
|
/**
|
|
* @var OrderOptionCateringLog
|
|
*/
|
|
protected OrderOptionCateringLog $logInfo;
|
|
|
|
/**
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function checkPrint(): array
|
|
{
|
|
$id = (int)$this->request->input('id');
|
|
|
|
// 获取数据源
|
|
$this->logInfo = $this->orderOptionCateringLogModel->find($id);
|
|
if (empty($this->logInfo)) throw new ErrException('配餐记录不存在');
|
|
|
|
$this->__initRedisKey();
|
|
|
|
$res = $this->checkIsPrint();
|
|
|
|
return $this->return->success('success', ['status' => $res]);
|
|
}
|
|
|
|
/**
|
|
* @var PrintOrderFactory
|
|
*/
|
|
#[Inject]
|
|
protected PrintOrderFactory $printOrderFactory;
|
|
|
|
/**
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function cancel(): array
|
|
{
|
|
$service = $this->printOrderFactory->handle((int)$this->request->input('type'));
|
|
$service->printId = (int)$this->request->input('print_id');
|
|
$service->handle();
|
|
$service->printCancel();
|
|
|
|
return $this->return->success('success');
|
|
}
|
|
} |