|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
|
|
+use App\Jobs\ProcessOssTask;
|
|
|
use App\Model\CustomFieldDefinitions;
|
|
use App\Model\CustomFieldDefinitions;
|
|
|
use App\Model\SysMenu;
|
|
use App\Model\SysMenu;
|
|
|
use App\Model\SysModules;
|
|
use App\Model\SysModules;
|
|
@@ -107,11 +108,11 @@ class CustomFieldSettingService extends Service
|
|
|
$title = SysMenu::where('id', $data['menu_id'])->value('title');
|
|
$title = SysMenu::where('id', $data['menu_id'])->value('title');
|
|
|
if(empty($title)) return [false, '菜单不存在或已被删除'];
|
|
if(empty($title)) return [false, '菜单不存在或已被删除'];
|
|
|
|
|
|
|
|
- $bool = SysModules::where('del_time',0)
|
|
|
|
|
- ->where('top_depart_id', $data['top_depart_id'])
|
|
|
|
|
- ->where('menu_id', $data['menu_id'])
|
|
|
|
|
- ->exists();
|
|
|
|
|
- if(! $bool) return [false, $title . '不允许增加自定义表头'];
|
|
|
|
|
|
|
+// $bool = SysModules::where('del_time',0)
|
|
|
|
|
+// ->where('top_depart_id', $data['top_depart_id'])
|
|
|
|
|
+// ->where('menu_id', $data['menu_id'])
|
|
|
|
|
+// ->exists();
|
|
|
|
|
+// if(! $bool) return [false, $title . '不允许增加自定义表头'];
|
|
|
|
|
|
|
|
if(empty($data['data'])) return [false,'自定义数据不能为空'];
|
|
if(empty($data['data'])) return [false,'自定义数据不能为空'];
|
|
|
|
|
|
|
@@ -163,71 +164,90 @@ class CustomFieldSettingService extends Service
|
|
|
public static function syncCustomFieldData($id, $data, $user)
|
|
public static function syncCustomFieldData($id, $data, $user)
|
|
|
{
|
|
{
|
|
|
$top_depart_id = $user['top_depart_id'];
|
|
$top_depart_id = $user['top_depart_id'];
|
|
|
- if (empty($data['menu_id'])) return [false, '菜单ID不能为空'];
|
|
|
|
|
- $menuId = $data['menu_id'];
|
|
|
|
|
-
|
|
|
|
|
- $definitions = CustomFieldDefinitions::where('menu_id', $menuId)
|
|
|
|
|
|
|
+ if (empty($data['menu_id'])) return [true, ''];
|
|
|
|
|
+ $definitions = CustomFieldDefinitions::where('menu_id', $data['menu_id'])
|
|
|
->where('top_depart_id', $top_depart_id)
|
|
->where('top_depart_id', $top_depart_id)
|
|
|
->get();
|
|
->get();
|
|
|
|
|
+ if(empty($definitions)) return [true, ''];
|
|
|
|
|
|
|
|
$pendingTasks = [];
|
|
$pendingTasks = [];
|
|
|
-
|
|
|
|
|
$time = time();
|
|
$time = time();
|
|
|
- foreach ($definitions as $df) {
|
|
|
|
|
- $key = $df->field_key;
|
|
|
|
|
- // 如果请求数据中没有这个自定义字段的 key,跳过(支持局部更新)
|
|
|
|
|
- if (!array_key_exists($key, $data)) continue;
|
|
|
|
|
-
|
|
|
|
|
- $newVal = (string)($data[$key] ?? '');
|
|
|
|
|
-
|
|
|
|
|
- // --- 附件类型逻辑处理 ---
|
|
|
|
|
- if ($df->field_type === 'file') {
|
|
|
|
|
- // 查询数据库中已有的旧路径
|
|
|
|
|
- $oldVal = DB::table('custom_field_values')
|
|
|
|
|
- ->where('model_id', $id)
|
|
|
|
|
- ->where('definition_id', $df->id)
|
|
|
|
|
- ->value('field_value') ?? '';
|
|
|
|
|
-
|
|
|
|
|
- if ($newVal !== $oldVal) {
|
|
|
|
|
- //产生一个【删除任务】
|
|
|
|
|
- if (!empty($oldVal)) {
|
|
|
|
|
- $pendingTasks[] = [
|
|
|
|
|
- 'type' => 1, // 删除旧文件
|
|
|
|
|
- 'url' => $oldVal,
|
|
|
|
|
- 'top_depart_id' => $top_depart_id,
|
|
|
|
|
- 'crt_time' => $time,
|
|
|
|
|
- ];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //产生一个【新增同步任务】
|
|
|
|
|
- if (!empty($newVal)) {
|
|
|
|
|
- $pendingTasks[] = [
|
|
|
|
|
- 'type' => 2, // 新增同步到 OSS
|
|
|
|
|
- 'url' => $newVal,
|
|
|
|
|
- 'top_depart_id' => $top_depart_id,
|
|
|
|
|
- 'crt_time' => $time,
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ foreach ($definitions as $df) {
|
|
|
|
|
+ $key = $df->field_key;
|
|
|
|
|
+ // 如果请求数据中没有这个自定义字段的 key,跳过
|
|
|
|
|
+ if (!array_key_exists($key, $data)) continue;
|
|
|
|
|
+
|
|
|
|
|
+ $newVal = (string)($data[$key] ?? '');
|
|
|
|
|
+
|
|
|
|
|
+ // --- 附件类型逻辑处理 ---
|
|
|
|
|
+ if ($df->field_type === CustomFieldDefinitions::TYPE_TWO) {
|
|
|
|
|
+ // 查询数据库中已有的旧路径
|
|
|
|
|
+ $oldVal = DB::table('custom_field_values')
|
|
|
|
|
+ ->where('model_id', $id)
|
|
|
|
|
+ ->where('definition_id', $df->id)
|
|
|
|
|
+ ->value('field_value') ?? '';
|
|
|
|
|
+
|
|
|
|
|
+ if ($newVal !== $oldVal) {
|
|
|
|
|
+ //产生一个【删除任务】
|
|
|
|
|
+ if (!empty($oldVal)) {
|
|
|
|
|
+ $pendingTasks[] = [
|
|
|
|
|
+ 'type' => SysOssTasks::type_one, // 删除旧文件
|
|
|
|
|
+ 'url' => $oldVal,
|
|
|
|
|
+ 'top_depart_id' => $top_depart_id,
|
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //产生一个【新增同步任务】
|
|
|
|
|
+ if (!empty($newVal)) {
|
|
|
|
|
+ $pendingTasks[] = [
|
|
|
|
|
+ 'type' => SysOssTasks::type_two, // 新增同步到 OSS
|
|
|
|
|
+ 'url' => $newVal,
|
|
|
|
|
+ 'top_depart_id' => $top_depart_id,
|
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // --- 统一更新业务值表 (文本或附件路径) ---
|
|
|
|
|
+ DB::table('custom_field_values')->updateOrInsert(
|
|
|
|
|
+ [
|
|
|
|
|
+ 'model_id' => $id,
|
|
|
|
|
+ 'definition_id' => $df->id,
|
|
|
|
|
+ 'top_depart_id' => $top_depart_id,
|
|
|
|
|
+ 'field_type' => $df->field_type
|
|
|
|
|
+ ],
|
|
|
|
|
+ [
|
|
|
|
|
+ 'field_value' => $newVal, // 如果是删除,这里存入空字符串
|
|
|
|
|
+ 'upd_time' => time()
|
|
|
|
|
+ ]
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // --- 统一更新业务值表 (文本或附件路径) ---
|
|
|
|
|
- DB::table('custom_field_values')->updateOrInsert(
|
|
|
|
|
- [
|
|
|
|
|
- 'model_id' => $id,
|
|
|
|
|
- 'definition_id' => $df->id,
|
|
|
|
|
- 'top_depart_id' => $top_depart_id,
|
|
|
|
|
- ],
|
|
|
|
|
- [
|
|
|
|
|
- 'field_value' => $newVal, // 如果是删除,这里存入空字符串
|
|
|
|
|
- 'upd_time' => time()
|
|
|
|
|
- ]
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //需要执行的oss的任务 调用这个方法的地方在 事务结束后触发下队列
|
|
|
|
|
+ if(! empty($pendingTasks)) {
|
|
|
|
|
+ SysOssTasks::insert($pendingTasks);
|
|
|
|
|
|
|
|
- //需要执行的oss的任务 调用这个方法的地方在 事务结束后触发下队列 todo
|
|
|
|
|
- if(! empty($pendingTasks)) SysOssTasks::insert($pendingTasks);
|
|
|
|
|
|
|
+ ProcessOssTask::dispatch()->onQueue(SysOssTasks::job);
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (\Throwable $exception){
|
|
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return [true, ''];
|
|
return [true, ''];
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public function fillDataCustomField(&$data){
|
|
|
|
|
+ if(! empty($data['custom_field_values'])){
|
|
|
|
|
+ $fileUploadService = new FileUploadService();
|
|
|
|
|
+ foreach ($data['custom_field_values'] as $key => $value){
|
|
|
|
|
+ if($value['field_type'] == CustomFieldDefinitions::TYPE_TWO){
|
|
|
|
|
+ $img_str = $fileUploadService->getFileShow($value['field_value']);
|
|
|
|
|
+ $data['custom_field_values'][$key]['field_value_show'] = $img_str;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|