@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\Pharmacy;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatform;
|
||||
use App\Utils\Log;
|
||||
@@ -21,6 +22,18 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
#[Command]
|
||||
class getProductCommand extends HyperfCommand
|
||||
{
|
||||
protected array $active_pharmacies = [];
|
||||
|
||||
protected function getPharmacy(string $code)
|
||||
{
|
||||
if (empty($this->active_pharmacies)) {
|
||||
$list = Pharmacy::where('status', 1)->get();
|
||||
foreach ($list as $p) {
|
||||
$this->active_pharmacies[$p->pharmacy_code] = $p;
|
||||
}
|
||||
}
|
||||
return $this->active_pharmacies[$code] ?? null;
|
||||
}
|
||||
public function __construct(protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct('getProduct:command');
|
||||
@@ -117,13 +130,8 @@ class getProductCommand extends HyperfCommand
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
|
||||
$pharmacy_code = \Hyperf\Config\config("prescription_platform.pharmacy_code");
|
||||
if (empty($pharmacy_code)) {
|
||||
$pharmacy_code = "JG-10009";
|
||||
}
|
||||
|
||||
// 非药店编码
|
||||
if ($pharmacy_code != $item['thirdCode']) {
|
||||
$pharmacy = $this->getPharmacy($item['thirdCode']);
|
||||
if (empty($pharmacy)) {
|
||||
Db::rollBack();
|
||||
return false;
|
||||
}
|
||||
@@ -133,6 +141,7 @@ class getProductCommand extends HyperfCommand
|
||||
$params['product_platform_code'] = $item['drugCode'];
|
||||
$params['product_pharmacy_code'] = $item['thirdDrugCode'];
|
||||
$params['license_number'] = $item['approvalNumber'];
|
||||
$params['pharmacy_code'] = $item['thirdCode'];
|
||||
$product_platform = ProductPlatform::getOne($params);
|
||||
if (!empty($product_platform)) {
|
||||
// 已存在,更新
|
||||
@@ -214,6 +223,10 @@ class getProductCommand extends HyperfCommand
|
||||
}
|
||||
}
|
||||
|
||||
$product_platform_data['pharmacy_code'] = $item['thirdCode'];
|
||||
$product_data['pharmacy_code'] = $item['thirdCode'];
|
||||
$product_data['pharmacy_id'] = (string)$pharmacy->pharmacy_id;
|
||||
|
||||
if (!empty($product_platform_data)) {
|
||||
// 更新商品表-处方平台
|
||||
$params = array();
|
||||
@@ -236,6 +249,7 @@ class getProductCommand extends HyperfCommand
|
||||
} else {
|
||||
// 不存在,创建
|
||||
$data = array();
|
||||
$data['pharmacy_code'] = $item['thirdCode'];
|
||||
// 商品名称
|
||||
if (isset($item['tradeName'])) {
|
||||
$data['product_name'] = $item['tradeName'];
|
||||
|
||||
@@ -48,7 +48,8 @@ class getProductStockCommand extends HyperfCommand
|
||||
|
||||
foreach ($product['data'] as $item){
|
||||
if (!empty($item['product_pharmacy_code'])){
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code']);
|
||||
$pharmacy_code = $item['pharmacy_code'] ?? '';
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code'], $pharmacy_code);
|
||||
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +58,7 @@ class getProductStockCommand extends HyperfCommand
|
||||
for ($i = 2; $i <= $product['last_page']; $i++) {
|
||||
// 获取商品
|
||||
$params = array();
|
||||
$params['product_status'] = 1;
|
||||
$product = Product::getPage($params,['*'],$i,10);
|
||||
if (empty($product['data'])){
|
||||
$this->line("商品库存更新成功,无可更新库存商品");
|
||||
@@ -67,7 +69,8 @@ class getProductStockCommand extends HyperfCommand
|
||||
|
||||
foreach ($product['data'] as $item){
|
||||
if (!empty($item['product_pharmacy_code'])){
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code']);
|
||||
$pharmacy_code = $item['pharmacy_code'] ?? '';
|
||||
$result = $prescription->getProdStock($item['product_pharmacy_code'], $pharmacy_code);
|
||||
$this->handleData($item['product_platform_id'],$item['product_platform_code'],$result[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Request\DoctorPharmacyRequest;
|
||||
use App\Services\DoctorPharmacyService;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class DoctorPharmacyController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 获取医生绑定的药房列表
|
||||
*/
|
||||
public function getDoctorPharmacyList(): ResponseInterface
|
||||
{
|
||||
$service = new DoctorPharmacyService();
|
||||
$data = $service->getDoctorPharmacyList();
|
||||
return $this->response->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置医生默认药房
|
||||
*/
|
||||
public function setDoctorDefaultPharmacy(): ResponseInterface
|
||||
{
|
||||
$request = $this->container->get(DoctorPharmacyRequest::class);
|
||||
$request->scene('setDefault')->validateResolved();
|
||||
|
||||
$service = new DoctorPharmacyService();
|
||||
$data = $service->setDoctorDefaultPharmacy();
|
||||
return $this->response->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取平台公开正常运营的药房列表
|
||||
*/
|
||||
public function getPublicPharmacyList(): ResponseInterface
|
||||
{
|
||||
$service = new DoctorPharmacyService();
|
||||
$data = $service->getPublicPharmacyList();
|
||||
return $this->response->json($data);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联处方疾病表
|
||||
*/
|
||||
|
||||
@@ -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表
|
||||
*/
|
||||
|
||||
@@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class DoctorPharmacyRequest extends FormRequest
|
||||
{
|
||||
protected array $scenes = [
|
||||
'setDefault' => ['pharmacy_id'],
|
||||
'bindPharmacy' => ['pharmacy_id'],
|
||||
];
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'pharmacy_id' => 'required|numeric',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'pharmacy_id.required' => '药房ID不能为空',
|
||||
'pharmacy_id.numeric' => '药房ID必须为数字',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class PatientOrderRequest extends FormRequest
|
||||
"address_id",
|
||||
"product_ids",
|
||||
"client_type",
|
||||
"delivery_type",
|
||||
],
|
||||
'getPatientPrescriptionOrderList' => [ // 获取处方订单列表
|
||||
],
|
||||
@@ -84,7 +85,8 @@ class PatientOrderRequest extends FormRequest
|
||||
'order_no' => 'required',
|
||||
|
||||
'order_prescription_id' => 'required',
|
||||
'address_id' => 'required',
|
||||
'address_id' => 'nullable',
|
||||
'delivery_type' => ['nullable', 'integer', Rule::in([1, 2])],
|
||||
'product_ids' => 'required|array|min:1',
|
||||
'detection_status' => 'required|integer|min:0|max:5',
|
||||
'order_service_status' => 'required|integer|min:0|max:4',
|
||||
|
||||
@@ -56,6 +56,7 @@ class UserDoctorRequest extends FormRequest
|
||||
'prescription_icd',// 诊断疾病[]
|
||||
// 'doctor_advice', // 医嘱
|
||||
'prescription_product',// 处方药品[]
|
||||
'pharmacy_id', // 药房id(可选,未传则取默认药房)
|
||||
],
|
||||
'getDoctorMessageList' => [ // 获取医生问诊消息列表
|
||||
'message_inquiry_type',// 消息订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:结束)
|
||||
@@ -94,6 +95,7 @@ class UserDoctorRequest extends FormRequest
|
||||
'prescription_icd' => 'required|array|min:1',
|
||||
'doctor_advice' => 'required',
|
||||
'prescription_product' => 'required|array|min:1|max:5',
|
||||
'pharmacy_id' => 'nullable|numeric',
|
||||
'message_inquiry_type' => 'required|integer|min:1|max:5',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ use App\Model\HospitalDepartmentCustom;
|
||||
use App\Model\HotSearchKeyword;
|
||||
use App\Model\OperationManual;
|
||||
use App\Model\Product;
|
||||
use App\Model\DoctorPharmacy;
|
||||
use App\Model\Pharmacy;
|
||||
use Hyperf\Redis\Redis;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -242,6 +244,24 @@ class BasicDataService extends BaseService
|
||||
$params = array();
|
||||
$params['product_status'] = 1;
|
||||
$params['is_delete'] = 0;
|
||||
|
||||
// 若是医生端,则只展示医生选定/默认药房下的药品
|
||||
if (isset($user_info['user_type']) && $user_info['user_type'] == 2) {
|
||||
$doctor_id = $user_info['client_user_id'] ?? 0;
|
||||
$pharmacy_id = $this->request->input('pharmacy_id');
|
||||
if (isset($pharmacy_id) && $pharmacy_id !== '') {
|
||||
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
|
||||
} else {
|
||||
$defaultPharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
|
||||
$pharmacy = ($defaultPharmacy && $defaultPharmacy->Pharmacy && $defaultPharmacy->Pharmacy->status == 1) ? $defaultPharmacy->Pharmacy : null;
|
||||
}
|
||||
|
||||
if (empty($pharmacy) || empty($pharmacy->pharmacy_code)) {
|
||||
return success([]);
|
||||
}
|
||||
$params['pharmacy_code'] = $pharmacy->pharmacy_code;
|
||||
}
|
||||
|
||||
$product = Product::getSearchKeywordList($params, $product_keyword,$fields);
|
||||
if (empty($product)) {
|
||||
return success();
|
||||
@@ -449,6 +469,30 @@ class BasicDataService extends BaseService
|
||||
$params = array();
|
||||
$params['product_status'] = 1;
|
||||
$params['is_delete'] = 0;
|
||||
|
||||
// 若是医生端,则只展示医生选定/默认药房下的药品
|
||||
if (isset($user_info['user_type']) && $user_info['user_type'] == 2) {
|
||||
$doctor_id = $user_info['client_user_id'] ?? 0;
|
||||
$pharmacy_id = $this->request->input('pharmacy_id');
|
||||
if (isset($pharmacy_id) && $pharmacy_id !== '') {
|
||||
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
|
||||
} else {
|
||||
$defaultPharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
|
||||
$pharmacy = ($defaultPharmacy && $defaultPharmacy->Pharmacy && $defaultPharmacy->Pharmacy->status == 1) ? $defaultPharmacy->Pharmacy : null;
|
||||
}
|
||||
|
||||
if (empty($pharmacy) || empty($pharmacy->pharmacy_code)) {
|
||||
return success([
|
||||
'total' => 0,
|
||||
'per_page' => (int)$per_page,
|
||||
'current_page' => (int)$page,
|
||||
'last_page' => 0,
|
||||
'data' => [],
|
||||
]);
|
||||
}
|
||||
$params['pharmacy_code'] = $pharmacy->pharmacy_code;
|
||||
}
|
||||
|
||||
$product = Product::getWithAmountPage($params, $keyword,$fields, $page, $per_page);
|
||||
if (empty($product['data'])) {
|
||||
return success($product);
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Model\DoctorPharmacy;
|
||||
use App\Model\Pharmacy;
|
||||
use Hyperf\DbConnection\Db;
|
||||
|
||||
class DoctorPharmacyService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 获取医生已绑定的药房列表
|
||||
*/
|
||||
public function getDoctorPharmacyList(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$doctor_id = $user_info['client_user_id'] ?? 0;
|
||||
|
||||
if (empty($doctor_id)) {
|
||||
return fail(HttpEnumCode::CLIENT_HTTP_UNAUTHORIZED, "用户未登录");
|
||||
}
|
||||
|
||||
$list = DoctorPharmacy::with(['Pharmacy'])->where([
|
||||
'doctor_id' => (string) $doctor_id,
|
||||
'status' => 1,
|
||||
])->get();
|
||||
|
||||
$data = [];
|
||||
foreach ($list as $item) {
|
||||
$pharmacy = $item->Pharmacy;
|
||||
if (empty($pharmacy) || $pharmacy->status != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[] = [
|
||||
'doctor_pharmacy_id' => $item->doctor_pharmacy_id,
|
||||
'pharmacy_id' => $pharmacy->pharmacy_id,
|
||||
'pharmacy_name' => $pharmacy->pharmacy_name,
|
||||
'pharmacy_code' => $pharmacy->pharmacy_code,
|
||||
'postage' => $pharmacy->postage,
|
||||
'free_shipping_threshold' => $pharmacy->free_shipping_threshold,
|
||||
'is_pickup' => $pharmacy->is_pickup,
|
||||
'telephone' => $pharmacy->telephone,
|
||||
'province' => $pharmacy->province,
|
||||
'city' => $pharmacy->city,
|
||||
'county' => $pharmacy->county,
|
||||
'address' => $pharmacy->address,
|
||||
'full_address' => $pharmacy->province . $pharmacy->city . $pharmacy->county . $pharmacy->address,
|
||||
'is_default' => $item->is_default,
|
||||
];
|
||||
}
|
||||
|
||||
return success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置医生默认药房
|
||||
*/
|
||||
public function setDoctorDefaultPharmacy(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$doctor_id = $user_info['client_user_id'] ?? 0;
|
||||
$pharmacy_id = $this->request->input('pharmacy_id');
|
||||
|
||||
if (empty($doctor_id)) {
|
||||
return fail(HttpEnumCode::CLIENT_HTTP_UNAUTHORIZED, "用户未登录");
|
||||
}
|
||||
|
||||
if (!isset($pharmacy_id) || $pharmacy_id === '') {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "缺少药房ID");
|
||||
}
|
||||
|
||||
// 验证医生是否绑定了该药房
|
||||
$bind = DoctorPharmacy::where([
|
||||
'doctor_id' => (string) $doctor_id,
|
||||
'pharmacy_id' => (string) $pharmacy_id,
|
||||
'status' => 1,
|
||||
])->first();
|
||||
|
||||
if (empty($bind)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "未绑定该药房或绑定已被禁用");
|
||||
}
|
||||
|
||||
// 验证药房是否存在且有效
|
||||
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
|
||||
if (empty($pharmacy)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "药房不存在或已暂停服务");
|
||||
}
|
||||
|
||||
if (empty($pharmacy->pharmacy_code)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "该药房未配置药房编码,无法设为默认药房");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 将该医生所有绑定的 is_default 置为 0
|
||||
DoctorPharmacy::where('doctor_id', (string) $doctor_id)->update(['is_default' => 0]);
|
||||
|
||||
// 将目标药房的 is_default 置为 1
|
||||
DoctorPharmacy::where([
|
||||
'doctor_id' => (string) $doctor_id,
|
||||
'pharmacy_id' => (string) $pharmacy_id,
|
||||
])->update(['is_default' => 1]);
|
||||
|
||||
Db::commit();
|
||||
return success(null, "设置默认药房成功");
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "设置默认药房失败:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取平台公开正常运营的药房列表
|
||||
*/
|
||||
public function getPublicPharmacyList(): array
|
||||
{
|
||||
$list = Pharmacy::where('status', 1)->get([
|
||||
'pharmacy_id',
|
||||
'pharmacy_name',
|
||||
'pharmacy_code',
|
||||
'postage',
|
||||
'free_shipping_threshold',
|
||||
'is_pickup',
|
||||
'telephone',
|
||||
'province',
|
||||
'city',
|
||||
'county',
|
||||
'address',
|
||||
]);
|
||||
|
||||
return success($list->toArray());
|
||||
}
|
||||
}
|
||||
@@ -405,7 +405,11 @@ class OrderPrescriptionService extends BaseService
|
||||
$arg['payDate'] = $order_product['pay_time']; // 支付时间
|
||||
$arg['money'] = $order_product['payment_amount_total']; // 订单金额
|
||||
$arg['freight'] = $order_product['logistics_fee']; // 运费(单位:元)
|
||||
$arg['takeTypeCode'] = 2; // 取货方式 1 自提 2 快递,目前只支持快递,传固定值 2
|
||||
$arg['takeTypeCode'] = ($order_product['delivery_type'] == 1) ? 1 : 2; // 取货方式 1 自提 2 快递
|
||||
if (empty($order_product['pharmacy_code'])) {
|
||||
throw new BusinessException("订单药房编码缺失,无法上报处方平台");
|
||||
}
|
||||
$arg['pharmacyCode'] = $order_product['pharmacy_code'];
|
||||
$arg['buyerName'] = $order_product['consignee_name'];// 收货人姓名
|
||||
$arg['buyerPhone'] = $order_product['consignee_tel'];// 收货人联系方式
|
||||
$arg['buyerAddress'] = $order_product['address'];// 收货人地址
|
||||
@@ -417,6 +421,7 @@ class OrderPrescriptionService extends BaseService
|
||||
$arg['districtName'] = $order_product['county']; // 收货地址(区 县)名称
|
||||
|
||||
$arg['presList'][0]['prescriptionNo'] = $order_prescription['prescription_code']; // 处方编号
|
||||
$arg['presList'][0]['pharmacyCode'] = $order_product['pharmacy_code'];
|
||||
$arg['presList'][0]['prescriptionSubType'] = 1; // 处方类型 0:无类型 1:普 通处方 2:儿科处 方
|
||||
$arg['presList'][0]['patientName'] = $order_prescription['patient_name']; // 就诊人姓名
|
||||
$arg['presList'][0]['patientPhone'] = $user['mobile']; // 就诊人联系方式
|
||||
|
||||
@@ -42,6 +42,7 @@ use App\Model\PatientFamily;
|
||||
use App\Model\PatientFamilyHealth;
|
||||
use App\Model\PatientFamilyPersonal;
|
||||
use App\Model\PatientFollow;
|
||||
use App\Model\Pharmacy;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
use App\Model\SystemInquiryConfig;
|
||||
@@ -1482,6 +1483,7 @@ class PatientOrderService extends BaseService
|
||||
$address_id = $this->request->input('address_id');
|
||||
$product_ids = $this->request->input('product_ids');
|
||||
$client_type = $this->request->input('client_type');
|
||||
$delivery_type = (int)$this->request->input('delivery_type', 2); // 1: 自提 2: 快递
|
||||
|
||||
// 获取处方数据
|
||||
$params = array();
|
||||
@@ -1493,6 +1495,13 @@ class PatientOrderService extends BaseService
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 获取处方药房信息
|
||||
$pharmacy_id = $order_prescription['pharmacy_id'] ?? 0;
|
||||
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
|
||||
if (empty($pharmacy) || empty($pharmacy['pharmacy_code'])) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方所属药房异常,无法下单");
|
||||
}
|
||||
|
||||
// 验证处方状态
|
||||
if ($order_prescription['prescription_status'] == 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||||
@@ -1516,7 +1525,21 @@ class PatientOrderService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||||
}
|
||||
|
||||
// 检测收货地址
|
||||
// 检测收货方式及收货地址
|
||||
$user_ship_address = null;
|
||||
if ($delivery_type == 1) {
|
||||
// 自提模式,检查药房是否支持自提
|
||||
if ($pharmacy['is_pickup'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "该药房不支持到店自提");
|
||||
}
|
||||
if (!empty($address_id)) {
|
||||
$params = array();
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
$params['address_id'] = $address_id;
|
||||
$user_ship_address = UserShipAddress::getOne($params);
|
||||
}
|
||||
} else {
|
||||
// 快递模式,必须有收货地址
|
||||
$params = array();
|
||||
$params['user_id'] = $user_info['user_id'];
|
||||
$params['address_id'] = $address_id;
|
||||
@@ -1524,6 +1547,7 @@ class PatientOrderService extends BaseService
|
||||
if (empty($user_ship_address)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "收货地址错误");
|
||||
}
|
||||
}
|
||||
|
||||
$not_enough_product_ids = [];
|
||||
|
||||
@@ -1710,17 +1734,17 @@ class PatientOrderService extends BaseService
|
||||
|
||||
// 处理运费数据
|
||||
$app_env = config('app_env', 'prod');
|
||||
if (env("APP_ENV") == "prod") {
|
||||
// $Prescription = new Prescription();
|
||||
// $result = $Prescription->getLogisticsFee();
|
||||
// if ($freight_calculation_amount < $result['drugCost']) {
|
||||
// $logistics_fee = $result['freight'];
|
||||
// }
|
||||
//测试环境 运费
|
||||
$logistics_fee = 7;
|
||||
}else{
|
||||
//测试环境 运费
|
||||
$logistics_fee = 0;
|
||||
$logistics_fee = 0.00;
|
||||
if ($delivery_type == 1) {
|
||||
$logistics_fee = 0.00;
|
||||
} else {
|
||||
$postage = (float)($pharmacy['postage'] ?? 0.00);
|
||||
$threshold = (float)($pharmacy['free_shipping_threshold'] ?? 0.00);
|
||||
if ($threshold > 0 && (float)$freight_calculation_amount >= $threshold) {
|
||||
$logistics_fee = 0.00;
|
||||
} else {
|
||||
$logistics_fee = $postage;
|
||||
}
|
||||
}
|
||||
|
||||
// 实际支付金额=商品总金额-优惠卷金额+运费金额
|
||||
@@ -1730,7 +1754,7 @@ class PatientOrderService extends BaseService
|
||||
(string)$coupon_amount_total,
|
||||
2
|
||||
),
|
||||
$logistics_fee,
|
||||
(string)$logistics_fee,
|
||||
2
|
||||
);
|
||||
|
||||
@@ -1792,6 +1816,11 @@ class PatientOrderService extends BaseService
|
||||
$data['coupon_amount_total'] = $coupon_amount_total; // 优惠卷总金额
|
||||
$data['payment_amount_total'] = $payment_amount_total; // 实际付款金额
|
||||
$data['logistics_fee'] = $logistics_fee; // 运费金额
|
||||
$data['pharmacy_id'] = $pharmacy['pharmacy_id'];
|
||||
$data['pharmacy_code'] = $pharmacy['pharmacy_code'];
|
||||
$data['pharmacy_name'] = $pharmacy['pharmacy_name'];
|
||||
$data['delivery_type'] = $delivery_type;
|
||||
if (!empty($user_ship_address)) {
|
||||
$data['province_id'] = $user_ship_address['province_id'];
|
||||
$data['province'] = $user_ship_address['province'];
|
||||
$data['city_id'] = $user_ship_address['city_id'];
|
||||
@@ -1804,6 +1833,20 @@ class PatientOrderService extends BaseService
|
||||
$data['consignee_name_mask'] = $user_ship_address['consignee_name_mask'];
|
||||
$data['consignee_tel'] = $user_ship_address['consignee_tel'];
|
||||
$data['consignee_tel_mask'] = $user_ship_address['consignee_tel_mask'];
|
||||
} else {
|
||||
$data['province_id'] = 0;
|
||||
$data['province'] = "";
|
||||
$data['city_id'] = 0;
|
||||
$data['city'] = "";
|
||||
$data['county_id'] = 0;
|
||||
$data['county'] = "";
|
||||
$data['address'] = $pharmacy['pickup_address'] ?? "到店自提";
|
||||
$data['address_mask'] = $pharmacy['pickup_address'] ?? "到店自提";
|
||||
$data['consignee_name'] = $order_prescription['patient_name'] ?? "";
|
||||
$data['consignee_name_mask'] = $order_prescription['patient_name'] ?? "";
|
||||
$data['consignee_tel'] = "";
|
||||
$data['consignee_tel_mask'] = "";
|
||||
}
|
||||
$order_product = OrderProduct::addOrderProduct($data);
|
||||
if (empty($order_product)) {
|
||||
Db::rollBack();
|
||||
@@ -2154,7 +2197,10 @@ class PatientOrderService extends BaseService
|
||||
|
||||
$fields = [
|
||||
"order_prescription_id",
|
||||
"order_inquiry_id"
|
||||
"order_inquiry_id",
|
||||
"pharmacy_id",
|
||||
"pharmacy_code",
|
||||
"pharmacy_name",
|
||||
];
|
||||
|
||||
$params = array();
|
||||
@@ -2357,19 +2403,19 @@ class PatientOrderService extends BaseService
|
||||
// 获取可用优惠卷总金额
|
||||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
|
||||
|
||||
// 获取运费金额
|
||||
$logistics_fee = 0;
|
||||
if (env("APP_ENV") == "prod") {
|
||||
// $Prescription = new Prescription();
|
||||
// $result = $Prescription->getLogisticsFee();
|
||||
// if ($freight_calculation_amount < $result['drugCost']) {
|
||||
// $logistics_fee = $result['freight'];
|
||||
// }
|
||||
//测试环境 运费
|
||||
$logistics_fee = 7;
|
||||
}else{
|
||||
//测试环境 运费
|
||||
$logistics_fee = 0;
|
||||
// 获取运费金额及药房信息
|
||||
$pharmacy_id = $order_prescription['pharmacy_id'] ?? 0;
|
||||
$pharmacy = Pharmacy::getValidPharmacy($pharmacy_id);
|
||||
|
||||
$logistics_fee = 0.00;
|
||||
if (!empty($pharmacy)) {
|
||||
$postage = (float)($pharmacy['postage'] ?? 0.00);
|
||||
$threshold = (float)($pharmacy['free_shipping_threshold'] ?? 0.00);
|
||||
if ($threshold > 0 && (float)$freight_calculation_amount >= $threshold) {
|
||||
$logistics_fee = 0.00;
|
||||
} else {
|
||||
$logistics_fee = $postage;
|
||||
}
|
||||
}
|
||||
|
||||
// 实际支付金额=商品总金额-优惠卷金额+运费金额
|
||||
@@ -2399,6 +2445,16 @@ class PatientOrderService extends BaseService
|
||||
$result['logistics_fee'] = $logistics_fee;
|
||||
$result['user_ship_address'] = $user_ship_address;
|
||||
$result['order_prescription_product'] = $order_prescription_products;
|
||||
$result['pharmacy_info'] = !empty($pharmacy) ? [
|
||||
'pharmacy_id' => (string)$pharmacy['pharmacy_id'],
|
||||
'pharmacy_code' => $pharmacy['pharmacy_code'],
|
||||
'pharmacy_name' => $pharmacy['pharmacy_name'],
|
||||
'telephone' => $pharmacy['telephone'] ?? '',
|
||||
'is_pickup' => $pharmacy['is_pickup'] ?? 0,
|
||||
'postage' => (string)($pharmacy['postage'] ?? '0.00'),
|
||||
'free_shipping_threshold' => (string)($pharmacy['free_shipping_threshold'] ?? '0.00'),
|
||||
'pickup_address' => $pharmacy['pickup_address'] ?? '',
|
||||
] : null;
|
||||
|
||||
return success($result);
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ use App\Model\OrderServicePackageInquiry;
|
||||
use App\Model\PatientFollow;
|
||||
use App\Model\PatientHistoryInquiry;
|
||||
use App\Model\PatientHistoryInquiry as PatientHistoryInquiryModel;
|
||||
use App\Model\DoctorPharmacy;
|
||||
use App\Model\Pharmacy;
|
||||
use App\Model\Popup;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
@@ -1199,9 +1201,24 @@ class UserDoctorService extends BaseService
|
||||
$result['message'] = "成功";
|
||||
$result['data'] = [];
|
||||
|
||||
// 校验医生是否已配置有效的默认药房
|
||||
$doctor_id = $user_info['client_user_id'] ?? 0;
|
||||
$default_pharmacy = DoctorPharmacy::getDoctorDefaultPharmacy($doctor_id);
|
||||
if (empty($default_pharmacy) || empty($default_pharmacy->Pharmacy) || $default_pharmacy->Pharmacy->status != 1 || empty($default_pharmacy->Pharmacy->pharmacy_code)) {
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "您尚未配置默认药房或药房已停用,请前往【我的-药房设置】完成绑定后再开具处方";
|
||||
return success($result);
|
||||
}
|
||||
|
||||
$result['data']['default_pharmacy'] = [
|
||||
'pharmacy_id' => (string)$default_pharmacy->Pharmacy->pharmacy_id,
|
||||
'pharmacy_code' => $default_pharmacy->Pharmacy->pharmacy_code,
|
||||
'pharmacy_name' => $default_pharmacy->Pharmacy->pharmacy_name,
|
||||
];
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$params['doctor_id'] = $user_info['client_user_id'];
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
$order_prescription = OrderPrescription::getOne($params);
|
||||
if (empty($order_prescription)){
|
||||
return success($result);
|
||||
@@ -1462,6 +1479,22 @@ class UserDoctorService extends BaseService
|
||||
$doctor_advice = $this->request->input('doctor_advice');
|
||||
$prescription_product = $this->request->input('prescription_product');
|
||||
$disease_desc = $this->request->input('disease_desc'); // 病情主诉
|
||||
$input_pharmacy_id = $this->request->input('pharmacy_id');
|
||||
|
||||
// 获取开方药房
|
||||
$pharmacy = null;
|
||||
if (isset($input_pharmacy_id) && $input_pharmacy_id !== '') {
|
||||
$pharmacy = Pharmacy::getValidPharmacy($input_pharmacy_id);
|
||||
} else {
|
||||
$doctor_default = DoctorPharmacy::getDoctorDefaultPharmacy($user_info['client_user_id'] ?? 0);
|
||||
if ($doctor_default && $doctor_default->Pharmacy && $doctor_default->Pharmacy->status == 1) {
|
||||
$pharmacy = $doctor_default->Pharmacy;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($pharmacy) || empty($pharmacy['pharmacy_code'])) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "未找到有效的开方药房或药房已被停用,无法开具处方");
|
||||
}
|
||||
|
||||
// 获取医生信息
|
||||
$params = array();
|
||||
@@ -1635,6 +1668,9 @@ class UserDoctorService extends BaseService
|
||||
$data['patient_sex'] = $order_inquiry['patient_sex'];
|
||||
$data['patient_age'] = $order_inquiry['patient_age'];
|
||||
$data['doctor_advice'] = $doctor_advice;
|
||||
$data['pharmacy_id'] = $pharmacy['pharmacy_id'];
|
||||
$data['pharmacy_code'] = $pharmacy['pharmacy_code'];
|
||||
$data['pharmacy_name'] = $pharmacy['pharmacy_name'];
|
||||
$order_prescription = OrderPrescription::addOrderPrescription($data);
|
||||
if (empty($order_prescription)) {
|
||||
Db::rollBack();
|
||||
@@ -1689,6 +1725,12 @@ class UserDoctorService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"药品" . $product['product_name'] . "已被删除,无法开具");
|
||||
}
|
||||
|
||||
// 校验药品所属药房是否与处方药房一致
|
||||
if (!empty($product['pharmacy_code']) && $product['pharmacy_code'] !== $pharmacy['pharmacy_code']) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "药品【" . $product['product_name'] . "】不属于当前药房");
|
||||
}
|
||||
|
||||
// 检测药品是否超出最大可开数
|
||||
if ($item['prescription_product_num'] > $product['prescription_num']) {
|
||||
// 库存不足
|
||||
|
||||
@@ -18,6 +18,7 @@ use App\Controller\DetectionController;
|
||||
use App\Controller\DoctorAccountController;
|
||||
use App\Controller\DoctorAuthController;
|
||||
use App\Controller\DoctorInquiryConfigController;
|
||||
use App\Controller\DoctorPharmacyController;
|
||||
use App\Controller\IndexController;
|
||||
use App\Controller\InquiryController;
|
||||
use App\Controller\LoginController;
|
||||
@@ -259,6 +260,15 @@ Router::addGroup('/doctor', function () {
|
||||
Router::get('/check', [UserDoctorController::class, 'checkOpenPrescription']);
|
||||
});
|
||||
|
||||
// 药房
|
||||
Router::addGroup('/pharmacy', function () {
|
||||
// 获取医生绑定的药房列表
|
||||
Router::get('', [DoctorPharmacyController::class, 'getDoctorPharmacyList']);
|
||||
|
||||
// 设置医生默认药房
|
||||
Router::put('/default', [DoctorPharmacyController::class, 'setDoctorDefaultPharmacy']);
|
||||
});
|
||||
|
||||
// 常用语
|
||||
Router::addGroup('/words', function () {
|
||||
// 获取常用语列表
|
||||
@@ -772,6 +782,9 @@ Router::addGroup('/basic', function () {
|
||||
|
||||
// 获取检测疾病分类列表
|
||||
Router::get('/detection/disease', [BasicDataController::class, 'getDetectionDiseaseList']);
|
||||
|
||||
// 获取公共药房列表
|
||||
Router::get('/pharmacy', [DoctorPharmacyController::class, 'getPublicPharmacyList']);
|
||||
});
|
||||
|
||||
// 获取医生评价
|
||||
|
||||
@@ -136,13 +136,15 @@ class Prescription
|
||||
/**
|
||||
* 获取商品库存
|
||||
* @param string $product_platform_code 处方平台商品编码(此处使用第三方药店商品编码!)
|
||||
* @param string $pharmacy_code 药房编码
|
||||
* @return array
|
||||
*/
|
||||
public function getProdStock(string $product_platform_code): array
|
||||
public function getProdStock(string $product_platform_code, string $pharmacy_code = ""): array
|
||||
{
|
||||
$code = !empty($pharmacy_code) ? $pharmacy_code : $this->pharmacy_code;
|
||||
$option = [
|
||||
"json" => array(
|
||||
"pharmacyCode" => $this->pharmacy_code,
|
||||
"pharmacyCode" => $code,
|
||||
"drugCode" => $product_platform_code,
|
||||
),
|
||||
];
|
||||
@@ -165,13 +167,15 @@ class Prescription
|
||||
|
||||
/**
|
||||
* 获取运费
|
||||
* @param string $pharmacy_code 药房编码
|
||||
* @return array
|
||||
*/
|
||||
public function getLogisticsFee(): array
|
||||
public function getLogisticsFee(string $pharmacy_code = ""): array
|
||||
{
|
||||
$code = !empty($pharmacy_code) ? $pharmacy_code : $this->pharmacy_code;
|
||||
$option = [
|
||||
"json" => array(
|
||||
"pharmacyCode" => $this->pharmacy_code,
|
||||
"pharmacyCode" => $code,
|
||||
),
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user