3246 lines
130 KiB
PHP
3246 lines
130 KiB
PHP
<?php
|
||
|
||
namespace App\Services;
|
||
|
||
use App\Amqp\Producer\AssignDoctorDelayDirectProducer;
|
||
use App\Amqp\Producer\CancelUnInquiryOrdersDelayDirectProducer;
|
||
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
||
use App\Amqp\Producer\DoctorNotYetInquiryDelayDirectProducer;
|
||
use App\Amqp\Producer\GrantUserCouponDelayDirectProducer;
|
||
use App\Constants\DoctorTitleCode;
|
||
use App\Constants\HttpEnumCode;
|
||
use App\Model\BasicLogisticsCompany;
|
||
use App\Model\Coupon;
|
||
use App\Model\DetectionProject;
|
||
use App\Model\DiseaseClass;
|
||
use App\Model\DoctorInquiryConfig;
|
||
use App\Model\HealthPackage;
|
||
use App\Model\Hospital;
|
||
use App\Model\InquiryCaseProduct;
|
||
use App\Model\Order;
|
||
use App\Model\OrderCoupon;
|
||
use App\Model\OrderDetection;
|
||
use App\Model\OrderInquiry;
|
||
use App\Model\OrderInquiryCase;
|
||
use App\Model\OrderInquiryCoupon;
|
||
use App\Model\OrderInquiryRefund;
|
||
use App\Model\OrderPrescription;
|
||
use App\Model\OrderPrescriptionFile;
|
||
use App\Model\OrderPrescriptionProduct;
|
||
use App\Model\OrderProduct;
|
||
use App\Model\OrderProductCoupon;
|
||
use App\Model\OrderProductItem;
|
||
use App\Model\OrderProductLogistic;
|
||
use App\Model\OrderRefund;
|
||
use App\Model\OrderServicePackage;
|
||
use App\Model\OrderServicePackageCase;
|
||
use App\Model\OrderServicePackageDetail;
|
||
use App\Model\OrderServicePackageInquiry;
|
||
use App\Model\OrderServicePackageProduct;
|
||
use App\Model\OrderServicePackageRefund;
|
||
use App\Model\PatientFamily;
|
||
use App\Model\PatientFamilyHealth;
|
||
use App\Model\PatientFamilyPersonal;
|
||
use App\Model\PatientFollow;
|
||
use App\Model\Product;
|
||
use App\Model\ProductPlatformAmount;
|
||
use App\Model\SystemInquiryConfig;
|
||
use App\Model\UserCoupon;
|
||
use App\Model\UserDoctor;
|
||
use App\Model\UserDoctorInfo;
|
||
use App\Model\UserPharmacistInfo;
|
||
use App\Model\UserShipAddress;
|
||
use App\Utils\Log;
|
||
use App\Utils\PcreMatch;
|
||
use Extend\Prescription\Prescription;
|
||
use Extend\Wechat\WechatPay;
|
||
use GuzzleHttp\Exception\GuzzleException;
|
||
use Hyperf\Amqp\Producer;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Redis\Redis;
|
||
use Hyperf\Snowflake\IdGeneratorInterface;
|
||
use Hyperf\Utils\ApplicationContext;
|
||
use Psr\Container\ContainerExceptionInterface;
|
||
use Psr\Container\NotFoundExceptionInterface;
|
||
|
||
/**
|
||
* 患者订单
|
||
*/
|
||
class PatientOrderService extends BaseService
|
||
{
|
||
/**
|
||
* 获取患者问诊订单列表
|
||
* @return array
|
||
*/
|
||
public function getPatientInquiryOrderList(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$inquiry_status = $this->request->input('inquiry_status', 0);
|
||
$family_id = $this->request->input('family_id');
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
if (!empty($family_id)) {
|
||
$params['family_id'] = $family_id;
|
||
}
|
||
|
||
$inquiry_status_params = [];
|
||
if (!empty($inquiry_status) && $inquiry_status != 0) {
|
||
// 问诊订单状态(0:全部 1:待支付 2:待接诊 3:问诊中 4:完成/取消
|
||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||
if ($inquiry_status == 1) {
|
||
$inquiry_status_params = [1];
|
||
}
|
||
|
||
if ($inquiry_status == 2) {
|
||
$inquiry_status_params = [2, 3];
|
||
}
|
||
|
||
if ($inquiry_status == 3) {
|
||
$inquiry_status_params = [4];
|
||
}
|
||
|
||
if ($inquiry_status == 4) {
|
||
$inquiry_status_params = [5, 6, 7];
|
||
}
|
||
}
|
||
|
||
$params['is_delete'] = 0;
|
||
|
||
$fields = [
|
||
'order_inquiry_id',
|
||
'patient_id',
|
||
'doctor_id',
|
||
'family_id',
|
||
'inquiry_type',
|
||
'inquiry_mode',
|
||
'inquiry_status',
|
||
'is_delete',
|
||
'inquiry_refund_status',
|
||
'inquiry_pay_channel',
|
||
'inquiry_pay_status',
|
||
'inquiry_no',
|
||
'escrow_trade_no',
|
||
'amount_total',
|
||
'payment_amount_total',
|
||
'patient_name',
|
||
'patient_name_mask',
|
||
'patient_sex',
|
||
'patient_age',
|
||
'created_at',
|
||
];
|
||
$order_inquiry = OrderInquiry::getPatientOrderInquiryPage($params, $inquiry_status_params, $fields, $page, $per_page);
|
||
if (empty($order_inquiry['data'])) {
|
||
return success($order_inquiry);
|
||
}
|
||
|
||
foreach ($order_inquiry['data'] as &$item) {
|
||
$item['disease_desc'] = $item['OrderInquiryCase']['disease_desc'];
|
||
unset($item['OrderInquiryCase']);
|
||
|
||
// 获取医生数据
|
||
$item['user_doctor'] = [];
|
||
if (!empty($item['doctor_id'])) {
|
||
$fields = [
|
||
'doctor_id',
|
||
'user_name',
|
||
'doctor_title',
|
||
'hospital_id',
|
||
"avatar"
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $item['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 转换医生职称
|
||
$user_doctor['doctor_title'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 获取医生医院名称
|
||
$user_doctor['hospital_name'] = "";
|
||
$user_doctor['hospital_level_name'] = "";
|
||
|
||
// 医生头像
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
'hospital_level_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params, $fields);
|
||
if (!empty($hospital)) {
|
||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||
}
|
||
|
||
$item['user_doctor'] = $user_doctor;
|
||
unset($hospital);
|
||
unset($user_doctor);
|
||
}
|
||
}
|
||
|
||
return success($order_inquiry);
|
||
}
|
||
|
||
/**
|
||
* 获取患者问诊订单详情
|
||
* @return array
|
||
*/
|
||
public function getPatientInquiryOrderInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_inquiry_id = $this->request->route('order_inquiry_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$params['is_delete'] = 0;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取病例信息
|
||
$fields = [
|
||
'disease_class_name',
|
||
'disease_desc',
|
||
];
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params, $fields);
|
||
if (empty($order_inquiry_case)) {
|
||
$order_inquiry['case'] = [];
|
||
} else {
|
||
$order_inquiry['case'] = $order_inquiry_case->toArray();
|
||
}
|
||
|
||
// 获取医生数据
|
||
$order_inquiry['user_doctor'] = [];
|
||
if (!empty($order_inquiry['doctor_id'])) {
|
||
$fields = [
|
||
'user_id',
|
||
'doctor_id',
|
||
'user_name',
|
||
'doctor_title',
|
||
'hospital_id',
|
||
'avatar',
|
||
'department_custom_name',
|
||
'multi_point_status',
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 转换医生职称
|
||
$user_doctor['doctor_title'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 头像
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
// 获取医生医院名称
|
||
$user_doctor['hospital_name'] = "";
|
||
$user_doctor['hospital_level_name'] = "";
|
||
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
'hospital_level_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params, $fields);
|
||
if (!empty($hospital)) {
|
||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||
}
|
||
|
||
// 获取医生关注状态
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$user_doctor['follow'] = PatientFollow::getExists($params);
|
||
|
||
// 获取医生问诊配置-问诊购药
|
||
$user_doctor['multi_point_enable'] = 0;
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$params['inquiry_type'] = 4;
|
||
$params['inquiry_mode'] = 1;
|
||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||
if (!empty($doctor_inquiry_config)) {
|
||
if ($doctor_inquiry_config['is_enable'] == 1) {
|
||
$user_doctor['multi_point_enable'] = 1;
|
||
}
|
||
}
|
||
|
||
$order_inquiry['user_doctor'] = $user_doctor;
|
||
|
||
unset($hospital);
|
||
unset($user_doctor);
|
||
}
|
||
|
||
// 获取退款数据
|
||
$order_inquiry['order_inquiry_refund'] = array();
|
||
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$order_inquiry_refund = OrderInquiryRefund::getList($params);
|
||
if (!empty($order_inquiry_refund)){
|
||
$order_inquiry['order_inquiry_refund'] = $order_inquiry_refund;
|
||
}
|
||
|
||
return success($order_inquiry->toArray());
|
||
}
|
||
|
||
/**
|
||
* 取消患者问诊订单
|
||
* @return array
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
public function putCancelPatientInquiryOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_inquiry_id = $this->request->route('order_inquiry_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$params['is_delete'] = 0;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail();
|
||
}
|
||
|
||
$redis = $this->container->get(Redis::class);
|
||
$redis_key = "order_inquiry_lock_" . $order_inquiry_id;
|
||
$redis_lock = $redis->setnx($redis_key, 1);
|
||
if (!$redis_lock) {
|
||
// 设置失败,表示已经设置该值
|
||
return fail(HttpEnumCode::HTTP_SUCCESS, "请您稍后重试");
|
||
}
|
||
|
||
// 设置过期时间
|
||
$redis->expire($redis_key, 3);
|
||
|
||
// 检测订单状态
|
||
if (!in_array($order_inquiry['inquiry_status'], [1, 2, 3])) {
|
||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法取消");
|
||
}
|
||
|
||
if ($order_inquiry['inquiry_refund_status'] == 1) {
|
||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单申请退款中,请您稍后取消");
|
||
}
|
||
|
||
if ($order_inquiry['inquiry_refund_status'] == 2) {
|
||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款中,请您稍后取消");
|
||
}
|
||
|
||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 退款成功
|
||
// 修改问诊订单为取消
|
||
$data = array();
|
||
$data['inquiry_status'] = 7;
|
||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||
$data['cancel_reason'] = 2; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
OrderInquiry::edit($params, $data);
|
||
|
||
// 修改订单为取消
|
||
$data = array();
|
||
$data['cancel_status'] = 1;
|
||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||
$data['cancel_remarks'] = "主动取消"; // 取消订单备注
|
||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_inquiry['inquiry_no'];
|
||
Order::edit($params, $data);
|
||
|
||
// 检测支付状态,判断是否需要退款处理
|
||
if ($order_inquiry['inquiry_pay_status'] == 2 && $order_inquiry['inquiry_refund_status'] != 3) {
|
||
// 需退款
|
||
$OrderService = new OrderService();
|
||
$OrderService->orderRefund($order_inquiry['inquiry_no'], "取消问诊");
|
||
}
|
||
|
||
// 删除锁
|
||
$redis->del($redis_key);
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
try {
|
||
if (!empty($order_inquiry['doctor_id'])) {
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, "取消失败");
|
||
}
|
||
|
||
// 推送医生-患者取消问诊
|
||
$MessagePush = new MessagePush($user_doctor['user_id'], $order_inquiry['inquiry_no']);
|
||
$MessagePush->patientCancelInquiryToDoctor();
|
||
}
|
||
} catch (\Exception $e) {
|
||
return success();
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 删除问诊订单
|
||
* 支付超时
|
||
* 取消问诊
|
||
* 问诊结束
|
||
* @return array
|
||
*/
|
||
public function deletePatientInquiryOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_inquiry_id = $this->request->route('order_inquiry_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$params['is_delete'] = 0;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail();
|
||
}
|
||
|
||
// 检测订单状态
|
||
if (!in_array($order_inquiry['inquiry_status'], [6, 7])) {
|
||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 修改问诊订单删除状态
|
||
$data = array();
|
||
$data['is_delete'] = 1;
|
||
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
OrderInquiry::edit($params, $data);
|
||
|
||
$data = array();
|
||
$data['is_delete'] = 1;
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_inquiry['inquiry_no'];
|
||
Order::edit($params, $data);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR,$e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 问诊订单取消支付
|
||
* @return array
|
||
*/
|
||
public function putPatientInquiryOrderCancelPay(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_inquiry_id = $this->request->route('order_inquiry_id');
|
||
|
||
Db::beginTransaction();
|
||
|
||
try {
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$params['is_delete'] = 0;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
$OrderService = new OrderService();
|
||
$result = $OrderService->cancelUnpayOrder($order_inquiry['inquiry_no'],2,"主动取消");
|
||
if ($result['status'] != 1) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $result['message']);
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 获取药品订单列表
|
||
* @return array
|
||
*/
|
||
public function getPatientProductOrderList(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_product_status = $this->request->input('order_product_status', 0);
|
||
$family_id = $this->request->input('family_id');
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
if (!empty($family_id)) {
|
||
$params['family_id'] = $family_id;
|
||
}
|
||
|
||
if (!empty($order_product_status) && $order_product_status != 0) {
|
||
// 入参订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||
// 数据库订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||
$params['order_product_status'] = $order_product_status;
|
||
}
|
||
|
||
$params['is_delete'] = 0;
|
||
|
||
$fields = [
|
||
'order_product_id',
|
||
'order_inquiry_id',
|
||
'order_prescription_id',
|
||
'doctor_id',
|
||
'patient_id',
|
||
'family_id',
|
||
'order_product_status',
|
||
'pay_status',
|
||
'cancel_reason',
|
||
'logistics_no',
|
||
'remarks',
|
||
'refund_status',
|
||
'cancel_remarks',
|
||
'created_at',
|
||
];
|
||
|
||
$order_product = OrderProduct::getPatientOrderProductPage($params, $fields, $page, $per_page);
|
||
|
||
if (!empty($order_product['data'])) {
|
||
foreach ($order_product['data'] as $item) {
|
||
foreach ($item['orderProductItem'] as &$product_item) {
|
||
$product_item['product_cover_img'] = addAliyunOssWebsite($product_item['product_cover_img']);
|
||
}
|
||
}
|
||
}
|
||
|
||
return success($order_product);
|
||
}
|
||
|
||
/**
|
||
* 获取药品订单详情
|
||
* @return array
|
||
*/
|
||
public function getPatientProductOrderInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_product_id = $this->request->route('order_product_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_product_id'] = $order_product_id;
|
||
$params['is_delete'] = 0;
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)) {
|
||
return fail();
|
||
}
|
||
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product['order_product_id'];
|
||
$order_product_item = OrderProductItem::getList($params);
|
||
if (empty($order_product_item)) {
|
||
return fail();
|
||
}
|
||
|
||
// 处理商品图片
|
||
foreach ($order_product_item as &$item) {
|
||
$item['product_cover_img'] = addAliyunOssWebsite($item['product_cover_img']);
|
||
}
|
||
|
||
if (!empty($order_product['doctor_id'])) {
|
||
// 获取问诊医生数据
|
||
$fields = [
|
||
'doctor_id',
|
||
'user_name',
|
||
'multi_point_status',
|
||
'avatar',
|
||
'doctor_title',
|
||
'department_custom_name',
|
||
'be_good_at',
|
||
'hospital_id',
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $order_product['doctor_id'];
|
||
$user_doctor = UserDoctor::getWithHospitalOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
// 获取医生问诊配置-问诊购药
|
||
$user_doctor['multi_point_enable'] = 0;
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$params['inquiry_type'] = 4;
|
||
$params['inquiry_mode'] = 1;
|
||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||
if (!empty($doctor_inquiry_config)) {
|
||
if ($doctor_inquiry_config['is_enable'] == 1) {
|
||
$user_doctor['multi_point_enable'] = 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
$result = array();
|
||
$result['user_doctor'] = $user_doctor ?? [];
|
||
$result['order_product'] = $order_product;
|
||
$result['order_product_item'] = $order_product_item;
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 药品订单取消支付
|
||
* @return array
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
public function putPatientProductOrderCancelPay(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_product_id = $this->request->route('order_product_id');
|
||
|
||
$redis = $this->container->get(Redis::class);
|
||
$redis_key = "order_product_lock_" . $order_product_id;
|
||
$redis_lock = $redis->setnx($redis_key, 1);
|
||
if (!$redis_lock) {
|
||
// 设置失败,表示已经设置该值
|
||
return fail(HttpEnumCode::HTTP_SUCCESS, "请您稍后重试");
|
||
}
|
||
|
||
// 设置过期时间
|
||
$redis->expire($redis_key, 3);
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 获取药品订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_product_id'] = $order_product_id;
|
||
$params['is_delete'] = 0;
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
$OrderService = new OrderService();
|
||
$result = $OrderService->cancelUnpayOrder($order_product['order_product_no'], 1, "主动取消");
|
||
if ($result['status'] != 1) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $result['message']);
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (\Throwable $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 删除药品订单
|
||
* 已收货
|
||
* 取消订单
|
||
* @return array
|
||
*/
|
||
public function deletePatientProductOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_product_id = $this->request->route('order_product_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_product_id'] = $order_product_id;
|
||
$params['is_delete'] = 0;
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)) {
|
||
return fail();
|
||
}
|
||
|
||
if (!in_array($order_product['order_product_status'], [4, 5])) {
|
||
Db::rollBack();
|
||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 修改药品订单状态
|
||
$data = array();
|
||
$data['is_delete'] = 1;
|
||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product_id;
|
||
OrderProduct::edit($params, $data);
|
||
|
||
$data = array();
|
||
$data['is_delete'] = 1;
|
||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_product['order_product_no'];
|
||
Order::edit($params, $data);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR,$e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 获取患者订单支付数据
|
||
* @return array
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
public function getPatientOrderPayInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_type = $this->request->input('order_type');
|
||
$order_no = $this->request->input('order_no');
|
||
|
||
$return_result = array();
|
||
$return_result['data'] = null;
|
||
$return_result['status'] = 2; // 状态 1:正常 2:状态错误 3:存在问诊订单
|
||
$return_result['message'] = "";
|
||
|
||
// 获取订单金额
|
||
$result = array();
|
||
$result['amount_total'] = 0; // 订单总额
|
||
$result['payment_amount_total'] = 0; // 实际订单金额
|
||
$result['coupon_amount_total'] = 0; // 优惠金额
|
||
$result['order_no'] = $order_no; // 订单编号
|
||
$result['order_id'] = ""; // 订单主键id(问诊订单:order_inquiry_id 药品订单:order_product_id)
|
||
$result['created_at'] = ""; // 创建时间
|
||
$result['inquiry_type'] = 0; // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
|
||
$result['inquiry_mode'] = 0; // 接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员 6:疑难会诊)
|
||
$result['pay_config'] = []; // 小程序支付配置
|
||
$result['cannot_use_coupon_reason'] = ""; // 不可使用优惠卷原因
|
||
|
||
// 问诊订单
|
||
if ($order_type == 1) {
|
||
$params = array();
|
||
$params['inquiry_no'] = $order_no;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if ($order_inquiry['inquiry_status'] != 1) {
|
||
$return_result['message'] = "订单状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_inquiry['order_inquiry_id'];
|
||
$return_result['data']['order_status'] = $order_inquiry['inquiry_status'];
|
||
$return_result['data']['order_pay_status'] = $order_inquiry['inquiry_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单支付状态
|
||
if ($order_inquiry['inquiry_pay_status'] != 1) {
|
||
$return_result['message'] = "订单支付状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_inquiry['order_inquiry_id'];
|
||
$return_result['data']['order_status'] = $order_inquiry['inquiry_status'];
|
||
$return_result['data']['order_pay_status'] = $order_inquiry['inquiry_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单过期支付时间
|
||
$diff_time = (strtotime($order_inquiry['created_at']) - time()) / 60;
|
||
if ($diff_time >= 30) {
|
||
$return_result['message'] = "订单已过期";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_inquiry['order_inquiry_id'];
|
||
$return_result['data']['order_status'] = $order_inquiry['inquiry_status'];
|
||
$return_result['data']['order_pay_status'] = $order_inquiry['inquiry_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
$result['order_id'] = $order_inquiry['order_inquiry_id'];
|
||
$result['created_at'] = $order_inquiry['created_at'];
|
||
$result['inquiry_type'] = $order_inquiry['inquiry_type'];
|
||
$result['inquiry_mode'] = $order_inquiry['inquiry_mode'];
|
||
|
||
// 获取订单金额
|
||
$result['amount_total'] = $order_inquiry['amount_total']; // 订单金额
|
||
$result['payment_amount_total'] = $order_inquiry['payment_amount_total']; // 实际订单金额
|
||
$result['coupon_amount_total'] = $order_inquiry['coupon_amount_total'];; // 优惠金额
|
||
|
||
if ($order_inquiry['payment_amount_total'] > 0) {
|
||
// 发起支付
|
||
$WechatPay = new WechatPay(1, 1);
|
||
|
||
|
||
// 获取预支付交易会话标识
|
||
$prepay = $WechatPay->getJsapiPrepayId($order_no, (int)round($order_inquiry['payment_amount_total'] * 100), $user_info['open_id'], "问诊服务");
|
||
if (empty($prepay)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 获取小程序支付配置
|
||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||
}
|
||
}
|
||
|
||
// 药品订单
|
||
if ($order_type == 2) {
|
||
$params = array();
|
||
$params['order_product_no'] = $order_no;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if ($order_product['order_product_status'] != 1) {
|
||
$return_result['message'] = "订单状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_product['order_product_id'];
|
||
$return_result['data']['order_status'] = $order_product['order_product_status'];
|
||
$return_result['data']['order_pay_status'] = $order_product['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单支付状态
|
||
if ($order_product['pay_status'] != 1) {
|
||
$return_result['message'] = "订单支付状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_product_id'] = $order_product['order_product_id'];
|
||
$return_result['data']['order_product_status'] = $order_product['order_product_status'];
|
||
$return_result['data']['order_pay_status'] = $order_product['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单过期支付时间
|
||
$diff_time = (strtotime($order_product['created_at']) - time()) / 60;
|
||
if ($diff_time >= 30) {
|
||
$return_result['message'] = "订单已过期";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_product_id'] = $order_product['order_product_id'];
|
||
$return_result['data']['order_product_status'] = $order_product['order_product_status'];
|
||
$return_result['data']['order_pay_status'] = $order_product['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
$result['order_id'] = $order_product['order_product_id'];
|
||
$result['created_at'] = $order_product['created_at'];
|
||
|
||
// 获取订单金额
|
||
$result['amount_total'] = $order_product['amount_total']; // 订单金额
|
||
$result['payment_amount_total'] = $order_product['payment_amount_total']; // 实际订单金额
|
||
$result['coupon_amount_total'] = $order_product['coupon_amount_total']; // 优惠金额
|
||
|
||
// 获取优惠卷不可用原因。存在优惠卷,但是未使用-暂时废弃
|
||
/*if ($order_product['coupon_amount_total'] == 0){
|
||
// 优惠卷商品数据
|
||
$coupon_product_datas = array();
|
||
|
||
// 获取药品订单关联处方商品数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_product['order_prescription_id'];
|
||
$order_prescription_products = OrderPrescriptionProduct::getList($params);
|
||
if (empty($order_prescription_products)) {
|
||
$return_result['message'] = "优惠卷数据错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_product_id'] = $order_product['order_product_id'];
|
||
$return_result['data']['order_product_status'] = $order_product['order_product_status'];
|
||
$return_result['data']['order_pay_status'] = $order_product['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
foreach ($order_prescription_products as $order_prescription_product){
|
||
$params = array();
|
||
$params['product_id'] = $order_prescription_product['product_id'];
|
||
$product = Product::getWithAmountOne($params);
|
||
if (empty($product)) {
|
||
$return_result['message'] = "优惠卷数据错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_product_id'] = $order_product['order_product_id'];
|
||
$return_result['data']['order_product_status'] = $order_product['order_product_status'];
|
||
$return_result['data']['order_pay_status'] = $order_product['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 优惠卷商品数据
|
||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||
$coupon_product_data = $product->toArray();
|
||
$coupon_product_datas[] = $coupon_product_data;
|
||
}
|
||
|
||
// 获取患者购药可用的优惠卷
|
||
$userCouponService = new UserCouponService();
|
||
$user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $coupon_product_datas);
|
||
}*/
|
||
|
||
if ($order_product['payment_amount_total'] > 0) {
|
||
// 发起支付
|
||
$WechatPay = new WechatPay(1, 2);
|
||
|
||
// 获取预支付交易会话标识
|
||
$prepay = $WechatPay->getJsapiPrepayId($order_no, (int)round($order_product['payment_amount_total'] * 100), $user_info['open_id'], "问诊服务");
|
||
if (empty($prepay)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 获取小程序支付配置
|
||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||
}
|
||
}
|
||
|
||
// 检测订单
|
||
if ($order_type == 3) {
|
||
// 获取检测订单数据
|
||
$params = array();
|
||
$params['detection_no'] = $order_no;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if ($order_detection['detection_status'] != 1) {
|
||
$return_result['message'] = "订单状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_detection['order_detection_id'];
|
||
$return_result['data']['order_status'] = $order_detection['detection_status'];
|
||
$return_result['data']['order_pay_status'] = $order_detection['detection_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单支付状态
|
||
if ($order_detection['detection_pay_status'] != 1) {
|
||
$return_result['message'] = "订单支付状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_detection['order_detection_id'];
|
||
$return_result['data']['order_status'] = $order_detection['detection_status'];
|
||
$return_result['data']['order_pay_status'] = $order_detection['detection_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单过期支付时间
|
||
$diff_time = (strtotime($order_detection['created_at']) - time()) / 60;
|
||
if ($diff_time >= 30) {
|
||
$return_result['message'] = "订单已过期";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_detection['order_detection_id'];
|
||
$return_result['data']['order_status'] = $order_detection['detection_status'];
|
||
$return_result['data']['order_pay_status'] = $order_detection['detection_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
$result['order_id'] = $order_detection['order_detection_id'];
|
||
$result['created_at'] = $order_detection['created_at'];
|
||
|
||
// 获取订单金额
|
||
$result['amount_total'] = $order_detection['amount_total']; // 订单金额
|
||
$result['payment_amount_total'] = $order_detection['amount_total'] - 0; // 实际订单金额
|
||
$result['coupon_amount_total'] = 0; // 优惠金额
|
||
|
||
if ($order_detection['payment_amount_total'] > 0) {
|
||
// 发起支付
|
||
$WechatPay = new WechatPay(1, 3);
|
||
|
||
// 获取预支付交易会话标识
|
||
$prepay = $WechatPay->getJsapiPrepayId($order_no, (int)round($order_detection['payment_amount_total'] * 100), $user_info['open_id'], "检测服务");
|
||
if (empty($prepay)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 获取小程序支付配置
|
||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||
}
|
||
|
||
}
|
||
|
||
// 服务包订单
|
||
if ($order_type == 4 || $order_type == 5) {
|
||
// 获取检测订单数据
|
||
$params = array();
|
||
$params['order_service_no'] = $order_no;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if ($order_service_package['order_service_status'] != 1) {
|
||
$return_result['message'] = "订单状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_service_package['order_service_id'];
|
||
$return_result['data']['order_status'] = $order_service_package['order_service_status'];
|
||
$return_result['data']['order_pay_status'] = $order_service_package['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单支付状态
|
||
if ($order_service_package['pay_status'] != 1) {
|
||
$return_result['message'] = "订单支付状态错误";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_service_package['order_service_id'];
|
||
$return_result['data']['order_status'] = $order_service_package['order_service_status'];
|
||
$return_result['data']['order_pay_status'] = $order_service_package['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 验证订单过期支付时间
|
||
$diff_time = (strtotime($order_service_package['created_at']) - time()) / 60;
|
||
if ($diff_time >= 30) {
|
||
$return_result['message'] = "订单已过期";
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_no;
|
||
$return_result['data']['order_id'] = $order_service_package['order_service_id'];
|
||
$return_result['data']['order_status'] = $order_service_package['order_service_status'];
|
||
$return_result['data']['order_pay_status'] = $order_service_package['pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
$result['order_id'] = $order_service_package['order_service_id'];
|
||
$result['created_at'] = $order_service_package['created_at'];
|
||
$result['inquiry_type'] = 1;
|
||
|
||
if ($order_service_package['order_service_type'] == 1){
|
||
$inquiry_mode = 8;
|
||
}else{
|
||
$inquiry_mode = 9;
|
||
}
|
||
$result['inquiry_mode'] = $inquiry_mode;
|
||
|
||
// 获取订单金额
|
||
$result['amount_total'] = $order_service_package['amount_total']; // 订单金额
|
||
$result['payment_amount_total'] = $order_service_package['amount_total'] - 0; // 实际订单金额
|
||
$result['coupon_amount_total'] = 0; // 优惠金额
|
||
|
||
// 检测是否存在同类型未完成的问诊订单
|
||
$PatientOrderService = new PatientOrderService();
|
||
$order_inquiry_id = $PatientOrderService->getNotFinishedOrderInquiry(1, $inquiry_mode, $user_info['client_user_id']);
|
||
if (!empty($order_inquiry_id)) {
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
$return_result['message'] = "当前患者存在进行中的问诊订单";
|
||
$return_result['status'] = 3;
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_inquiry['inquiry_no'];
|
||
$return_result['data']['order_id'] = $order_inquiry['order_inquiry_id'];
|
||
$return_result['data']['order_status'] = $order_inquiry['inquiry_status'];
|
||
$return_result['data']['order_pay_status'] = $order_inquiry['inquiry_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
// 检测当前医生是否和患者存在未完成问诊订单
|
||
$InquiryService = new InquiryService();
|
||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($user_info['client_user_id'], $order_service_package['doctor_id']);
|
||
if (!empty($order_inquiry)) {
|
||
$return_result['message'] = "您和当前医生存在问诊中订单,无法够买服务包";
|
||
$return_result['status'] = 3;
|
||
$return_result['data'] = $result;
|
||
$return_result['data']['order_no'] = $order_inquiry['inquiry_no'];
|
||
$return_result['data']['order_id'] = $order_inquiry['order_inquiry_id'];
|
||
$return_result['data']['order_status'] = $order_inquiry['inquiry_status'];
|
||
$return_result['data']['order_pay_status'] = $order_inquiry['inquiry_pay_status'];
|
||
return success($return_result);
|
||
}
|
||
|
||
if ($order_service_package['payment_amount_total'] > 0) {
|
||
// 发起支付
|
||
$WechatPay = new WechatPay(1, 4);
|
||
|
||
// 获取预支付交易会话标识
|
||
$prepay = $WechatPay->getJsapiPrepayId($order_no, (int)round($order_service_package['payment_amount_total'] * 100), $user_info['open_id'], "检测服务");
|
||
if (empty($prepay)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 获取小程序支付配置
|
||
$pay_config = $WechatPay->getAppletsPayConfig($prepay['prepay_id']);
|
||
}
|
||
}
|
||
|
||
$result['pay_config'] = $pay_config ?? [];
|
||
|
||
$return_result['message'] = "成功";
|
||
$return_result['status'] = 1;
|
||
$return_result['data'] = $result;
|
||
return success($return_result);
|
||
}
|
||
|
||
/**
|
||
*模拟支付成功-金额为0时使用
|
||
* @return array
|
||
*/
|
||
public function addPatientOrderPay(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_type = $this->request->input('order_type');
|
||
$order_no = $this->request->input('order_no');
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
switch ($order_type) {
|
||
case 1: // 问诊订单
|
||
$params = array();
|
||
$params['inquiry_no'] = $order_no;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
// 获取病例数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||
if (empty($order_inquiry_case)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "患者病例错误");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if ($order_inquiry['inquiry_status'] != 1) {
|
||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "支付失败");
|
||
}
|
||
|
||
// 验证支付金额
|
||
if ($order_inquiry['payment_amount_total'] != 0) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "支付失败");
|
||
}
|
||
|
||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||
$escrow_trade_no = "GD" . $generator->generate(); // 第三方支付流水号
|
||
|
||
// 修改问诊订单支付状态
|
||
$data = array();
|
||
$data['inquiry_pay_channel'] = 3; // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||
$data['inquiry_pay_status'] = 2;
|
||
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3) {
|
||
// 专家-公益
|
||
$data['inquiry_status'] = 3;// 3:待接诊
|
||
} elseif ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4) {
|
||
// 快速-购药
|
||
$data['inquiry_status'] = 2;// 2:待分配
|
||
}
|
||
|
||
$data['escrow_trade_no'] = $escrow_trade_no;
|
||
$data['pay_time'] = date('Y-m-d H:i:s', time());// 支付时间
|
||
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
OrderInquiry::edit($params, $data);
|
||
|
||
// 修改订单表支付状态
|
||
$data = array();
|
||
$data['pay_status'] = 2;
|
||
$data['pay_time'] = date('Y-m-d H:i:s', time());// 支付时间
|
||
$data['escrow_trade_no'] = $escrow_trade_no;
|
||
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_inquiry['inquiry_no'];
|
||
Order::edit($params,$data);
|
||
|
||
// 加入分配医生队列-快速-购药
|
||
if ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4) {
|
||
$data = array();
|
||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
|
||
$message = new AssignDoctorDelayDirectProducer($data);
|
||
$message->setDelayMs(1000 * 5);
|
||
$producer = $this->container->get(Producer::class);
|
||
$res = $producer->produce($message);
|
||
if (!$res) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "分配医生失败");
|
||
}
|
||
}
|
||
|
||
// 发送首条im消息-专家-公益
|
||
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3) {
|
||
// 获取订单医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "医生数据错误");
|
||
}
|
||
|
||
// 发送im消息
|
||
$imService = new ImService();
|
||
|
||
// 等待医生接诊
|
||
$imService->waitDoctorInquiry($order_inquiry, $user_doctor['user_id'], $order_inquiry['user_id']);
|
||
|
||
// 发送站内、订阅失败发送短信消息-医生有新问诊
|
||
$MessagePush = new MessagePush($user_doctor['user_id'], $order_inquiry['inquiry_no']);
|
||
$MessagePush->doctorHaveNewInquiry();
|
||
|
||
// 加入xx时间未接诊通知队列
|
||
$data = array();
|
||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
|
||
$time = 1000 * 60 * 60 * 2;
|
||
$message = new DoctorNotYetInquiryDelayDirectProducer($data);
|
||
$message->setDelayMs($time);
|
||
$producer = $this->container->get(Producer::class);
|
||
$producer->produce($message);
|
||
}
|
||
|
||
break;
|
||
case 2: // 药品订单
|
||
$params = array();
|
||
$params['order_product_no'] = $order_no;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if ($order_product['order_product_status'] != 1) {
|
||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "支付失败");
|
||
}
|
||
|
||
// 验证支付金额
|
||
if ($order_product['payment_amount_total'] != 0) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "支付失败");
|
||
}
|
||
|
||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||
$escrow_trade_no = "GD" . $generator->generate(); // 第三方支付流水号
|
||
|
||
// 修改药品订单支付状态
|
||
$data = array();
|
||
$data['order_product_status'] = 2;
|
||
$data['pay_status'] = 2;
|
||
$data['pay_channel'] = 3; // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||
$data['escrow_trade_no'] = $escrow_trade_no;
|
||
$data['pay_time'] = date('Y-m-d H:i:s', time());// 支付时间
|
||
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
||
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product['order_product_id'];
|
||
OrderProduct::edit($params, $data);
|
||
|
||
// 修改订单表支付状态
|
||
$data = array();
|
||
$data['pay_status'] = 2;
|
||
$data['pay_time'] = date('Y-m-d H:i:s', time());// 支付时间
|
||
$data['escrow_trade_no'] = $escrow_trade_no;
|
||
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_product['order_product_no'];
|
||
Order::edit($params,$data);
|
||
|
||
try {
|
||
if ($order_product['coupon_amount_total'] > 0){
|
||
// 获取药品订单优惠卷数据
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product['order_product_id'];
|
||
$order_product_coupons = OrderProductCoupon::getList($params);
|
||
if (!empty($order_product_coupons)){
|
||
foreach ($order_product_coupons as $order_product_coupon){
|
||
// 获取用户优惠卷数据
|
||
$params = array();
|
||
$params['user_coupon_id'] = $order_product_coupon['user_coupon_id'];
|
||
$user_coupon = UserCoupon::getOne($params);
|
||
if (!empty($user_coupon)){
|
||
// 获取优惠卷数据
|
||
$params = array();
|
||
$params['coupon_id'] = $user_coupon['coupon_id'];
|
||
$coupon = Coupon::getOne($params);
|
||
if (!empty($coupon)){
|
||
if ($coupon['reissue_interval_days'] > 0){
|
||
$data = array();
|
||
$data['coupon_id'] = $coupon['coupon_id'];
|
||
$data['user_id'] = $user_coupon['user_id'];
|
||
|
||
$time = $coupon['reissue_interval_days'] * 24 * 60 * 60 * 1000;
|
||
$message = new GrantUserCouponDelayDirectProducer($data);
|
||
$message->setDelayMs($time);
|
||
$producer = $this->container->get(Producer::class);
|
||
$res = $producer->produce($message);
|
||
if (!$res) {
|
||
Log::getInstance("PatientOrderService-addPatientOrderPay")->error("再次发放优惠卷失败");
|
||
}
|
||
|
||
Log::getInstance("PatientOrderService-addPatientOrderPay")->info("再次发放优惠卷成功");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}catch (\Throwable $e){
|
||
// 此处异常不做处理
|
||
Log::getInstance("PatientOrderService-addPatientOrderPay")->error($e->getMessage());
|
||
}
|
||
|
||
break;
|
||
case 3: // 检测订单
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单类型");
|
||
case 4: // 健康包订单
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单类型");
|
||
|
||
case 5: // 随访包订单
|
||
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单类型");
|
||
default:
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "支付失败");
|
||
}
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 创建药品订单
|
||
* @return array
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
public function addPatientProductOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_prescription_id = $this->request->input('order_prescription_id');
|
||
$address_id = $this->request->input('address_id');
|
||
$product_ids = $this->request->input('product_ids');
|
||
$client_type = $this->request->input('client_type');
|
||
|
||
// 获取处方数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription_id;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['is_delete'] = 0;
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
if (empty($order_prescription)) {
|
||
return fail();
|
||
}
|
||
|
||
// 验证处方状态
|
||
if ($order_prescription['prescription_status'] == 1) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||
}
|
||
if ($order_prescription['prescription_status'] == 4) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方已失效");
|
||
}
|
||
if ($order_prescription['prescription_status'] == 5) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方已使用");
|
||
}
|
||
|
||
if ($order_prescription['pharmacist_audit_status'] != 1) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||
}
|
||
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)){
|
||
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||
}
|
||
|
||
// 检测收货地址
|
||
$params = array();
|
||
$params['user_id'] = $user_info['user_id'];
|
||
$params['address_id'] = $address_id;
|
||
$user_ship_address = UserShipAddress::getOne($params);
|
||
if (empty($user_ship_address)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "收货地址错误");
|
||
}
|
||
|
||
$not_enough_product_ids = [];
|
||
$amount_total = 0;
|
||
|
||
// 商品数据
|
||
$product_datas = array();
|
||
|
||
foreach ($product_ids as $product_id) {
|
||
// 检测药品是否存在于处方中
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
$params['product_id'] = $product_id;
|
||
$order_prescription_product = OrderPrescriptionProduct::getOne($params);
|
||
if (empty($order_prescription_product)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "创建订单失败");
|
||
}
|
||
|
||
$params = array();
|
||
$params['product_id'] = $product_id;
|
||
$product = Product::getWithAmountOne($params);
|
||
if (empty($product)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||
}
|
||
|
||
// 检测商品状态
|
||
// 检测商品库存
|
||
if (!empty($product['ProductPlatformAmount'])) {
|
||
if ($order_prescription_product['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) {
|
||
// 库存不足
|
||
$not_enough_product_ids[] = $product_id;
|
||
}
|
||
}
|
||
|
||
// 获取订单金额
|
||
$amount_total = bcadd($amount_total, ($product['product_price'] * $order_prescription_product['prescription_product_num']), 2);
|
||
|
||
// 商品数据
|
||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||
$product_data = $product->toArray();
|
||
$product_datas[] = $product_data;
|
||
}
|
||
|
||
// 库存不足返回错误
|
||
if (!empty($not_enough_product_ids)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "存在库存不足商品", $not_enough_product_ids);
|
||
}
|
||
|
||
if (empty($product_datas)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取患者家庭成员进行中的服务包订单-健康包
|
||
$OrderServicePackageService = new OrderServicePackageService();
|
||
$order_service_package = $OrderServicePackageService->getPatientFamilyInProgressServicePackage($order_inquiry['user_id'],$order_inquiry['family_id'],$order_inquiry['doctor_id'],1);
|
||
if (!empty($order_service_package)){
|
||
// 处理健康包赠送商品-金额、数量
|
||
// 获取服务包订单详情
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||
if (empty($order_service_package_detail)){
|
||
return fail();
|
||
}
|
||
|
||
// 此处不检测未支付的商品订单,在创建订单时会进行数量的扣减
|
||
// 处理商品数量
|
||
$OrderServicePackageService = new OrderServicePackageService();
|
||
|
||
$amount_total = 0;
|
||
foreach ($product_datas as &$product_data){
|
||
// 获取服务包内某一药品的总数量
|
||
$total_quantity = $OrderServicePackageService->getOrderServiceProductTotalQuantity($order_service_package_detail['package_id'],$product_data['product_id']);
|
||
|
||
// 获取服务包内某一药品的剩余数量
|
||
$remaining_quantity = $OrderServicePackageService->getOrderServiceProductCanUseQuantity($order_service_package['order_service_id'],$product_data['product_id'],$total_quantity);
|
||
|
||
// 可用数量大于处方商品数量
|
||
if ($remaining_quantity >= $product_data['product_num']){
|
||
// 把商品价格置为0。金额按照0计算
|
||
$product_data['product_price'] = 0;
|
||
|
||
// 已使用数量 = 原数量+此次使用数量
|
||
$product_data['used_quantity'] = $product_data['product_num'];
|
||
}else{
|
||
// 已使用数量 = 最大可用数量;表示此服务包商品已使用完毕
|
||
$product_data['used_quantity'] = $remaining_quantity;
|
||
}
|
||
|
||
// 此处重新计算药品总金额
|
||
$amount_total = bcadd(
|
||
$amount_total,
|
||
bcmul(
|
||
$product_data['product_price'],
|
||
$product_data['product_num'],
|
||
2
|
||
),
|
||
2
|
||
);
|
||
}
|
||
}
|
||
|
||
// 获取患者购药可用的优惠卷
|
||
$userCouponService = new UserCouponService();
|
||
$user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $product_datas);
|
||
|
||
// 获取可用优惠卷总金额
|
||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
|
||
|
||
// 处理运费数据
|
||
$app_env = config('app_env', 'prod');
|
||
if ($app_env != "dev") {
|
||
// 获取运费金额
|
||
$Prescription = new Prescription();
|
||
|
||
$result = $Prescription->getLogisticsFee();
|
||
if ($amount_total >= $result['drugCost']) {
|
||
$logistics_fee = 0;
|
||
} else {
|
||
$logistics_fee = $result['freight'];
|
||
}
|
||
} else {
|
||
$logistics_fee = 0;
|
||
}
|
||
|
||
// 实际支付金额=商品总金额-优惠卷金额+运费金额
|
||
$payment_amount_total = bcadd(
|
||
bcsub(
|
||
$amount_total ,
|
||
$coupon_amount_total,
|
||
2
|
||
),
|
||
$logistics_fee,
|
||
2
|
||
);
|
||
if ($app_env == "dev") {
|
||
if ($payment_amount_total > 0){
|
||
$payment_amount_total = 0.01;
|
||
}
|
||
}
|
||
|
||
if ($payment_amount_total < 0){
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 确定支付渠道
|
||
// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||
if ($client_type == 1) {
|
||
$pay_channel = 1;
|
||
} elseif ($client_type == 2) {
|
||
$pay_channel = 2;
|
||
}else{
|
||
return fail(HttpEnumCode::HTTP_ERROR, "支付方式错误");
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
|
||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||
|
||
try {
|
||
// 生成订单表
|
||
$data = array();
|
||
$data['user_id'] = $user_info['user_id'];
|
||
$data['patient_id'] = $order_prescription['patient_id'];
|
||
$data['doctor_id'] = $order_prescription['doctor_id'];
|
||
$data['order_type'] = 2; // 订单类型(1:问诊订单 2:药品订单 3:检测订单 4:随访包订单 5:健康包订单)
|
||
$data['inquiry_pay_channel'] = $pay_channel;// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||
$data['pay_status'] = 1;// 1:待支付
|
||
$data['order_no'] = "P" . $generator->generate();// 订单编号
|
||
$data['amount_total'] = $amount_total;// 订单金额
|
||
$data['coupon_amount_total'] = $coupon_amount_total;// 优惠卷总金额
|
||
$data['payment_amount_total'] = $payment_amount_total;// 实际付款金额
|
||
$order = Order::addOrder($data);
|
||
if (empty($order)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||
}
|
||
|
||
// 新增药品订单
|
||
$data = array();
|
||
$data['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$data['order_id'] = $order['order_id'];
|
||
$data['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
$data['doctor_id'] = $order_prescription['doctor_id'];
|
||
$data['patient_id'] = $order_prescription['patient_id'];
|
||
$data['family_id'] = $order_prescription['family_id'];
|
||
$data['order_product_no'] = $order['order_no'];
|
||
$data['order_product_status'] = 1; // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||
$data['pay_channel'] = $pay_channel; // 支付渠道(1:小程序支付 2:微信扫码支付)
|
||
$data['amount_total'] = $amount_total; // 订单金额
|
||
$data['coupon_amount_total'] = $coupon_amount_total; // 优惠卷总金额
|
||
$data['payment_amount_total'] = $payment_amount_total; // 实际付款金额
|
||
$data['logistics_fee'] = $logistics_fee; // 运费金额
|
||
$data['province_id'] = $user_ship_address['province_id'];
|
||
$data['province'] = $user_ship_address['province'];
|
||
$data['city_id'] = $user_ship_address['city_id'];
|
||
$data['city'] = $user_ship_address['city'];
|
||
$data['county_id'] = $user_ship_address['county_id'];
|
||
$data['county'] = $user_ship_address['county'];
|
||
$data['address'] = $user_ship_address['address'];
|
||
$data['address_mask'] = $user_ship_address['address_mask'];
|
||
$data['consignee_name'] = $user_ship_address['consignee_name'];
|
||
$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'];
|
||
$order_product = OrderProduct::addOrderProduct($data);
|
||
if (empty($order_product)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 新增药品订单详情
|
||
foreach ($product_datas as $product_data) {
|
||
$params = array();
|
||
$params['product_platform_code'] = $product_data['product_platform_code'];
|
||
$product_platform_amount = ProductPlatformAmount::getSharedLockOne($params);
|
||
if (empty($product_platform_amount)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "无商品库存数据");
|
||
}
|
||
|
||
$data = array();
|
||
$data['order_product_id'] = $order_product['order_product_id'];
|
||
$data['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$data['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
$data['product_id'] = $product_data['product_id'];
|
||
$data['product_name'] = $product_data['product_name'];
|
||
$data['product_price'] = bcmul($product_data['product_price'],$product_data['product_num'],3);
|
||
$data['product_platform_code'] = $product_data['product_platform_code'];
|
||
$data['amount'] = $product_data['product_num'];
|
||
$data['manufacturer'] = $product_data['manufacturer'];
|
||
$data['product_cover_img'] = $product_data['product_cover_img'];
|
||
$data['product_spec'] = $product_data['product_spec'];
|
||
$order_product_item = OrderProductItem::addOrderProductItem($data);
|
||
if (empty($order_product_item)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 处方药品表标记为已使用
|
||
$data = array();
|
||
$data['use_status'] = 1;
|
||
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
$params['product_id'] = $product_data['product_id'];
|
||
OrderPrescriptionProduct::edit($params, $data);
|
||
|
||
// 锁定库存
|
||
// 库存-1
|
||
$params = array();
|
||
$params['amount_id'] = $product_platform_amount['amount_id'];
|
||
ProductPlatformAmount::dec($params, 'stock', $product_data['product_num']);
|
||
|
||
// 处理健康包数据,增加使用数量
|
||
if (!empty($order_service_package) && !empty($order_service_package_detail)){
|
||
// 获取服务包内所有药品
|
||
$health_package_products = $OrderServicePackageService->getOrderServiceProduct($order_service_package_detail['package_id']);
|
||
foreach ($health_package_products as $health_package_product) {
|
||
if ($health_package_product['product_id'] == $product_data['product_id']){
|
||
$data = array();
|
||
$data['order_service_id'] = $order_service_package['order_service_id'];
|
||
$data['order_product_id'] = $order_product['order_product_id'];
|
||
$data['order_product_no'] = $order_product['order_product_no'];
|
||
$data['product_item_id'] = $order_product_item['product_item_id'];
|
||
$data['product_id'] = $product_data['product_id'];
|
||
$data['used_quantity'] = $product_data['used_quantity'];
|
||
|
||
OrderServicePackageProduct::addOrderServicePackageProduct($data);
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 修改处方为已使用
|
||
$data = array();
|
||
$data['prescription_status'] = 4;
|
||
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
OrderPrescription::edit($params, $data);
|
||
|
||
// 处理优惠卷数据
|
||
if (!empty($user_coupons)) {
|
||
foreach ($user_coupons as $user_coupon){
|
||
// 增加订单优惠卷表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];// 订单id
|
||
$data['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||
$data['coupon_name'] = $user_coupon['coupon_name'];
|
||
$data['coupon_use_price'] = $user_coupon['coupon_price'];
|
||
$order_coupon = OrderCoupon::addOrderCoupon($data);
|
||
if (empty($order_coupon)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||
}
|
||
|
||
// 增加问诊优惠卷表
|
||
$data = array();
|
||
$data['order_product_id'] = $order_product['order_product_id'];// 订单-商品id
|
||
$data['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||
$data['coupon_name'] = $user_coupon['coupon_name'];
|
||
$data['coupon_use_price'] = $user_coupon['coupon_price'];
|
||
$order_product_coupon = OrderProductCoupon::addOrderProductCoupon($data);
|
||
if (empty($order_product_coupon)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||
}
|
||
|
||
// 修改优惠卷使用状态
|
||
$data = array();
|
||
$data['user_coupon_status'] = 1;
|
||
$data['coupon_use_date'] = date('Y-m-d H:i:s', time());
|
||
|
||
$params = array();
|
||
$params['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||
UserCoupon::edit($params, $data);
|
||
}
|
||
}
|
||
|
||
// 增加至未支付取消订单延迟队列
|
||
$time = 60 * 30;
|
||
if (\Hyperf\Config\config('app_env') == "dev"){
|
||
$time = 60 * 5;
|
||
}
|
||
|
||
$data = array();
|
||
$data['order_no'] = (string)$order_product['order_product_no'];
|
||
$data['order_type'] = 2;
|
||
|
||
$message = new CancelUnpayOrdersDelayDirectProducer($data);
|
||
$message->setDelayMs(1000 * $time);
|
||
$producer = $this->container->get(Producer::class);
|
||
$res = $producer->produce($message);
|
||
if (!$res) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
||
}
|
||
|
||
$result = array();
|
||
$result['inquiry_no'] = (string)$order_product['order_product_no']; // 订单编号
|
||
$result['order_product_id'] = (string)$order_product['order_product_id']; // 订单主键id
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 获取药品订单物流数据
|
||
* @return array
|
||
*/
|
||
public function getPatientProductOrderLogistics(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_product_id = $this->request->route('order_product_id');
|
||
|
||
// 获取药品订单数据
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product_id;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)) {
|
||
return fail();
|
||
}
|
||
|
||
// 地址数据
|
||
$address = array();
|
||
$address['province_id'] = $order_product['province_id'];
|
||
$address['province'] = $order_product['province'];
|
||
$address['city_id'] = $order_product['city_id'];
|
||
$address['city'] = $order_product['city'];
|
||
$address['county_id'] = $order_product['county_id'];
|
||
$address['county'] = $order_product['county'];
|
||
$address['address'] = $order_product['address'];
|
||
$address['address_mask'] = $order_product['address_mask'];
|
||
$address['consignee_name'] = $order_product['consignee_name'];
|
||
$address['consignee_name_mask'] = $order_product['consignee_name_mask'];
|
||
$address['consignee_tel'] = $order_product['consignee_tel'];
|
||
$address['consignee_tel_mask'] = $order_product['consignee_tel_mask'];
|
||
|
||
$result = array();
|
||
$result['logistics'] = null;
|
||
$result['address'] = $address;
|
||
|
||
// 获取物流数据
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product_id;
|
||
$order_product_logistics = OrderProductLogistic::getOne($params);
|
||
if (empty($order_product_logistics)) {
|
||
if (!empty($order_product['logistics_no']) && !empty($order_product['logistics_company_code'])) {
|
||
// 获取快递公司名称
|
||
$params = array();
|
||
$params['company_code'] = $order_product['logistics_company_code'];
|
||
$params['company_type'] = 1;
|
||
$basic_logistics_company = BasicLogisticsCompany::getOne($params);
|
||
if (!empty($basic_logistics_company)) {
|
||
$logistics = array();
|
||
$logistics['order_product_id'] = $order_product_id;
|
||
$logistics['company_name'] = $basic_logistics_company['company_name'];
|
||
$logistics['company_code'] = $order_product['logistics_company_code'];
|
||
$logistics['logistics_no'] = $order_product['logistics_no'];
|
||
$result['logistics'] = $logistics;
|
||
}
|
||
}
|
||
} else {
|
||
$order_product_logistics = $order_product_logistics->toArray();
|
||
|
||
$order_product_logistics['logistics_content'] = json_decode($order_product_logistics['logistics_content'], true);
|
||
$result['logistics'] = $order_product_logistics;
|
||
}
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 获取处方订单列表
|
||
* @return array
|
||
*/
|
||
public function getPatientPrescriptionOrderList(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
// 获取处方数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['pharmacist_audit_status'] = 1;
|
||
$params['platform_audit_status'] = 1;
|
||
$params['is_delete'] = 0;
|
||
$order_prescription = OrderPrescription::getWithPage($params, ['*'], $page, $per_page);
|
||
if (!empty($order_prescription['data'])) {
|
||
foreach ($order_prescription['data'] as &$item) {
|
||
if (!empty($item['UserDoctor'])) {
|
||
$item['UserDoctor']['doctor_title'] = DoctorTitleCode::getMessage($item['UserDoctor']['doctor_title']);
|
||
}
|
||
}
|
||
}
|
||
|
||
return success($order_prescription);
|
||
}
|
||
|
||
/**
|
||
* 获取处方订单详情
|
||
* @return array
|
||
*/
|
||
public function getPatientPrescriptionOrderInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_prescription_id = $this->request->route('order_prescription_id');
|
||
|
||
// 获取处方数据
|
||
$fields = [
|
||
'order_prescription_id',
|
||
'prescription_status',
|
||
'pharmacist_id',
|
||
'doctor_id',
|
||
];
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription_id;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['pharmacist_audit_status'] = 1;
|
||
$params['platform_audit_status'] = 1;
|
||
$params['is_delete'] = 0;
|
||
$order_prescription = OrderPrescription::getOne($params, $fields);
|
||
if (empty($order_prescription)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取处方文件数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription_id;
|
||
$order_prescription_file = OrderPrescriptionFile::getOne($params);
|
||
if (empty($order_prescription_file)) {
|
||
return fail();
|
||
}
|
||
|
||
$order_prescription['prescription_img_oss_path'] = addAliyunOssWebsite($order_prescription_file['prescription_img_oss_path']);
|
||
|
||
// 获取处方中医生签名
|
||
$params = array();
|
||
$params['doctor_id'] = $order_prescription['doctor_id'];
|
||
$user_doctor_info = UserDoctorInfo::getOne($params);
|
||
if (empty($user_doctor_info)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
$order_prescription['doctor_sign_image'] = addAliyunOssWebsite($user_doctor_info['sign_image']);
|
||
|
||
// 获取处方中药师签名
|
||
$params = array();
|
||
$params['pharmacist_id'] = $order_prescription['pharmacist_id'];
|
||
$user_pharmacist_info = UserPharmacistInfo::getOne($params);
|
||
if (empty($user_pharmacist_info)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
$order_prescription['pharmacist_sign_image'] = addAliyunOssWebsite($user_pharmacist_info['sign_image']);
|
||
|
||
// 获取处方医院签名
|
||
$order_prescription['hospital_sign_image'] = "https://img.applets.igandanyiyuan.com/basic/file/hospital_signature.png";
|
||
|
||
return success($order_prescription->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取处方订单支付页详情
|
||
* @return array
|
||
*/
|
||
public function getPatientPrescriptionOrderPayInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_prescription_id = $this->request->route('order_prescription_id');
|
||
|
||
$fields = [
|
||
"order_prescription_id",
|
||
"order_inquiry_id"
|
||
];
|
||
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription_id;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['is_delete'] = 0;
|
||
$order_prescription = OrderPrescription::getOne($params, $fields);
|
||
if (empty($order_prescription)) {
|
||
return fail();
|
||
}
|
||
|
||
// 验证处方状态
|
||
if ($order_prescription['prescription_status'] == 1) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方未审核");
|
||
}
|
||
|
||
if ($order_prescription['prescription_status'] == 3) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方已失效");
|
||
}
|
||
|
||
if ($order_prescription['prescription_status'] == 4) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方已使用");
|
||
}
|
||
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)){
|
||
return fail();
|
||
}
|
||
|
||
// 获取处方药品信息
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
$order_prescription_products = OrderPrescriptionProduct::getList($params);
|
||
if (empty($order_prescription_products)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 处理药品数据
|
||
$amount_total = 0; // 总金额
|
||
$product_datas = array(); // 商品数据
|
||
|
||
foreach ($order_prescription_products as &$order_prescription_product) {
|
||
$params = array();
|
||
$params['product_id'] = $order_prescription_product['product_id'];
|
||
$product = Product::getWithAmountOne($params);
|
||
if (empty($product)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方存在未知药品");
|
||
}
|
||
|
||
$order_prescription_product['status'] = 1; // 正常
|
||
|
||
// 检测商品库存
|
||
if (!empty($product['ProductPlatformAmount'])) {
|
||
if ($order_prescription_product['prescription_product_num'] > $product['ProductPlatformAmount']['stock']) {
|
||
// 库存不足
|
||
$order_prescription_product['status'] = 2;
|
||
}
|
||
}
|
||
|
||
$amount_total = bcadd($amount_total,($product['product_price'] * $order_prescription_product['prescription_product_num']),2);
|
||
|
||
// 处方药品数据
|
||
$product['product_num'] = $order_prescription_product['prescription_product_num'];
|
||
$product_data = $product->toArray();
|
||
$product_datas[] = $product_data;
|
||
}
|
||
|
||
if (empty($product_datas)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取患者家庭成员进行中的服务包订单
|
||
$OrderServicePackageService = new OrderServicePackageService();
|
||
$order_service_package = $OrderServicePackageService->getPatientFamilyInProgressServicePackage($order_inquiry['user_id'],$order_inquiry['family_id'],$order_inquiry['doctor_id'],1);
|
||
if (!empty($order_service_package)){
|
||
// 处理健康包赠送商品
|
||
// 获取服务包订单详情
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||
if (empty($order_service_package_detail)){
|
||
return fail();
|
||
}
|
||
|
||
// 此处不检测未支付的商品订单,在创建订单时会进行数量的扣减
|
||
// 处理商品数量、金额
|
||
$amount_total = 0;
|
||
foreach ($product_datas as &$product_data){
|
||
// 获取服务包内某一药品的总数量
|
||
$total_quantity = $OrderServicePackageService->getOrderServiceProductTotalQuantity($order_service_package_detail['package_id'],$product_data['product_id']);
|
||
|
||
// 获取服务包内某一药品的剩余数量
|
||
$remaining_quantity = $OrderServicePackageService->getOrderServiceProductCanUseQuantity($order_service_package['order_service_id'],$product_data['product_id'],$total_quantity);
|
||
|
||
// 可用数量大于处方商品数量
|
||
if ($remaining_quantity >= $product_data['product_num']){
|
||
// 把商品价格置为0。金额按照0计算
|
||
$product_data['product_price'] = 0;
|
||
}
|
||
|
||
// 此处重新计算药品总金额
|
||
$amount_total = bcadd(
|
||
$amount_total,
|
||
bcmul(
|
||
$product_data['product_price'],
|
||
$product_data['product_num'],
|
||
2
|
||
),
|
||
2
|
||
);
|
||
}
|
||
}
|
||
|
||
// 获取患者购药可用的优惠卷
|
||
$userCouponService = new UserCouponService();
|
||
$user_coupons = $userCouponService->getUserProductUsableCoupon($user_info['user_id'], $product_datas);
|
||
|
||
// 获取可用优惠卷总金额
|
||
$coupon_amount_total = $userCouponService->getCouponTotalPrice($user_coupons);
|
||
|
||
// 获取运费金额
|
||
$logistics_fee = 0;
|
||
if (env("APP_ENV") == "prod") {
|
||
$Prescription = new Prescription();
|
||
$result = $Prescription->getLogisticsFee();
|
||
if ($amount_total < $result['drugCost']) {
|
||
$logistics_fee = $result['freight'];
|
||
}
|
||
}
|
||
|
||
// 实际支付金额=商品总金额-优惠卷金额+运费金额
|
||
$payment_amount_total = bcadd(bcsub($amount_total , $coupon_amount_total,2), $logistics_fee, 2);
|
||
|
||
// 获取收货地址
|
||
$params = array();
|
||
$params['user_id'] = $user_info['user_id'];
|
||
$user_ship_addresss = UserShipAddress::getList($params);
|
||
|
||
foreach ($user_ship_addresss as $item) {
|
||
if ($item['is_default'] == 1) {
|
||
$user_ship_address = $item;
|
||
}
|
||
}
|
||
|
||
// 无默认地址,选择第一个
|
||
if (empty($user_ship_address)) {
|
||
$user_ship_address = $user_ship_addresss[0] ?? NULL;
|
||
}
|
||
|
||
$result = array();
|
||
$result['amount_total'] = $amount_total;
|
||
$result['coupon_amount_total'] = $coupon_amount_total;
|
||
$result['payment_amount_total'] = $payment_amount_total;
|
||
$result['logistics_fee'] = $logistics_fee;
|
||
$result['user_ship_address'] = $user_ship_address;
|
||
$result['order_prescription_product'] = $order_prescription_products;
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 删除处方订单记录
|
||
* @return array
|
||
*/
|
||
public function deletePatientPrescriptionOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_prescription_id = $this->request->route('order_prescription_id');
|
||
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription_id;
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
if (empty($order_prescription)) {
|
||
return fail();
|
||
}
|
||
|
||
// 验证处方状态
|
||
if ($order_prescription['prescription_status'] == 1) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "处方无法删除");
|
||
}
|
||
|
||
if ($order_prescription['is_delete'] == 1) {
|
||
return success();
|
||
}
|
||
|
||
$data = array();
|
||
$data['is_delete'] = 1;
|
||
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription['order_prescription_id'];
|
||
OrderPrescription::edit($params, $data);
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 获取患者检测订单列表
|
||
* @return array
|
||
*/
|
||
public function getPatientDetectionOrderList(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$detection_status = $this->request->input('detection_status', 0);
|
||
$family_id = $this->request->input('family_id');
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
if (!empty($family_id)) {
|
||
$params['family_id'] = $family_id;
|
||
}
|
||
|
||
$detection_status_params = [];
|
||
if (!empty($detection_status) && $detection_status != 0) {
|
||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||
$detection_status_params = [$detection_status];
|
||
}
|
||
|
||
$params['is_delete'] = 0;
|
||
|
||
$fields = [
|
||
'order_detection_id',
|
||
'patient_id',
|
||
'doctor_id',
|
||
'family_id',
|
||
'detection_status',
|
||
'is_delete',
|
||
'detection_refund_status',
|
||
'detection_pay_channel',
|
||
'detection_pay_status',
|
||
'detection_no',
|
||
'escrow_trade_no',
|
||
'amount_total',
|
||
'payment_amount_total',
|
||
'patient_name',
|
||
'patient_name_mask',
|
||
'patient_sex',
|
||
'patient_age',
|
||
'created_at',
|
||
];
|
||
$order_detection = OrderDetection::getPatientOrderDetectionPage($params, $detection_status_params, $fields, $page, $per_page);
|
||
if (empty($order_detection['data'])) {
|
||
return success($order_detection);
|
||
}
|
||
|
||
foreach ($order_detection['data'] as &$item) {
|
||
// 获取医生数据
|
||
$item['user_doctor'] = [];
|
||
if (!empty($item['doctor_id'])) {
|
||
$fields = [
|
||
'doctor_id',
|
||
'user_name',
|
||
'doctor_title',
|
||
'hospital_id',
|
||
"avatar"
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $item['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 转换医生职称
|
||
$user_doctor['doctor_title'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 获取医生医院名称
|
||
$user_doctor['hospital_name'] = "";
|
||
$user_doctor['hospital_level_name'] = "";
|
||
|
||
// 医生头像
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
'hospital_level_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params, $fields);
|
||
if (!empty($hospital)) {
|
||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||
}
|
||
|
||
$item['user_doctor'] = $user_doctor;
|
||
unset($hospital);
|
||
unset($user_doctor);
|
||
}
|
||
}
|
||
|
||
return success($order_detection);
|
||
}
|
||
|
||
/**
|
||
* 获取患者检测订单详情
|
||
* @return array
|
||
*/
|
||
public function getPatientDetectionOrderInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['detection_no'] = $order_no;
|
||
$params['is_delete'] = 0;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)) {
|
||
return fail();
|
||
}
|
||
|
||
$order_detection = $order_detection->toArray();
|
||
|
||
// 获取医生数据
|
||
$order_detection['user_doctor'] = [];
|
||
if (!empty($order_detection['doctor_id'])) {
|
||
$fields = [
|
||
'user_id',
|
||
'doctor_id',
|
||
'user_name',
|
||
'doctor_title',
|
||
'hospital_id',
|
||
'avatar',
|
||
'department_custom_name',
|
||
'multi_point_status',
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $order_detection['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 转换医生职称
|
||
$user_doctor['doctor_title'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 头像
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
// 获取医生医院名称
|
||
$user_doctor['hospital_name'] = "";
|
||
$user_doctor['hospital_level_name'] = "";
|
||
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
'hospital_level_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params, $fields);
|
||
if (!empty($hospital)) {
|
||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||
}
|
||
|
||
// 获取医生关注状态
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$user_doctor['follow'] = PatientFollow::getExists($params);
|
||
|
||
// 获取医生问诊配置-问诊购药
|
||
$user_doctor['multi_point_enable'] = 0;
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$params['inquiry_type'] = 4;
|
||
$params['inquiry_mode'] = 1;
|
||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||
if (!empty($doctor_inquiry_config)) {
|
||
if ($doctor_inquiry_config['is_enable'] == 1) {
|
||
$user_doctor['multi_point_enable'] = 1;
|
||
}
|
||
}
|
||
|
||
$order_detection['user_doctor'] = $user_doctor;
|
||
|
||
unset($hospital);
|
||
unset($user_doctor);
|
||
}
|
||
|
||
// 检测管图片
|
||
if (!empty($order_detection['detection_pic'])) {
|
||
$detection_pic = explode(',', $order_detection['detection_pic']);
|
||
foreach ($detection_pic as &$value) {
|
||
$value = addAliyunOssWebsite($value);
|
||
}
|
||
$order_detection['detection_pic'] = $detection_pic;
|
||
}
|
||
|
||
// 获取项目名称
|
||
$params = array();
|
||
$params['detection_project_id'] = $order_detection['detection_project_id'];
|
||
$detection_project = DetectionProject::getOne($params);
|
||
if (empty($detection_project)) {
|
||
return fail();
|
||
}
|
||
|
||
$order_detection['detection_project_name'] = $detection_project['detection_project_name'];
|
||
$order_detection['detection_result_pdf'] = addAliyunOssWebsite($order_detection['detection_result_pdf']);
|
||
|
||
// 检测成功时间
|
||
$detection_success_time = date('Y-m-d', time() + 60 * 60 * $detection_project['detection_time']);
|
||
$order_detection['detection_success_time'] = $detection_success_time;
|
||
|
||
return success($order_detection);
|
||
}
|
||
|
||
/**
|
||
* 删除检测订单
|
||
* @return array
|
||
*/
|
||
public function deletePatientDetectionOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_detection_id = $this->request->route('order_detection_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_detection_id'] = $order_detection_id;
|
||
$params['is_delete'] = 0;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)) {
|
||
return fail();
|
||
}
|
||
|
||
// 检测订单状态
|
||
if (!in_array($order_detection['detection_status'], [5])) {
|
||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 修改检测订单删除状态
|
||
$data = array();
|
||
$data['is_delete'] = 1;
|
||
|
||
$params = array();
|
||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||
OrderDetection::editOrderDetection($params, $data);
|
||
|
||
$data = array();
|
||
$data['is_delete'] = 1;
|
||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_detection['detection_no'];
|
||
Order::edit($params, $data);
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR,$e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 取消检测订单
|
||
* @return array
|
||
* @throws ContainerExceptionInterface
|
||
* @throws NotFoundExceptionInterface
|
||
*/
|
||
public function putCancelPatientDetectionOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_detection_id = $this->request->route('order_detection_id');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_detection_id'] = $order_detection_id;
|
||
$params['is_delete'] = 0;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)) {
|
||
return fail();
|
||
}
|
||
|
||
$redis = $this->container->get(Redis::class);
|
||
$redis_key = "order_detection_lock_" . $order_detection_id;
|
||
$redis_lock = $redis->setnx($redis_key, 1);
|
||
// 设置过期时间
|
||
$redis->expire($redis_key, 3);
|
||
if (!$redis_lock) {
|
||
// 设置失败,表示已经设置该值
|
||
return fail(HttpEnumCode::HTTP_SUCCESS, "请您稍后重试");
|
||
}
|
||
|
||
// 检测订单状态
|
||
if (!in_array($order_detection['detection_status'], [2])) {
|
||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法取消");
|
||
}
|
||
|
||
if ($order_detection['detection_refund_status'] == 1) {
|
||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单申请退款中,请您稍后取消");
|
||
}
|
||
|
||
if ($order_detection['detection_refund_status'] == 2) {
|
||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款中,请您稍后取消");
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 退款成功
|
||
// 修改问诊订单为取消
|
||
$data = array();
|
||
$data['detection_status'] = 5;
|
||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||
$data['cancel_reason'] = 1; // 取消订单原因(1:主动取消 2:客服取消 3:支付超时)
|
||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||
|
||
$params = array();
|
||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||
OrderDetection::editOrderDetection($params, $data);
|
||
|
||
// 修改订单为取消
|
||
$data = array();
|
||
$data['cancel_status'] = 1;
|
||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||
$data['cancel_remarks'] = "主动取消"; // 取消订单备注
|
||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||
|
||
$params = array();
|
||
$params['order_no'] = $order_detection['detection_no'];
|
||
Order::edit($params, $data);
|
||
|
||
// 检测支付状态,判断是否需要退款处理
|
||
if ($order_detection['detection_pay_status'] == 2 && $order_detection['detection_refund_status'] != 3) {
|
||
// 需退款
|
||
$OrderService = new OrderService();
|
||
$OrderService->orderRefund($order_detection['detection_no'],"取消检测");
|
||
}
|
||
|
||
// 删除锁
|
||
$redis->del($redis_key);
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
try {
|
||
// 推送患者-订单取消成功通知
|
||
$MessagePush = new MessagePush($order_detection['user_id']);
|
||
$MessagePush->patientCancelDetectionOrderSuccess($order_detection['order_detection_id']);
|
||
} catch (\Exception $e) {
|
||
return success();
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 检测订单取消支付
|
||
* @return array
|
||
*/
|
||
public function putPatientDetectionOrderCancelPay(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_detection_id = $this->request->route('order_detection_id');
|
||
|
||
Db::beginTransaction();
|
||
|
||
try {
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_detection_id'] = $order_detection_id;
|
||
$params['is_delete'] = 0;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
// 检测订单取消
|
||
// 取消订单原因(1:主动取消 2:客服取消 3:支付超时)
|
||
$DetectionService = new DetectionService();
|
||
$result = $DetectionService->cancelUnpayDetectionOrder($order_detection['detection_no'], 1, "主动取消");
|
||
if ($result['status'] != 1) {
|
||
Db::rollBack();
|
||
return fail();
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 服务包订单取消支付-1未支付
|
||
* @return array
|
||
*/
|
||
public function putPatientServiceOrderCancelPay(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
Db::beginTransaction();
|
||
|
||
try {
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_service_no'] = $order_no;
|
||
$params['is_delete'] = 0;
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
$OrderService = new OrderService();
|
||
$result = $OrderService->cancelUnpayOrder($order_service_package['order_service_no'],2,"主动取消");
|
||
if ($result['status'] != 1) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $result['message']);
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 订单取消支付-1未支付
|
||
* @return array
|
||
*/
|
||
public function putPatientOrderCancelPay(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
Db::beginTransaction();
|
||
|
||
try {
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_no'] = $order_no;
|
||
$order = Order::getOne($params);
|
||
if (empty($order)){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
$OrderService = new OrderService();
|
||
$result = $OrderService->cancelUnpayOrder($order['order_no'],2,"主动取消");
|
||
if ($result['status'] != 1) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $result['message']);
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 取消订单-问诊/检测/服务包
|
||
* @return array
|
||
*/
|
||
public function putCancelPatientOrder(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
Db::beginTransaction();
|
||
|
||
try {
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_no;
|
||
$order = Order::getOne($params);
|
||
if (empty($order)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法订单");
|
||
}
|
||
|
||
$OrderService = new OrderService();
|
||
$result = $OrderService->PatientActiveCancelOrder($order_no);
|
||
if ($result['status'] != 1) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $result['message']);
|
||
}
|
||
|
||
Db::commit();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
// 推送消息
|
||
try {
|
||
// 处理对应订单
|
||
switch ($order['order_type']) {
|
||
case 1: // 问诊订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['inquiry_no'] = $order_no;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (!empty($order_inquiry)) {
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (!empty($user_doctor)) {
|
||
// 推送医生-患者取消问诊
|
||
$MessagePush = new MessagePush($user_doctor['user_id'], $order_inquiry['inquiry_no']);
|
||
$MessagePush->patientCancelInquiryToDoctor();
|
||
}
|
||
}
|
||
|
||
break;
|
||
case 3: // 检测订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['detection_no'] = $order_no;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (!empty($order_detection)) {
|
||
// 推送患者-订单取消成功通知
|
||
$MessagePush = new MessagePush($order_detection['user_id'],$order_detection['detection_no']);
|
||
$MessagePush->patientCancelDetectionOrderSuccess($order_detection['order_detection_id']);
|
||
}
|
||
|
||
break;
|
||
case 4: // 健康包订单
|
||
case 5: // 随访包订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_service_no'] = $order_no;
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
$result['status'] = 0;
|
||
$result['message'] = "订单数据为空";
|
||
return $result;
|
||
}
|
||
|
||
// 获取问诊订单数据-此处只会存在一个
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_inquiry = OrderServicePackageInquiry::getOne($params);
|
||
if (!empty($order_service_package_inquiry)){
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_service_package['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (!empty($user_doctor)) {
|
||
// 医生-患者取消服务包订单
|
||
$MessagePush = new MessagePush($user_doctor['user_id'], $order_service_package_inquiry['inquiry_no']);
|
||
$MessagePush->doctorPatientCancelServicePackage();
|
||
}
|
||
}
|
||
|
||
break;
|
||
default:
|
||
// 错误不处理
|
||
}
|
||
}catch (\Throwable $e){
|
||
// 错误不处理
|
||
Log::getInstance("PatientOrderService-putCancelPatientOrder")->error($e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
|
||
/**
|
||
* 获取患者服务包订单列表
|
||
* @return array
|
||
*/
|
||
public function getPatientServiceOrderList(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_service_status = $this->request->input('order_service_status', 0);
|
||
$family_id = $this->request->input('family_id');
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
if (!empty($family_id)) {
|
||
$params['family_id'] = $family_id;
|
||
}
|
||
|
||
$order_service_status_params = [];
|
||
if (!empty($order_service_status) && $order_service_status != 0) {
|
||
// 订单状态(0:全部 1:待支付、2:待接诊 3:服务中 4:完成/取消)
|
||
if ($order_service_status == 1) {
|
||
$order_service_status_params = [1];
|
||
}
|
||
|
||
if ($order_service_status == 2) {
|
||
$order_service_status_params = [3];
|
||
}
|
||
|
||
if ($order_service_status == 3) {
|
||
$order_service_status_params = [3];
|
||
}
|
||
|
||
if ($order_service_status == 4) {
|
||
$order_service_status_params = [4,5];
|
||
}
|
||
}
|
||
|
||
$params['is_delete'] = 0;
|
||
|
||
$fields = [
|
||
'order_service_id',
|
||
'order_id',
|
||
'patient_id',
|
||
'doctor_id',
|
||
'family_id',
|
||
'order_service_type',
|
||
'order_service_status',
|
||
'is_delete',
|
||
'refund_status',
|
||
'pay_channel',
|
||
'pay_status',
|
||
'order_service_no',
|
||
'escrow_trade_no',
|
||
'amount_total',
|
||
'payment_amount_total',
|
||
'start_time',
|
||
'finish_time',
|
||
'patient_name',
|
||
'patient_name_mask',
|
||
'patient_sex',
|
||
'patient_age',
|
||
'created_at',
|
||
];
|
||
$order_service_package = OrderServicePackage::getPatientOrderServicePage($params, $order_service_status_params, $fields, $page, $per_page);
|
||
if (empty($order_service_package['data'])) {
|
||
return success($order_service_package);
|
||
}
|
||
|
||
foreach ($order_service_package['data'] as &$item) {
|
||
$item['disease_desc'] = $item['OrderServicePackageCase']['disease_desc'];
|
||
unset($item['OrderServicePackageCase']);
|
||
|
||
// 获取医生数据
|
||
$item['user_doctor'] = [];
|
||
if (!empty($item['doctor_id'])) {
|
||
$fields = [
|
||
'doctor_id',
|
||
'user_name',
|
||
'doctor_title',
|
||
'hospital_id',
|
||
"avatar"
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $item['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 转换医生职称
|
||
$user_doctor['doctor_title'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 获取医生医院名称
|
||
$user_doctor['hospital_name'] = "";
|
||
$user_doctor['hospital_level_name'] = "";
|
||
|
||
// 医生头像
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
'hospital_level_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params, $fields);
|
||
if (!empty($hospital)) {
|
||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||
}
|
||
|
||
$item['user_doctor'] = $user_doctor;
|
||
unset($hospital);
|
||
unset($user_doctor);
|
||
}
|
||
}
|
||
|
||
return success($order_service_package);
|
||
}
|
||
|
||
/**
|
||
* 获取患者服务包订单详情
|
||
* @return array
|
||
*/
|
||
public function getPatientServiceOrderInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_service_no'] = $order_no;
|
||
$params['is_delete'] = 0;
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
return fail();
|
||
}
|
||
|
||
// 获取病例信息
|
||
$fields = [
|
||
'disease_class_name',
|
||
'disease_desc',
|
||
];
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_case = OrderServicePackageCase::getOne($params, $fields);
|
||
if (empty($order_service_package_case)) {
|
||
$order_service_package['case'] = [];
|
||
} else {
|
||
$order_service_package['case'] = $order_service_package_case->toArray();
|
||
}
|
||
|
||
// 获取医生数据
|
||
$order_service_package['user_doctor'] = [];
|
||
if (!empty($order_service_package['doctor_id'])) {
|
||
$fields = [
|
||
'user_id',
|
||
'doctor_id',
|
||
'user_name',
|
||
'doctor_title',
|
||
'hospital_id',
|
||
'avatar',
|
||
'department_custom_name',
|
||
'multi_point_status',
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $order_service_package['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
// 转换医生职称
|
||
$user_doctor['doctor_title'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 头像
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
// 获取医生医院名称
|
||
$user_doctor['hospital_name'] = "";
|
||
$user_doctor['hospital_level_name'] = "";
|
||
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
'hospital_level_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params, $fields);
|
||
if (!empty($hospital)) {
|
||
$user_doctor['hospital_name'] = $hospital['hospital_name'];
|
||
$user_doctor['hospital_level_name'] = $hospital['hospital_level_name'];
|
||
}
|
||
|
||
// 获取医生关注状态
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$user_doctor['follow'] = PatientFollow::getExists($params);
|
||
|
||
// 处理医生是否可处方
|
||
$user_doctor['multi_point_enable'] = 0;
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$params['inquiry_type'] = 4;
|
||
$params['inquiry_mode'] = 1;
|
||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||
if (!empty($doctor_inquiry_config)) {
|
||
if ($doctor_inquiry_config['is_enable'] == 1) {
|
||
$user_doctor['multi_point_enable'] = 1;
|
||
}
|
||
}
|
||
|
||
$order_service_package['user_doctor'] = $user_doctor;
|
||
|
||
unset($hospital);
|
||
unset($user_doctor);
|
||
}
|
||
|
||
// 获取退款数据
|
||
$order_service_package['order_service_package_refund'] = array();
|
||
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_refund = OrderServicePackageRefund::getList($params);
|
||
if (!empty($order_service_package_refund)){
|
||
$order_service_package['order_service_package_refund'] = $order_service_package_refund;
|
||
}
|
||
|
||
$order_service_package['discount_product_total_amount'] = 0;
|
||
|
||
if ($order_service_package['order_service_type'] == 1){
|
||
// 获取健康包配置
|
||
$params = array();
|
||
$health_package = HealthPackage::getOne($params);
|
||
if (empty($health_package)){
|
||
return fail();
|
||
}
|
||
|
||
$order_service_package['discount_product_total_amount'] = $health_package['discount_product_total_amount'];
|
||
}
|
||
|
||
// 获取退款金额
|
||
$order_service_package['refund_total'] = 0;
|
||
|
||
$params = array();
|
||
$params['order_id'] = $order_service_package['order_id'];
|
||
$order_refund = OrderRefund::getOne($params);
|
||
if (!empty($order_refund)){
|
||
$order_service_package['refund_total'] = $order_refund['refund_total'];
|
||
}
|
||
|
||
// 获取退款数据
|
||
$order_service_package['order_refund'] = array();
|
||
|
||
$params = array();
|
||
$params['order_id'] = $order_service_package['order_id'];
|
||
$order_refund = OrderRefund::getList($params);
|
||
if (!empty($order_refund)){
|
||
$order_service_package['order_refund'] = $order_refund;
|
||
}
|
||
|
||
return success($order_service_package->toArray());
|
||
}
|
||
|
||
/**
|
||
* 获取患者服务包订单服务权益详情
|
||
* @return array
|
||
*/
|
||
public function getPatientServiceOrderDetailInfo(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$order_no = $this->request->route('order_no');
|
||
|
||
// 获取订单数据
|
||
$fields = [
|
||
"order_service_id",
|
||
"start_time",
|
||
"finish_time",
|
||
"order_service_type",
|
||
"doctor_id",
|
||
"order_service_status",
|
||
"family_id",
|
||
"doctor_id",
|
||
"user_id",
|
||
"pay_time",
|
||
];
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['order_service_no'] = $order_no;
|
||
$params['is_delete'] = 0;
|
||
$order_service_package = OrderServicePackage::getOne($params,$fields);
|
||
if (empty($order_service_package)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR,"非法订单");
|
||
}
|
||
|
||
// 获取订单详情数据
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_detail = OrderServicePackageDetail::getOne($params);
|
||
if (empty($order_service_package_detail)){
|
||
return fail(HttpEnumCode::HTTP_ERROR,"非法订单");
|
||
}
|
||
|
||
// 定义返回数据
|
||
$result = array();
|
||
$result['order_service_package'] = $order_service_package->toArray(); // 订单详情数据
|
||
$result['order_service_package_detail'] = $order_service_package_detail->toArray(); // 订单详情数据
|
||
$result['order_service_package_product'] = []; // 健康包商品数据
|
||
$result['order_service_package_coupon'] = []; // 健康包关联优惠卷数据
|
||
$result['order_inquiry'] = []; // 健康包问诊订单数据
|
||
$result['order_product'] = []; // 健康包药品订单数据
|
||
|
||
$OrderServicePackageService = new OrderServicePackageService();
|
||
|
||
// 获取问诊订单数据
|
||
if (in_array($order_service_package['order_service_status'],[2,3,4,5])){
|
||
// 订单状态(1:待支付 2:未开始 3:服务中 4:服务完成 5:服务取消)
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_inquirys = OrderServicePackageInquiry::getList($params);
|
||
foreach ($order_service_package_inquirys as $key => $order_service_package_inquiry){
|
||
// 获取问诊订单数据
|
||
$fields = [
|
||
'order_inquiry_id',
|
||
'inquiry_status',
|
||
'created_at',
|
||
];
|
||
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_service_package_inquiry['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params,$fields);
|
||
if (!empty($order_inquiry)){
|
||
$result['order_inquiry'][$key] = $order_inquiry->toArray();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (in_array($order_service_package['order_service_status'],[3,4,5])){
|
||
// 订单状态(1:待支付 2:未开始 3:服务中 4:服务完成 5:服务取消)
|
||
if (!empty($order_service_package['start_time'])){
|
||
// 当月时间
|
||
$current_month_date = $OrderServicePackageService->getCurrentMonthDate($order_service_package['start_time']);
|
||
$result['order_service_package']['current_month_start_date'] = $current_month_date['current_month_start_date'];
|
||
$result['order_service_package']['current_month_finish_date'] = $current_month_date['current_month_finish_date'];
|
||
|
||
// 获取服务包当月已问诊次数
|
||
$month_inquiry_count = $OrderServicePackageService->getCurrentMonthInquiryCount($order_service_package['pay_time'],$order_service_package['order_service_type'],$order_service_package['user_id'], $order_service_package['doctor_id']);
|
||
|
||
// 获取服务包当月剩余问诊次数
|
||
if ($order_service_package_detail['monthly_frequency'] != 0) {
|
||
// 获取服务包当月剩余问诊次数
|
||
$remaining_inquiry_count = $order_service_package_detail['monthly_frequency'] - $month_inquiry_count;
|
||
if ($remaining_inquiry_count < 0){
|
||
$remaining_inquiry_count = 0;
|
||
}
|
||
}else{
|
||
$remaining_inquiry_count = "不限";
|
||
}
|
||
|
||
$result['order_service_package_detail']['month_inquiry_count'] = $month_inquiry_count;
|
||
$result['order_service_package_detail']['remaining_inquiry_count'] = $remaining_inquiry_count;
|
||
}
|
||
}
|
||
|
||
// 健康包数据
|
||
if ($order_service_package['order_service_type'] == 1){
|
||
// 健康包关联优惠卷数据
|
||
if (in_array($order_service_package['order_service_status'],[3,4,5])){
|
||
// 订单状态(1:待支付 2:未开始 3:服务中 4:服务完成 5:服务取消)
|
||
// 获取患者某一类型下的全部优惠卷
|
||
$coupon = UserCoupon::getUserAllObjectTypeCoupon($order_service_package['user_id'],7);
|
||
if (!empty($coupon)){
|
||
$result['order_service_package_coupon'] = $coupon->toArray();
|
||
}
|
||
}
|
||
|
||
// 健康包药品订单数据-周期内所有药品订单
|
||
if (in_array($order_service_package['order_service_status'],[3,4,5])){
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_products = OrderServicePackageProduct::getList($params);
|
||
foreach ($order_service_package_products as $order_service_package_product){
|
||
$params = array();
|
||
$params['order_product_id'] = $order_service_package_product['order_product_id'];
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (!empty($order_product)){
|
||
$result['order_product'][] = $order_product->toArray();
|
||
}
|
||
}
|
||
|
||
// 获取服务包内所有药品
|
||
$health_package_products = $OrderServicePackageService->getOrderServiceProduct($order_service_package_detail['package_id']);
|
||
foreach ($health_package_products as $health_package_product) {
|
||
// 获取服务包内某一药品的剩余数量
|
||
$result['order_service_package_detail']['remaining_quantity'] = $OrderServicePackageService->getOrderServiceProductCanUseQuantity($order_service_package['order_service_id'],$health_package_product['product_id'],$health_package_product['quantity']);
|
||
}
|
||
}
|
||
}
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 获取患者未完成订单
|
||
* @param string $patient_id
|
||
* @param string|int $inquiry_type
|
||
* @param string|int $inquiry_mode
|
||
* @param string $family_id
|
||
* @return string
|
||
*/
|
||
public function getNotFinishedOrderInquiry(string|int $inquiry_type,string|int $inquiry_mode, string $patient_id = '', string $family_id = ''): string
|
||
{
|
||
$params = array();
|
||
if (!empty($patient_id)) {
|
||
$params[] = ['patient_id', '=', $patient_id];
|
||
}
|
||
|
||
if (!empty($family_id)) {
|
||
$params[] = ['family_id', '=', $family_id];
|
||
}
|
||
|
||
$params[] = ['inquiry_type', '=', $inquiry_type];
|
||
$params[] = ['inquiry_mode', '=', $inquiry_mode];
|
||
$params[] = ['inquiry_refund_status', '=', 0];
|
||
$order_inquiry = OrderInquiry::getOrderOne($params);
|
||
if (!empty($order_inquiry)) {
|
||
// 1:待支付 2:待分配 3:待接诊 4:已接诊
|
||
if (in_array($order_inquiry['inquiry_status'], [1, 2, 3, 4])) {
|
||
return $order_inquiry['order_inquiry_id'];
|
||
}
|
||
}
|
||
|
||
return "";
|
||
}
|
||
} |