OperationalAdjustmentsDimensionService.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace common\services;
  3. use common\components\AjaxException;
  4. use common\models\OperationalAdjustments;
  5. use common\models\OperationalAdjustmentsDimension;
  6. use Yii;
  7. use yii\db\ActiveQuery;
  8. use yii\db\Exception;
  9. class OperationalAdjustmentsDimensionService
  10. {
  11. public static function getQuery(): ActiveQuery
  12. {
  13. return OperationalAdjustmentsDimension::find()->where(["delete_time" => 0]);
  14. }
  15. public static function add(OperationalAdjustments $OperationalAdjustments)
  16. {
  17. $param = [
  18. "accident_id",
  19. "operational_adjustments_id",
  20. "content",
  21. "type",
  22. "update_time"
  23. ];
  24. $time = time();
  25. $paramData = [];
  26. foreach (AccidentCasesDimensionService::$typeList as $type) {
  27. $paramData[] = [
  28. "accident_id" => $OperationalAdjustments->accident_id,
  29. "operational_adjustments_id" => $OperationalAdjustments->id,
  30. "content" => "",
  31. "type" => $type,
  32. "update_time" => $time,
  33. ];
  34. }
  35. Yii::$app->db->createCommand()->batchInsert(OperationalAdjustmentsDimension::tableName(), $param, $paramData)->execute();
  36. }
  37. /**
  38. * @param $allParams
  39. * @return void
  40. * @throws AjaxException
  41. * @throws Exception
  42. */
  43. public static function update($allParams, $userInfo)
  44. {
  45. /** @var OperationalAdjustmentsDimension $model */
  46. $model = self::getQuery()->andWhere(["operational_adjustments_id" => $allParams["operational_adjustments_id"], "type" => $allParams["type"]])->one();
  47. if (!$model) {
  48. throw new AjaxException("该评价维度不存在!");
  49. }
  50. $origin = AdminLogService::getOrigin($model, $allParams);
  51. $case = CaseService::checkIsPublish($model->accident_id, $userInfo);
  52. $model->content = $allParams["content"];
  53. $model->status = $allParams["status"];
  54. $model->update_time = time();
  55. if (!$model->save()) {
  56. throw new Exception($model->getErrorSummary(true)[0]);
  57. }
  58. AdminLogService::saveLogWithUpdateHistory($origin, $model, $case->id, $case->title, $allParams);
  59. }
  60. /**
  61. * @param $OperationalAdjustmentsId
  62. * @return OperationalAdjustmentsDimension[]
  63. */
  64. public static function getListByOperationalAdjustmentsId($OperationalAdjustmentsId): array
  65. {
  66. return self::getQuery()->andWhere(["operational_adjustments_id" => $OperationalAdjustmentsId])->all();
  67. }
  68. public static function deleteByOperationalAdjustmentsId($OperationalAdjustmentsId): void
  69. {
  70. OperationalAdjustmentsDimension::updateAll(["delete_time" => time()], ["operational_adjustments_id" => $OperationalAdjustmentsId]);
  71. }
  72. public static function deleteByAccidentId($AccidentId): void
  73. {
  74. OperationalAdjustmentsDimension::updateAll(["delete_time" => time()], ["accident_id" => $AccidentId]);
  75. }
  76. }