feat : catering
This commit is contained in:
@@ -502,6 +502,7 @@ class CateringService extends CateringBaseService
|
||||
// 先加当前数量
|
||||
$printBoxNum++;
|
||||
|
||||
//todo 数据加载做一下
|
||||
$service->data = [
|
||||
'pickup_code' => $copiesItem['pickup_code'],
|
||||
'driver_num' => '',
|
||||
|
||||
96
app/Service/Admin/Catering/Option/CompleteListService.php
Normal file
96
app/Service/Admin/Catering/Option/CompleteListService.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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\Constants\Common\OrderCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderOptionCateringLog;
|
||||
use App\Model\PickupCode;
|
||||
use App\Service\Admin\Catering\CateringBaseService;
|
||||
use App\Service\ServiceTrait\Admin\Catering\PrintTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class CompleteListService extends CateringBaseService
|
||||
{
|
||||
use PrintTrait;
|
||||
|
||||
/**
|
||||
* @var OrderOptionCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderOptionCateringLog $orderOptionCateringLogModel;
|
||||
|
||||
/**
|
||||
* @var OrderOptionCateringLog
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderOptionCateringLog $logInfo;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @var PickupCode
|
||||
*/
|
||||
#[Inject]
|
||||
protected PickupCode $pickupCodeModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
// 获取数据源
|
||||
$this->logInfo = $this->orderOptionCateringLogModel->find($id);
|
||||
if (empty($this->logInfo)) throw new ErrException('配餐记录不存在');
|
||||
|
||||
$this->__initRedisKey();
|
||||
|
||||
if (!$this->isBuildPickupCode() || !$this->isCateringByCache() || !$this->checkIsPrint()) throw new ErrException('先执行整线路配餐后才可以获取已配餐信息');
|
||||
|
||||
if ($this->logInfo->quantity <= 0) throw new ErrException('该点无任何配餐数据');
|
||||
|
||||
$siteInfo = $this->siteModel->getInfoById($this->logInfo->site_id);
|
||||
if (empty($siteInfo)) throw new ErrException('配餐地址不存在,请确认信息');
|
||||
|
||||
$driverInfo = $this->driverSequenceModel->getInfoByDriverId($siteInfo->delivered_id);
|
||||
if (empty($driverInfo)) throw new ErrException('线路司机信息不存在,请确认信息');
|
||||
|
||||
$orderIds = $this->orderModel
|
||||
->where('site_id', $siteInfo->id)
|
||||
->where('cycle_id', $this->cycleId)
|
||||
->where('type',OrderCode::ORDER_TYPE_OPTIONAL)
|
||||
->where('status',OrderCode::PAYED)
|
||||
->orderBy('id')
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
if (empty($orderIds)) throw new ErrException('该点无任何配餐数据');
|
||||
|
||||
$pickUpCodeList = $this->pickupCodeModel->whereIn('order_id',$orderIds)->select(['pickup_code','order_id','copies','id'])->get();
|
||||
if ($pickUpCodeList->isEmpty()) throw new ErrException('该点未生成取餐码');
|
||||
|
||||
return $this->return->success('success', [
|
||||
'list' => $pickUpCodeList->toArray(),
|
||||
'site_name' => $siteInfo->name,
|
||||
'driver_num' => $driverInfo->driver_num.'-'.$siteInfo->sequence
|
||||
]);
|
||||
}
|
||||
}
|
||||
147
app/Service/Admin/Catering/Option/CompletePrintService.php
Normal file
147
app/Service/Admin/Catering/Option/CompletePrintService.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?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\Constants\Admin\CateringCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderGood;
|
||||
use App\Model\PickupCode;
|
||||
use App\Model\User;
|
||||
use App\Service\Admin\Catering\CateringBaseService;
|
||||
use App\Service\Admin\Catering\Print\JdPrintService;
|
||||
use App\Service\Admin\Catering\Print\PrintOrderFactory;
|
||||
use App\Service\Admin\Catering\Print\YlyPrintService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class CompletePrintService extends CateringBaseService
|
||||
{
|
||||
/**
|
||||
* @var PickupCode
|
||||
*/
|
||||
#[Inject]
|
||||
protected PickupCode $pickupCodeModel;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @var OrderGood
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderGood $orderGoodModel;
|
||||
|
||||
/**
|
||||
* @var PrintOrderFactory
|
||||
*/
|
||||
#[Inject]
|
||||
protected PrintOrderFactory $printOrderFactory;
|
||||
//
|
||||
// /**
|
||||
// * @var PickupCode
|
||||
// */
|
||||
// protected PickupCode $pickupCodeInfo;
|
||||
//
|
||||
// /**
|
||||
// * @var Order
|
||||
// */
|
||||
// protected Order $orderInfo;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
#[Inject]
|
||||
protected User $userModel;
|
||||
|
||||
/**
|
||||
* @var YlyPrintService|JdPrintService
|
||||
*/
|
||||
protected YlyPrintService|JdPrintService $printService;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$pickupCodeInfo = $this->pickupCodeModel->find($this->request->input('id'));
|
||||
if (empty($pickupCodeInfo)) throw new ErrException('取餐数据不存在');
|
||||
|
||||
$orderInfo = $this->orderModel->find($pickupCodeInfo->order_id);
|
||||
if (empty($this->orderInfo)) throw new ErrException('订单数据不存在');
|
||||
|
||||
$skuArr = $this->orderGoodModel->where('order_id',$pickupCodeInfo->order_id)->where('copies',$pickupCodeInfo->copies)->pluck('quantity','sku_id')->toArray();
|
||||
if (empty($skuArr)) throw new ErrException('订单商品数据不存在');
|
||||
$skuIds = array_keys($skuArr);
|
||||
|
||||
$skuInfo = $this->skuModel->whereIn('id',$skuIds)->pluck('code_number','id');
|
||||
$skuCopies = [];
|
||||
foreach ($skuArr as $skuId => $quantity) {
|
||||
$skuCopies[] = [
|
||||
'code_number' => $skuInfo[$skuId],
|
||||
'quantity' => $quantity,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$siteInfo = $this->siteModel->find($orderInfo->site_id);
|
||||
|
||||
$userInfo = $this->userModel->find($orderInfo->user_id);
|
||||
|
||||
$driverInfo = $this->driverSequenceModel->find($siteInfo->delivered_id);
|
||||
|
||||
$this->printService = $this->printOrderFactory->handle($this->request->input('type'));
|
||||
// 打印或者喷码
|
||||
match ($this->request->input('type')) {
|
||||
CateringCode::OPTION_PRINT_YLY => $this->printOrderByYly(),
|
||||
CateringCode::OPTION_PRINT_CODING => $this->printOrderByCoding(),
|
||||
};
|
||||
|
||||
$this->printService->data = [
|
||||
'pickup_code' => $pickupCodeInfo->pickup_code,
|
||||
'driver_num' => $driverInfo->driver_num,
|
||||
'site_order' => $siteInfo->sequence,
|
||||
'site_text' => $siteInfo->name,
|
||||
'order_sno' => $orderInfo->order_sno,
|
||||
'username' => $userInfo->nickname,
|
||||
'date' => date('Y-m-d'),
|
||||
'mobile' => $userInfo->mobile,
|
||||
'heapsort' => $pickupCodeInfo->heapsort,
|
||||
'sku' => $skuCopies
|
||||
];
|
||||
|
||||
$res = $this->printService->printSingleOrder();
|
||||
|
||||
return $this->return->success('success', ['data' => $res]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function printOrderByYly(): void
|
||||
{
|
||||
$this->printService->printId = (int)$this->request->input('print_id');
|
||||
$this->printService->handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function printOrderByCoding() {}
|
||||
}
|
||||
@@ -10,17 +10,71 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Catering\Option;
|
||||
|
||||
use App\Service\Admin\BaseService;
|
||||
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\ServiceTrait\Admin\Catering\PrintTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class PrintService extends BaseService
|
||||
class PrintService extends CateringBaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
/**
|
||||
* @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]);
|
||||
}
|
||||
|
||||
public function check()
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ namespace App\Service\Admin\Catering\Print;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Lib\Print\YlyBasicsLib;
|
||||
use App\Model\Printer;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -45,13 +46,18 @@ class YlyPrintService implements PrintOrderInterface
|
||||
*/
|
||||
private string $content;
|
||||
|
||||
|
||||
/**
|
||||
* @var YlyBasicsLib
|
||||
*/
|
||||
#[Inject]
|
||||
protected YlyBasicsLib $ylyBasicsLib;
|
||||
|
||||
/**
|
||||
* @var Printer
|
||||
*/
|
||||
#[Inject]
|
||||
protected Printer $printerModel;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -60,7 +66,7 @@ class YlyPrintService implements PrintOrderInterface
|
||||
public function handle(): void
|
||||
{
|
||||
//todo 加入打印机验证 orderOptionCateringLogModel
|
||||
$printInfo = $this->orderOptionCateringLogModel->where('id',$this->printId)->first();
|
||||
$printInfo = $this->printerModel->where('id',$this->printId)->first();
|
||||
|
||||
if (empty($printInfo)) throw new ErrException('打印机不存在-1');
|
||||
|
||||
|
||||
@@ -82,6 +82,16 @@ trait PrintTrait
|
||||
$this->redis->hSet($this->printKey, $this->logInfo->id, CateringCode::REDIS_FINISH_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function checkIsPrint(): bool
|
||||
{
|
||||
return CateringCode::REDIS_FINISH_VALUE == $this->redis->hGet($this->printKey, $this->logInfo->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
|
||||
Reference in New Issue
Block a user