DistAppearance.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. //复制原始模版到指定分销商
  53. DistAppearanceTemplate::copyTemplateToDist($appearanceId, $distId);
  54. DistAppearanceVariable::copyAppearanceVariable($appearanceId, $distId);
  55. //发报到正式环境
  56. DistAppearancePublishList::publish($appearanceId,$distId);
  57. //清除缓存
  58. DistAdminDistributor::clearCache($distId);
  59. return true;
  60. }
  61. /*
  62. * 初始化分销商模版与变量
  63. */
  64. public static function initTheme($appearanceId,$distId)
  65. {
  66. //请空模版与变量
  67. DistAppearanceTemplate::deleteTemplates($appearanceId,$distId);
  68. DistAppearanceVariable::deleteVariable($appearanceId, $distId);
  69. //重新生成模版与变量
  70. self::switchTheme($appearanceId, $distId);
  71. }
  72. }