@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Database\Model\Relations\HasMany;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int|string $pharmacy_id 主键ID
|
||||
* @property string $pharmacy_name 药房名称
|
||||
* @property string $pharmacy_code 药房代码
|
||||
* @property string $postage 基础邮费
|
||||
* @property string $free_shipping_threshold 满额包邮门槛
|
||||
* @property int $is_pickup 是否支持自提(0:否 1:是)
|
||||
* @property string $telephone 联系电话
|
||||
* @property int $province_id 省份ID
|
||||
* @property string $province 省份名称
|
||||
* @property int $city_id 城市ID
|
||||
* @property string $city 城市名称
|
||||
* @property int $county_id 区县ID
|
||||
* @property string $county 区县名称
|
||||
* @property string $address 详细地址
|
||||
* @property int $status 状态(0:禁用 1:正常 2:删除)
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
* @property-read Collection|DoctorPharmacy[] $DoctorPharmacy
|
||||
*/
|
||||
class Pharmacy extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'pharmacy';
|
||||
|
||||
/**
|
||||
* The primary key for the model.
|
||||
*/
|
||||
protected string $primaryKey = 'pharmacy_id';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = [
|
||||
'pharmacy_id',
|
||||
'pharmacy_name',
|
||||
'pharmacy_code',
|
||||
'postage',
|
||||
'free_shipping_threshold',
|
||||
'is_pickup',
|
||||
'telephone',
|
||||
'province_id',
|
||||
'province',
|
||||
'city_id',
|
||||
'city',
|
||||
'county_id',
|
||||
'county',
|
||||
'address',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = [
|
||||
'pharmacy_id' => 'string',
|
||||
'postage' => 'string',
|
||||
'free_shipping_threshold' => 'string',
|
||||
'is_pickup' => 'integer',
|
||||
'province_id' => 'integer',
|
||||
'city_id' => 'integer',
|
||||
'county_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联医生药房绑定表
|
||||
*/
|
||||
public function DoctorPharmacy(): HasMany
|
||||
{
|
||||
return $this->hasMany(DoctorPharmacy::class, 'pharmacy_id', 'pharmacy_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条有效药房数据
|
||||
*/
|
||||
public static function getValidPharmacy(int|string $pharmacyId): ?self
|
||||
{
|
||||
return self::where([
|
||||
'pharmacy_id' => (string) $pharmacyId,
|
||||
'status' => 1,
|
||||
])->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单条药房信息
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): ?self
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取药房列表
|
||||
*/
|
||||
public static function getList(array $params = [], array $fields = ['*']): Collection
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询药房
|
||||
*/
|
||||
public static function getPage(array $params, array $fields = ['*'], ?int $page = null, ?int $per_page = 10): array
|
||||
{
|
||||
$raw = self::where($params)->paginate($per_page, $fields, 'page', $page);
|
||||
return [
|
||||
'current_page' => $raw->currentPage(),
|
||||
'total' => $raw->total(),
|
||||
'data' => $raw->items(),
|
||||
'per_page' => $raw->perPage(),
|
||||
'last_page' => $raw->lastPage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user