70 lines
1.6 KiB
PHP
70 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Modules\Mall\Models\Traits;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Modules\Mall\Models\Region;
|
|
|
|
trait HasRegion
|
|
{
|
|
|
|
/**
|
|
* Notes : 省份
|
|
*
|
|
* @Date : 2021/5/11 9:49 上午
|
|
* @Author : < Jason.C >
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function province(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Region::class, 'province_id');
|
|
}
|
|
|
|
/**
|
|
* Notes : 市
|
|
*
|
|
* @Date : 2021/5/11 9:50 上午
|
|
* @Author : < Jason.C >
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function city(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Region::class, 'city_id');
|
|
}
|
|
|
|
/**
|
|
* Notes : 区
|
|
*
|
|
* @Date : 2021/5/11 9:50 上午
|
|
* @Author : < Jason.C >
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function district(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Region::class, 'district_id');
|
|
}
|
|
|
|
/**
|
|
* Notes : 获取完整地址
|
|
*
|
|
* @Date : 2021/5/11 9:49 上午
|
|
* @Author : < Jason.C >
|
|
* @param string $separators 地址的分隔符
|
|
* @return string
|
|
*/
|
|
public function getFullAddress(string $separators = ''): string
|
|
{
|
|
return
|
|
$this->province->name.$separators.
|
|
$this->city->name.$separators.
|
|
$this->district->name.$separators.
|
|
$this->address;
|
|
}
|
|
|
|
public function getAllAddress()
|
|
{
|
|
return $this->name.' '.$this->mobile.' '.$this->getFullAddress();
|
|
}
|
|
|
|
}
|