AccidentCasesScoreCommentController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace frontend\modules\api\controllers;
  3. use common\components\AjaxException;
  4. use common\models\AccidentCasesScoreComment;
  5. use common\services\AdminLogService;
  6. use frontend\modules\api\components\BaseAdminController;
  7. use Yii;
  8. use yii\base\InvalidConfigException;
  9. use yii\db\Exception;
  10. use yii\web\Response;
  11. class AccidentCasesScoreCommentController extends BaseAdminController
  12. {
  13. /**
  14. * 评价用语列表
  15. * @param int $current
  16. * @param int $page
  17. * @return Response
  18. */
  19. public function actionList(int $current = 1, int $page = 10)
  20. {
  21. //重新整合数据
  22. $query = AccidentCasesScoreComment::find()
  23. ->limit($page)
  24. ->offset(($current - 1) * $page);
  25. //排序
  26. $this->initSequence($query);
  27. //主要筛选条件
  28. $this->addConditionToQuery("type", $query);
  29. $this->addConditionToQuery("type_two", $query);
  30. $this->addConditionToQuery("content", $query, true);
  31. $this->addConditionToQuery("status", $query);
  32. //组合数据
  33. $data['data'] = $query->all();
  34. $data['total'] = $query->count();
  35. return $this->asJson($data);
  36. }
  37. /**
  38. * 评价用语显示列表
  39. * @return Response
  40. */
  41. public function actionShowList()
  42. {
  43. //重新整合数据
  44. $query = AccidentCasesScoreComment::find()->where(["status" => 1]);
  45. //排序
  46. $this->initSequence($query);
  47. //主要筛选条件
  48. $this->addConditionToQuery("type", $query);
  49. $this->addConditionToQuery("type_two", $query);
  50. $this->addConditionToQuery("content", $query, true);
  51. //组合数据
  52. $data['data'] = $query->all();
  53. return $this->asJson($data);
  54. }
  55. /**
  56. * 评价用语修改
  57. * @return Response
  58. * @throws AjaxException
  59. * @throws Exception
  60. * @throws InvalidConfigException
  61. */
  62. public function actionUpdate()
  63. {
  64. $post = Yii::$app->request->post();
  65. $model = AccidentCasesScoreComment::findOne($post["id"]);
  66. if (!$model) {
  67. throw new AjaxException("评价用语不存在");
  68. }
  69. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  70. $model->type = $post["type"];
  71. $model->type_two = $post["type_two"];
  72. $model->content = $post["content"];
  73. $model->status = $post["status"];
  74. if (!$model->save()) {
  75. throw new Exception($model->getErrorSummary(true)[0]);
  76. }
  77. AdminLogService::saveLogWithUpdateHistory($origin, $model, 0, "", $this->getAllParams());
  78. $data = [];
  79. return $this->asJson($data);
  80. }
  81. /**
  82. * 评价用语添加
  83. * @return Response
  84. * @throws Exception
  85. * @throws InvalidConfigException
  86. */
  87. public function actionAdd()
  88. {
  89. $post = Yii::$app->request->post();
  90. $param = [
  91. "type" => $post["type"],
  92. "type_two" => $post["type_two"],
  93. "content" => $post["content"],
  94. "status" => $post["status"],
  95. ];
  96. $model = new AccidentCasesScoreComment($param);
  97. $origin = AdminLogService::getOrigin($model, $this->getAllParams(), true);
  98. if (!$model->save()) {
  99. throw new Exception($model->getErrorSummary(true)[0]);
  100. }
  101. AdminLogService::saveLogWithUpdateHistory($origin, $model, 0, "", $this->getAllParams());
  102. $data = [];
  103. return $this->asJson($data);
  104. }
  105. }