DistAdminDistributor.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. //把null转为''
  10. public function setNameAttribute($value)
  11. {
  12. $this->attributes['name'] = $value ?? '';
  13. }
  14. /*
  15. * 用户一对多关联
  16. */
  17. public function user()
  18. {
  19. return $this->hasMany(DistAdminUser::class, 'dist_id', 'id');
  20. }
  21. /*
  22. * 外观一对一关联
  23. */
  24. public function appearance()
  25. {
  26. return $this->hasOne(DistAppearance::class, 'id', 'appearance_id');
  27. }
  28. /*
  29. * 得到分销商域名
  30. * type 0:当前域名 1:二级域名 2:自定义域名
  31. */
  32. public function getDomain($distId,$type = 0)
  33. {
  34. $domain = '';
  35. $row = $this->where('id', $distId)->first();
  36. if ($row) {
  37. if ($type == 0) {
  38. if ($row->domain_type == 0) {
  39. $domain = 'http://'.$row->secondary_domain;
  40. } else {
  41. $domain = 'http://'.$row->custom_domain;
  42. }
  43. } else if ($type == 1) {
  44. $domain = 'http://'.$row->secondary_domain;
  45. } else {
  46. $domain = 'http://'.$row->custom_domain;
  47. }
  48. }
  49. if (env('DIST_SITE_PORT') != 80) {
  50. $domain .= ':' . env('DIST_SITE_PORT');
  51. }
  52. return $domain;
  53. }
  54. }