|
|
@@ -147,6 +147,7 @@ class ItemService extends Service
|
|
|
$modelClass = $modelMap[$from] ?? "";
|
|
|
$item = $modelClass::where('id', $id)->where('del_time', 0)->first();
|
|
|
if (!$item) return [false, $fromMap[$from] . "不存在或已被删除"];
|
|
|
+ if ($item->state == Item::TYPE_THREE) return [false, '已完成状态不允许上传文件'];
|
|
|
|
|
|
$itemId = $item->item_id ?? $item->id;
|
|
|
$itemNodeId = $item->item_node_id ?? ($from == ItemFile::from_one ? 0 : $item->id);
|
|
|
@@ -196,7 +197,7 @@ class ItemService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
- public function itemFileUpDelete($data,$user){
|
|
|
+ public function itemFileUpDelete1($data,$user){
|
|
|
$fromMap = [
|
|
|
'custom_fields' => CustomFieldValue::class,
|
|
|
'item_file' => ItemFile::class,
|
|
|
@@ -213,6 +214,21 @@ class ItemService extends Service
|
|
|
$modelClass = $fromMap[$type] ?? "";
|
|
|
$item = $modelClass::where('id', $id)->where('del_time', 0)->first();
|
|
|
if (! $item) return [false, "文件不存在或已被删除"];
|
|
|
+ $modelMap = [
|
|
|
+ ItemFile::from_one => Item::class,
|
|
|
+ ItemFile::from_two => ItemNode::class,
|
|
|
+ ItemFile::from_three => ItemNodeMission::class,
|
|
|
+ ];
|
|
|
+ $modelClass = $modelMap[$item->from] ?? "";
|
|
|
+ if(! $modelClass) return [false, '来源不存在'];
|
|
|
+ $model2Map = [
|
|
|
+ ItemFile::from_one => 'item_id',
|
|
|
+ ItemFile::from_two => 'item_node_id',
|
|
|
+ ItemFile::from_three => 'item_node_mission_id',
|
|
|
+ ];
|
|
|
+ $id = $model2Map[$item->from];
|
|
|
+ $m = $modelClass::where('id', $id)->where('del_time', 0)->first();
|
|
|
+ if ($m->state == Item::TYPE_THREE) return [false, '已完成状态不允许删除文件'];
|
|
|
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
|
@@ -246,7 +262,94 @@ class ItemService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
- public function itemFileIsDelivery($data, $user)
|
|
|
+ public function itemFileUpDelete($data, $user)
|
|
|
+ {
|
|
|
+ $fromMap = [
|
|
|
+ 'custom_fields' => CustomFieldValue::class,
|
|
|
+ 'item_file' => ItemFile::class,
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 1. 基础参数校验
|
|
|
+ $type = $data['type'] ?? null;
|
|
|
+ if (empty($type)) return [false, '删除来源类型不能为空'];
|
|
|
+ if (!isset($fromMap[$type])) return [false, '删除来源类型错误'];
|
|
|
+
|
|
|
+ $id = $data['id'] ?? null;
|
|
|
+ if (empty($id)) return [false, '来源ID不能为空'];
|
|
|
+
|
|
|
+ // 2. 查询当前文件记录
|
|
|
+ $modelClass = $fromMap[$type];
|
|
|
+ $item = $modelClass::where('id', $id)->where('del_time', 0)->first();
|
|
|
+ if (!$item) return [false, "文件不存在或已被删除"];
|
|
|
+
|
|
|
+ // 3. 【核心统一】根据 from 动态映射对应的上级主体 Model 类名
|
|
|
+ $modelMap = [
|
|
|
+ ItemFile::from_one => Item::class,
|
|
|
+ ItemFile::from_two => ItemNode::class,
|
|
|
+ ItemFile::from_three => ItemNodeMission::class,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $upperClass = $modelMap[$item->from] ?? null;
|
|
|
+ if (!$upperClass) return [false, '未知的来源所属类型'];
|
|
|
+
|
|
|
+ // 4. 根据 from 动态匹配当前模型里的外键字段名
|
|
|
+ $foreignKeyMap = [
|
|
|
+ ItemFile::from_one => 'item_id',
|
|
|
+ ItemFile::from_two => 'item_node_id',
|
|
|
+ ItemFile::from_three => 'item_node_mission_id',
|
|
|
+ ];
|
|
|
+ $foreignKey = $foreignKeyMap[$item->from] ?? 'item_id';
|
|
|
+
|
|
|
+ // 动态获取外键 ID 值(例如 $item->item_node_id)
|
|
|
+ $upperId = $item->$foreignKey ?? 0;
|
|
|
+
|
|
|
+ // 5. 查询上级主体,校验完结状态
|
|
|
+ $upperModel = $upperClass::where('id', $upperId)->where('del_time', 0)->first();
|
|
|
+ if ($upperModel && $upperModel->state == Item::TYPE_THREE) return [false, '已完成状态不允许删除文件'];
|
|
|
+
|
|
|
+ // 6. 执行删除事务与异步 OSS 任务
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+
|
|
|
+ if ($type === 'custom_fields') {
|
|
|
+ if (empty($item->field_value)) return [false, '文件为空'];
|
|
|
+ $fileUrl = $item->field_value;
|
|
|
+
|
|
|
+ // 清空自定义字段
|
|
|
+ $item->update([
|
|
|
+ 'field_value' => '',
|
|
|
+ 'field_name' => ''
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ if (empty($item->url)) return [false, '文件为空'];
|
|
|
+ $fileUrl = $item->url;
|
|
|
+
|
|
|
+ // 软删除附件记录
|
|
|
+ $item->update(['del_time' => $time]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // OSS 文件真实清理任务
|
|
|
+ $pendingTask = [
|
|
|
+ 'type' => SysOssTasks::type_one,
|
|
|
+ 'url' => $fileUrl,
|
|
|
+ 'top_depart_id' => $user['top_depart_id'],
|
|
|
+ 'crt_time' => $time
|
|
|
+ ];
|
|
|
+ SysOssTasks::insert($pendingTask);
|
|
|
+ ProcessOssTask::dispatch()->onQueue(SysOssTasks::job);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function itemFileIsDelivery1($data, $user)
|
|
|
{
|
|
|
$typeMap = [
|
|
|
1 => '标记为交付物',
|
|
|
@@ -296,6 +399,92 @@ class ItemService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
+ public function itemFileIsDelivery($data, $user)
|
|
|
+ {
|
|
|
+ $typeMap = [
|
|
|
+ 1 => '标记为交付物',
|
|
|
+ 2 => '解除交付物',
|
|
|
+ ];
|
|
|
+ $fromMap = [
|
|
|
+ 'custom_fields' => CustomFieldValue::class,
|
|
|
+ 'item_file' => ItemFile::class,
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 1. 基础参数校验
|
|
|
+ if (empty($data['opt_type']) || !isset($typeMap[$data['opt_type']])) return [false, '操作标识错误'];
|
|
|
+ if (empty($data['data']) || !is_array($data['data'])) return [false, '文件数据不能为空'];
|
|
|
+
|
|
|
+ $statusValue = ($data['opt_type'] == 1) ? 1 : 0;
|
|
|
+
|
|
|
+ // 按文件分类归拢 ID
|
|
|
+ $idsByType = [
|
|
|
+ 'custom_fields' => [],
|
|
|
+ 'item_file' => [],
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($data['data'] as $value) {
|
|
|
+ if (empty($value['id'])) return [false, '文件ID不能为空'];
|
|
|
+ if (empty($value['type']) || !isset($fromMap[$value['type']])) return [false, '文件类型错误'];
|
|
|
+
|
|
|
+ $idsByType[$value['type']][] = $value['id'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 【核心新增】上级主体完结状态校验(防止已完结的主体还能修改交付物状态)
|
|
|
+ $modelMap = [
|
|
|
+ ItemFile::from_one => Item::class,
|
|
|
+ ItemFile::from_two => ItemNode::class,
|
|
|
+ ItemFile::from_three => ItemNodeMission::class,
|
|
|
+ ];
|
|
|
+ $foreignKeyMap = [
|
|
|
+ ItemFile::from_one => 'item_id',
|
|
|
+ ItemFile::from_two => 'item_node_id',
|
|
|
+ ItemFile::from_three => 'item_node_mission_id',
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($idsByType as $type => $ids) {
|
|
|
+ if (empty($ids)) continue;
|
|
|
+
|
|
|
+ $modelClass = $fromMap[$type];
|
|
|
+ // 批量一次性查出这些文件记录
|
|
|
+ $files = $modelClass::whereIn('id', $ids)->where('del_time', 0)->get();
|
|
|
+
|
|
|
+ foreach ($files as $file) {
|
|
|
+ $upperClass = $modelMap[$file->from] ?? null;
|
|
|
+ $foreignKey = $foreignKeyMap[$file->from] ?? 'item_id';
|
|
|
+ $upperId = $file->$foreignKey ?? 0;
|
|
|
+
|
|
|
+ if ($upperClass && $upperId > 0) {
|
|
|
+ // 校验上级主体状态
|
|
|
+ $upperModel = $upperClass::where('id', $upperId)->where('del_time', 0)->first();
|
|
|
+ if ($upperModel && $upperModel->state == Item::TYPE_THREE) {
|
|
|
+ return [false, '相关项目/节点/任务已完结,无法修改交付物状态'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 执行批量更新事务
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ foreach ($idsByType as $type => $ids) {
|
|
|
+ if (!empty($ids)) {
|
|
|
+ $modelClass = $fromMap[$type];
|
|
|
+ $modelClass::whereIn('id', $ids)->update([
|
|
|
+ 'is_delivery' => $statusValue,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
+
|
|
|
public function changedCommon($user, $oldData){
|
|
|
//是否存在审批流
|
|
|
if(empty($oldData['review_id'])) return false;
|