feat: driver
This commit is contained in:
85
app/Service/Api/Driver/LoadActionService.php
Normal file
85
app/Service/Api/Driver/LoadActionService.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Driver;
|
||||
|
||||
use App\Constants\Admin\CateringCode;
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class LoadActionService extends BaseDriverService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
if (
|
||||
($this->orderOptionCateringLogModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->where('status',CateringCode::CATERING_STATUS_UNDERWAY)
|
||||
->whereIn('site_id', $this->siteIds)
|
||||
->where('quantity','>',0)
|
||||
->sum('quantity') ?? 0) > 0
|
||||
) throw new ErrException('自选配餐还未完成');
|
||||
|
||||
if (
|
||||
($this->orderMealCateringLogModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->where('status',CateringCode::CATERING_STATUS_UNDERWAY)
|
||||
->whereIn('site_id', $this->siteIds)
|
||||
->where('quantity','>',0)
|
||||
->sum('quantity') ?? 0) > 0
|
||||
) throw new ErrException('套餐配餐还未完成');
|
||||
|
||||
$orderIds = $this->orderModel
|
||||
->where('cycle_id',$this->cycleId)
|
||||
->where('status',OrderCode::PLAN)
|
||||
->whereIn('site_id',$this->siteIds)
|
||||
->pluck('id')
|
||||
->toArray();
|
||||
|
||||
if (empty($orderIds)) throw new ErrException('数据不存在');
|
||||
|
||||
$list = $this->buildListData();
|
||||
foreach ($list as &$one) {
|
||||
$one['meal_list'] = json_encode($one['meal_list']);
|
||||
}
|
||||
|
||||
Db::transaction(function () use ($orderIds,$list) {
|
||||
// $this->orderModel->whereIn('id', $orderIds)->update([
|
||||
// 'status' => OrderCode::DEPART,
|
||||
// 'set_out_time' => date('Y-m-d H:i:s'),
|
||||
// ]);
|
||||
|
||||
$this->driverStatusModel->insert($list);
|
||||
|
||||
$dateTime = date('Y-m-d H:i:s');
|
||||
foreach (array_chunk($orderIds, 500) as $chunk) {
|
||||
$this->orderModel->whereIn('id', $chunk)->update([
|
||||
'status' => OrderCode::DEPART,
|
||||
'set_out_time' => $dateTime,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user