Files
hyperf_service/app/Model/AdminSection.php
2024-11-11 13:06:26 +08:00

98 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Model;
use App\Constants\Admin\AuthCode;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Hyperf\DbConnection\Model\Model;
use Hyperf\Tappable\HigherOrderTapProxy;
/**
* @property int $id
* @property int $pid
* @property string $name
* @property int $city_id
* @property string $remark
* @property int $status
* @property string $create_time
* @property string $update_time
*/
class AdminSection extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'admin_section';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
protected array $guarded = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'city_id' => 'integer', 'status' => 'integer'];
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
/**
* @param int $id
* @return \Hyperf\Database\Model\Model|Builder|null
*/
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
{
return $this->where('id',$id)->first(['id','pid','name','status','remark']);
}
/**
* @param int $pid
* @return Builder[]|Collection
*/
public function getInfoByPid(int $pid): Collection|array
{
return $this->where('pid',$pid)->get();
}
/**
* 获取所有
* @return array
*/
public function getList(): array
{
return $this
->where('status', AuthCode::SECTION_STATUS_ENABLE)
->get([['id','pid','name','status','remark']])
->toArray();
}
/**
* @param int $id
* @return int
*/
public function getCityById(int $id): int
{
return $this->where('id',$id)->value('city_id') ?? 0;
}
/**
* @param int $cityId
* @return array
*/
public function getIdsByCityId(int $cityId): array
{
return $this
->where('city_id',$cityId)
->where('status',AuthCode::SECTION_STATUS_ENABLE)
->pluck('id')
->toArray();
}
}