liyinglin 3 years ago
parent 30b6319823
commit 4c6ab589ae

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Models\Study; use App\Models\Study;
use App\Models\StudyAsk;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use App\Helpers\ResponseCode; 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="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="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="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\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
* @OA\Response( * @OA\Response(
* response="200", * response="200",
@ -112,6 +114,9 @@ class StudyController extends CommonController
try { try {
if (isset($all['id'])) { if (isset($all['id'])) {
$model = Study::find($all['id']); $model = Study::find($all['id']);
if (isset($all['ask_list'])) {
$model->asks()->delete();
}
} else { } else {
$model = new Study(); $model = new Study();
$all['admin_id'] = $this->getUserId(); $all['admin_id'] = $this->getUserId();
@ -119,6 +124,9 @@ class StudyController extends CommonController
} }
$model->fill($all); $model->fill($all);
$model->save(); $model->save();
if (isset($all['ask_list']) && !empty($all['ask_list'])) {
$model->asks()->createMany($all['ask_list']);
}
DB::commit(); DB::commit();
return $this->success('更新成功'); return $this->success('更新成功');
} catch (\Exception $exception) { } catch (\Exception $exception) {
@ -154,6 +162,7 @@ class StudyController extends CommonController
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
} }
Study::where('id', $all['id'])->delete(); Study::where('id', $all['id'])->delete();
StudyAsk::where('study_id', $all['id'])->delete();
return $this->success('删除成功'); return $this->success('删除成功');
} }
} }

Loading…
Cancel
Save