64 lines
1.8 KiB
PHP
64 lines
1.8 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
|
|
{
|
|
$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('暂无未送达数据');
|
|
|
|
$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();
|
|
}
|
|
} |