Files
usedcar/app/console/service/VehicleApplyService.php
T
2025-05-14 13:19:23 +08:00

80 lines
2.2 KiB
PHP

<?php
namespace app\console\service;
use app\console\model\VehicleApplyModel;
use app\mzl\common\services\BaseService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use support\exception\BusinessException;
use app\apis\model\VehicleDataModel;
class VehicleApplyService extends BaseService
{
/**
* 定义模型
*
* @return string
*/
public function getModel(): string
{
return VehicleApplyModel::class;
}
/**
* 多场景配置
*/
public function queryScenes(): array
{
return [
'default' => function ($params) {
return [
'filters' => [
// ['field' => '***', 'operator' => '=', 'value' => '***']
],
'fields' => ['id', 'vehicle_data_id', 'apply_status', 'desc', 'created_at', 'updated_at'],
'relations' => [
'vehicleDataInfo.translation' => ['vehicle_id', 'name']
],
'sorts' => [
['field' => 'id', 'direction' => 'desc']
],
'pagination' => [
'page' => $params['page'] ?? 1,
'per_page' => $params['per_page'] ?? 10,
]
];
}
];
}
/**
* 操作审核
*/
public function doApply(array $data, int $id): bool
{
$info = $this->model->where('id', $id)->first();
if (!$info) {
throw new BusinessException('未找到待审核信息', 404);
}
$info->apply_status = $data['apply_status'];
$info->desc = $data['desc'];
$info->admin_id = 1;
$vDataInfo = VehicleDataModel::where('id', $info->vehicle_data_id)->first();
if (!$vDataInfo) {
throw new BusinessException('未找到审核信息关联的车辆信息', 404);
}
$vDataInfo->info_status = $data['apply_status'];
if (!$info->save() || !$vDataInfo->save()) {
throw new BusinessException('审核失败,请重试', 500);
}
return true;
}
}