962 lines
42 KiB
PHP
962 lines
42 KiB
PHP
<?php
|
||
|
||
namespace App\Controller;
|
||
|
||
use App\Amqp\Producer\AssignDoctorDelayDirectProducer;
|
||
use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer;
|
||
use App\Amqp\Producer\AutoFinishInquiryDelayDirectProducer;
|
||
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
||
use App\Amqp\Producer\SendSmsMessageProducer;
|
||
use App\Amqp\Producer\UserCouponExpiredDelayDirectProducer;
|
||
use App\Constants\DoctorTitleCode;
|
||
use App\Constants\HttpEnumCode;
|
||
use App\Exception\BusinessException;
|
||
use App\Factory\CacheFactory;
|
||
use App\Factory\ProdRedisFactory;
|
||
use App\Model\DoctorAccountDay;
|
||
use App\Model\DoctorConfigFollowPackage;
|
||
use App\Model\DoctorConfigFollowPackageItem;
|
||
use App\Model\DoctorConfigHealthPackage;
|
||
use App\Model\DoctorInquiryTime;
|
||
use App\Model\HospitalDepartmentCustom;
|
||
use App\Model\Order;
|
||
use App\Model\OrderCoupon;
|
||
use App\Model\OrderDetection;
|
||
use App\Model\OrderDetectionRefund;
|
||
use App\Model\OrderInquiryCase;
|
||
use App\Model\OrderInquiryRefund;
|
||
use App\Model\OrderPrescriptionProduct;
|
||
use App\Model\OrderProduct;
|
||
use App\Model\OrderProductItem;
|
||
use App\Model\OrderProductRefund;
|
||
use App\Model\OrderRefund;
|
||
use App\Model\OrderServicePackage;
|
||
use App\Model\OrderServicePackageInquiry;
|
||
use App\Model\OrderServicePackageProduct;
|
||
use App\Model\OrderServicePackageRefund;
|
||
use App\Model\PatientFamily;
|
||
use App\Model\ReportRegulatory;
|
||
use App\Model\User;
|
||
use App\Model\UserCaCert;
|
||
use App\Model\OrderInquiry;
|
||
use App\Model\OrderPrescription;
|
||
use App\Model\OrderPrescriptionIcd;
|
||
use App\Model\UserDoctor;
|
||
use App\Model\UserDoctorInfo;
|
||
use App\Services\CouponService;
|
||
use App\Services\ImService;
|
||
use App\Services\InquiryService;
|
||
use App\Services\MessagePush;
|
||
use App\Services\OrderPrescriptionService;
|
||
use App\Services\OrderProductService;
|
||
use App\Services\OrderService;
|
||
use App\Services\OrderServicePackageService;
|
||
use App\Services\PatientOrderService;
|
||
use App\Services\UserCouponService;
|
||
use App\Services\UserDoctorService;
|
||
use App\Utils\Data;
|
||
use App\Utils\Jwt;
|
||
use App\Utils\Log;
|
||
use App\Utils\Mask;
|
||
use Extend\Alibaba\Oss;
|
||
use Extend\Ca\Ca;
|
||
use Extend\Ca\CaOnline;
|
||
use Extend\Kuaidi100\Kuaidi;
|
||
use Extend\Prescription\Prescription;
|
||
use Extend\RegulatoryPlatform\regulatoryPlatform;
|
||
use Extend\TencentIm\RecentContact;
|
||
use Extend\VerifyDun\IdCard;
|
||
use Extend\Wechat\Wechat;
|
||
use Extend\Wechat\WechatPay;
|
||
use GuzzleHttp\Client;
|
||
use Hyperf\Amqp\Producer;
|
||
use Hyperf\Cache\Cache;
|
||
use Hyperf\DbConnection\Db;
|
||
use Hyperf\Redis\Redis;
|
||
use Hyperf\Snowflake\IdGeneratorInterface;
|
||
use Hyperf\Utils\ApplicationContext;
|
||
use Hyperf\Utils\Coroutine\Concurrent;
|
||
use Intervention\Image\ImageManager;
|
||
use Psr\SimpleCache\CacheInterface;
|
||
use Swoole\Coroutine;
|
||
use Swoole\Coroutine\Channel;
|
||
use Swoole\Coroutine\WaitGroup;
|
||
use TCPDF;
|
||
|
||
class TestController extends AbstractController
|
||
{
|
||
// 疾病名称
|
||
protected string $icd_name;
|
||
|
||
public function test(){
|
||
// $this->test_8();
|
||
// $this->test_3();
|
||
// $this->test_4();
|
||
// $this->test_6();
|
||
// $this->test_9();
|
||
// $this->test_10();
|
||
// $this->test_11();
|
||
// $this->test_5();
|
||
// $this->test_1();
|
||
// $this->test_11();
|
||
// $this->test_12();
|
||
// $this->test_13();
|
||
// $this->test_14();
|
||
$this->test_17();
|
||
}
|
||
|
||
// 获取未接诊的医生
|
||
public function uninquiry(): \Psr\Http\Message\ResponseInterface
|
||
{
|
||
$datas = array();
|
||
|
||
$params = array();
|
||
$params['inquiry_status'] = 3;// 待接诊
|
||
$order_inquirys = OrderInquiry::getList($params);
|
||
$order_inquirys = $order_inquirys->toArray();
|
||
if (!empty($order_inquirys)){
|
||
foreach ($order_inquirys as $row) {
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $row['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
|
||
if ($row['inquiry_type'] == 1){
|
||
$inquiry_type = "专家问诊";
|
||
}elseif ($row['inquiry_type'] == 2){
|
||
$inquiry_type = "快速问诊";
|
||
}elseif ($row['inquiry_type'] == 3){
|
||
$inquiry_type = "公益问诊";
|
||
}elseif ($row['inquiry_type'] == 4){
|
||
$inquiry_type = "问诊购药";
|
||
}
|
||
$data = array();
|
||
$data['user_name'] = $user_doctor['user_name'];
|
||
$data['inquiry_type'] = $inquiry_type;
|
||
$data['patient_name'] = $row['patient_name'];
|
||
$data['pay_time'] = $row['pay_time'];
|
||
|
||
$datas[] = $data;
|
||
}
|
||
}
|
||
|
||
return $this->response->json(success($datas));
|
||
}
|
||
|
||
|
||
// 处方上报处方平台
|
||
public function test_11(){
|
||
|
||
$order_prescription_id = "501751534291394561";
|
||
|
||
// 获取处方数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription_id;
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
if (empty($order_prescription)) {
|
||
throw new BusinessException("处方数据错误");
|
||
}
|
||
|
||
// 获取处方关联商品数据
|
||
$params = array();
|
||
$params['order_prescription_id'] = $order_prescription_id;
|
||
$order_prescription_product = OrderPrescriptionProduct::getList($params);
|
||
if (empty($order_prescription_product)) {
|
||
throw new BusinessException("处方药品数据错误1");
|
||
}
|
||
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
throw new BusinessException("处方药品数据错误2");
|
||
}
|
||
|
||
// 获取商品订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)) {
|
||
throw new BusinessException("处方药品数据错误3");
|
||
}
|
||
|
||
// 获取商品订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id'];
|
||
$order_product_item = OrderProductItem::getList($params);
|
||
if (empty($order_product_item)) {
|
||
throw new BusinessException("处方药品数据错误4");
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
// 上报监管平台
|
||
public function test_12(){
|
||
$regulatoryPlatform = new regulatoryPlatform();
|
||
|
||
$order_inquiry_id = "502434942043090944";
|
||
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
throw new BusinessException("处方药品数据错误");
|
||
}
|
||
$order_inquiry = $order_inquiry->toArray();
|
||
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)) {
|
||
throw new BusinessException("医生数据错误");
|
||
}
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||
$user_doctor_info = UserDoctorInfo::getOne($params);
|
||
if (empty($user_doctor_info)) {
|
||
throw new BusinessException("医生数据错误");
|
||
}
|
||
|
||
// 获取医生自定义科室数据
|
||
$params = array();
|
||
$params['department_custom_id'] = $user_doctor['department_custom_id'];
|
||
$hospital_department_custom = HospitalDepartmentCustom::getOne($params);
|
||
if (empty($hospital_department_custom)) {
|
||
throw new BusinessException("医生自定义数据错误");
|
||
}
|
||
|
||
// 获取问诊患者数据
|
||
$params = array();
|
||
$params['family_id'] = $order_inquiry['family_id'];
|
||
$patient_family = PatientFamily::getOne($params);
|
||
if (empty($patient_family)){
|
||
throw new BusinessException("医生自定义数据错误");
|
||
}
|
||
|
||
// 获取患者问诊病例
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$params['status'] = 1;
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||
if (empty($order_inquiry_case)){
|
||
throw new BusinessException("医生自定义数据错误");
|
||
}
|
||
|
||
// 获取问诊处方数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$params['pharmacist_audit_status'] = 1;
|
||
$params['platform_audit_status'] = 1;
|
||
$order_prescription = OrderPrescription::getOne($params);
|
||
|
||
// 网络咨询(网络门诊)服务
|
||
$arg = array();
|
||
$arg['thirdUniqueid'] = $order_inquiry['order_inquiry_id']; // 唯一标识
|
||
$arg['orgName'] = "成都金牛欣欣相照互联网医院"; // 机构名称
|
||
$arg['orgCode'] = "MA6CGUDA251010619D2112"; // 机构编码
|
||
$arg['channelName'] = "成都金牛欣欣相照互联网医院";//平台名称
|
||
$arg['section'] = $hospital_department_custom['department_name'];//科室名称
|
||
$arg['sectionCode'] = $hospital_department_custom['department_code'];//科室编码
|
||
$arg['docName'] = $user_doctor['user_name'];// 姓名(医师、护师、技师)
|
||
$arg['certificateNum'] = $user_doctor_info['qualification_cert_num']; // 执业资格证号
|
||
$arg['patientName'] = $order_inquiry['patient_name']; // 患者姓名
|
||
$arg['patientAge'] = $order_inquiry['patient_age']; // 患者年龄
|
||
$arg['patientSex'] = $order_inquiry['patient_sex'] == 0 ?: 1; // 患者性别
|
||
$arg['patientIdcardType'] = 1; // 证件类型
|
||
$arg['patientIdcardNum'] = $patient_family['id_number']; // 患者证件号码
|
||
$arg['serviceType'] = 1; // 服务类型 1网络咨询 2网络门诊
|
||
$arg['consultNo'] = $order_inquiry['inquiry_no']; // 网络咨询或网络门诊编号 订单编号
|
||
$arg['consultType'] = 1; // 咨询类别 1、图文咨询 2语音咨询3、视频咨询
|
||
$arg['consultApplyTime'] = $order_inquiry['created_at']; // 咨询申请时间
|
||
$arg['consultStartTime'] = $order_inquiry['reception_time']; // 咨询开始时间
|
||
$arg['consultEndTime'] = $order_inquiry['complete_time']; // 咨询结束时间
|
||
$arg['feeType'] = 1; // 费别 1自费 2医保
|
||
$arg['price'] = $order_inquiry['payment_amount_total']; // 咨询价格 元
|
||
$arg['isReply'] = 1; //咨询是否回复 0未回复 1已回复
|
||
$arg['patientEvaluate'] = 1; //患者满意度 1-5 1代表非常满意 5代表非常不满意
|
||
$arg['complainInfo'] = "无"; //投诉举报信息
|
||
$arg['disposeResult'] = "无"; //处理结果信息
|
||
$arg['isRiskWarn'] = 1; //是否进行诊前风险提示 0否 1是
|
||
$arg['isPatientSign'] = 1; //是否确认患者为签约对象 0否 1是
|
||
$arg['uploadTime'] = date('Y-m-d H:i:s',time()); //上传时间
|
||
$arg['medicalHistory'] = $order_inquiry_case['disease_desc']; //患者病史描述
|
||
$arg['docAdvice'] = $order_prescription['doctor_advice'] ?? "无"; // 医生建议描述 医嘱
|
||
$arg['isMark'] = 1;//是否留痕 1:代表留痕;0代表未留痕
|
||
|
||
$result = $regulatoryPlatform->uploadConsult($arg);
|
||
|
||
//上报 网络复诊服务
|
||
// $arg = array();
|
||
// $arg['thirdUniqueid'] =
|
||
//
|
||
// $result = $regulatoryPlatform->uploadFurtherConsult($arg);
|
||
dump($result);
|
||
}
|
||
|
||
// 获取云证书-线上
|
||
public function test_14(){
|
||
$CaOnline = new CaOnline();
|
||
|
||
// 测试医生
|
||
// $data = array();
|
||
// $data['user_id'] = "491925054435950592";
|
||
// $data['mobile'] = "13028643897";
|
||
// $data['card_name'] = "郝明明";
|
||
// $data['card_num'] = "130582199202032038";
|
||
// $data['orgDept'] = "科室名称";
|
||
// $data['org_name'] = "成都金牛欣欣相照互联网医院有限公司";
|
||
// $data['org_number'] = "91510106MABTJY4K9R";
|
||
// $result = $CaOnline->getCloudCert($data);
|
||
//
|
||
// $data = array();
|
||
// $data['user_id'] = "491925054435950592";
|
||
// $data['type'] = 2;
|
||
// $data['cert_base64'] = $result['certBase64'];
|
||
// $data['cert_chain_p7'] = $result['certP7'];
|
||
// $data['cert_serial_number'] = $result['certSerialnumber'];
|
||
// $data['ca_pin'] = "491925054435950592";
|
||
// $doctor_pharmacist_cert = UserCaCert::addUserCaCert($data);
|
||
// if (empty($doctor_pharmacist_cert)){
|
||
// return fail();
|
||
// }
|
||
// dump(111);
|
||
|
||
// 测试药师
|
||
// $data = array();
|
||
// $data['user_id'] = "534534546";
|
||
// $data['mobile'] = "18812345678";
|
||
// $data['card_name'] = "仝成亮";
|
||
// $data['card_num'] = "411322199212122054";
|
||
// $data['orgDept'] = "科室名称";
|
||
// $data['org_name'] = "成都金牛欣欣相照互联网医院有限公司";
|
||
// $data['org_number'] = "91510106MABTJY4K9R";
|
||
// $result = $CaOnline->getCloudCert($data);
|
||
//
|
||
// $data = array();
|
||
// $data['user_id'] = "534534546";
|
||
// $data['type'] = 2;
|
||
// $data['cert_base64'] = $result['certBase64'];
|
||
// $data['cert_chain_p7'] = $result['certP7'];
|
||
// $data['cert_serial_number'] = $result['certSerialnumber'];
|
||
// $data['ca_pin'] = "534534546";
|
||
// $doctor_pharmacist_cert = UserCaCert::addUserCaCert($data);
|
||
// if (empty($doctor_pharmacist_cert)){
|
||
// return fail();
|
||
// }
|
||
|
||
// 测试医院
|
||
// $data = array();
|
||
// $data['user_id'] = "5345345461";
|
||
// $data['mobile'] = "18221234167";
|
||
// $data['card_name'] = "吴从兴";
|
||
// $data['card_num'] = "372929199610075412";
|
||
// $data['org_name'] = "成都金牛欣欣相照互联网医院有限公司";
|
||
// $data['org_number'] = "91510106MABTJY4K9R";
|
||
//
|
||
// $result = $CaOnline->getCloudCert($data,'Organizational');
|
||
//
|
||
// $data = array();
|
||
// $data['is_system'] = 1;
|
||
// $data['type'] = 2;
|
||
// $data['cert_base64'] = $result['certBase64'];
|
||
// $data['cert_chain_p7'] = $result['certP7'];
|
||
// $data['cert_serial_number'] = $result['certSerialnumber'];
|
||
// $data['ca_pin'] = "5345345461";
|
||
// $doctor_pharmacist_cert = UserCaCert::addUserCaCert($data);
|
||
// if (empty($doctor_pharmacist_cert)){
|
||
// return fail();
|
||
// }
|
||
return 111;
|
||
}
|
||
|
||
public function test_15(){
|
||
$CaOnline = new CaOnline();
|
||
|
||
$a = array(
|
||
"user_id" => 5345345461
|
||
);
|
||
$data = $CaOnline->removeCloudCert($a);
|
||
|
||
dump($data);
|
||
}
|
||
|
||
|
||
// 更新云证书-线上
|
||
public function test_16(){
|
||
$CaOnline = new CaOnline();
|
||
|
||
// 测试医生
|
||
$data = array();
|
||
$data['user_id'] = "491925054435950592";
|
||
$data['mobile'] = "13028643897";
|
||
$data['card_name'] = "郝明明";
|
||
$data['card_num'] = "130582199202032038";
|
||
$data['orgDept'] = "科室名称";
|
||
$data['org_name'] = "成都金牛欣欣相照互联网医院有限公司";
|
||
$data['org_number'] = "91510106MABTJY4K9R";
|
||
$result = $CaOnline->getCloudCert($data);
|
||
|
||
$data = array();
|
||
$data['user_id'] = "491925054435950592";
|
||
$data['type'] = 2;
|
||
$data['cert_base64'] = $result['certBase64'];
|
||
$data['cert_chain_p7'] = $result['certP7'];
|
||
$data['cert_serial_number'] = $result['certSerialnumber'];
|
||
$data['ca_pin'] = "491925054435950592";
|
||
$doctor_pharmacist_cert = UserCaCert::addUserCaCert($data);
|
||
if (empty($doctor_pharmacist_cert)){
|
||
return fail();
|
||
}
|
||
dump(111);
|
||
|
||
// // 测试药师
|
||
// $data = array();
|
||
// $data['user_id'] = "534534546";
|
||
// $data['mobile'] = "18812345678";
|
||
// $data['card_name'] = "仝成亮";
|
||
// $data['card_num'] = "411322199212122054";
|
||
// $data['orgDept'] = "科室名称";
|
||
// $data['org_name'] = "成都金牛欣欣相照互联网医院有限公司";
|
||
// $data['org_number'] = "91510106MABTJY4K9R";
|
||
// $result = $CaOnline->getCloudCert($data);
|
||
//
|
||
// $data = array();
|
||
// $data['user_id'] = "534534546";
|
||
// $data['type'] = 2;
|
||
// $data['cert_base64'] = $result['certBase64'];
|
||
// $data['cert_chain_p7'] = $result['certP7'];
|
||
// $data['cert_serial_number'] = $result['certSerialnumber'];
|
||
// $data['ca_pin'] = "534534546";
|
||
// $doctor_pharmacist_cert = UserCaCert::addUserCaCert($data);
|
||
// if (empty($doctor_pharmacist_cert)){
|
||
// return fail();
|
||
// }
|
||
//
|
||
// $params = array();
|
||
// $params['ca_pin'] = "491925054435950592";
|
||
// $params['type'] = "2";
|
||
// $user_ca_cert = UserCaCert::getOne($params);
|
||
// if (empty($user_ca_cert)){
|
||
// return fail();
|
||
// }
|
||
|
||
return 122;
|
||
// // 测试医院
|
||
// $data = array();
|
||
// $data['user_id'] = "491925054435950592";
|
||
// $result = $CaOnline->renewCloudCert($data);
|
||
//
|
||
// dump($result);
|
||
//
|
||
// $data = array();
|
||
// $data['cert_base64'] = $result['certBase64'];
|
||
// $data['cert_chain_p7'] = $result['certP7'];
|
||
// $data['cert_serial_number'] = $result['certSerialnumber'];
|
||
// $data['ca_pin'] = "491925054435950592";
|
||
//
|
||
// $params = array();
|
||
// $params['cert_id'] = $user_ca_cert['cert_id'];
|
||
// $res = UserCaCert::edit($params,$data);
|
||
// if (empty($res)){
|
||
// return fail();
|
||
// }
|
||
}
|
||
|
||
public function test_17(){
|
||
// 测试计算药品订单明细实际金额
|
||
// $product_datas = array(
|
||
// array(
|
||
// "product_id" => 1,
|
||
// "product_price" => 10,
|
||
// "actual_product_price" => 10,
|
||
// "actual_quantity" => 2,
|
||
// ),
|
||
// array(
|
||
// "product_id" => 2,
|
||
// "product_price" => 20,
|
||
// "actual_product_price" => 20,
|
||
// "actual_quantity" => 2,
|
||
// ),
|
||
// array(
|
||
// "product_id" => 3,
|
||
// "product_price" => 5,
|
||
// "actual_product_price" => 5,
|
||
// "actual_quantity" => 2,
|
||
// ),
|
||
// );
|
||
//
|
||
// $coupons = array(
|
||
// array(
|
||
// "application_scope" => 1,
|
||
// "coupon_price" => 3,
|
||
// "product_id" => "",
|
||
// ),
|
||
// array(
|
||
// "application_scope" => 5,
|
||
// "coupon_price" => 1,
|
||
// "product_id" => "1",
|
||
// )
|
||
// );
|
||
//
|
||
// $PatientOrderService = new PatientOrderService();
|
||
// $product_datas = $PatientOrderService->calculateProductOrderItemActualPrice($product_datas,$coupons);
|
||
// dump($product_datas);
|
||
}
|
||
|
||
// 退款
|
||
public function refund(){
|
||
$order_no = $this->request->input('order_no');
|
||
|
||
Db::beginTransaction();
|
||
try {
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_no'] = $order_no;
|
||
$order = Order::getOne($params);
|
||
if (empty($order)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "未查询到对应订单数据");
|
||
}
|
||
|
||
// 修改订单为取消
|
||
$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_no;
|
||
Order::edit($params, $data);
|
||
|
||
// 处理对应订单
|
||
switch ($order['order_type']) {
|
||
case 1: // 问诊订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['inquiry_no'] = $order_no;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "未查询到对应订单数据");
|
||
}
|
||
|
||
// 修改问诊订单为取消
|
||
$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);
|
||
|
||
break;
|
||
case 3: // 检测订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['detection_no'] = $order_no;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "未查询到对应订单数据");
|
||
}
|
||
|
||
// 修改检测订单为取消
|
||
$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);
|
||
|
||
break;
|
||
case 4: // 健康包订单
|
||
case 5: // 随访包订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_service_no'] = $order_no;
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "未查询到对应订单数据");
|
||
}
|
||
|
||
// 修改服务包订单为取消
|
||
$data = array();
|
||
$data['order_service_status'] = 5;
|
||
$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_service_id'] = $order_service_package['order_service_id'];
|
||
OrderServicePackage::edit($params, $data);
|
||
|
||
// 获取问诊订单数据-此处只会存在一个
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$order_service_package_inquirys = OrderServicePackageInquiry::getList($params);
|
||
if (empty($order_service_package_inquirys)){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "未查询到对应订单数据");
|
||
}
|
||
|
||
foreach ($order_service_package_inquirys as $order_service_package_inquiry){
|
||
$params = array();
|
||
$params['inquiry_no'] = $order_service_package_inquiry['inquiry_no'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "未查询到对应订单数据");
|
||
}
|
||
|
||
if (in_array($order_inquiry['inquiry_status'], [5, 6 , 7])) {
|
||
continue;
|
||
}
|
||
|
||
if ($order_inquiry['inquiry_refund_status'] == 1) {
|
||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
continue;
|
||
}
|
||
|
||
if ($order_inquiry['inquiry_refund_status'] == 2) {
|
||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
continue;
|
||
}
|
||
|
||
// 修改问诊订单为取消
|
||
$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);
|
||
}
|
||
|
||
break;
|
||
default:
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "未查询到对应订单数据");
|
||
}
|
||
|
||
// 检测支付状态,判断是否需要退款处理
|
||
if ($order['pay_status'] == 2 && $order['refund_status'] != 3) {
|
||
// 系统退款编号
|
||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||
$refund_no = $generator->generate();
|
||
|
||
// 检测订单金额
|
||
if ($order['payment_amount_total'] > 0) {
|
||
// 发起退款
|
||
$WechatPay = new WechatPay(1, $order['order_type']);
|
||
|
||
$options = array();
|
||
$options['transaction_id'] = $order['escrow_trade_no'];
|
||
$options['out_refund_no'] = (string)$refund_no;
|
||
$options['reason'] = "主动取消";
|
||
$options['amount'] = [
|
||
'refund' => (int)round($order['payment_amount_total'] * 100),
|
||
'total' => (int)round($order['payment_amount_total'] * 100),
|
||
'currency' => "CNY",
|
||
];
|
||
|
||
$refund_result = $WechatPay->refund($options);
|
||
|
||
// 处理订单退款状态
|
||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||
$success_time = "";
|
||
if ($refund_result['status'] == "SUCCESS") {
|
||
// 退款成功
|
||
$refund_status = 3;
|
||
$success_time = $refund_result['success_time'];
|
||
} elseif ($refund_result['status'] == "CLOSED") {
|
||
// 退款关闭
|
||
$refund_status = 5;
|
||
} elseif ($refund_result['status'] == "PROCESSING") {
|
||
// 退款处理中
|
||
$refund_status = 2;
|
||
} elseif ($refund_result['status'] == "ABNORMAL") {
|
||
// 退款异常,此情况不处理,进行短信通知
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单退款状态异常");
|
||
} else {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单退款状态异常");
|
||
}
|
||
|
||
$refund_id = $refund_result['refund_id'];
|
||
} else {
|
||
// 模拟退款
|
||
$refund_status = 3;
|
||
|
||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||
$refund_id = "模拟退款:" . $generator->generate();
|
||
$success_time = date("Y-m-d H:i:s", time());
|
||
|
||
// 模拟退款时手动退还优惠卷
|
||
if (!empty($order['coupon_amount_total']) && $order['coupon_amount_total'] > 0) {
|
||
// 获取该订单全部优惠卷数据
|
||
$params = array();
|
||
$params['order_id'] = $order['order_id'];
|
||
$order_coupons = OrderCoupon::getList($params);
|
||
if (!empty($order_coupons)) {
|
||
$userCouponService = new UserCouponService();
|
||
foreach ($order_coupons as $order_coupon) {
|
||
// 退还优惠卷
|
||
$userCouponService->returnUserCoupon($order_coupon['user_coupon_id']);
|
||
|
||
// 发送站内消息-优惠卷退还
|
||
$MessagePush = new MessagePush($order_coupon['user_id']);
|
||
$MessagePush->patientRefundCoupon($order_coupon['coupon_name']);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 新增退款表
|
||
$data = array();
|
||
$data['order_id'] = $order['order_id'];
|
||
$data['patient_id'] = $order['patient_id'];
|
||
$data['order_no'] = $order['order_no'];
|
||
$data['refund_no'] = $refund_no;
|
||
$data['inquiry_refund_no'] = $refund_no;
|
||
$data['refund_id'] = $refund_id;
|
||
$data['refund_status'] = $refund_status;
|
||
$data['refund_total'] = $order['payment_amount_total'];
|
||
$data['refund_reason'] = "主动取消";
|
||
if ($refund_status == 3 && !empty($success_time)) {
|
||
$data['success_time'] = date("Y-m-d H:i:s", strtotime($success_time)); // 退款成功时间
|
||
}
|
||
$order_refund = OrderRefund::addOrderRefund($data);
|
||
if (empty($order_refund)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "添加退款表失败");
|
||
}
|
||
|
||
switch ($order['order_type']) {
|
||
case 1: // 问诊订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['inquiry_no'] = $order_no;
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单数据为空");
|
||
}
|
||
|
||
// 新增退款表
|
||
$data = array();
|
||
$data['patient_id'] = $order['patient_id'];
|
||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$data['inquiry_no'] = $order_inquiry['inquiry_no'];
|
||
$data['inquiry_refund_no'] = $refund_no;
|
||
$data['refund_id'] = $refund_id;
|
||
$data['inquiry_refund_status'] = $refund_status;
|
||
$data['refund_total'] = $order_inquiry['payment_amount_total'];
|
||
$data['refund_reason'] = "主动取消";
|
||
if ($refund_status == 3 && !empty($success_time)) {
|
||
$data['success_time'] = date("Y-m-d H:i:s", strtotime($success_time)); // 退款成功时间
|
||
}
|
||
|
||
$order_inquiry_refund = OrderInquiryRefund::addOrderInquiryRefund($data);
|
||
if (empty($order_inquiry_refund)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "添加退款表失败");
|
||
}
|
||
|
||
// 修改问诊订单表状态
|
||
$data = array();
|
||
$data['inquiry_refund_status'] = $refund_status;
|
||
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
OrderInquiry::edit($params, $data);
|
||
|
||
break;
|
||
case 2: // 药品订单
|
||
// 获取药品订单数据
|
||
$params = array();
|
||
$params['order_product_no'] = $order['order_no'];
|
||
$order_product = OrderProduct::getOne($params);
|
||
if (empty($order_product)){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单数据为空");
|
||
}
|
||
|
||
$data = array();
|
||
$data['patient_id'] = $order_product['patient_id'];
|
||
$data['order_product_id'] = $order_product['order_product_id'];
|
||
$data['order_product_no'] = $order_product['order_product_no'];
|
||
$data['product_refund_no'] = $refund_no;
|
||
$data['refund_id'] = $refund_id;
|
||
$data['product_refund_status'] = $refund_status;
|
||
$data['refund_total'] = $order_product['payment_amount_total'];
|
||
$data['refund_reason'] = "主动取消";
|
||
|
||
if ($refund_status == 3 && !empty($success_time)) {
|
||
$data['success_time'] = date("Y-m-d H:i:s", strtotime($success_time)); // 退款成功时间
|
||
}
|
||
|
||
$order_product_refund = OrderProductRefund::addOrderProductRefund($data);
|
||
if (empty($order_product_refund)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "添加退款表失败");
|
||
}
|
||
|
||
// 修改药品订单表状态
|
||
$data = array();
|
||
$data['refund_status'] = $refund_status;
|
||
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product['order_product_id'];
|
||
OrderProduct::edit($params,$data);
|
||
|
||
// 获取问诊订单数据
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $order_product['order_inquiry_id'];
|
||
$order_inquiry = OrderInquiry::getOne($params);
|
||
if (empty($order_inquiry)){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单数据为空");
|
||
}
|
||
|
||
// 获取订单商品订单列表
|
||
$params = array();
|
||
$params['order_product_id'] = $order_product['order_product_id'];
|
||
$order_product_items = OrderProductItem::getList($params);
|
||
if (empty($order_product_items)){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单数据为空");
|
||
}
|
||
|
||
// 获取患者家庭成员进行中的服务包订单-健康包
|
||
$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)){
|
||
// 回退服务包已使用药品数量
|
||
foreach ($order_product_items as $order_product_item){
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
$params['order_product_id'] = $order_product_item['order_product_id'];
|
||
$params['product_item_id'] = $order_product_item['product_item_id'];
|
||
$params['product_id'] = $order_product_item['product_id'];
|
||
$order_service_package_product = OrderServicePackageProduct::getOne($params);
|
||
if (!empty($order_service_package_product)){
|
||
$params = array();
|
||
$params['service_product_id'] = $order_service_package_product['service_product_id'];
|
||
|
||
$data = array();
|
||
$data['used_quantity'] = 0;
|
||
OrderServicePackageProduct::edit($params,$data);
|
||
}
|
||
}
|
||
}
|
||
|
||
break;
|
||
case 3: // 检测订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['detection_no'] = $order_no;
|
||
$order_detection = OrderDetection::getOne($params);
|
||
if (empty($order_detection)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单数据为空");
|
||
}
|
||
|
||
// 新增退款表
|
||
$data = array();
|
||
$data['patient_id'] = $order['patient_id'];
|
||
$data['order_detection_id'] = $order_detection['order_detection_id'];
|
||
$data['detection_no'] = $order_detection['detection_no'];
|
||
$data['detection_refund_no'] = $refund_no;
|
||
$data['refund_id'] = $refund_id;
|
||
$data['detection_refund_status'] = $refund_status;
|
||
$data['refund_total'] = $order_detection['payment_amount_total'];
|
||
$data['refund_reason'] = "主动取消";
|
||
if ($refund_status == 3 && !empty($success_time)) {
|
||
$data['success_time'] = date("Y-m-d H:i:s", strtotime($success_time)); // 退款成功时间
|
||
}
|
||
$order_detection_refund = OrderDetectionRefund::add($data);
|
||
if (empty($order_detection_refund)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "添加退款表失败");
|
||
}
|
||
|
||
// 修改问诊订单表状态
|
||
$data = array();
|
||
$data['detection_refund_status'] = $refund_status;
|
||
|
||
$params = array();
|
||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||
OrderDetection::editOrderDetection($params, $data);
|
||
|
||
break;
|
||
case 4: // 健康包订单
|
||
case 5: // 随访包订单订单
|
||
// 获取订单数据
|
||
$params = array();
|
||
$params['order_service_no'] = $order_no;
|
||
$order_service_package = OrderServicePackage::getOne($params);
|
||
if (empty($order_service_package)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单数据为空");
|
||
}
|
||
|
||
// 新增服务包退款表
|
||
$data = array();
|
||
$data['patient_id'] = $order['patient_id'];
|
||
$data['order_service_id'] = $order_service_package['order_service_id'];
|
||
$data['order_service_no'] = $order_service_package['order_service_no'];
|
||
$data['service_refund_no'] = $refund_no;
|
||
$data['refund_id'] = $refund_id;
|
||
$data['refund_status'] = $refund_status;
|
||
$data['refund_total'] = $order_service_package['payment_amount_total'];
|
||
$data['refund_reason'] = "主动取消";
|
||
if ($refund_status == 3 && !empty($success_time)) {
|
||
$data['success_time'] = date("Y-m-d H:i:s", strtotime($success_time)); // 退款成功时间
|
||
}
|
||
$order_service_package_refund = OrderServicePackageRefund::addOrderServicePackageRefund($data);
|
||
if (empty($order_service_package_refund)) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "添加退款表失败");
|
||
}
|
||
|
||
// 修改订单表状态
|
||
$data = array();
|
||
$data['refund_status'] = $refund_status;
|
||
|
||
$params = array();
|
||
$params['order_service_id'] = $order_service_package['order_service_id'];
|
||
OrderServicePackage::edit($params, $data);
|
||
|
||
break;
|
||
default:
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, "订单类型错误");
|
||
}
|
||
}
|
||
|
||
|
||
Db::commit();
|
||
}catch (\Throwable $e){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||
}
|
||
|
||
return success();
|
||
}
|
||
} |