DistAppearanceTemplateLog.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Models\DistAppearanceTemplateLog as Model;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. class DistAppearanceTemplateLog extends EloquentRepository
  6. {
  7. /**
  8. * Model.
  9. *
  10. * @var string
  11. */
  12. protected $eloquentClass = Model::class;
  13. /*
  14. * 添加模版修改日志
  15. * $currentContent 修改后的内容
  16. * $previousContent 修改前的内容
  17. */
  18. public static function insertLog($appearanceId,$distId,$fileName,$filePath,$templateCode,$currentContent,$previousContent)
  19. {
  20. $model = new Model();
  21. $model->dist_id = $distId;
  22. $model->file_name = $fileName;
  23. $model->file_path = $filePath;
  24. $model->appearance_id = $appearanceId;
  25. $model->template_code = $templateCode;
  26. $model->current_content = $currentContent;
  27. $model->previous_content = $previousContent;
  28. $model->version = generateVersionNumber();
  29. $model->save();
  30. }
  31. /*
  32. * 获取模版修改日志
  33. */
  34. public static function fetchTemplateLogs($appearanceId,$distId,$templateCode)
  35. {
  36. $model = new Model();
  37. $model = $model->where('appearance_id','=',$appearanceId)->where('dist_id','=',$distId)->where('template_code','=',$templateCode)->orderBy('id','desc')->select('id','version','created_at')->get();
  38. return $model;
  39. }
  40. /*
  41. * 获取单条模版修改日志内容
  42. */
  43. public static function fetchTemplateLogContent($logId)
  44. {
  45. $model = new Model();
  46. $model = $model->where('id','=',$logId)->first();
  47. return $model;
  48. }
  49. /*
  50. * 还原模版
  51. */
  52. public static function restoreTemplateLog($logId) {
  53. $model = new Model();
  54. $model = $model->where('id', '=', $logId)->first();
  55. if ($model) {
  56. $appearanceId = $model->appearance_id;
  57. $distId = $model->dist_id;
  58. $templateCode = $model->template_code;
  59. $content = $model->previous_content;
  60. DistAppearanceTemplate::saveContent($appearanceId, $distId, $templateCode, $content);
  61. }
  62. }
  63. }