调整备货单功能
This commit is contained in:
@@ -161,7 +161,8 @@ class StockOrdersService
|
||||
{
|
||||
// 启动审批
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
$appro->start('stock_orders', 'stock_orders', $item->id, [], $item->salesperson_id);
|
||||
$formData = $this->checkNewOrUsedVehicles($item->id);
|
||||
$appro->start('stock_orders', 'stock_orders', $item->id, $formData, $item->salesperson_id);
|
||||
// 异步生成pdf文件
|
||||
\Webman\RedisQueue\Redis::send('stock-order-pdf', ['id'=>$item->id]);
|
||||
}
|
||||
@@ -295,7 +296,8 @@ class StockOrdersService
|
||||
public function approvalNullify($item)
|
||||
{
|
||||
$appro = new \app\common\utils\approval\service\ApprovalFlowService();
|
||||
$appro->startNullify('stock_orders_nullify', 'stock_orders', $item->id, [], $item->salesperson_id);
|
||||
$formData = $this->checkNewOrUsedVehicles($item->id);
|
||||
$appro->startNullify('stock_orders_nullify', 'stock_orders', $item->id, $formData, $item->salesperson_id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,14 +481,19 @@ class StockOrdersService
|
||||
// 检查数据中是否存在该字段且为数组
|
||||
if (!empty($data[$field]) && is_array($data[$field])) {
|
||||
// 处理该字段下的每个文件
|
||||
foreach ($data[$field] as $fileUrl) {
|
||||
foreach ($data[$field] as $fileInfo) {
|
||||
$fileData = [
|
||||
'order_id' => $order->id,
|
||||
'file_code' => $fileCode,
|
||||
'file_url' => $fileUrl,
|
||||
'file_url' => $fileInfo['url'] ?? '',
|
||||
'file_name' => StockOrdersFiles::FILE_CODE[$fileCode],
|
||||
'original_name' => $fileInfo['original_name'] ?? StockOrdersFiles::FILE_CODE[$fileCode],
|
||||
];
|
||||
StockOrdersFiles::create($fileData);
|
||||
|
||||
// 只有当file_url不为空时才创建记录
|
||||
if (!empty($fileData['file_url'])) {
|
||||
StockOrdersFiles::create($fileData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -905,6 +912,7 @@ class StockOrdersService
|
||||
'id' => $file->id,
|
||||
'file_url' => $file->file_url,
|
||||
'file_full_url' => $this->getFileUrl($file->file_url),
|
||||
'original_name' => $file->original_name,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -978,4 +986,42 @@ class StockOrdersService
|
||||
}
|
||||
return (new \app\common\service\OssService)->generatePrivateUrl($fileUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查备货单中的车辆是新车还是二手车
|
||||
* @param int $stockOrderId 备货单ID
|
||||
* @return array 返回包含has_new和has_used的数组
|
||||
*/
|
||||
public function checkNewOrUsedVehicles(int $stockOrderId): array
|
||||
{
|
||||
// 获取备货单关联的所有车辆项
|
||||
$vehicles = StockOrderItems::where('order_id', $stockOrderId)->get();
|
||||
|
||||
$hasNew = false;
|
||||
$hasUsed = false;
|
||||
$submitNote = '';
|
||||
|
||||
foreach ($vehicles as $vehicle) {
|
||||
// 判断是否为二手车(mileage > 0)
|
||||
if ($vehicle->mileage > 0) {
|
||||
$hasUsed = true;
|
||||
$submitNote = '本单只有二手车';
|
||||
} else {
|
||||
$hasNew = true;
|
||||
$submitNote = '本单只有新车';
|
||||
}
|
||||
|
||||
// 如果两种类型都已经存在,可以提前退出循环
|
||||
if ($hasNew && $hasUsed) {
|
||||
$submitNote = '本单包含新车和二手车';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'has_new' => $hasNew ? 1 : 0,
|
||||
'has_used' => $hasUsed ? 1 : 0,
|
||||
'submit_note' => $submitNote
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user