DistAppearanceTemplateLog.php 2.2 KB

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