74 lines
2.2 KiB
PHP
74 lines
2.2 KiB
PHP
<?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\Common\DriverCode;
|
|
use App\Exception\ErrException;
|
|
use App\Model\DriverException;
|
|
use Hyperf\DbConnection\Db;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
class AbnormalReportingService extends BaseDriverService
|
|
{
|
|
/**
|
|
* @var DriverException
|
|
*/
|
|
#[Inject]
|
|
protected DriverException $driverExceptionModel;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$info = $this->driverStatusModel
|
|
->where('cycle_id',$this->cycleId)
|
|
->where('site_id',$this->request->input('site_id'))
|
|
->where('driver_id',$this->adminInfo->id)
|
|
->first();
|
|
|
|
if (empty($info)) throw new ErrException('今日无该点位的送餐数据');
|
|
|
|
if ($info->status == DriverCode::DESTINATION) throw new ErrException('该点位已送达,无需上报异常信息');
|
|
|
|
$todaySiteIds = $this->driverStatusModel
|
|
->where('cycle_id',$this->cycleId)
|
|
->where('driver_id',$this->adminInfo->id)
|
|
->whereIn('status',[DriverCode::DEPARTURES,DriverCode::EXCEPTIONS])
|
|
->pluck('site_id')
|
|
->toArray();
|
|
if (empty($todaySiteIds)) throw new ErrException('数据错误-1');
|
|
|
|
$insertData = [];
|
|
foreach ($todaySiteIds as $siteId) {
|
|
$insertData[] = [
|
|
'cycle_id' => $this->cycleId,
|
|
'site_id' => $siteId,
|
|
'driver_id' => $this->adminInfo->id,
|
|
'exceptions_msg' => $this->request->input('exceptions_msg'),
|
|
'image_id' => $this->request->input('image_id'),
|
|
'create_time' => date('Y-m-d H:i:s')
|
|
];
|
|
}
|
|
|
|
if (empty($insertData)) throw new ErrException('数据错误-2');
|
|
|
|
Db::transaction(function () use ($todaySiteIds,$insertData) {
|
|
$this->driverExceptionModel->insert($insertData);
|
|
|
|
$this->driverStatusModel->update([
|
|
'status' => DriverCode::EXCEPTIONS,
|
|
]);
|
|
});
|
|
|
|
return $this->return->success();
|
|
}
|
|
} |