EventOverviewController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace frontend\modules\api\controllers;
  3. use common\components\AjaxException;
  4. use common\models\EventOverview;
  5. use common\services\AdminLogService;
  6. use common\services\CaseService;
  7. use common\services\EventOverviewService;
  8. use frontend\modules\api\components\BaseAdminController;
  9. use Yii;
  10. use yii\base\InvalidConfigException;
  11. use yii\db\Exception;
  12. use yii\web\Response;
  13. class EventOverviewController extends BaseAdminController
  14. {
  15. /**
  16. * 事件概览列表
  17. * @param int $accident_id
  18. * @return Response
  19. */
  20. public function actionList(int $accident_id)
  21. {
  22. $query = EventOverviewService::getEventOverviewQuery()->andWhere(["accident_id" => $accident_id]);
  23. //排序
  24. $this->initSequence($query, "start_time desc,id desc");
  25. //组合数据
  26. $data['data'] = EventOverviewService::dealwithList($query->all(), $accident_id);
  27. return $this->asJson($data);
  28. }
  29. /**
  30. * 时间概览添加
  31. * @return Response
  32. * @throws AjaxException
  33. * @throws Exception
  34. * @throws InvalidConfigException
  35. */
  36. public function actionAdd()
  37. {
  38. $post = Yii::$app->request->post();
  39. $case = CaseService::checkIsPublish($post["accident_id"], $this->userInfo);
  40. $param = [
  41. "accident_id" => $post["accident_id"],
  42. "assess" => $post["assess"],
  43. "assess_two" => $post["assess_two"],
  44. "content" => $post["content"],
  45. "important_content" => $post["important_content"],
  46. "is_important" => $post["is_important"] ? 1 : 0,
  47. "is_time_period" => isset($post["is_time_period"]) && $post["is_time_period"] ? 1 : 0,
  48. "end_time" => isset($post["end_time"]) && $post["end_time"] !== "" ? $post["end_time"] : 0,
  49. "source_data" => $post["source_data"],
  50. "start_time" => $post["start_time"],
  51. ];
  52. $model = new EventOverview($param);
  53. $origin = AdminLogService::getOrigin($model, $this->getAllParams(), true);
  54. if (!$model->save()) {
  55. throw new Exception($model->getErrorSummary(true)[0]);
  56. }
  57. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  58. $data = [];
  59. return $this->asJson($data);
  60. }
  61. /**
  62. * 事件概览修改
  63. * @param $id
  64. * @return Response
  65. * @throws AjaxException
  66. * @throws InvalidConfigException
  67. */
  68. public function actionUpdate($id)
  69. {
  70. $model = EventOverviewService::getEventOverviewById($id);
  71. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  72. $case = CaseService::checkIsPublish($model->accident_id, $this->userInfo);
  73. $this->setAttributeFromGetAndPost($model);
  74. if ($model->save()) {
  75. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  76. return $this->asJson();
  77. } else {
  78. return $this->returnError($model->getErrorSummary(true)[0]);
  79. }
  80. }
  81. /**
  82. * 事件概览删除
  83. * @param $id
  84. * @return Response
  85. * @throws AjaxException
  86. * @throws Exception
  87. */
  88. public function actionDelete($id)
  89. {
  90. $model = EventOverviewService::getEventOverviewById($id);
  91. $case = CaseService::checkIsPublish($model->accident_id, $this->userInfo);
  92. $model->delete_time = time();
  93. if (!$model->save()) {
  94. throw new Exception($model->getErrorSummary(true)[0]);
  95. }
  96. //返回数据
  97. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  98. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  99. return $this->asJson();
  100. }
  101. }