123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace frontend\modules\api\controllers;
- use common\components\AjaxException;
- use common\models\EventOverview;
- use common\services\AdminLogService;
- use common\services\CaseService;
- use common\services\EventOverviewService;
- use frontend\modules\api\components\BaseAdminController;
- use Yii;
- use yii\base\InvalidConfigException;
- use yii\db\Exception;
- use yii\web\Response;
- class EventOverviewController extends BaseAdminController
- {
- /**
- * 事件概览列表
- * @param int $accident_id
- * @return Response
- */
- public function actionList(int $accident_id)
- {
- $query = EventOverviewService::getEventOverviewQuery()->andWhere(["accident_id" => $accident_id]);
- //排序
- $this->initSequence($query, "start_time desc,id desc");
- //组合数据
- $data['data'] = EventOverviewService::dealwithList($query->all(), $accident_id);
- return $this->asJson($data);
- }
- /**
- * 时间概览添加
- * @return Response
- * @throws AjaxException
- * @throws Exception
- * @throws InvalidConfigException
- */
- public function actionAdd()
- {
- $post = Yii::$app->request->post();
- $case = CaseService::checkIsPublish($post["accident_id"], $this->userInfo);
- $param = [
- "accident_id" => $post["accident_id"],
- "assess" => $post["assess"],
- "assess_two" => $post["assess_two"],
- "content" => $post["content"],
- "important_content" => $post["important_content"],
- "is_important" => $post["is_important"] ? 1 : 0,
- "is_time_period" => isset($post["is_time_period"]) && $post["is_time_period"] ? 1 : 0,
- "end_time" => isset($post["end_time"]) && $post["end_time"] !== "" ? $post["end_time"] : 0,
- "source_data" => $post["source_data"],
- "start_time" => $post["start_time"],
- ];
- $model = new EventOverview($param);
- $origin = AdminLogService::getOrigin($model, $this->getAllParams(), true);
- if (!$model->save()) {
- throw new Exception($model->getErrorSummary(true)[0]);
- }
- AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
- $data = [];
- return $this->asJson($data);
- }
- /**
- * 事件概览修改
- * @param $id
- * @return Response
- * @throws AjaxException
- * @throws InvalidConfigException
- */
- public function actionUpdate($id)
- {
- $model = EventOverviewService::getEventOverviewById($id);
- $origin = AdminLogService::getOrigin($model, $this->getAllParams());
- $case = CaseService::checkIsPublish($model->accident_id, $this->userInfo);
- $this->setAttributeFromGetAndPost($model);
- if ($model->save()) {
- AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
- return $this->asJson();
- } else {
- return $this->returnError($model->getErrorSummary(true)[0]);
- }
- }
- /**
- * 事件概览删除
- * @param $id
- * @return Response
- * @throws AjaxException
- * @throws Exception
- */
- public function actionDelete($id)
- {
- $model = EventOverviewService::getEventOverviewById($id);
- $case = CaseService::checkIsPublish($model->accident_id, $this->userInfo);
- $model->delete_time = time();
- if (!$model->save()) {
- throw new Exception($model->getErrorSummary(true)[0]);
- }
- //返回数据
- $origin = AdminLogService::getOrigin($model, $this->getAllParams());
- AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
- return $this->asJson();
- }
- }
|