feat : deliver

This commit is contained in:
2025-04-03 10:52:03 +08:00
parent 2fb997fb3b
commit 41b9993f36
9 changed files with 190 additions and 142 deletions

View File

@@ -0,0 +1,95 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Amqp\Statement;
use App\Constants\Admin\CateringCode;
use App\Constants\Common\GoodCode;
use App\Model\Cycle;
use App\Model\DriverStatus;
use App\Model\OrderMealCateringLog;
use App\Model\OrderOptionCateringLog;
use App\Model\Site;
use App\Model\SiteDriverStatement;
use App\Model\Sku;
use Exception;
use Hyperf\Di\Annotation\Inject;
class DeliverStatementService
{
/**
* @var int
*/
public int $cycleId;
/**
* @var int
*/
public int $siteId;
/**
* @var DriverStatus
*/
#[Inject]
protected DriverStatus $driverStatusModel;
/**
* @var Site
*/
#[Inject]
protected Site $siteModel;
/**
* @var Cycle
*/
#[Inject]
protected Cycle $cycleModel;
/**
* @var SiteDriverStatement
*/
#[Inject]
protected SiteDriverStatement $siteDriverStatementModel;
/**
* @return void
* @throws Exception
*/
public function handle(): void
{
$siteInfo = $this->siteModel->where('id', $this->siteId)->first();
if (empty($siteInfo)) throw new Exception('站点数据不存在');
$cycleInfo = $this->cycleModel->where('id', $this->cycleId)->first();
if (empty($cycleInfo)) throw new Exception('周期数据不存在');
$info = $this->driverStatusModel->where('cycle_id', $this->cycleId)->where('site_id',$this->siteId)->first();
if (empty($info)) throw new Exception('今日该点数据不存在');
$this->siteDriverStatementModel->where('cycle_id', $this->cycleId)->where('site_id',$this->siteId)->delete();
$insertModel = new SiteDriverStatement();
$insertModel->date = $cycleInfo->dates;
$insertModel->cycle_id = $this->cycleId;
$insertModel->site_id = $this->siteId;
$insertModel->kitchen_id = $siteInfo->kitchen_id;
$insertModel->driver_id = $info->driver_id;
$insertModel->option_order_number = $info->option_order_number;
$insertModel->meal_order_number = $info->meal_order_number;
$insertModel->option_copies = $info->option_copies;
$insertModel->meal_copies = $info->meal_copies;
$insertModel->option_add_staple_food_num = $info->option_add_staple_food_num;
$insertModel->meal_add_staple_food_num = $info->meal_add_staple_food_num;
if (!$insertModel->save()) throw new Exception('保存点位数据失败');
}
}