cqp 1 месяц назад
Родитель
Сommit
22bafe73ce

+ 0 - 3
app/Http/Controllers/Api/BaseController.php

@@ -3,10 +3,7 @@
 namespace App\Http\Controllers\Api;
 namespace App\Http\Controllers\Api;
 
 
 use App\Http\Controllers\Controller;
 use App\Http\Controllers\Controller;
-use App\Models\SystemL;
-use App\Service\DisPatchAppService;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
-use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Facades\Storage;
 
 
 class BaseController extends Controller
 class BaseController extends Controller

+ 3 - 3
app/Jobs/ProcessOssTask.php

@@ -16,7 +16,7 @@ class ProcessOssTask implements ShouldQueue
 {
 {
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
 
-    public $timeout = 300;
+    public $timeout = 50;
 
 
     public function __construct()
     public function __construct()
     {
     {
@@ -36,12 +36,12 @@ class ProcessOssTask implements ShouldQueue
 
 
                     foreach ($tasks as $task) {
                     foreach ($tasks as $task) {
                         $status_db = 2;
                         $status_db = 2;
-                        if($task['type'] == 1){
+                        if($task['type'] == SysOssTasks::type_one){
                             //删除
                             //删除
                             list($status, $msg) = $service->createOssUploadOldSingle($task->url);
                             list($status, $msg) = $service->createOssUploadOldSingle($task->url);
                             if($status) $status_db = 1;
                             if($status) $status_db = 1;
 
 
-                        }elseif ($task['type'] == 2){
+                        }elseif ($task['type'] == SysOssTasks::type_two){
                             //新增
                             //新增
                             list($status, $msg) = $service->createOssUploadSingle($task->url);
                             list($status, $msg) = $service->createOssUploadSingle($task->url);
                             if($status) $status_db = 1;
                             if($status) $status_db = 1;

+ 7 - 5
app/Model/Item.php

@@ -12,13 +12,17 @@ class Item extends DataScopeBaseModel
     protected $dateFormat = 'U';
     protected $dateFormat = 'U';
     const employee_column = "crt_id";
     const employee_column = "crt_id";
 
 
-    public static $field = ['title','id','code','start_time','end_time','mark','crt_id','crt_time','state','budget','charge_id','item_attribute','field'];
+    public static $field = ['title','id','code','start_time','end_time','mark','crt_id','crt_time','state','budget','charge_id','item_attribute','field','is_review_required','review_id','priority_id'];
     public static $report_field_1 = ['title','id','code','start_time','end_time','mark','budget','field'];
     public static $report_field_1 = ['title','id','code','start_time','end_time','mark','budget','field'];
 
 
+    const TYPE_MINUS_TWO = -2;
+    const TYPE_MINUS_ONE = -1;
     const TYPE_ONE = 1;
     const TYPE_ONE = 1;
     const TYPE_TWO = 2;
     const TYPE_TWO = 2;
     const TYPE_THREE = 3;
     const TYPE_THREE = 3;
     const State_Type = [
     const State_Type = [
+        self::TYPE_MINUS_ONE => '审核中',
+        self::TYPE_MINUS_TWO => '已超期',
         self::TYPE_ONE => '待开始',
         self::TYPE_ONE => '待开始',
         self::TYPE_TWO => '进行中',
         self::TYPE_TWO => '进行中',
         self::TYPE_THREE => '已完成',
         self::TYPE_THREE => '已完成',
@@ -38,15 +42,13 @@ class Item extends DataScopeBaseModel
     // 作用域 里面关联了客户自定义的表头数据
     // 作用域 里面关联了客户自定义的表头数据
     public function scopeWithCustomData($query, $menuId, $user)
     public function scopeWithCustomData($query, $menuId, $user)
     {
     {
-        if (empty($menuId)) {
-            return $query;
-        }
+        if (empty($menuId)) return $query;
 
 
         $top_depart_id = $user['top_depart_id'];
         $top_depart_id = $user['top_depart_id'];
 
 
         return $query->with(['customFieldValues' => function ($subQuery) use ($menuId, $top_depart_id) {
         return $query->with(['customFieldValues' => function ($subQuery) use ($menuId, $top_depart_id) {
             //只查询设置的id 和 自定义字段的值 还有业务单据/档案的id(这个必须要 预加载里没有主外键关联关系就查询失败)
             //只查询设置的id 和 自定义字段的值 还有业务单据/档案的id(这个必须要 预加载里没有主外键关联关系就查询失败)
-            $subQuery->select(['definition_id', 'field_value', 'model_id'])
+            $subQuery->select(['definition_id', 'field_value', 'model_id', 'field_type'])
                 ->where('top_depart_id', $top_depart_id)
                 ->where('top_depart_id', $top_depart_id)
                 ->whereHas('definition', function ($q) use ($menuId) {
                 ->whereHas('definition', function ($q) use ($menuId) {
                     $q->where('menu_id', $menuId);
                     $q->where('menu_id', $menuId);

+ 3 - 0
app/Model/SysOssTasks.php

@@ -12,4 +12,7 @@ class SysOssTasks extends Model
     const UPDATED_AT = 'upd_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
     protected $dateFormat = 'U';
 
 
+    const type_one = 1;
+    const type_two = 2;
+    const job = 'sync_oss_file';
 }
 }

+ 79 - 59
app/Service/CustomFieldSettingService.php

@@ -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;
+                }
+            }
+        }
+    }
 }
 }

+ 30 - 14
app/Service/ItemService.php

@@ -6,6 +6,8 @@ use App\Model\Device;
 use App\Model\Employee;
 use App\Model\Employee;
 use App\Model\Item;
 use App\Model\Item;
 use App\Model\ItemDetails;
 use App\Model\ItemDetails;
+use App\Model\Priority;
+use App\Model\SysMenu;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\DB;
 
 
 class ItemService extends Service
 class ItemService extends Service
@@ -28,6 +30,14 @@ class ItemService extends Service
             $model->charge_id = $data['charge_id'] ?? 0;
             $model->charge_id = $data['charge_id'] ?? 0;
             $model->field = $data['field'] ?? "";
             $model->field = $data['field'] ?? "";
             $model->item_attribute = $data['item_attribute'] ?? 0;
             $model->item_attribute = $data['item_attribute'] ?? 0;
+
+            //项目管理的字段
+            if($user['select_tree_type'] == SysMenu::tree_type_one){
+                $model->is_review_required = $data['is_review_required'] ?? 0;
+                $model->review_id = $data['review_id'] ?? 0;
+                $model->priority_id = $data['priority_id'] ?? 0;
+            }
+
             $model->save();
             $model->save();
 
 
             $time = time();
             $time = time();
@@ -36,6 +46,12 @@ class ItemService extends Service
                 ->update(['del_time' => $time]);
                 ->update(['del_time' => $time]);
             $this->saveDetail($model->id, $time, $data);
             $this->saveDetail($model->id, $time, $data);
 
 
+            list($status, $msg) = CustomFieldSettingService::syncCustomFieldData($model->id,$data,$user);
+            if (! $status) {
+                DB::rollBack();
+                return [false, $msg];
+            }
+
             DB::commit();
             DB::commit();
         }catch (\Exception $exception){
         }catch (\Exception $exception){
             DB::rollBack();
             DB::rollBack();
@@ -63,17 +79,20 @@ class ItemService extends Service
             $model->charge_id = $data['charge_id'] ?? 0;
             $model->charge_id = $data['charge_id'] ?? 0;
             $model->field = $data['field'] ?? "";
             $model->field = $data['field'] ?? "";
             $model->item_attribute = $data['item_attribute'] ?? 0;
             $model->item_attribute = $data['item_attribute'] ?? 0;
+            $model->is_review_required = $data['is_review_required'] ?? 0;
+            $model->review_id = $data['review_id'] ?? 0;
+            $model->priority_id = $data['priority_id'] ?? 0;
             $model->crt_id = $user['id'];
             $model->crt_id = $user['id'];
             $model->top_depart_id = $data['top_depart_id'];
             $model->top_depart_id = $data['top_depart_id'];
             $model->save();
             $model->save();
 
 
             $this->saveDetail($model->id, time(), $data);
             $this->saveDetail($model->id, time(), $data);
 
 
-//            list($status, $msg) = CustomFieldSettingService::syncCustomFieldData($model->id,$data,$user);
-//            if (!$status) {
-//                DB::rollBack();
-//                return [false, $msg];
-//            }
+            list($status, $msg) = CustomFieldSettingService::syncCustomFieldData($model->id,$data,$user);
+            if (!$status) {
+                DB::rollBack();
+                return [false, $msg];
+            }
 
 
             DB::commit();
             DB::commit();
         }catch (\Exception $exception){
         }catch (\Exception $exception){
@@ -153,18 +172,10 @@ class ItemService extends Service
             }
             }
         }
         }
 
 
-        $detail = [
+        return [
             'man_list' => $unit,
             'man_list' => $unit,
             'device_list' => $receipt,
             'device_list' => $receipt,
         ];
         ];
-
-        //foreach ($detail as $key => $value) {
-           // if (empty($value)) {
-                //$detail[$key] = (object)[]; // 转成 stdClass 对象
-            //}
-        //}
-
-        return $detail;
     }
     }
 
 
     public function getItemMap($ids){
     public function getItemMap($ids){
@@ -210,12 +221,17 @@ class ItemService extends Service
             ->first();
             ->first();
         if(empty($customer)) return [false,'项目不存在或已被删除'];
         if(empty($customer)) return [false,'项目不存在或已被删除'];
         $customer = $customer->toArray();
         $customer = $customer->toArray();
+
+        //填充自定义表头附件地址
+        (new CustomFieldSettingService())->fillDataCustomField($customer);
+
         $customer['start_time']  = ! empty($customer['start_time']) ? date("Y-m-d", $customer['start_time']) : "";
         $customer['start_time']  = ! empty($customer['start_time']) ? date("Y-m-d", $customer['start_time']) : "";
         $customer['end_time']  = ! empty($customer['end_time']) ? date("Y-m-d", $customer['end_time']) : "";
         $customer['end_time']  = ! empty($customer['end_time']) ? date("Y-m-d", $customer['end_time']) : "";
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('title');
         $customer['charge_name'] = Employee::where('id',$customer['charge_id'])->value('title');
         $customer['charge_name'] = Employee::where('id',$customer['charge_id'])->value('title');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
         $customer['state_title'] = Item::State_Type[$customer['state']] ?? '';
         $customer['state_title'] = Item::State_Type[$customer['state']] ?? '';
+        $customer['priority_title'] = Priority::where('id', $customer['priority_id'])->value('title') ?? "";
 
 
         $details = $this->getDetail($data['id']);
         $details = $this->getDetail($data['id']);
         $customer = array_merge($customer, $details);
         $customer = array_merge($customer, $details);