feat : statement
This commit is contained in:
65
app/Service/Admin/Order/FinishService.php
Normal file
65
app/Service/Admin/Order/FinishService.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user