多药房
Build Docker / build (push) Canceled after 0s

This commit is contained in:
haomingming
2026-09-08 10:09:07 +08:00
parent 4dfcdacb12
commit d3fce247e5
20 changed files with 782 additions and 65 deletions
+132
View File
@@ -0,0 +1,132 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Relations\HasOne;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property int|string $doctor_pharmacy_id 主键ID
* @property int|string $doctor_id 医生ID
* @property int|string $pharmacy_id 药房ID
* @property int $is_default 是否默认药房(0:否 1:是)
* @property int $status 绑定状态(0:禁用 1:正常)
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
* @property-read Pharmacy|null $Pharmacy
* @property-read UserDoctor|null $UserDoctor
*/
class DoctorPharmacy extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'doctor_pharmacy';
/**
* The primary key for the model.
*/
protected string $primaryKey = 'doctor_pharmacy_id';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [
'doctor_pharmacy_id',
'doctor_id',
'pharmacy_id',
'is_default',
'status',
'created_at',
'updated_at',
];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = [
'doctor_pharmacy_id' => 'string',
'doctor_id' => 'string',
'pharmacy_id' => 'string',
'is_default' => 'integer',
'status' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 关联药房信息表
*/
public function Pharmacy(): HasOne
{
return $this->hasOne(Pharmacy::class, 'pharmacy_id', 'pharmacy_id');
}
/**
* 关联医生表
*/
public function UserDoctor(): HasOne
{
return $this->hasOne(UserDoctor::class, 'doctor_id', 'doctor_id');
}
/**
* 获取医生当前绑定的有效默认药房(包含药房有效性及 pharmacy_code 非空校验)
*/
public static function getDoctorDefaultPharmacy(int|string $doctorId): ?Pharmacy
{
$bind = self::where([
'doctor_id' => (string) $doctorId,
'is_default' => 1,
'status' => 1,
])->first();
if (empty($bind)) {
return null;
}
$pharmacy = Pharmacy::getValidPharmacy($bind->pharmacy_id);
if (empty($pharmacy) || empty($pharmacy->pharmacy_code)) {
return null;
}
return $pharmacy;
}
/**
* 获取单条数据
*/
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 addDoctorPharmacy(array $data): self
{
return self::create($data);
}
/**
* 修改
*/
public static function edit(array $params, array $data): int
{
return self::where($params)->update($data);
}
}
+17 -1
View File
@@ -36,12 +36,16 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property string $patient_name 患者姓名-就诊人
* @property int $patient_sex 患者性别-就诊人(1:男 2:女)
* @property int $patient_age 患者年龄-就诊人
* @property int|string $pharmacy_id 开方药房id
* @property string $pharmacy_code 开方药房代码快照
* @property string $pharmacy_name 开方药房名称快照
* @property string $doctor_advice 医嘱
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionIcd[] $OrderPrescriptionIcd
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionProduct[] $OrderPrescriptionProduct
* @property-read UserDoctor $UserDoctor
* @property-read Pharmacy|null $Pharmacy
*/
class OrderPrescription extends Model
{
@@ -55,10 +59,22 @@ class OrderPrescription extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'patient_id', 'family_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_verify_time', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_time', 'platform_fail_reason', 'is_auto_phar_verify', 'doctor_created_time', 'expired_time', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'doctor_advice', 'created_at', 'updated_at'];
protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'pharmacy_id', 'pharmacy_code', 'pharmacy_name', 'patient_id', 'family_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_verify_time', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_time', 'platform_fail_reason', 'is_auto_phar_verify', 'doctor_created_time', 'expired_time', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'doctor_advice', 'created_at', 'updated_at'];
protected array $casts = [
'pharmacy_id' => 'string',
];
protected string $primaryKey = "order_prescription_id";
/**
* 关联药房表
*/
public function Pharmacy(): HasOne
{
return $this->hasOne(Pharmacy::class, 'pharmacy_id', 'pharmacy_id');
}
/**
* 关联处方疾病表
*/
+19 -1
View File
@@ -55,12 +55,17 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property string $consignee_name_mask 收货人姓名(掩码)
* @property string $consignee_tel 收货人电话
* @property string $consignee_tel_mask 收货人电话(掩码)
* @property int|string $pharmacy_id 发货药房id
* @property string $pharmacy_code 发货药房代码快照
* @property string $pharmacy_name 发货药房名称快照
* @property int $delivery_type 配送方式(1:自提 2:快递)
* @property Carbon $created_at 创建时间
* @property Carbon $updated_at 修改时间
* @property-read Collection|OrderProductItem[]|null $OrderProductItem
* @property-read OrderPrescription|null $OrderPrescription
* @property-read PatientFamily|null $PatientFamily
* @property-read Collection|OrderPrescriptionIcd[]|null $OrderPrescriptionIcd
* @property-read Pharmacy|null $Pharmacy
*/
class OrderProduct extends Model
{
@@ -74,10 +79,23 @@ class OrderProduct extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'order_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'order_id', 'doctor_id', 'pharmacy_id', 'pharmacy_code', 'pharmacy_name', 'delivery_type', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
protected array $casts = [
'pharmacy_id' => 'string',
'delivery_type' => 'integer',
];
protected string $primaryKey = "order_product_id";
/**
* 关联药房表
*/
public function Pharmacy(): HasOne
{
return $this->hasOne(Pharmacy::class, 'pharmacy_id', 'pharmacy_id');
}
/**
* 关联订单商品item表
*/
+133
View File
@@ -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(),
];
}
}
+7 -1
View File
@@ -23,6 +23,8 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property int $product_type 药品类型(0:未知 1:中成药 2:西药)
* @property string $product_platform_code 处方平台商品编码
* @property string $product_pharmacy_code 第三方药店商品编码
* @property int|string $pharmacy_id 所属药房ID
* @property string $pharmacy_code 所属药房编码
* @property string $product_cover_img 商品封面图
* @property string $product_spec 商品规格
* @property string $license_number 批准文号
@@ -49,7 +51,11 @@ class Product extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['product_id', 'product_platform_id', 'product_status', 'is_delete', 'prescription_num', 'product_name', 'common_name', 'product_price', 'mnemonic_code', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_cover_img', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'product_remarks', 'created_at', 'updated_at'];
protected array $fillable = ['product_id', 'product_platform_id', 'pharmacy_id', 'pharmacy_code', 'product_status', 'is_delete', 'prescription_num', 'product_name', 'common_name', 'product_price', 'mnemonic_code', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_cover_img', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'single_use', 'packaging_unit', 'frequency_use', 'available_days', 'product_remarks', 'created_at', 'updated_at'];
protected array $casts = [
'pharmacy_id' => 'string',
];
protected string $primaryKey = "product_id";
+2 -1
View File
@@ -16,6 +16,7 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property int $product_type 药品类型(0:未知 1:中成药 2:西药)
* @property string $product_platform_code 处方平台商品编码
* @property string $product_pharmacy_code 第三方药店商品编码
* @property string $pharmacy_code 所属药房编码
* @property string $product_spec 商品规格
* @property string $license_number 批准文号
* @property string $manufacturer 生产厂家
@@ -38,7 +39,7 @@ class ProductPlatform extends Model
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['product_platform_id', 'product_name', 'product_price', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'packaging_unit', 'packaging_count', 'retail_unit', 'created_at', 'updated_at'];
protected array $fillable = ['product_platform_id', 'pharmacy_code', 'product_name', 'product_price', 'product_type', 'product_platform_code', 'product_pharmacy_code', 'product_spec', 'license_number', 'manufacturer', 'single_unit', 'packaging_unit', 'packaging_count', 'retail_unit', 'created_at', 'updated_at'];
protected string $primaryKey = "product_platform_id";
+9
View File
@@ -121,6 +121,15 @@ class UserDoctor extends Model
return $this->hasMany(OrderInquiry::class, "doctor_id", "doctor_id");
}
/**
* 关联医生药房绑定表
* @return HasMany
*/
public function DoctorPharmacy(): HasMany
{
return $this->hasMany(DoctorPharmacy::class, "doctor_id", "doctor_id");
}
/**
* 获取医生信息-单条
* @param array $params