96 lines
3.0 KiB
PHP
96 lines
3.0 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\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
|
|
]);
|
|
}
|
|
} |