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.

47 lines
1.0 KiB

5 years ago
5 years ago
  1. <?php
  2. namespace App\Model\v3;
  3. use App\Model\Model;
  4. use Hyperf\Database\Model\Builder;
  5. class Market extends Model
  6. {
  7. protected $table = 'lanzu_market';
  8. protected $appends = [
  9. 'province_name',
  10. 'city_name',
  11. 'region_name'
  12. ];
  13. protected function boot(): void
  14. {
  15. parent::boot();
  16. self::addGlobalScope('normal', function (Builder $builder) {
  17. $builder->where([$this->getTable().'.status' => 1]);
  18. });
  19. }
  20. public function getProvinceNameAttribute()
  21. {
  22. $area = Area::query()->find($this->attributes['province_id']);
  23. return $area->name ?? '';
  24. }
  25. public function getCityNameAttribute()
  26. {
  27. $area = Area::query()->find($this->attributes['city_id']);
  28. return $area->name ?? '';
  29. }
  30. public function getRegionNameAttribute()
  31. {
  32. $area = Area::query()->find($this->attributes['region_id']);
  33. return $area->name ?? '';
  34. }
  35. public function stores()
  36. {
  37. return $this->hasMany(Store::class,'market_id','id');
  38. }
  39. }