DistAppearance.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Models\DistAppearance as Model;
  4. use Carbon\Carbon;
  5. use Dcat\Admin\Repositories\EloquentRepository;
  6. class DistAppearance extends EloquentRepository
  7. {
  8. /**
  9. * Model.
  10. *
  11. * @var string
  12. */
  13. protected $eloquentClass = Model::class;
  14. /*
  15. * 获取一个标签
  16. */
  17. public static function getOneById($id)
  18. {
  19. return Model::where('id', $id)->first();
  20. }
  21. public static function selectOptions($valueShowId = false)
  22. {
  23. $data = Model::where('enabled', 1)->get();
  24. $options = [];
  25. foreach ($data as $item) {
  26. if ($valueShowId) {
  27. $options[$item->id] = $item->id.' - '.$item->title;
  28. } else {
  29. $options[$item->id] = $item->title;
  30. }
  31. }
  32. return $options;
  33. }
  34. /*
  35. * 设置状态为已导入
  36. */
  37. public static function setStatusToImported($id)
  38. {
  39. $row = Model::where('id', $id)->first();
  40. if ($row) {
  41. $row->updated_at = Carbon::now();
  42. $row->imported = 1;
  43. $row->save();
  44. }
  45. return true;
  46. }
  47. /*
  48. * 切换主题操作,生成销应商主题模版与变量
  49. * (如果原本就有模板与变量,不会重复生成)
  50. */
  51. public static function switchTheme($appearanceId,$distId) {
  52. DistAppearanceTemplate::copyTemplateToDist($appearanceId, $distId);
  53. DistAppearanceVariable::copyAppearanceVariable($appearanceId, $distId);
  54. //发报到正式环境
  55. DistAppearancePublishList::publish($appearanceId,$distId);
  56. //清除缓存
  57. DistAdminDistributor::clearCache($distId);
  58. return true;
  59. }
  60. /*
  61. * 初始化分销商模版与变量
  62. */
  63. public static function initTheme($appearanceId,$distId)
  64. {
  65. //请空模版与变量
  66. DistAppearanceTemplate::deleteTemplates($appearanceId,$distId);
  67. DistAppearanceVariable::deleteVariable($appearanceId, $distId);
  68. //重新生成模版与变量
  69. self::switchTheme($appearanceId, $distId);
  70. }
  71. }