feat : statement

This commit is contained in:
2025-03-21 17:41:10 +08:00
parent 8176feb77b
commit 005fc4879a
12 changed files with 450 additions and 2 deletions

View File

@@ -0,0 +1,65 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Admin\Order;
use App\Constants\Common\OrderCode;
use App\Exception\ErrException;
use App\Model\Order;
use App\Model\OrderGood;
use App\Service\Admin\BaseService;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject;
class FinishService extends BaseService
{
/**
* @var Order
*/
#[Inject]
protected Order $orderModel;
/**
* @var OrderGood
*/
#[Inject]
protected OrderGood $orderGoodModel;
public function handle()
{
$kitchenId = (int)$this->request->input('kitchenId');
$cycleId = (int)$this->request->input('cycleId');
$orderIds = $this->orderModel
->where('kitchen_id', $kitchenId)
->where('cycle_id', $cycleId)
->whereIn('status', [
OrderCode::PLAN,
OrderCode::DEPART,
OrderCode::ARRIVE,
])
->pluck('id')
->toArray();
Db::transaction(function () use ($orderIds) {
foreach (array_chunk($orderIds, 100) as $chunk) {
$orderFinish = $this->orderModel->whereIn('id', $chunk)->update(['status' => OrderCode::FINISH]);
$orderGoodFinish = $this->orderGoodModel->whereIn('order_id', $chunk)->update(['status' => OrderCode::FINISH]);
if (!$orderFinish && !$orderGoodFinish) throw new ErrException('更新失败,数据回滚,请重新操作');
}
});
return $this->return->success();
}
}