DistAdminDistributor.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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(0);
  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->dist_email = $info['dist_email'];
  69. $row->whats_app = $info['whats_app'];
  70. $row->facebook = $info['facebook'];
  71. $row->instagram = $info['instagram'];
  72. $row->youtube = $info['youtube'];
  73. $row->linkedin = $info['linkedin'];
  74. $row->tiktok = $info['tiktok'];
  75. $row->copy_right = $info['copy_right'];//copy_right
  76. $row->seo_title = $info['seo_title'];//seo_title
  77. $row->seo_keywords = $info['seo_keywords'];//seo_keywords
  78. $row->seo_description = $info['seo_description'];//seo_description
  79. $row->save();
  80. }
  81. /*
  82. * 分销商切换主题
  83. */
  84. public static function enableTheme($appearanceId)
  85. {
  86. $appearanceId = intval($appearanceId);
  87. $distId = getDistributorId();
  88. $distAppearance = new DistAppearance();
  89. $appearanceRow = $distAppearance->model()->find($appearanceId);
  90. if ($appearanceRow && $appearanceRow->enabled == 1) {
  91. //修改分销商主题
  92. $row = Model::find($distId);
  93. $row->appearance_id = $appearanceId;
  94. $row->save();
  95. //切换主题
  96. DistAppearance::switchTheme($appearanceId, $distId);
  97. return true;
  98. }
  99. return false;
  100. }
  101. public static function all()
  102. {
  103. $result = Model::all();
  104. return $result;
  105. }
  106. public static function tags_all()
  107. {
  108. $result = Model::all();
  109. // 遍历结果并返回数组
  110. $tags = [];
  111. foreach ($result as $item) {
  112. $tags[$item->id] = $item->client_code; // 假设 company_name 是你想要显示的字段
  113. }
  114. return $tags;
  115. }
  116. public static function getCompanyNamesByIds(array $ids)
  117. {
  118. return Model::whereIn('id', $ids)->pluck('company_name')->toArray();
  119. }
  120. }