DistAdminDistributor.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. */
  26. public function getDomain($distId)
  27. {
  28. $domain = '';
  29. $row = $this->where('id', $distId)->first();
  30. if ($row) {
  31. if ($row->domain_type == 0) {
  32. $domain = 'http://'.$row->secondary_domain;
  33. } else {
  34. $domain = 'http://'.$row->custom_domain;
  35. }
  36. }
  37. if (env('DIST_SITE_PORT') != 80) {
  38. $domain .= ':' . env('DIST_SITE_PORT');
  39. }
  40. return $domain;
  41. }
  42. }