You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.0 KiB
48 lines
1.0 KiB
<?php
|
|
|
|
namespace App\Model\v3;
|
|
|
|
use App\Model\Model;
|
|
use Hyperf\Database\Model\Builder;
|
|
|
|
class Market extends Model
|
|
{
|
|
protected $table = 'lanzu_market';
|
|
|
|
protected $appends = [
|
|
'province_name',
|
|
'city_name',
|
|
'region_name'
|
|
];
|
|
|
|
protected function boot(): void
|
|
{
|
|
parent::boot();
|
|
self::addGlobalScope('normal', function (Builder $builder) {
|
|
$builder->where([$this->getTable().'.status' => 1]);
|
|
});
|
|
}
|
|
|
|
public function getProvinceNameAttribute()
|
|
{
|
|
$area = Area::query()->find($this->attributes['province_id']);
|
|
return $area->name ?? '';
|
|
}
|
|
|
|
public function getCityNameAttribute()
|
|
{
|
|
$area = Area::query()->find($this->attributes['city_id']);
|
|
return $area->name ?? '';
|
|
}
|
|
|
|
public function getRegionNameAttribute()
|
|
{
|
|
$area = Area::query()->find($this->attributes['region_id']);
|
|
return $area->name ?? '';
|
|
}
|
|
|
|
public function stores()
|
|
{
|
|
return $this->hasMany(Store::class,'market_id','id');
|
|
}
|
|
}
|