|
|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
|
|
use App\Models\Study;
|
|
|
|
|
use App\Models\StudyAsk;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use App\Helpers\ResponseCode;
|
|
|
|
|
@ -89,6 +90,7 @@ class StudyController extends CommonController
|
|
|
|
|
* @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), required=false, description="内容"),
|
|
|
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=false, description="类型1访客2施工3车辆"),
|
|
|
|
|
* @OA\Parameter(name="file", in="query", @OA\Schema(type="string"), required=false, description="文件id数组"),
|
|
|
|
|
* @OA\Parameter(name="ask_list", in="query", @OA\Schema(type="string"), required=false, description="问题数组。包括:type类型1单选2多选,title问题内容,answer回答选项二维数组,包括:content答案内容,result是否正确0错误1正确"),
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
@ -112,6 +114,9 @@ class StudyController extends CommonController
|
|
|
|
|
try {
|
|
|
|
|
if (isset($all['id'])) {
|
|
|
|
|
$model = Study::find($all['id']);
|
|
|
|
|
if (isset($all['ask_list'])) {
|
|
|
|
|
$model->asks()->delete();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$model = new Study();
|
|
|
|
|
$all['admin_id'] = $this->getUserId();
|
|
|
|
|
@ -119,6 +124,9 @@ class StudyController extends CommonController
|
|
|
|
|
}
|
|
|
|
|
$model->fill($all);
|
|
|
|
|
$model->save();
|
|
|
|
|
if (isset($all['ask_list']) && !empty($all['ask_list'])) {
|
|
|
|
|
$model->asks()->createMany($all['ask_list']);
|
|
|
|
|
}
|
|
|
|
|
DB::commit();
|
|
|
|
|
return $this->success('更新成功');
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
|
@ -154,6 +162,7 @@ class StudyController extends CommonController
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
}
|
|
|
|
|
Study::where('id', $all['id'])->delete();
|
|
|
|
|
StudyAsk::where('study_id', $all['id'])->delete();
|
|
|
|
|
return $this->success('删除成功');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|