Bläddra i källkod

删除试卷,视频集,同时删除对应子集

罗永浩 5 månader sedan
förälder
incheckning
48cfb635c1

+ 45 - 12
addons/admin/src/views/exam/examList.vue

@@ -95,7 +95,8 @@
                         <template slot-scope="{ row }">
                             <el-link @click="openForm(row)" icon="el-icon-edit" type="primary" :underline="false"
                                 v-if="permission.includes(permissionMap['edit'])">修改</el-link>
-                            <el-popconfirm title="确定要删除此试卷吗?" @confirm="remove(row)" class="ele-action">
+                            <el-popconfirm title="确定要删除此试卷吗?删除后该试卷下的所有试题也将被删除!" confirm-button-text="确定删除"
+                                cancel-button-text="取消" @confirm="remove(row)" class="ele-action">
                                 <el-link slot="reference" icon="el-icon-delete" type="danger" :underline="false"
                                     v-if="permission.includes(permissionMap['delete'])">删除</el-link>
                             </el-popconfirm>
@@ -234,13 +235,34 @@ export default {
         remove(row) {
             let ids = row ? [row.id] : this.choose.map((d) => d.id);
             if (ids.length === 0) return this.$message.error("请至少选择一条数据");
-            this.$confirm("确定要删除选中的试卷吗?", "提示", { type: "warning" }).then(() => {
-                this.$http.post("/papers/delete", { id: ids }).then((res) => {
-                    if (res.data.code === 0) {
-                        this.$message.success(res.data.msg);
-                        this.$refs.table.reload();
-                    } else this.$message.error(res.data.msg);
+
+            // 批量删除时使用确认对话框
+            if (!row && ids.length > 0) {
+                const paperText = ids.length === 1 ? '此试卷' : `选中的${ids.length}个试卷`;
+                this.$confirm(`确定要删除${paperText}吗?删除后该试卷下的所有试题也将被删除!`, "提示", {
+                    type: "warning",
+                    confirmButtonText: "确定删除",
+                    cancelButtonText: "取消"
+                }).then(() => {
+                    this.doDelete(ids);
+                }).catch(() => {
+                    // 用户取消删除
                 });
+            } else {
+                // 单个删除时直接执行(el-popconfirm已经确认过了)
+                this.doDelete(ids);
+            }
+        },
+        doDelete(ids) {
+            this.$http.post("/papers/delete", { id: ids }).then((res) => {
+                if (res.data.code === 0) {
+                    this.$message.success(res.data.msg || "删除成功");
+                    this.$refs.table.reload();
+                } else {
+                    this.$message.error(res.data.msg);
+                }
+            }).catch(e => {
+                this.$message.error("删除失败:" + e.message);
             });
         },
         beforeUpload(file) {
@@ -260,14 +282,25 @@ export default {
         batchRemove() {
             let ids = this.choose.map(d => d.id);
             if (ids.length === 0) return this.$message.warning("请至少选择一条数据");
-            this.$confirm("确定要删除选中的试卷吗?", "提示", { type: "warning" }).then(() => {
-                this.$http.post("/exam/papers/delete", { ids }).then(res => {
+            const paperText = ids.length === 1 ? '此试卷' : `选中的${ids.length}个试卷`;
+            this.$confirm(`确定要删除${paperText}吗?删除后该试卷下的所有试题也将被删除!`, "提示", {
+                type: "warning",
+                confirmButtonText: "确定删除",
+                cancelButtonText: "取消"
+            }).then(() => {
+                this.$http.post("/papers/delete", { id: ids }).then(res => {
                     if (res.data.code === 0) {
                         this.$message.success("删除成功")
                         this.$refs.table.reload()
-                    } else this.$message.error(res.data.msg);
-                })
-            })
+                    } else {
+                        this.$message.error(res.data.msg);
+                    }
+                }).catch(e => {
+                    this.$message.error("删除失败:" + e.message);
+                });
+            }).catch(() => {
+                // 用户取消删除
+            });
         },
         // 打开试题管理弹窗
         openTopicManager(row) {

+ 29 - 9
addons/admin/src/views/video/video.vue

@@ -92,7 +92,8 @@
                         <template slot-scope="{ row }">
                             <el-link @click="openForm(row)" icon="el-icon-edit" type="primary" :underline="false"
                                 v-if="permission.includes('sys:video:edit')">修改</el-link>
-                            <el-popconfirm title="确定要删除吗?" @confirm="remove(row)" class="ele-action">
+                            <el-popconfirm title="确定要删除此视频集吗?删除后该视频集下的所有视频列表也将被删除!" confirm-button-text="确定删除"
+                                cancel-button-text="取消" @confirm="remove(row)" class="ele-action">
                                 <el-link slot="reference" icon="el-icon-delete" type="danger" :underline="false"
                                     v-if="permission.includes('sys:video:delete')">删除</el-link>
                             </el-popconfirm>
@@ -209,15 +210,34 @@ export default {
         remove(row) {
             let ids = row ? [row.id] : this.choose.map(d => d.id);
             if (!ids.length) return this.$message.warning("请选择数据");
-            this.$confirm("确定要删除选中视频集吗?", "提示", { type: "warning" }).then(() => {
-                this.$http.post("/videos/delete", { id: ids }).then(res => {
-                    if (res.data.code === 0) {
-                        this.$message.success("删除成功");
-                        this.loadTableData();
-                    } else {
-                        this.$message.error(res.data.msg);
-                    }
+
+            // 批量删除时使用确认对话框
+            if (!row && ids.length > 0) {
+                const videoSetText = ids.length === 1 ? '此视频集' : `选中的${ids.length}个视频集`;
+                this.$confirm(`确定要删除${videoSetText}吗?删除后该视频集下的所有视频列表也将被删除!`, "提示", {
+                    type: "warning",
+                    confirmButtonText: "确定删除",
+                    cancelButtonText: "取消"
+                }).then(() => {
+                    this.doDelete(ids);
+                }).catch(() => {
+                    // 用户取消删除
                 });
+            } else {
+                // 单个删除时直接执行(el-popconfirm已经确认过了)
+                this.doDelete(ids);
+            }
+        },
+        doDelete(ids) {
+            this.$http.post("/videos/delete", { id: ids }).then(res => {
+                if (res.data.code === 0) {
+                    this.$message.success("删除成功");
+                    this.$refs.table.reload();
+                } else {
+                    this.$message.error(res.data.msg);
+                }
+            }).catch(e => {
+                this.$message.error("删除失败:" + e.message);
             });
         },
         openFormCourses(row) {

+ 32 - 1
app/Services/Common/VideoService.php

@@ -1,8 +1,10 @@
 <?php
+
 namespace App\Services\Common;
 
 use App\Models\ActionLogModel;
 use App\Models\VideoModel;
+use App\Models\VideoCoursesModel;
 use App\Services\BaseService;
 
 class VideoService extends BaseService
@@ -106,7 +108,7 @@ class VideoService extends BaseService
 
         // 校验视频集名称是否唯一
         $videoName = trim($data['video_name'] ?? '');
-        $checkId = $this->model->where(['video_name' => $videoName,'type'=>$type, 'mark' => 1])->value('id');
+        $checkId = $this->model->where(['video_name' => $videoName, 'type' => $type, 'mark' => 1])->value('id');
         if ($checkId && $id != $checkId) {
             return message('视频集名称已存在', false);
         }
@@ -167,7 +169,36 @@ class VideoService extends BaseService
         // 设置日志标题
         ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => "删除视频信息", 'content' => json_encode(request()->post(), 256), 'module' => 'admin']);
         ActionLogModel::record();
+
+        // 获取要删除的课程集ID
+        $ids = request()->post('id', []);
+        if (!is_array($ids)) {
+            $ids = [$ids];
+        }
+
+        // 删除该课程集下关联的所有视频课程
+        if (!empty($ids)) {
+            $videoCoursesModel = new VideoCoursesModel();
+            // 查询该课程集下的所有视频课程
+            $courseIds = $videoCoursesModel->whereIn('video_id', $ids)
+                ->where('mark', 1)
+                ->pluck('id')
+                ->toArray();
+
+            if (!empty($courseIds)) {
+                // 软删除视频课程(标记mark=0)
+                $videoCoursesModel->whereIn('id', $courseIds)->update([
+                    'mark' => 0,
+                    'update_time' => time()
+                ]);
+            }
+        }
+
+        // 清理七天前标记软删除的数据
         $this->model->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
+        $videoCoursesModel = new VideoCoursesModel();
+        $videoCoursesModel->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
+
         return parent::delete();
     }
 }

+ 30 - 1
app/Services/Exam/PaperService.php

@@ -1,4 +1,5 @@
 <?php
+
 namespace App\Services\Exam;
 
 use App\Models\ExamPaperModel;
@@ -125,8 +126,36 @@ class PaperService extends BaseService
         // 设置日志标题
         ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => "删除试卷信息", 'content' => json_encode(request()->post(), 256), 'module' => 'admin']);
         ActionLogModel::record();
+
+        // 获取要删除的试卷ID
+        $ids = request()->post('id', []);
+        if (!is_array($ids)) {
+            $ids = [$ids];
+        }
+
+        // 删除该试卷下关联的所有试题
+        if (!empty($ids)) {
+            $topicModel = new ExamTopicModel();
+            // 查询该试卷下的所有试题
+            $topicIds = $topicModel->whereIn('paper_id', $ids)
+                ->where('mark', 1)
+                ->pluck('id')
+                ->toArray();
+
+            if (!empty($topicIds)) {
+                // 软删除试题(标记mark=0)
+                $topicModel->whereIn('id', $topicIds)->update([
+                    'mark' => 0,
+                    'update_time' => time()
+                ]);
+            }
+        }
+
+        // 清理七天前标记软删除的数据
         $this->model->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
+        $topicModel = new ExamTopicModel();
+        $topicModel->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
+
         return parent::delete();
     }
-
 }