71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Constants\Common\CityCode;
|
|
use Hyperf\Database\Model\Builder;
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $title
|
|
* @property int $status
|
|
* @property int $city_id
|
|
* @property int $province_id
|
|
* @property string $create_time
|
|
* @property string $update_time
|
|
* @property int $is_del
|
|
*/
|
|
class SystemCity extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'system_city';
|
|
|
|
/**
|
|
* 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', 'status' => 'integer', 'city_id' => 'integer', 'province_id' => 'integer', 'is_del' => 'integer'];
|
|
|
|
const CREATED_AT = 'create_time';
|
|
|
|
const UPDATED_AT = 'update_time';
|
|
|
|
/**
|
|
* @param int $cityId
|
|
* @return Builder|\Hyperf\Database\Model\Model|null
|
|
*/
|
|
public function getInfoByCityId(int $cityId): \Hyperf\Database\Model\Model|Builder|null
|
|
{
|
|
return $this->where('city_id', $cityId)->where('is_del',CityCode::IS_NOT_DELETE)->first();
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return Builder|\Hyperf\Database\Model\Model|null
|
|
*/
|
|
public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null
|
|
{
|
|
return $this->where('id', $id)->where('is_del',CityCode::IS_NOT_DELETE)->first();
|
|
}
|
|
|
|
/**
|
|
* @param $ids
|
|
* @return array
|
|
*/
|
|
public function getCityNameByIds($ids): array
|
|
{
|
|
return $this->whereIn('id',$ids)->pluck('title','id')->toArray();
|
|
}
|
|
}
|