You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.4 KiB
PHP
89 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class QuestionQuestionController extends Controller
|
|
{
|
|
public function create(Request $request)
|
|
{
|
|
$question = $request->post('question');
|
|
$type = $request->post('type');
|
|
$option = $request->post('option');
|
|
if (!$question) {
|
|
return \Yz::echoError('请填写题目');
|
|
}
|
|
if (mb_strlen($question) > 200) {
|
|
return \Yz::echoError('题目过长');
|
|
}
|
|
$type_array = ['select', 'input'];
|
|
if (!in_array($type, $type_array)) {
|
|
return \Yz::echoError('题目类型异常');
|
|
}
|
|
DB::table('question_questions')->insert([
|
|
'question' => $question,
|
|
'type' => $type,
|
|
'option' => $option ?? '{}',
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
return \Yz::Return(true, '操作完成');
|
|
}
|
|
|
|
public function update(Request $request)
|
|
{
|
|
$id = $request->post('id');
|
|
$question = $request->post('question');
|
|
$type = $request->post('type');
|
|
$option = $request->post('option');
|
|
if (!$question) {
|
|
return \Yz::echoError('请填写题目');
|
|
}
|
|
if (mb_strlen($question) > 200) {
|
|
return \Yz::echoError('题目过长');
|
|
}
|
|
$type_array = ['select', 'input'];
|
|
if (!in_array($type, $type_array)) {
|
|
return \Yz::echoError('题目类型异常');
|
|
}
|
|
DB::table('question_questions')->where('id', $id)->update([
|
|
'question' => $question,
|
|
'type' => $type,
|
|
'option' => $option ?? '{}',
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
]);
|
|
return \Yz::Return(true, '操作完成');
|
|
}
|
|
|
|
public function delete(Request $request)
|
|
{
|
|
$id = $request->post('id');
|
|
DB::table('question_questions')->where('id', $id)->delete();
|
|
return \Yz::Return(true, '操作完成');
|
|
}
|
|
|
|
public function list(Request $request)
|
|
{
|
|
$search = $request->post('search');
|
|
$db = DB::table('question_questions');
|
|
if (!!$search) {
|
|
$db->where('question', 'like', "%$search%");
|
|
}
|
|
$list = $db->orderBy('id', 'desc')->paginate(20);
|
|
return \Yz::Return(true, '操作完成', [
|
|
'list' => $list
|
|
]);
|
|
}
|
|
|
|
public function select(Request $request)
|
|
{
|
|
$list = DB::table('question_questions')->select(['id', 'question'])->get();
|
|
return \Yz::Return(true, '操作完成', [
|
|
'list' => $list
|
|
]);
|
|
}
|
|
}
|