OperationalAdjustmentsController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace frontend\modules\api\controllers;
  3. use common\models\OperationalAdjustments;
  4. use common\services\AccidentCasesScoreService;
  5. use common\services\AdminLogService;
  6. use common\services\CaseService;
  7. use common\services\EmergencyResponseService;
  8. use common\services\OperationalAdjustmentsDimensionService;
  9. use common\services\OperationalAdjustmentsRelateToRulesPointsService;
  10. use common\services\OperationalAdjustmentsService;
  11. use common\util\DealWithPostData;
  12. use frontend\modules\api\components\BaseAdminController;
  13. use Throwable;
  14. use Yii;
  15. use yii\base\InvalidConfigException;
  16. use yii\db\Exception;
  17. use yii\web\Response;
  18. class OperationalAdjustmentsController extends BaseAdminController
  19. {
  20. /**
  21. * 运营调整列表
  22. * @param $accident_id
  23. * @return Response
  24. */
  25. public function actionList($accident_id)
  26. {
  27. $query = OperationalAdjustmentsService::getQuery()->andWhere(["accident_id" => $accident_id]);
  28. //排序
  29. $this->initSequence($query, "start_time desc");
  30. //主要筛选条件
  31. $query = $this->addConditionToQuery("type_first", $query);
  32. //组合数据
  33. $list = OperationalAdjustmentsService::dealWithList($query->all(), $accident_id);
  34. OperationalAdjustmentsService::listAddDimension($list);
  35. $list = EmergencyResponseService::getEmergencyResponseObjList($list);
  36. $data['data'] = $list;
  37. list($data['scoreList'], $data['totalScore']) = AccidentCasesScoreService::getOperationalAdjustmentsScore($accident_id);
  38. return $this->asJson($data);
  39. }
  40. /**
  41. * 添加运营调整
  42. * @return Response
  43. * @throws Exception
  44. * @throws Throwable
  45. */
  46. public function actionAdd()
  47. {
  48. $post = Yii::$app->request->post();
  49. $post = DealWithPostData::changePostDataArrayToJson($post);
  50. $case = CaseService::checkIsPublish($post["accident_id"], $this->userInfo);
  51. $param = [
  52. "accident_id" => $post["accident_id"],
  53. "assess" => $post["assess"],
  54. "assess_two" => $post["assess_two"],
  55. "content" => $post["content"],
  56. "important_content" => $post["important_content"],
  57. "is_important" => $post["is_important"] ? 1 : 0,
  58. "is_time_period" => isset($post["is_time_period"]) && $post["is_time_period"] ? 1 : 0,
  59. "end_time" => isset($post["end_time"]) && $post["end_time"] !== "" ? $post["end_time"] : 0,
  60. "rules" => $post["rules"],
  61. "source_data" => $post["source_data"],
  62. "start_time" => $post["start_time"],
  63. "type_first" => $post["type_first"],
  64. "type_second" => $post["type_second"],
  65. "type_third" => $post["type_third"],
  66. "type_fourth" => $post["type_fourth"],
  67. ];
  68. $model = new OperationalAdjustments($param);
  69. $origin = AdminLogService::getOrigin($model, $this->getAllParams(), true);
  70. Yii::$app->db->transaction(function () use ($model) {
  71. if (!$model->save()) {
  72. throw new Exception($model->getErrorSummary(true)[0]);
  73. }
  74. //将运营调整与规章表的关系添加
  75. OperationalAdjustmentsRelateToRulesPointsService::add($model);
  76. //评价维度表添加
  77. OperationalAdjustmentsDimensionService::add($model);
  78. });
  79. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  80. return $this->asJson();
  81. }
  82. /**
  83. * 运营调整修改
  84. * @param $id
  85. * @return Response
  86. * @throws InvalidConfigException
  87. * @throws Exception
  88. * @throws Throwable
  89. */
  90. public function actionUpdate($id)
  91. {
  92. $model = OperationalAdjustmentsService::getOperationalAdjustmentsById($id);
  93. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  94. $case = CaseService::checkIsPublish($model->accident_id, $this->userInfo);
  95. Yii::$app->request->setBodyParams(DealWithPostData::changePostDataArrayToJson(Yii::$app->request->post()));
  96. $this->setAttributeFromGetAndPost($model);
  97. Yii::$app->db->transaction(function () use ($model) {
  98. if (!$model->save()) {
  99. throw new Exception($model->getErrorSummary(true)[0]);
  100. }
  101. //将运营调整与规章表的关系修改
  102. OperationalAdjustmentsRelateToRulesPointsService::update($model);
  103. });
  104. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  105. return $this->asJson();
  106. }
  107. /**
  108. * 运营调整删除
  109. * @param $id
  110. * @return Response
  111. * @throws Exception
  112. * @throws Throwable
  113. */
  114. public function actionDelete($id)
  115. {
  116. $model = OperationalAdjustmentsService::getOperationalAdjustmentsById($id);
  117. $case = CaseService::checkIsPublish($model->accident_id, $this->userInfo);
  118. $model->delete_time = time();
  119. Yii::$app->db->transaction(function () use ($model) {
  120. if (!$model->save()) {
  121. throw new Exception($model->getErrorSummary(true)[0]);
  122. }
  123. //将运营调整与规章表的关系删除
  124. OperationalAdjustmentsRelateToRulesPointsService::deleteByOperationalAdjustmentsId($model->id);
  125. //删除评价维度
  126. OperationalAdjustmentsDimensionService::deleteByOperationalAdjustmentsId($model->id);
  127. });
  128. //返回数据
  129. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  130. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  131. return $this->asJson();
  132. }
  133. }