| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Http\Controllers\Admin;
- use App\Services\Exam\PaperService;
- /**
- * 试卷管理-控制器
- */
- class PaperController extends Backend
- {
- public function __construct()
- {
- parent::__construct();
- $this->service = PaperService::make();
- }
- public function index()
- {
- $pageSize = request()->get('limit', 10);
- $list = $this->service->customList(request()->all(), $pageSize);
- $message = array(
- "msg" => '操作成功',
- "code" => 0,
- "data" => isset($list['list']) ? $list['list'] : [],
- "count" => isset($list['total']) ? $list['total'] : 0,
- );
- return $message;
- }
- public function import()
- {
- $formData = request()->input('formData', []);
- $topicsData = request()->input('topicsData', []);
- // 基本校验
- if (empty($formData['name'])) {
- return response()->json(['code' => 1, 'msg' => '试卷名称不能为空']);
- }
- if (empty($formData['subject_id'])) {
- return response()->json(['code' => 1, 'msg' => '题目分类不能为空']);
- }
- if (!is_array($topicsData) || count($topicsData) === 0) {
- return response()->json(['code' => 1, 'msg' => '题目数据不能为空']);
- }
- // 题目数据合法性检查
- foreach ($topicsData as $index => $topic) {
- if (empty($topic['topic_name'])) {
- return response()->json(['code' => 1, 'msg' => "第" . ($index + 1) . "题目内容不能为空"]);
- }
- if (empty($topic['score'])) {
- return response()->json(['code' => 1, 'msg' => "第" . ($index + 1) . "题目分数不能为空"]);
- }
- if (empty($topic['topic_type'])) {
- return response()->json(['code' => 1, 'msg' => "第" . ($index + 1) . "题目类型不能为空"]);
- }
- }
- return $this->service->createPaperWithTopics($formData, $topicsData);
- }
- }
|