DistAdminDistributor.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. if ($row) {
  32. if ($type == 0) {
  33. if ($row->domain_type == 0) {
  34. $domain = 'http://'.$row->secondary_domain;
  35. } else {
  36. $domain = 'http://'.$row->custom_domain;
  37. }
  38. } else if ($type == 1) {
  39. $domain = 'http://'.$row->secondary_domain;
  40. } else {
  41. $domain = 'http://'.$row->custom_domain;
  42. }
  43. }
  44. if (env('DIST_SITE_PORT') != 80) {
  45. $domain .= ':' . env('DIST_SITE_PORT');
  46. }
  47. return $domain;
  48. }
  49. }