修正编辑后的备货单绕过文件上传
This commit is contained in:
@@ -73,6 +73,7 @@ class StockOrdersService
|
|||||||
case 'print':
|
case 'print':
|
||||||
case 'approval':
|
case 'approval':
|
||||||
$config['where']['id'] = $p['id'];
|
$config['where']['id'] = $p['id'];
|
||||||
|
$config['with'][] = 'files'; // 添加文件附件关联
|
||||||
break;
|
break;
|
||||||
case 'detail':
|
case 'detail':
|
||||||
case 'show':
|
case 'show':
|
||||||
@@ -102,22 +103,14 @@ class StockOrdersService
|
|||||||
public function beforeServiceStore($data, Request $request)
|
public function beforeServiceStore($data, Request $request)
|
||||||
{
|
{
|
||||||
$userId = $request->user->uid;
|
$userId = $request->user->uid;
|
||||||
|
// 检查绑定
|
||||||
$data['order_no'] = generateStockNo();
|
(new UserService())->checkBind($userId);
|
||||||
$data['biz_date'] = strtotime($data['biz_date']);
|
// 保存不检查文件上传
|
||||||
$data['eta_ship_date'] = strtotime($data['eta_ship_date']);
|
if ($data['approval_status'] != 0) {
|
||||||
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']);
|
$this->validateRequiredFiles($data);
|
||||||
$data['salesperson_id'] = $userId;
|
}
|
||||||
$data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? '';
|
// 终版备货单时,至少一个车辆填写了vin
|
||||||
$data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0;
|
|
||||||
|
|
||||||
// if ($data['is_final'] == 1) {
|
|
||||||
$data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0;
|
|
||||||
$data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if ($data['is_final'] == 1) {
|
if ($data['is_final'] == 1) {
|
||||||
// 检查是否至少有一个车辆填写了vin
|
|
||||||
$hasVin = false;
|
$hasVin = false;
|
||||||
foreach ($data['veh_list'] as $k => $v) {
|
foreach ($data['veh_list'] as $k => $v) {
|
||||||
if ($v['vin'] != '') {
|
if ($v['vin'] != '') {
|
||||||
@@ -125,17 +118,105 @@ class StockOrdersService
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果没有任何车辆填写vin,则抛出异常
|
|
||||||
if (!$hasVin) {
|
if (!$hasVin) {
|
||||||
throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核');
|
throw new BusinessException('至少需要为一辆车辆填写vin,才能提交审核');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$data['order_no'] = generateStockNo();
|
||||||
// 检查绑定
|
$data['biz_date'] = strtotime($data['biz_date']);
|
||||||
(new UserService())->checkBind($userId);
|
$data['eta_ship_date'] = strtotime($data['eta_ship_date']);
|
||||||
|
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']);
|
||||||
|
$data['salesperson_id'] = $userId;
|
||||||
|
$data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? '';
|
||||||
|
$data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0;
|
||||||
|
$data['pick_up_date'] = $data['pick_up_date'] ? strtotime($data['pick_up_date']) : 0;
|
||||||
|
$data['collect_all_date'] = $data['collect_all_date'] ? strtotime($data['collect_all_date']) : 0;
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证创建备货单时必需的文件是否已提供
|
||||||
|
*
|
||||||
|
* @param array $data 提交的数据
|
||||||
|
* @throws BusinessException 当必需的文件缺失或为空时抛出异常
|
||||||
|
*/
|
||||||
|
private function validateRequiredFiles(array $data): void
|
||||||
|
{
|
||||||
|
$requiredFiles = [
|
||||||
|
'contract' => '合同',
|
||||||
|
'transaction_slip' => '水单',
|
||||||
|
'pi_doc' => 'PI'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($requiredFiles as $fileType => $fileLabel) {
|
||||||
|
if (!isset($data[$fileType]) || !is_array($data[$fileType]) || empty($data[$fileType])) {
|
||||||
|
throw new BusinessException("创建备货单时{$fileLabel}文件不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查文件数组中的每个条目是否都有有效的URL
|
||||||
|
$hasValidFile = false;
|
||||||
|
foreach ($data[$fileType] as $fileInfo) {
|
||||||
|
if (isset($fileInfo['url']) && !empty($fileInfo['url'])) {
|
||||||
|
$hasValidFile = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$hasValidFile) {
|
||||||
|
throw new BusinessException("创建备货单时{$fileLabel}文件不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证备货单审批时必需的文件是否存在
|
||||||
|
*
|
||||||
|
* @param StockOrders $item 备货单对象
|
||||||
|
* @throws BusinessException 当必需的文件缺失或为空时抛出异常
|
||||||
|
*/
|
||||||
|
private function validateRequiredFilesForApproval($item): void
|
||||||
|
{
|
||||||
|
// 确保已加载文件关联
|
||||||
|
if (!isset($item->files)) {
|
||||||
|
$item->load('files');
|
||||||
|
}
|
||||||
|
|
||||||
|
$requiredFiles = [
|
||||||
|
\app\common\model\StockOrdersFiles::CONTRACT => '合同',
|
||||||
|
\app\common\model\StockOrdersFiles::TRANSACTION_SLIP => '水单',
|
||||||
|
\app\common\model\StockOrdersFiles::PI_DOC => 'PI'
|
||||||
|
];
|
||||||
|
|
||||||
|
// 按文件类型分组现有文件
|
||||||
|
$existingFiles = [];
|
||||||
|
foreach ($item->files as $file) {
|
||||||
|
if (!isset($existingFiles[$file->file_code])) {
|
||||||
|
$existingFiles[$file->file_code] = [];
|
||||||
|
}
|
||||||
|
$existingFiles[$file->file_code][] = $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查每种必需文件是否存在
|
||||||
|
foreach ($requiredFiles as $fileCode => $fileLabel) {
|
||||||
|
if (!isset($existingFiles[$fileCode]) || empty($existingFiles[$fileCode])) {
|
||||||
|
throw new BusinessException("提交审批前必须上传{$fileLabel}文件");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查文件中是否有有效的URL
|
||||||
|
$hasValidFile = false;
|
||||||
|
foreach ($existingFiles[$fileCode] as $file) {
|
||||||
|
if (!empty($file->file_url)) {
|
||||||
|
$hasValidFile = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$hasValidFile) {
|
||||||
|
throw new BusinessException("提交审批前必须上传有效的{$fileLabel}文件");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function afterServiceStore($res)
|
protected function afterServiceStore($res)
|
||||||
{
|
{
|
||||||
// 处理原单
|
// 处理原单
|
||||||
@@ -271,10 +352,14 @@ class StockOrdersService
|
|||||||
public function serviceApproval(Request $request)
|
public function serviceApproval(Request $request)
|
||||||
{
|
{
|
||||||
$config = $this->buildQueryConfig($request, 'approval');
|
$config = $this->buildQueryConfig($request, 'approval');
|
||||||
|
$item = $this->logicShow($config);
|
||||||
|
|
||||||
|
// 检查备货单是否包含必需的文件
|
||||||
|
$this->validateRequiredFilesForApproval($item);
|
||||||
|
|
||||||
$this->logicUpdateBy($config, [
|
$this->logicUpdateBy($config, [
|
||||||
'approval_status' => 1
|
'approval_status' => 1
|
||||||
]);
|
]);
|
||||||
$item = $this->logicShow($config);
|
|
||||||
$this->startApproval($item);
|
$this->startApproval($item);
|
||||||
return $this->postProcess('Approval', $item);
|
return $this->postProcess('Approval', $item);
|
||||||
}
|
}
|
||||||
@@ -366,6 +451,9 @@ class StockOrdersService
|
|||||||
*/
|
*/
|
||||||
public function beforeServiceUpdate($data, Request $request)
|
public function beforeServiceUpdate($data, Request $request)
|
||||||
{
|
{
|
||||||
|
// 检查必填文件是否已上传
|
||||||
|
// $this->validateRequiredFiles($data);
|
||||||
|
|
||||||
$data['biz_date'] = strtotime($data['biz_date']);
|
$data['biz_date'] = strtotime($data['biz_date']);
|
||||||
$data['eta_ship_date'] = strtotime($data['eta_ship_date']);
|
$data['eta_ship_date'] = strtotime($data['eta_ship_date']);
|
||||||
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']);
|
$data['latest_arrival_date'] = strtotime($data['latest_arrival_date']);
|
||||||
@@ -1024,4 +1112,7 @@ class StockOrdersService
|
|||||||
'submit_note' => $submitNote
|
'submit_note' => $submitNote
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user