|
@@ -90,6 +90,56 @@ class ItemService extends Service
|
|
|
return [true, ''];
|
|
return [true, ''];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ 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不能为空'];
|
|
|
|
|
+
|
|
|
|
|
+ $modelClass = $fromMap[$type] ?? "";
|
|
|
|
|
+ $item = $modelClass::where('id', $id)->where('del_time', 0)->first();
|
|
|
|
|
+ if (! $item) return [false, "文件不存在或已被删除"];
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+
|
|
|
|
|
+ $time = time();
|
|
|
|
|
+ if($type == 'custom_fields'){
|
|
|
|
|
+ if(empty($item->field_value)) return [false, '文件为空'];
|
|
|
|
|
+ $pendingTasks[] = ['type' => SysOssTasks::type_one, 'url' => $item->field_value, 'top_depart_id' => $user['top_depart_id'], 'crt_time' => $time];
|
|
|
|
|
+ $item->update([
|
|
|
|
|
+ 'field_value' => '',
|
|
|
|
|
+ 'field_name' => ''
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ if(empty($item->url)) return [false, '文件为空'];
|
|
|
|
|
+ $pendingTasks[] = ['type' => SysOssTasks::type_one, 'url' => $item->url, 'top_depart_id' => $user['top_depart_id'], 'crt_time' => $time];
|
|
|
|
|
+ $item->update(['del_time' => $time]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //触发 OSS 任务
|
|
|
|
|
+ if (! empty($pendingTasks)) {
|
|
|
|
|
+ SysOssTasks::insert($pendingTasks);
|
|
|
|
|
+ ProcessOssTask::dispatch()->onQueue(SysOssTasks::job);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [true, ''];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function itemEdit($data,$user){
|
|
public function itemEdit($data,$user){
|
|
|
list($status,$msg) = $this->itemRule($data, $user, false);
|
|
list($status,$msg) = $this->itemRule($data, $user, false);
|
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|