feat : catering
This commit is contained in:
107
app/Service/Admin/Catering/Print/JdPrintService.php
Normal file
107
app/Service/Admin/Catering/Print/JdPrintService.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Catering\Print;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
class JdPrintService implements PrintOrderInterface
|
||||
{
|
||||
/**
|
||||
* 打印数据
|
||||
* @var array
|
||||
*/
|
||||
public array $data;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $res = [];
|
||||
|
||||
public function handle() {}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function printList(): array
|
||||
{
|
||||
$this->checkOrderData();
|
||||
|
||||
$this->buildOrderContent();
|
||||
|
||||
return $this->res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function checkOrderData(): void
|
||||
{
|
||||
if (empty($this->data)) throw new ErrException('打印商品数据不存在');
|
||||
|
||||
if (
|
||||
empty($this->data['pickup_code']) ||
|
||||
empty($this->data['driver_num']) ||
|
||||
empty($this->data['site_order']) ||
|
||||
empty($this->data['site_text']) ||
|
||||
empty($this->data['sku']) ||
|
||||
empty($this->data['order_sno']) ||
|
||||
empty($this->data['username']) ||
|
||||
empty($this->data['mobile']) ||
|
||||
empty($this->data['date']) ||
|
||||
empty($this->data['heapsort'])
|
||||
) throw new ErrException('打印数据丢失');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function buildOrderContent(): void
|
||||
{
|
||||
$this->res = [];
|
||||
|
||||
$this->res['pickup_code'] = $this->data['pickup_code'];
|
||||
$this->res['line_sort'] = sprintf('%s-%s', $this->data['driver_num'], $this->data['site_order']);
|
||||
$this->res['site_name'] = $this->data['site_text'];
|
||||
|
||||
$codeNum = [];
|
||||
foreach ($this->data['sku'] as $one) {
|
||||
for ($i = 0;$i < $one['num'];$i++) {
|
||||
$codeNum[] = $one['code_num'];
|
||||
}
|
||||
}
|
||||
sort($codeNum);
|
||||
$goodsArr = array_chunk($codeNum,3,true);
|
||||
$good =[];
|
||||
foreach ($goodsArr as $one) {
|
||||
$good[] = array_values($one);
|
||||
}
|
||||
$this->res['goods_arr'] = $good;
|
||||
|
||||
$this->res['order_end_number'] = substr($this->data['order_sno'], strlen($this->data['order_sno']) - 8, 8);
|
||||
$this->res['username'] = $this->data['username'];
|
||||
$this->res['mobile_end_number'] = substr($this->data['mobile'], strlen($this->data['mobile']) - 4, 4);
|
||||
$this->res['meal_dates'] = $this->data['date'];
|
||||
$this->res['build_date'] = $this->data['date'].config('print.common.production_date');
|
||||
$this->res['shelf_life'] = config('print.common.content_edible_time_tips');
|
||||
$this->res['heapsort'] = $this->data['heapsort'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function printSingleOrder(): array
|
||||
{
|
||||
return $this->printList();
|
||||
}
|
||||
|
||||
public function printCancel() {}
|
||||
}
|
||||
30
app/Service/Admin/Catering/Print/PrintOrderFactory.php
Normal file
30
app/Service/Admin/Catering/Print/PrintOrderFactory.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Catering\Print;
|
||||
|
||||
use App\Constants\Admin\CateringCode;
|
||||
use App\Exception\ErrException;
|
||||
|
||||
class PrintOrderFactory
|
||||
{
|
||||
/**
|
||||
* @param $type
|
||||
* @return JdPrintService|YlyPrintService
|
||||
*/
|
||||
public function handle($type): YlyPrintService|JdPrintService
|
||||
{
|
||||
return match ($type) {
|
||||
CateringCode::OPTION_PRINT_YLY => new YlyPrintService(),
|
||||
CateringCode::OPTION_PRINT_CODING => new JdPrintService(),
|
||||
default => throw new ErrException('Order printing class does not exist'),
|
||||
};
|
||||
}
|
||||
}
|
||||
20
app/Service/Admin/Catering/Print/PrintOrderInterface.php
Normal file
20
app/Service/Admin/Catering/Print/PrintOrderInterface.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Catering\Print;
|
||||
|
||||
interface PrintOrderInterface
|
||||
{
|
||||
public function printList();
|
||||
|
||||
public function printSingleOrder();
|
||||
|
||||
public function printCancel();
|
||||
}
|
||||
290
app/Service/Admin/Catering/Print/YlyPrintService.php
Normal file
290
app/Service/Admin/Catering/Print/YlyPrintService.php
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Catering\Print;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Lib\Print\YlyBasicsLib;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
class YlyPrintService implements PrintOrderInterface
|
||||
{
|
||||
/**
|
||||
* 打印数据
|
||||
* @var array
|
||||
*/
|
||||
public array $data;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $printId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $token;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $machineCode;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $content;
|
||||
|
||||
|
||||
/**
|
||||
* @var YlyBasicsLib
|
||||
*/
|
||||
#[Inject]
|
||||
protected YlyBasicsLib $ylyBasicsLib;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
//todo 加入打印机验证 orderOptionCateringLogModel
|
||||
$printInfo = $this->orderOptionCateringLogModel->where('id',$this->printId)->first();
|
||||
|
||||
if (empty($printInfo)) throw new ErrException('打印机不存在-1');
|
||||
|
||||
if (empty($printInfo->code_value) || $printInfo->code_value == '') throw new ErrException('打印机不存在-2');
|
||||
|
||||
$this->token = $this->ylyBasicsLib->selfAppAccredit();
|
||||
$this->machineCode = $printInfo->code_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function printList(): true
|
||||
{
|
||||
$this->checkOrderData();
|
||||
|
||||
$this->buildOrderContent();
|
||||
|
||||
$this->ylyBasicsLib->printTextRequest($this->token,$this->machineCode,$this->content);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function checkOrderData(): void
|
||||
{
|
||||
if (empty($this->data)) throw new ErrException('打印商品数据不存在');
|
||||
|
||||
if (
|
||||
empty($this->data['pickup_code']) ||
|
||||
empty($this->data['driver_num']) ||
|
||||
empty($this->data['site_order']) ||
|
||||
empty($this->data['site_text']) ||
|
||||
empty($this->data['sku']) ||
|
||||
empty($this->data['order_sno']) ||
|
||||
empty($this->data['username']) ||
|
||||
empty($this->data['mobile']) ||
|
||||
empty($this->data['date']) ||
|
||||
empty($this->data['heapsort'])
|
||||
) throw new ErrException('打印数据丢失');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function buildOrderContent(): void
|
||||
{
|
||||
//重置数据
|
||||
$this->content = '';
|
||||
|
||||
//设置高度
|
||||
$this->content .= "<PH>100,1</PH>";
|
||||
//设置宽度
|
||||
$this->content .= "<PW>048</PW>";
|
||||
|
||||
$this->content .= "\n";
|
||||
$this->content .= "\n";
|
||||
|
||||
//取餐号
|
||||
$this->content .= "<FS3><CA>{$this->data['pickup_code']}</CA></FS3>\n";
|
||||
|
||||
//司机号码 - 线路顺序
|
||||
$this->content .= "<FS><CA>线路:{$this->data['driver_num']}-{$this->data['site_order']}</CA></FS>\n";
|
||||
|
||||
//配送点
|
||||
$this->content .= "<FS><CA>配送点:{$this->data['site_text']}</CA></FS>\n";
|
||||
|
||||
// 表头
|
||||
$this->content .= "--------------------------------\n";
|
||||
|
||||
//菜品表格
|
||||
$codeNum = [];
|
||||
foreach ($this->data['sku'] as $one) {
|
||||
for ($i = 0;$i < $one['num'];$i++) {
|
||||
$codeNum[] = $one['code_num'];
|
||||
}
|
||||
}
|
||||
sort($codeNum);
|
||||
$goodsArr = array_chunk($codeNum,3,true);
|
||||
foreach ($goodsArr as $one) {
|
||||
$one = array_values($one);
|
||||
switch (count($one)) {
|
||||
case 1:
|
||||
$this->content .= "<FS4><CA>{$one[0]}</CA></FS4>\n";
|
||||
break;
|
||||
case 2:
|
||||
$this->content .= "<FS4><CA>{$one[0]}.{$one[1]}</CA></FS4>\n";
|
||||
break;
|
||||
case 3:
|
||||
$this->content .= "<FS4><CA>{$one[0]}.{$one[1]}.{$one[2]}</CA></FS4>\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//下面分割符号
|
||||
$this->content .= "--------------------------------\n";
|
||||
|
||||
//订单号 截取订单号
|
||||
$last8Chars = substr($this->data['order_sno'], strlen($this->data['order_sno']) - 8, 8);
|
||||
$this->content .= "<LR2>订单尾号,{$last8Chars}</LR2>";
|
||||
|
||||
//用户昵称
|
||||
$this->content .= "<LR2>用户昵称,{$this->data['username']}</LR2>";
|
||||
|
||||
//手机尾号
|
||||
$last4Chars = substr($this->data['mobile'], strlen($this->data['mobile']) - 4, 4);
|
||||
$this->content .= "<LR2>手机尾号,{$last4Chars}</LR2>";
|
||||
|
||||
//套餐日期
|
||||
$this->content .= "<LR2>套餐日期,{$this->data['date']}</LR2>";
|
||||
|
||||
//生产日期
|
||||
$productionTime = $this->data['date'].config('print.yly.production_time');
|
||||
$this->content .= "<LR2>生产日期,$productionTime</LR2>";
|
||||
|
||||
//保质期
|
||||
$contentEdibleTimeTips = config('print.yly.content_edible_time_tips');
|
||||
$this->content .= "<LR2>保质期,$contentEdibleTimeTips</LR2>";
|
||||
|
||||
$this->content .= "<FS3><CA>{$this->data['heapsort']}</CA></FS3>";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function printSingleOrder(): true
|
||||
{
|
||||
return $this->printList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function printCancel(): void
|
||||
{
|
||||
$this->ylyBasicsLib->cancelRequest($this->token,$this->machineCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function printBoxLabel(): true
|
||||
{
|
||||
$this->checkBoxLabelData();
|
||||
|
||||
$this->buildBoxContent();
|
||||
|
||||
$this->ylyBasicsLib->printTextRequest($this->token,$this->machineCode,$this->content);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function checkBoxLabelData(): void
|
||||
{
|
||||
if (empty($this->data)) throw new ErrException('打印标签数据不存在');
|
||||
|
||||
if (
|
||||
empty($this->data['driver_num']) ||
|
||||
empty($this->data['site_order']) ||
|
||||
empty($this->data['site_text']) ||
|
||||
empty($this->data['copies_num']) ||
|
||||
empty($this->data['driver_name']) ||
|
||||
empty($this->data['current_num']) ||
|
||||
empty($this->data['date_text'])
|
||||
) throw new ErrException('打印数据丢失');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function buildBoxContent(): void
|
||||
{
|
||||
// 重置
|
||||
$this->content = '';
|
||||
|
||||
//设置高度
|
||||
$this->content .= "<PH>100,1</PH>";
|
||||
//设置宽度
|
||||
$this->content .= "<PW>048</PW>";
|
||||
|
||||
//上下居中
|
||||
$this->content .= "\n";
|
||||
$this->content .= "\n";
|
||||
$this->content .= "\n";
|
||||
$this->content .= "\n";
|
||||
$this->content .= "\n";
|
||||
$this->content .= "\n";
|
||||
$this->content .= "\n";
|
||||
|
||||
// 司机号码 - 线路顺序
|
||||
$this->content .= "<FS3><CA>线路:{$this->data['driver_num']}-{$this->data['site_order']}</CA></FS3>\n";
|
||||
$this->content .= "\n";
|
||||
|
||||
// 总量
|
||||
$this->content .= "<FS><CA>总份数:{$this->data['copies_num']}</CA></FS>\n";
|
||||
$this->content .= "\n";
|
||||
|
||||
// 箱数
|
||||
$currentNum = str_pad($this->data['current_num'], 2, '0', STR_PAD_LEFT);
|
||||
$this->content .= "<FS2><CA>箱数:$currentNum</CA></FS2>\n";
|
||||
$this->content .= "\n";
|
||||
|
||||
// 配送点
|
||||
$this->content .= "<FS><CA>配送司机: {$this->data['driver_name']}</CA></FS>\n";
|
||||
$this->content .= "\n";
|
||||
|
||||
// 配送点
|
||||
$this->content .= "<FS><CA>配送点: {$this->data['site_text']}</CA></FS>\n";
|
||||
$this->content .= "\n";
|
||||
|
||||
// 套餐日期
|
||||
$this->content .= "<FS3><CA>{$this->data['date_text']}</CA></FS3>\n";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user