feat : catering

This commit is contained in:
2025-03-13 15:08:26 +08:00
parent d461790c2f
commit 3aa241350c
10 changed files with 530 additions and 11 deletions

View File

@@ -94,4 +94,20 @@ class AdminRedisKey
{ {
return 'catering:option:is:cycle_id:'.$cycleId; return 'catering:option:is:cycle_id:'.$cycleId;
} }
/**
* @return string
*/
public static function ylyPrinterList(): string
{
return '__system:yly:printer:list';
}
/**
* @return string
*/
public static function jdPrinterList(): string
{
return '__system:jd:printer:list';
}
} }

View File

@@ -0,0 +1,112 @@
<?php
namespace App\Cache\Redis\Admin;
use App\Cache\Redis\Common\CommonRedisKey;
use App\Cache\Redis\RedisCache;
use App\Constants\Admin\CateringCode;
use App\Constants\RedisCode;
use App\Model\Printer;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class PrinterCache
{
/**
* @var Printer
*/
#[Inject]
protected Printer $printerModel;
/**
* @var RedisCache
*/
#[Inject]
protected RedisCache $redisCache;
/**
* @var string 易联云打印机
*/
protected string $ylyPrinterKey;
/**
* @var string 集大自动化喷码机
*/
protected string $jdPrinterKey;
/**
* 构造函数注入 key
*/
public function __construct()
{
$this->ylyPrinterKey = AdminRedisKey::ylyPrinterList();
$this->jdPrinterKey = AdminRedisKey::jdPrinterList();
}
/**
* 初始化打印机列表数据
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function __initPrinterListData(): void
{
$printerList = $this->printerModel->get();
if ($printerList->isEmpty()) return;
$ylyPrinterList = [];
$jdPrinterList = [];
foreach ($printerList->toArray() as $printer) {
match ($printer['type']) {
CateringCode::OPTION_PRINT_YLY => $ylyPrinterList[] = $printer,
CateringCode::OPTION_PRINT_CODING => $jdPrinterList[] = $printer,
};
}
$this->delCache();
$this->redisCache->set($this->ylyPrinterKey, json_encode($ylyPrinterList));
$this->redisCache->set($this->jdPrinterKey, json_encode($jdPrinterList));
}
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getYlyPrinter(): array
{
if ($this->redisCache->exists($this->ylyPrinterKey,RedisCode::SYSTEM_DB)) $this->__initPrinterListData();
$res = $this->redisCache->get($this->ylyPrinterKey, RedisCode::SYSTEM_DB);
if (empty($res)) return [];
return json_decode($res, true);
}
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getOtherPrinter(): array
{
if ($this->redisCache->exists($this->jdPrinterKey,RedisCode::SYSTEM_DB)) $this->__initPrinterListData();
$res = $this->redisCache->get($this->jdPrinterKey, RedisCode::SYSTEM_DB);
if (empty($res)) return [];
return json_decode($res, true);
}
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function delCache(): void
{
$this->redisCache->delete($this->ylyPrinterKey);
$this->redisCache->delete($this->jdPrinterKey);
}
}

View File

@@ -6,6 +6,8 @@ namespace App\Controller\Admin;
use App\Middleware\Admin\JwtAuthMiddleware; use App\Middleware\Admin\JwtAuthMiddleware;
use App\Service\Admin\Catering\Meal\CycleListService as MealCycleListService; use App\Service\Admin\Catering\Meal\CycleListService as MealCycleListService;
use App\Service\Admin\Catering\Option\CompleteListService;
use App\Service\Admin\Catering\Option\CompletePrintService;
use App\Service\Admin\Catering\Option\CycleListService as OptionCycleListService; use App\Service\Admin\Catering\Option\CycleListService as OptionCycleListService;
use App\Service\Admin\Catering\Option\CateringService as OptionCateringService; use App\Service\Admin\Catering\Option\CateringService as OptionCateringService;
use App\Service\Admin\Catering\Option\PrintService; use App\Service\Admin\Catering\Option\PrintService;
@@ -61,6 +63,7 @@ class CateringController
} }
/** /**
* 自选配餐
* @return array * @return array
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
@@ -72,19 +75,55 @@ class CateringController
return (new OptionCateringService)->handle(); return (new OptionCateringService)->handle();
} }
/**
* 自选是否打印
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
#[RequestMapping(path: "option/check_is_print", methods: "POST")] #[RequestMapping(path: "option/check_is_print", methods: "POST")]
#[Scene(scene: "option_check_is_print")] #[Scene(scene: "option_check_is_print")]
public function optionCheckPrint() public function optionCheckPrint()
{ {
return (new PrintService)->check(); return (new PrintService)->checkPrint();
} }
#[RequestMapping(path: "option/catering", methods: "GET")] /**
#[Scene(scene: "option_catering")] * 打印机/喷码机列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
#[RequestMapping(path: "option/print_list", methods: "GET")]
#[Scene(scene: "option_print_list")]
public function optionPrintList() public function optionPrintList()
{ {
return (new PrintService)->handle(); return (new PrintService)->handle();
} }
/**
* 自选补打印列表
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
#[RequestMapping(path: "option/complete_list", methods: "GET")]
#[Scene(scene: "option_complete_list")]
public function completeList()
{
return (new CompleteListService)->handle();
}
/**
* 自选补打印
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
#[RequestMapping(path: "option/complete_print", methods: "GET")]
#[Scene(scene: "option_complete_print")]
public function completePrint()
{
return (new CompletePrintService)->handle();
}
} }

38
app/Model/Printer.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Collection;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property string $name
* @property int $type
* @property string $code_value
* @property string $create_time
* @property string $update_time
*/
class Printer extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'printer';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
protected array $guarded = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'type' => 'integer'];
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
}

View File

@@ -502,6 +502,7 @@ class CateringService extends CateringBaseService
// 先加当前数量 // 先加当前数量
$printBoxNum++; $printBoxNum++;
//todo 数据加载做一下
$service->data = [ $service->data = [
'pickup_code' => $copiesItem['pickup_code'], 'pickup_code' => $copiesItem['pickup_code'],
'driver_num' => '', 'driver_num' => '',

View 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
]);
}
}

View 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() {}
}

View File

@@ -10,17 +10,71 @@ declare(strict_types=1);
namespace App\Service\Admin\Catering\Option; 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]);
} }
} }

View File

@@ -12,6 +12,7 @@ namespace App\Service\Admin\Catering\Print;
use App\Exception\ErrException; use App\Exception\ErrException;
use App\Lib\Print\YlyBasicsLib; use App\Lib\Print\YlyBasicsLib;
use App\Model\Printer;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
@@ -45,13 +46,18 @@ class YlyPrintService implements PrintOrderInterface
*/ */
private string $content; private string $content;
/** /**
* @var YlyBasicsLib * @var YlyBasicsLib
*/ */
#[Inject] #[Inject]
protected YlyBasicsLib $ylyBasicsLib; protected YlyBasicsLib $ylyBasicsLib;
/**
* @var Printer
*/
#[Inject]
protected Printer $printerModel;
/** /**
* @return void * @return void
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
@@ -60,7 +66,7 @@ class YlyPrintService implements PrintOrderInterface
public function handle(): void public function handle(): void
{ {
//todo 加入打印机验证 orderOptionCateringLogModel //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'); if (empty($printInfo)) throw new ErrException('打印机不存在-1');

View File

@@ -82,6 +82,16 @@ trait PrintTrait
$this->redis->hSet($this->printKey, $this->logInfo->id, CateringCode::REDIS_FINISH_VALUE); $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 * @return void
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface