EventSourceDataController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace frontend\modules\api\controllers;
  3. use common\components\AjaxException;
  4. use common\models\EventSourceData;
  5. use common\services\AdminLogService;
  6. use common\services\CaseService;
  7. use common\services\EventSourceDataService;
  8. use common\util\Upload;
  9. use frontend\modules\api\components\BaseAdminController;
  10. use Yii;
  11. use yii\base\InvalidConfigException;
  12. use yii\db\Exception;
  13. use yii\web\Response;
  14. class EventSourceDataController extends BaseAdminController
  15. {
  16. /**
  17. * 原始资料列表
  18. * @param int $accident_id
  19. * @return Response
  20. */
  21. public function actionList(int $accident_id)
  22. {
  23. $query = EventSourceDataService::getQueryByAccidentId($accident_id)->orderBy("update_time desc,id desc");
  24. //组合数据
  25. $data['data'] = $query->asArray()->all();
  26. return $this->asJson($data);
  27. }
  28. /**
  29. * 原始资料添加
  30. * @return Response
  31. * @throws AjaxException
  32. * @throws Exception
  33. * @throws InvalidConfigException
  34. */
  35. public function actionAdd()
  36. {
  37. set_time_limit(0);
  38. if (!$_FILES) {
  39. throw new AjaxException("文件获取失败!");
  40. }
  41. $post = Yii::$app->request->post();
  42. $case = CaseService::checkIsPublish($post["accident_id"], $this->userInfo);
  43. $model = new EventSourceData($post);
  44. $origin = AdminLogService::getOrigin($model, $this->getAllParams(), true);
  45. list($model->file_name, $model->url) = Upload::dealWithEventSourceDataFile($model->accident_id);
  46. $model->update_time = time();
  47. if (!$model->save()) {
  48. throw new Exception($model->getErrorSummary(true)[0]);
  49. }
  50. //清除缓存
  51. EventSourceDataService::clearSourceDataListByAccidentIdCacheData($model->accident_id);
  52. //返回数据
  53. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  54. $data['data'] = $model->id;
  55. return $this->asJson($data);
  56. }
  57. /**
  58. * 原始资料删除
  59. * @param $id
  60. * @return Response
  61. * @throws AjaxException
  62. * @throws Exception
  63. * @throws InvalidConfigException
  64. */
  65. public function actionDelete($id)
  66. {
  67. //清除缓存
  68. $model = EventSourceDataService::getEventSourceDataById($id);
  69. $case = CaseService::checkIsPublish($model->accident_id, $this->userInfo);
  70. $model->delete_time = time();
  71. if (!$model->save()) {
  72. throw new Exception($model->getErrorSummary(true)[0]);
  73. }
  74. EventSourceDataService::clearSourceDataListByAccidentIdCacheData($model->accident_id);
  75. //返回数据
  76. $origin = AdminLogService::getOrigin($model, $this->getAllParams());
  77. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $this->getAllParams());
  78. return $this->asJson();
  79. }
  80. }