DistAdminDistributor.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace App\Distributor\Repositories;
  3. use App\Models\DistAdminDistributor as Model;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. class DistAdminDistributor extends EloquentRepository
  6. {
  7. /**
  8. * Model.
  9. *
  10. * @var string
  11. */
  12. protected $eloquentClass = Model::class;
  13. /*
  14. * 清缓存
  15. */
  16. public static function clearCache($timeOut = 2)
  17. {
  18. $domain = self::getDomain(1);
  19. $url = $domain . '/?__clear_cache=1';
  20. curlGet($url,$timeOut);
  21. }
  22. /*
  23. * 得到当前分销商的域名
  24. * type 0:当前域名 1:二级域名 2:自定义域名
  25. */
  26. public static function getDomain($type=0)
  27. {
  28. $distId = getDistributorId();
  29. $model = new Model();
  30. return $model->getDomain($distId,$type);
  31. }
  32. /*
  33. * 得到分销商信息
  34. */
  35. public static function getInfo()
  36. {
  37. $id = getDistributorId();
  38. $row = Model::find($id);
  39. if ($row) {
  40. foreach ($row->getAttributes() as $key => $value) {
  41. $row->{$key} = $value ?? ''; // 如果值为 null,替换为空字符串
  42. }
  43. }
  44. return $row;
  45. }
  46. /*
  47. * 修改域名名称
  48. */
  49. public static function updateDomain($domainType,$customDomain)
  50. {
  51. $id = getDistributorId();
  52. $row = Model::find($id);
  53. $row->domain_type = $domainType;
  54. if ($domainType == 1) {
  55. $row->custom_domain = $customDomain;
  56. }
  57. $row->save();
  58. }
  59. public static function updateInfo($info)
  60. {
  61. $id = getDistributorId();
  62. $row = Model::find($id);
  63. $row->logo = $info['logo'];
  64. $row->site_name = $info['site_name'];
  65. $row->company_name = $info['company_name'];
  66. $row->company_address = $info['company_address'];
  67. $row->service_hotline = $info['service_hotline'];
  68. $row->whats_app = $info['whats_app'];
  69. $row->facebook = $info['facebook'];
  70. $row->instagram = $info['instagram'];
  71. $row->youtube = $info['youtube'];
  72. $row->linkedin = $info['linkedin'];
  73. $row->tiktok = $info['tiktok'];
  74. $row->copy_right = $info['copy_right'];//copy_right
  75. $row->seo_title = $info['seo_title'];//seo_title
  76. $row->seo_keywords = $info['seo_keywords'];//seo_keywords
  77. $row->seo_description = $info['seo_description'];//seo_description
  78. $row->save();
  79. }
  80. /*
  81. * 分销商切换主题
  82. */
  83. public static function enableTheme($appearanceId)
  84. {
  85. $appearanceId = intval($appearanceId);
  86. $distId = getDistributorId();
  87. $distAppearance = new DistAppearance();
  88. $appearanceRow = $distAppearance->model()->find($appearanceId);
  89. if ($appearanceRow && $appearanceRow->enabled == 1) {
  90. //修改分销商主题
  91. $row = Model::find($distId);
  92. $row->appearance_id = $appearanceId;
  93. $row->save();
  94. //切换主题
  95. DistAppearance::switchTheme($appearanceId, $distId);
  96. return true;
  97. }
  98. return false;
  99. }
  100. public static function all()
  101. {
  102. $result = Model::all();
  103. return $result;
  104. }
  105. public static function tags_all()
  106. {
  107. $result = Model::all();
  108. // 遍历结果并返回数组
  109. $tags = [];
  110. foreach ($result as $item) {
  111. $tags[$item->id] = $item->company_name; // 假设 company_name 是你想要显示的字段
  112. }
  113. return $tags;
  114. }
  115. public static function getCompanyNamesByIds(array $ids)
  116. {
  117. return Model::whereIn('id', $ids)->pluck('company_name')->toArray();
  118. }
  119. }