107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Admin\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() {}
|
|
} |