DistAppearance.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. return true;
  55. }
  56. /*
  57. * 初始化分销商模版与变量
  58. */
  59. public static function initTheme($appearanceId,$distId)
  60. {
  61. //请空模版与变量
  62. DistAppearanceTemplate::deleteTemplates($appearanceId,$distId);
  63. DistAppearanceVariable::deleteVariable($appearanceId, $distId);
  64. //重新生成模版与变量
  65. self::switchTheme($appearanceId, $distId);
  66. }
  67. }