DistAdminDistributor.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\Model;
  5. class DistAdminDistributor extends Model
  6. {
  7. use HasDateTimeFormatter;
  8. protected $table = 'dist_admin_distributor';
  9. /*
  10. * 用户一对多关联
  11. */
  12. public function user()
  13. {
  14. return $this->hasMany(DistAdminUser::class, 'dist_id', 'id');
  15. }
  16. /*
  17. * 外观一对一关联
  18. */
  19. public function appearance()
  20. {
  21. return $this->hasOne(DistAppearance::class, 'id', 'appearance_id');
  22. }
  23. /*
  24. * 得到分销商域名
  25. * type 0:当前域名 1:二级域名 2:自定义域名
  26. */
  27. public function getDomain($distId,$type = 0)
  28. {
  29. $domain = '';
  30. $row = $this->where('id', $distId)->first();
  31. $http = 'http://';
  32. if (env('ADMIN_HTTPS') == true) {
  33. $http = 'https://';
  34. }
  35. if ($row) {
  36. if ($type == 0) {
  37. if ($row->domain_type == 0) {
  38. $domain = $http.$row->secondary_domain;
  39. } else {
  40. $domain = $http.$row->custom_domain;
  41. }
  42. } else if ($type == 1) {
  43. $domain = $http.$row->secondary_domain;
  44. } else {
  45. $domain = $http.$row->custom_domain;
  46. }
  47. }
  48. if (env('DIST_SITE_PORT') != 80) {
  49. $domain .= ':' . env('DIST_SITE_PORT');
  50. }
  51. return $domain;
  52. }
  53. }