校区服务
This commit is contained in:
80
app/Model/Campus.php
Normal file
80
app/Model/Campus.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Aether\AetherModel;
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\Database\Model\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* 校区模型(支持层级结构).
|
||||
* @property int $id
|
||||
* @property string $name 校区名称
|
||||
* @property int $parent_id 父级ID
|
||||
* @property int $level 层级:1-省份,2-地级市,3-校区
|
||||
* @property string $province 省份
|
||||
* @property string $city 地级市
|
||||
* @property string $address 详细地址
|
||||
* @property string $contact_phone 联系电话
|
||||
* @property string $contact_person 联系人
|
||||
* @property int $status 状态:0-禁用,1-启用
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
* @property Carbon $deleted_at
|
||||
*/
|
||||
class Campus extends AetherModel
|
||||
{
|
||||
protected ?string $table = 'campus';
|
||||
|
||||
protected array $fillable = [
|
||||
'name',
|
||||
'parent_id',
|
||||
'level',
|
||||
'province',
|
||||
'city',
|
||||
'address',
|
||||
'contact_phone',
|
||||
'status',
|
||||
];
|
||||
|
||||
protected array $casts = [
|
||||
'parent_id' => 'integer',
|
||||
'level' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取子校区.
|
||||
*/
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(self::class, 'parent_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 按省份查询.
|
||||
*/
|
||||
public function scopeProvince(Builder $query, string $province): Builder
|
||||
{
|
||||
return $query->where('province', $province);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按城市查询.
|
||||
*/
|
||||
public function scopeCity(Builder $query, string $city): Builder
|
||||
{
|
||||
return $query->where('city', $city);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按层级查询.
|
||||
*/
|
||||
public function scopeLevel(Builder $query, int $level): Builder
|
||||
{
|
||||
return $query->where('level', $level);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user