增加了订单主表,修改了所有订单相关,支付相关代码
This commit is contained in:
parent
c0f6fbca06
commit
944ab44305
@ -15,8 +15,10 @@ use App\Model\UserDoctor;
|
||||
use App\Services\ImService;
|
||||
use App\Services\InquiryService;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\UserDoctorService;
|
||||
use App\Utils\Log;
|
||||
use App\Utils\Utils;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
@ -49,14 +51,14 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
{
|
||||
Log::getInstance('queue-AssignDoctor')->info("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance('queue-AssignDoctor')->info(json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $data['order_inquiry_id'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
Log::getInstance('queue-AssignDoctor')->error("错误:未查询到对应订单数据");
|
||||
Log::getInstance('queue-AssignDoctor')->error("未查询到对应订单数据");
|
||||
return Result::DROP;// 销毁
|
||||
}
|
||||
|
||||
@ -65,14 +67,14 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||||
if (empty($order_inquiry_case)){
|
||||
Log::getInstance('queue-AssignDoctor')->error("错误:患者病例错误");
|
||||
Log::getInstance('queue-AssignDoctor')->error("患者病例错误");
|
||||
return Result::DROP;// 销毁
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
$res = $this->checkInquiryStatus($order_inquiry);
|
||||
if (!$res){
|
||||
Log::getInstance('queue-AssignDoctor')->error("错误:订单状态错误");
|
||||
Log::getInstance('queue-AssignDoctor')->error("订单状态错误");
|
||||
return Result::DROP;// 销毁
|
||||
}
|
||||
|
||||
@ -80,7 +82,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$pay_time = strtotime($order_inquiry['pay_time']);
|
||||
$diff_time = time() - $pay_time;
|
||||
if ($diff_time < 0) {
|
||||
Log::getInstance('queue-AssignDoctor')->error("错误:支付时间错误");
|
||||
Log::getInstance('queue-AssignDoctor')->error("支付时间错误");
|
||||
return Result::DROP;// 销毁
|
||||
}
|
||||
|
||||
@ -91,23 +93,25 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$is_system_time_pass = $inquiryService->checkSystemInquiryTime($order_inquiry['inquiry_type']);
|
||||
if (!$is_system_time_pass && $order_inquiry['inquiry_type'] == 4){
|
||||
// 非坐班时间
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:非坐班时间,执行退款");
|
||||
Log::getInstance("queue-AssignDoctor")->info("非坐班时间,执行退款");
|
||||
|
||||
$InquiryService = new InquiryService();
|
||||
|
||||
// 检测问诊订单执行退款次数
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:检测执行退款次数");
|
||||
$res = $InquiryService->checkInquiryRefundCount($order_inquiry['order_inquiry_id']);
|
||||
if (!$res){
|
||||
// 检测执行次数
|
||||
$Utils = new Utils();
|
||||
$redis_key = "inquiryRefund" . $order_inquiry['inquiry_no'];
|
||||
$res = $Utils->checkHandleNumber($redis_key);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:超出最大退款次数");
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("超出最大执行次数或检测错误");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:订单退款");
|
||||
$InquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "无可分配医生");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:取消问诊订单");
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefund($order_inquiry['inquiry_no'], "无可分配医生");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("取消问诊订单");
|
||||
|
||||
$save_data = array();
|
||||
$save_data['inquiry_status'] = 7;
|
||||
$save_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
@ -119,7 +123,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $save_data);
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("成功:已退款");
|
||||
Log::getInstance("queue-AssignDoctor")->info("已退款");
|
||||
|
||||
Db::commit();
|
||||
|
||||
@ -128,7 +132,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->assignDoctorFail();
|
||||
}catch (\Exception $e){
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:" . $e->getMessage());
|
||||
Log::getInstance("queue-AssignDoctor")->error( $e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
@ -136,23 +140,25 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
|
||||
// 检测分配时间
|
||||
if ($diff_time > 600) {
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:超出10分钟,执行退款");
|
||||
Log::getInstance("queue-AssignDoctor")->info("超出10分钟,执行退款");
|
||||
|
||||
$InquiryService = new InquiryService();
|
||||
|
||||
// 检测问诊订单执行退款次数
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:检测执行退款次数");
|
||||
$res = $InquiryService->checkInquiryRefundCount($order_inquiry['order_inquiry_id']);
|
||||
if (!$res){
|
||||
// 检测执行次数
|
||||
$Utils = new Utils();
|
||||
$redis_key = "inquiryRefund" . $order_inquiry['inquiry_no'];
|
||||
$res = $Utils->checkHandleNumber($redis_key);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:超出最大退款次数");
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("超出最大执行次数或检测错误");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:订单退款");
|
||||
$InquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "未分配到合适的医生");
|
||||
Log::getInstance("queue-AssignDoctor")->info("订单退款");
|
||||
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefund($order_inquiry['inquiry_no'], "未分配到合适的医生");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("取消问诊订单");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:取消问诊订单");
|
||||
$save_data = array();
|
||||
$save_data['inquiry_status'] = 7;
|
||||
$save_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
@ -164,7 +170,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $save_data);
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("成功:已退款");
|
||||
Log::getInstance("queue-AssignDoctor")->info("已退款");
|
||||
|
||||
Db::commit();
|
||||
|
||||
@ -173,7 +179,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->assignDoctorFail();
|
||||
}catch (\Exception $e){
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:" . $e->getMessage());
|
||||
Log::getInstance("queue-AssignDoctor")->error($e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
@ -183,9 +189,9 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$res = $this->checkHandleNumber($data['order_inquiry_id']);
|
||||
if (!$res) {
|
||||
// 超出执行次数后,不再进行分配,按照结束分配时间,重新加入队列。
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:超出最大执行次数或检测错误");
|
||||
Log::getInstance("queue-AssignDoctor")->info("超出最大执行次数或检测错误");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:重新加入延迟队列");
|
||||
Log::getInstance("queue-AssignDoctor")->info("重新加入延迟队列");
|
||||
|
||||
$queue_data = array();
|
||||
$queue_data['order_inquiry_id'] = $data['order_inquiry_id'];
|
||||
@ -199,7 +205,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:重新加入分配医生队列失败,重回队列");
|
||||
Log::getInstance("queue-AssignDoctor")->error("重新加入分配医生队列失败,重回队列");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
@ -208,14 +214,14 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:分配医生");
|
||||
Log::getInstance("queue-AssignDoctor")->info("分配医生");
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
$doctor_id = $UserDoctorService->getInquiryAssignDoctor($order_inquiry['inquiry_type'],$order_inquiry['patient_id'],$is_system_time_pass);
|
||||
if (empty($doctor_id)){
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:无合适医生");
|
||||
Log::getInstance("queue-AssignDoctor")->info("无合适医生");
|
||||
Db::rollBack();
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:重新加入延迟队列");
|
||||
Log::getInstance("queue-AssignDoctor")->info("重新加入延迟队列");
|
||||
|
||||
$queue_data = array();
|
||||
$queue_data['order_inquiry_id'] = $data['order_inquiry_id'];
|
||||
@ -226,7 +232,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:重新加入分配医生队列失败,重回队列");
|
||||
Log::getInstance("queue-AssignDoctor")->error("重新加入分配医生队列失败,重回队列");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
@ -253,7 +259,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:加入未接诊取消订单延迟队列失败");
|
||||
Log::getInstance("queue-AssignDoctor")->error("加入未接诊取消订单延迟队列失败");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
@ -261,7 +267,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
Log::getInstance("queue-AssignDoctor")->info("成功");
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("失败:" . $e->getMessage());
|
||||
Log::getInstance("queue-AssignDoctor")->error($e->getMessage());
|
||||
return Result::REQUEUE; // 重回队列
|
||||
}
|
||||
|
||||
@ -272,7 +278,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)) {
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:医生数据错误");
|
||||
Log::getInstance("queue-AssignDoctor")->error("医生数据错误");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
@ -296,7 +302,7 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$producer->produce($message);
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("queue-AssignDoctor")->error("发送消息异常错误:" . $e->getMessage());
|
||||
Log::getInstance("queue-AssignDoctor")->error($e->getMessage());
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ class AutoPharmacistCaVerifyDelayDirectConsumer extends ConsumerMessage
|
||||
return Result::ACK;
|
||||
}catch (\Throwable $e){
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AutoPharmacistCaVerify")->info("错误:" . $e->getMessage());
|
||||
Log::getInstance("queue-AutoPharmacistCaVerify")->error("错误:" . $e->getMessage());
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCoupon;
|
||||
use App\Model\UserCoupon;
|
||||
@ -12,7 +13,9 @@ use App\Model\UserDoctor;
|
||||
use App\Services\ImService;
|
||||
use App\Services\InquiryService;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderService;
|
||||
use App\Utils\Log;
|
||||
use App\Utils\Utils;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
@ -46,12 +49,23 @@ class CancelUnInquiryOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
* @param $data
|
||||
* @param AMQPMessage $message
|
||||
* @return string
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
{
|
||||
Log::getInstance()->error("开始执行 取消未接诊问诊订单 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->info(json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
try {
|
||||
// 检测执行次数
|
||||
$Utils = new Utils();
|
||||
$redis_key = "orderRefund" . $data['order_no'];
|
||||
$res = $Utils->checkHandleNumber($redis_key);
|
||||
if (!$res) {
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("超出最大执行次数或检测错误");
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error($e->getMessage());
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
@ -62,7 +76,7 @@ class CancelUnInquiryOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未接诊问诊订单失败:未找到对应问诊订单" );
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("未找到对应问诊订单" );
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
@ -70,66 +84,78 @@ class CancelUnInquiryOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
if ($order_inquiry['inquiry_status'] == 7) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未接诊问诊订单失败:订单已取消" );
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->info("订单已取消" );
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_status'] == 4) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未接诊问诊订单失败:订单已接诊" );
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->info("订单已接诊" );
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_status'] != 3) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未接诊问诊订单失败:订单状态非待接诊" );
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("订单状态非待接诊" );
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未接诊问诊订单失败:订单正在退款中" );
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("订单正在退款中" );
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 取消订单
|
||||
$order_data = array();
|
||||
$order_data['cancel_status'] = 1;
|
||||
$order_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$order_data['cancel_remarks'] = "医生未接诊";
|
||||
$order_data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
|
||||
$params = array();
|
||||
$params['order_no'] = $order_inquiry['inquiry_no'];
|
||||
Order::edit($params,$order_data);
|
||||
|
||||
// 取消问诊订单
|
||||
$save_data = array();
|
||||
$save_data['inquiry_status'] = 7;
|
||||
$save_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$save_data['cancel_reason'] = 1; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$save_data['cancel_remarks'] = "医生未接诊"; // 取消订单备注
|
||||
$save_data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
$order_inquiry_data = array();
|
||||
$order_inquiry_data['inquiry_status'] = 7;
|
||||
$order_inquiry_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$order_inquiry_data['cancel_reason'] = 1; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$order_inquiry_data['cancel_remarks'] = "医生未接诊"; // 取消订单备注
|
||||
$order_inquiry_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, $save_data);
|
||||
OrderInquiry::edit($params, $order_inquiry_data);
|
||||
|
||||
// 订单退款
|
||||
if ($order_inquiry['inquiry_pay_status'] == 2) {
|
||||
// 检测问诊订单执行退款次数
|
||||
$InquiryService = new InquiryService();
|
||||
$res = $InquiryService->checkInquiryRefundCount($order_inquiry['order_inquiry_id']);
|
||||
if (!$res){
|
||||
$redis_key = "orderRefund" . $order_inquiry['inquiry_no'];
|
||||
$res = $Utils->checkHandleNumber($redis_key);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未接诊问诊订单失败:超出最大退款次数");
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("超出最大退款次数");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
$InquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "医生未接诊");
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefund($order_inquiry['inquiry_no'], "医生未接诊");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消未接诊问诊订单失败:" . $e->getMessage());
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error($e->getMessage());
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
Log::getInstance()->info("取消未接诊问诊订单成功");
|
||||
Log::getInstance()->info("取消未接诊问诊订单成功,发送IM消息");
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("取消未接诊问诊订单成功");
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("开始发送IM消息");
|
||||
|
||||
try {
|
||||
// 获取订单医生数据
|
||||
@ -137,7 +163,7 @@ class CancelUnInquiryOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)) {
|
||||
Log::getInstance()->info("取消未接诊问诊订单成功,发送IM消息失败:医生数据错误");
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->error("发送IM消息失败:医生数据错误");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
@ -168,10 +194,10 @@ class CancelUnInquiryOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
}
|
||||
}
|
||||
|
||||
Log::getInstance()->info("取消未接诊问诊订单成功,发送消息成功");
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->info("发送IM消息成功");
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("取消未接诊问诊订单成功,发送消息失败:" . $e->getMessage());
|
||||
Log::getInstance("queue-CancelUnInquiryOrders")->info("发送IM消息失败:" . $e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
|
||||
@ -16,13 +16,16 @@ use App\Model\UserCoupon;
|
||||
use App\Services\DetectionService;
|
||||
use App\Services\InquiryService;
|
||||
use App\Services\OrderProductService;
|
||||
use App\Services\OrderService;
|
||||
use App\Utils\Log;
|
||||
use App\Utils\Utils;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Redis\Redis;
|
||||
use Hyperf\Snowflake\IdGeneratorInterface;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
@ -49,49 +52,53 @@ class CancelUnpayOrdersDelayDirectConsumer extends ConsumerMessage
|
||||
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
{
|
||||
Log::getInstance("queue-CancelUnpayOrders")->info("开始执行 取消未支付订单 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("queue-CancelUnpayOrders")->info(json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
try {
|
||||
$Utils = new Utils();
|
||||
$redis_key = "cancelUnpayOrders" . $data['order_no'];
|
||||
$res = $Utils->checkHandleNumber($redis_key);
|
||||
if (!$res) {
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error("超出最大执行次数或检测错误");
|
||||
}
|
||||
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error($e->getMessage());
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
if ($data['order_type'] == 1) {
|
||||
// 问诊订单取消
|
||||
$InquiryService = new InquiryService();
|
||||
$result = $InquiryService->cancelUnpayInquiryOrder($data['order_no'], 5, "支付超时");
|
||||
$OrderService = new OrderService();
|
||||
|
||||
if ($data['order_type'] == 1) {
|
||||
// 问诊订单
|
||||
$result = $OrderService->cancelUnpayOrder($data['order_no'],5,"支付超时");
|
||||
} elseif ($data['order_type'] == 2) {
|
||||
// 药品订单取消
|
||||
$OrderProductService = new OrderProductService();
|
||||
$result = $OrderProductService->cancelUnpayProductOrder($data['order_no'], 3, "支付超时");
|
||||
|
||||
// 药品订单
|
||||
$result = $OrderService->cancelUnpayOrder($data['order_no'],3,"支付超时");
|
||||
} elseif ($data['order_type'] == 3) {
|
||||
// 检测订单取消
|
||||
$DetectionService = new DetectionService();
|
||||
$result = $DetectionService->cancelUnpayDetectionOrder($data['order_no'], 3, "支付超时");
|
||||
// 检测订单
|
||||
$result = $OrderService->cancelUnpayOrder($data['order_no'],3,"支付超时");
|
||||
} else {
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error("取消未支付订单失败:order_type类型错误");
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error("order_type类型错误");
|
||||
return Result::DROP;// 销毁
|
||||
}
|
||||
|
||||
if ($result['status'] == 0) {
|
||||
if ($result['status'] != 1) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error("取消未支付订单失败:" . $result['message']);
|
||||
return Result::DROP;// 销毁
|
||||
} elseif ($result['status'] == 2) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-CancelUnpayOrders")->info("取消未支付订单成功:" . $result['message']);
|
||||
return Result::ACK;// 销毁
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error($result['message']);
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
Log::getInstance("queue-CancelUnpayOrders")->info("取消未支付订单 队列执行成功");
|
||||
Log::getInstance("queue-CancelUnpayOrders")->info("成功");
|
||||
return Result::ACK;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error("取消未支付订单执行失败:" . $e->getMessage());
|
||||
Log::getInstance("queue-CancelUnpayOrders")->error($e->getMessage());
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ use App\Model\UserPatient;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Services\OrderProductService;
|
||||
use App\Services\OrderService;
|
||||
use App\Utils\Log;
|
||||
use Extend\Kuaidi100\Kuaidi;
|
||||
use Extend\Prescription\Prescription;
|
||||
@ -102,8 +103,8 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
}
|
||||
|
||||
// 执行退款
|
||||
$OrderProductService = new OrderProductService();
|
||||
$OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款");
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefund($item['order_product_no'],"订单退款");
|
||||
}
|
||||
|
||||
if ($result['status'] == "CFD05"){
|
||||
|
||||
@ -16,6 +16,7 @@ use App\Model\Coupon;
|
||||
use App\Model\DetectionProject;
|
||||
use App\Model\Hospital;
|
||||
use App\Model\MessageIm;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderDetection;
|
||||
use App\Model\OrderDetectionCase;
|
||||
use App\Model\OrderDetectionRefund;
|
||||
@ -46,6 +47,7 @@ use App\Services\ImService;
|
||||
use App\Services\InquiryService;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\UserCouponService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Log;
|
||||
@ -88,19 +90,27 @@ class CallBackController extends AbstractController
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "问诊微信支付回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
Log::getInstance()->info("问诊微信支付回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->info(json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])) {
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理失败,缺少外部订单号");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error("问诊微信支付回调数据处理失败,缺少外部订单号");
|
||||
return $server->serve();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error($e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 查询订单
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $message['out_trade_no'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理失败,无订单数据");
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error("无订单数据");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -109,60 +119,89 @@ class CallBackController extends AbstractController
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||||
if (empty($order_inquiry_case)){
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理失败,患者病例错误");
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error("患者病例错误");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理失败,订单状态当前为" . $order_inquiry['inquiry_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error("订单状态当前为" . $order_inquiry['inquiry_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 支付状态无需验证,如第一次支付失败,会修改支付状态,再次支付时,会出现验证不通过的情况
|
||||
|
||||
// 修改支付状态
|
||||
$data = array();
|
||||
// 处理支付状态
|
||||
if ($message['trade_state'] == "SUCCESS") {
|
||||
// 支付成功
|
||||
$data['inquiry_pay_status'] = 2;
|
||||
$data['pay_time'] = date('Y-m-d H:i:s', strtotime($message['success_time']));// 支付时间
|
||||
$pay_status = 2;
|
||||
$pay_time = date('Y-m-d H:i:s', strtotime($message['success_time']));// 支付时间
|
||||
if ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3) {
|
||||
// 专家-公益
|
||||
$data['inquiry_status'] = 3;// 3:待接诊
|
||||
$inquiry_status = 3;// 3:待接诊
|
||||
} elseif ($order_inquiry['inquiry_type'] == 2 || $order_inquiry['inquiry_type'] == 4) {
|
||||
// 快速-购药
|
||||
$data['inquiry_status'] = 2;// 2:待分配
|
||||
$inquiry_status = 2;// 2:待分配
|
||||
}
|
||||
} elseif ($message['trade_state'] == "CLOSED") {
|
||||
// 已关闭
|
||||
$data['inquiry_pay_status'] = 6;
|
||||
$pay_status = 6;
|
||||
} elseif ($message['trade_state'] == "REVOKED") {
|
||||
// 已撤销(付款码支付)
|
||||
$data['inquiry_pay_status'] = 7;
|
||||
$pay_status = 7;
|
||||
} elseif ($message['trade_state'] == "USERPAYING") {
|
||||
// 用户支付中(付款码支付)
|
||||
$data['inquiry_pay_status'] = 3;
|
||||
$pay_status = 3;
|
||||
} elseif ($message['trade_state'] == "PAYERROR") {
|
||||
// 支付失败(其他原因,如银行返回失败)
|
||||
$data['inquiry_pay_status'] = 4;
|
||||
$pay_status = 4;
|
||||
}else{
|
||||
Db::rollBack();
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 修改问诊订单表
|
||||
$data = array();
|
||||
if (isset($inquiry_status)){
|
||||
$data['inquiry_status'] = $inquiry_status;
|
||||
}
|
||||
$data['inquiry_pay_status'] = $pay_status;
|
||||
if (isset($pay_time)){
|
||||
$data['pay_time'] = $pay_time;
|
||||
}
|
||||
$data['escrow_trade_no'] = $message['transaction_id'];
|
||||
$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'] = $pay_status;
|
||||
if (isset($pay_time)){
|
||||
$data['pay_time'] = $pay_time;
|
||||
}
|
||||
$data['escrow_trade_no'] = $message['transaction_id'];
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
||||
|
||||
$params = array();
|
||||
$params['order_no'] = $order_inquiry['inquiry_no'];
|
||||
Order::edit($params,$data);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("问诊微信支付回调数据处理失败:" . $e->getMessage());
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error($e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理成功");
|
||||
Log::getInstance()->info("问诊微信支付回调数据处理成功,开始分配医生/发送问诊消息");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->info("成功");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->info("分配医生/发送问诊消息");
|
||||
|
||||
try {
|
||||
if ($message['trade_state'] == "SUCCESS") {
|
||||
@ -179,21 +218,21 @@ class CallBackController extends AbstractController
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Log::getInstance()->info("加入分配医生队列失败");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error("加入分配医生队列失败");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
Log::getInstance()->info("加入分配医生队列成功");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->info("加入分配医生队列成功");
|
||||
} elseif ($order_inquiry['inquiry_type'] == 1 || $order_inquiry['inquiry_type'] == 3) {
|
||||
// 专家-公益,发送im消息
|
||||
Log::getInstance()->info("开始发送im消息");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->info("开始发送im消息");
|
||||
|
||||
// 获取订单医生数据
|
||||
$params = array();
|
||||
$params['doctor_id'] = $order_inquiry['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)) {
|
||||
Log::getInstance()->info("医生数据错误");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error("医生数据错误");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -217,16 +256,16 @@ class CallBackController extends AbstractController
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$producer->produce($message);
|
||||
|
||||
Log::getInstance()->info("发送im消息成功");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->info("发送im消息成功");
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("问诊微信支付回调数据处理成功,分配医生/发送问诊消息失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->error("问诊微信支付回调数据处理成功,分配医生/发送问诊消息失败:" . $e->getMessage());
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
Log::getInstance()->info("问诊微信支付回调处理成功");
|
||||
Log::getInstance("CallBack-wxPayInquirySuccess")->info("问诊微信支付回调处理成功");
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
@ -240,8 +279,6 @@ class CallBackController extends AbstractController
|
||||
*/
|
||||
public function wxPayInquiryRefundCallBack(): ResponseInterface
|
||||
{
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1, 1);
|
||||
@ -251,119 +288,73 @@ class CallBackController extends AbstractController
|
||||
// 获取解密消息
|
||||
$message = $server->getDecryptedMessage();
|
||||
if (empty($message)) {
|
||||
Db::rollBack();
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("微信退款回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->info(json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])) {
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("微信退款回调数据错误");
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("微信退款回调数据错误");
|
||||
return $server->serve();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error($e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 验证订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $message['out_trade_no'];
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("非法订单");
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("非法订单");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_inquiry['inquiry_status'] == 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("订单状态错误:当前为" . $order_inquiry['inquiry_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("订单状态错误:当前为" . $order_inquiry['inquiry_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单退款状态
|
||||
if ($order_inquiry['inquiry_refund_status'] == 3) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("订单退款状态错误:当前为" . $order_inquiry['inquiry_refund_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("订单退款状态错误:当前为" . $order_inquiry['inquiry_refund_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if (in_array($order_inquiry['inquiry_pay_status'], [1, 3, 4, 5, 6, 7])) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("订单支付状态错误:当前为" . $order_inquiry['inquiry_pay_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("订单支付状态错误:当前为" . $order_inquiry['inquiry_pay_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 退款状态
|
||||
if ($message['refund_status'] == "SUCCESS") {
|
||||
// 退款成功
|
||||
$inquiry_refund_status = 3;
|
||||
} elseif ($message['refund_status'] == "CLOSED") {
|
||||
// 退款关闭
|
||||
$inquiry_refund_status = 5;
|
||||
} elseif ($message['refund_status'] == "ABNORMAL") {
|
||||
// 退款异常
|
||||
$inquiry_refund_status = 6;
|
||||
}
|
||||
|
||||
if (empty($inquiry_refund_status)) {
|
||||
// 错误,无退款状态
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->info("订单支付状态错误:未接收到退款状态");
|
||||
return $this->wxPayErrorReturn("退款状态错误");
|
||||
}
|
||||
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
// 修改退款订单
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
$data['success_time'] = $message['success_time'];
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiryRefund::edit($params, $data);
|
||||
|
||||
// 恢复优惠卷
|
||||
if ($inquiry_refund_status == 3) {
|
||||
if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0) {
|
||||
// 获取该订单全部优惠卷数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_coupons = OrderInquiryCoupon::getList($params);
|
||||
if (!empty($order_inquiry_coupons)){
|
||||
$userCouponService = new UserCouponService();
|
||||
foreach ($order_inquiry_coupons as $order_inquiry_coupon){
|
||||
// 退还优惠卷
|
||||
$userCouponService->returnUserCoupon($order_inquiry_coupon['user_coupon_id']);
|
||||
|
||||
try {
|
||||
// 发送站内消息-优惠卷退还
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id']);
|
||||
$MessagePush->patientRefundCoupon($order_inquiry_coupon['coupon_name']);
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("CallBackController-wxPayInquiryRefundCallBack")->error("推送消息失败:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理退款回调结果
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefundResult($order_inquiry['inquiry_no'],$message['refund_status'],$message['success_time']);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("微信退款回调处理成功,推送消息");
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->info("微信退款回调处理成功,推送消息");
|
||||
|
||||
// 发送推送消息
|
||||
if ($inquiry_refund_status == 3) {
|
||||
if ($message['refund_status'] == "SUCCESS") {
|
||||
try {
|
||||
// 发送站内、订阅、短信消息-问诊服务退款成功
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'], $order_inquiry['order_inquiry_id']);
|
||||
@ -372,7 +363,7 @@ class CallBackController extends AbstractController
|
||||
$MessagePush->refundInquirySuccess($order_inquiry['cancel_reason']);
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("微信退款回调处理成功,推送消息失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("微信退款回调处理成功,推送消息失败:" . $e->getMessage());
|
||||
return $server->serve();
|
||||
}
|
||||
}
|
||||
@ -399,19 +390,19 @@ class CallBackController extends AbstractController
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "药品微信支付回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
Log::getInstance()->info("药品微信支付回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->info(json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])) {
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,缺少外部订单号");
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("缺少外部订单号");
|
||||
return $server->serve();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("药品微信支付回调数据处理失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error($e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("药品微信支付回调数据验证成功,执行数据库操作");
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->info("药品微信支付回调数据验证成功,执行数据库操作");
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
@ -422,7 +413,7 @@ class CallBackController extends AbstractController
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,无订单数据");
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("无订单数据");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -430,34 +421,44 @@ class CallBackController extends AbstractController
|
||||
if ($order_product['order_product_status'] != 1) {
|
||||
Db::rollBack();
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,订单状态当前为" . $order_product['order_product_status']);
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("药品微信支付回调数据处理失败,订单状态当前为" . $order_product['order_product_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 支付状态无需验证,如第一次支付失败,会修改支付状态,再次支付时,会出现验证不通过的情况
|
||||
|
||||
// 修改支付状态
|
||||
$data = array();
|
||||
// 处理支付状态
|
||||
if ($message['trade_state'] == "SUCCESS") {
|
||||
// 支付成功
|
||||
$data['order_product_status'] = 2;
|
||||
$data['pay_status'] = 2;// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$data['pay_time'] = date('Y-m-d H:i:s', strtotime($message['success_time']));// 支付时间
|
||||
|
||||
$order_product_status = 2;
|
||||
$pay_status = 2;// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$pay_time = date('Y-m-d H:i:s', strtotime($message['success_time']));// 支付时间
|
||||
} elseif ($message['trade_state'] == "CLOSED") {
|
||||
// 已关闭
|
||||
$data['pay_status'] = 6;
|
||||
$pay_status = 6;
|
||||
} elseif ($message['trade_state'] == "REVOKED") {
|
||||
// 已撤销(付款码支付)
|
||||
$data['pay_status'] = 7;
|
||||
$pay_status = 7;
|
||||
} elseif ($message['trade_state'] == "USERPAYING") {
|
||||
// 用户支付中(付款码支付)
|
||||
$data['pay_status'] = 3;
|
||||
$pay_status = 3;
|
||||
} elseif ($message['trade_state'] == "PAYERROR") {
|
||||
// 支付失败(其他原因,如银行返回失败)
|
||||
$data['pay_status'] = 4;
|
||||
$pay_status = 4;
|
||||
} else {
|
||||
Db::rollBack();
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 修改药品订单表
|
||||
$data = array();
|
||||
if (isset($order_product_status)){
|
||||
$data['order_product_status'] = $order_product_status;
|
||||
}
|
||||
if (isset($pay_time)){
|
||||
$data['pay_time'] = $pay_time;
|
||||
}
|
||||
$data['pay_status'] = $pay_status;
|
||||
$data['escrow_trade_no'] = $message['transaction_id'];
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', time());
|
||||
|
||||
@ -465,24 +466,37 @@ class CallBackController extends AbstractController
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
OrderProduct::edit($params, $data);
|
||||
|
||||
// 修改订单表
|
||||
$data = array();
|
||||
$data['pay_status'] = $pay_status;
|
||||
if (isset($pay_time)){
|
||||
$data['pay_time'] = $pay_time;
|
||||
}
|
||||
$data['escrow_trade_no'] = $message['transaction_id'];
|
||||
$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);
|
||||
|
||||
// 获取订单商品订单列表
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
$order_product_item = OrderProductItem::getList($params);
|
||||
if (empty($order_product_item)) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("药品微信支付回调数据处理失败,未查询到对应订单商品订单列表");
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("未查询到对应订单商品订单列表");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("药品微信支付回调数据处理失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("药品微信支付回调数据处理失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->error("药品微信支付回调数据处理成功");
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("药品微信支付回调数据处理成功");
|
||||
|
||||
try {
|
||||
// 再次发放优惠卷数据
|
||||
@ -514,10 +528,10 @@ class CallBackController extends AbstractController
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Log::getInstance()->error("再次发放优惠卷失败");
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("再次发放优惠卷失败");
|
||||
}
|
||||
|
||||
Log::getInstance()->info("再次发放优惠卷成功");
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->info("再次发放优惠卷成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -525,7 +539,7 @@ class CallBackController extends AbstractController
|
||||
}
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance()->error("药品微信支付回调数据处理失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayProductSuccess")->error("药品微信支付回调数据处理失败:" . $e->getMessage());
|
||||
}
|
||||
return $server->serve();
|
||||
}
|
||||
@ -539,8 +553,6 @@ class CallBackController extends AbstractController
|
||||
*/
|
||||
public function wxPayProductRefundCallBack(): ResponseInterface
|
||||
{
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1, 2);
|
||||
@ -554,20 +566,27 @@ class CallBackController extends AbstractController
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("微信退款回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->info(json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])) {
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("药品微信退款回调数据处理失败,缺少外部订单号");
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error("缺少外部订单号");
|
||||
return $server->serve();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error($e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 查询药品订单
|
||||
$params = array();
|
||||
$params['order_product_no'] = $message['out_trade_no'];
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("药品微信退款回调数据处理失败,无订单数据");
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error("无订单数据");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -577,100 +596,47 @@ class CallBackController extends AbstractController
|
||||
$user_patient = UserPatient::getOne($params);
|
||||
if (empty($user_patient)) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("药品微信退款回调数据处理失败,无患者数据");
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->info("无患者数据");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_product['order_product_status'] == 1) {
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("药品微信退款回调数据处理失败,订单状态错误:当前为" . $order_product['order_product_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error("药品微信退款回调数据处理失败,订单状态错误:当前为" . $order_product['order_product_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单退款状态
|
||||
if ($order_product['refund_status'] == 3) {
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("药品微信退款回调数据处理失败,订单退款状态为" . $order_product['refund_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error("药品微信退款回调数据处理失败,订单退款状态为" . $order_product['refund_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if (in_array($order_product['pay_status'], [1, 3, 4, 5, 6, 7])) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->error("药品微信退款回调数据处理失败:订单未支付");
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error("订单未支付");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 退款状态
|
||||
if ($message['refund_status'] == "SUCCESS") {
|
||||
// 退款成功
|
||||
$refund_status = 3;
|
||||
} elseif ($message['refund_status'] == "CLOSED") {
|
||||
// 退款关闭
|
||||
$refund_status = 5;
|
||||
} elseif ($message['refund_status'] == "ABNORMAL") {
|
||||
// 退款异常
|
||||
$refund_status = 6;
|
||||
}
|
||||
|
||||
if (empty($refund_status)) {
|
||||
// 错误,无退款状态
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->error("药品微信退款回调数据处理失败:订单未支付");
|
||||
return $this->wxPayErrorReturn("退款状态错误");
|
||||
}
|
||||
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
OrderProduct::edit($params, $data);
|
||||
|
||||
// 修改退款订单
|
||||
$data = array();
|
||||
$data['product_refund_status'] = $refund_status;
|
||||
$data['success_time'] = $message['success_time'];
|
||||
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
OrderProductRefund::edit($params, $data);
|
||||
|
||||
// 恢复优惠卷
|
||||
if ($refund_status == 3) {
|
||||
if (!empty($order_product['coupon_amount_total']) && $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)){
|
||||
$userCouponService = new UserCouponService();
|
||||
foreach ($order_product_coupons as $order_product_coupon){
|
||||
// 退还优惠卷
|
||||
$userCouponService->returnUserCoupon($order_product_coupon['user_coupon_id']);
|
||||
|
||||
// 发送站内消息-优惠卷退还
|
||||
try {
|
||||
$MessagePush = new MessagePush($user_patient['user_id']);
|
||||
$MessagePush->patientRefundCoupon($order_product_coupon['coupon_name']);
|
||||
}catch (\Throwable $e){
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->error("推送消息失败:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 处理退款回调结果
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefundResult($order_product['order_product_no'],$message['refund_status'],$message['success_time']);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->error("药品微信退款回调数据处理失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error("药品微信退款回调数据处理失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->info("药品微信退款回调数据处理成功");
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->info("药品微信退款回调数据处理成功");
|
||||
|
||||
// 发送推送消息
|
||||
try {
|
||||
@ -685,11 +651,10 @@ class CallBackController extends AbstractController
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance("CallBackController-wxPayProductRefundCallBack")->error("微信退款回调处理成功,推送消息失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayProductRefund")->error("微信退款回调处理成功,推送消息失败:" . $e->getMessage());
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 告知处方平台
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -1159,54 +1124,75 @@ class CallBackController extends AbstractController
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "问诊微信支付回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
Log::getInstance()->info("检测微信支付回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->info(json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])) {
|
||||
Log::getInstance()->info("检测微信支付回调数据处理失败,缺少外部订单号");
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->error("缺少外部订单号");
|
||||
return $server->serve();
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
// 验证失败
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->error($e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 查询订单
|
||||
$params = array();
|
||||
$params['detection_no'] = $message['out_trade_no'];
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)) {
|
||||
Log::getInstance()->info("检测微信支付回调数据处理失败,无订单数据");
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->info("无订单数据");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_detection['detection_status'] != 1) {
|
||||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
Log::getInstance()->info("检测微信支付回调数据处理失败,订单状态当前为" . $order_detection['detection_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->error("检测微信支付回调数据处理失败,订单状态当前为" . $order_detection['detection_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 支付状态无需验证,如第一次支付失败,会修改支付状态,再次支付时,会出现验证不通过的情况
|
||||
|
||||
// 修改支付状态
|
||||
$data = array();
|
||||
// 处理支付状态
|
||||
if ($message['trade_state'] == "SUCCESS") {
|
||||
// 支付成功
|
||||
$data['detection_pay_status'] = 2;
|
||||
$data['pay_time'] = date('Y-m-d H:i:s', strtotime($message['success_time']));// 支付时间
|
||||
$data['detection_status'] = 2;// 2:待绑定
|
||||
$pay_status = 2;
|
||||
$pay_time = date('Y-m-d H:i:s', strtotime($message['success_time']));// 支付时间
|
||||
$detection_status = 2;// 2:待绑定
|
||||
if (empty($message['amount'])){
|
||||
Log::getInstance()->error("检测微信支付回调数据处理失败:无支付金额");
|
||||
return $this->wxPayErrorReturn("检测微信支付回调数据处理失败:无支付金额");
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->error("无支付金额");
|
||||
return $this->wxPayErrorReturn("无支付金额");
|
||||
}
|
||||
} elseif ($message['trade_state'] == "CLOSED") {
|
||||
// 已关闭
|
||||
$data['detection_pay_status'] = 6;
|
||||
$pay_status = 6;
|
||||
} elseif ($message['trade_state'] == "REVOKED") {
|
||||
// 已撤销(付款码支付)
|
||||
$data['detection_pay_status'] = 7;
|
||||
$pay_status = 7;
|
||||
} elseif ($message['trade_state'] == "USERPAYING") {
|
||||
// 用户支付中(付款码支付)
|
||||
$data['detection_pay_status'] = 3;
|
||||
$pay_status = 3;
|
||||
} elseif ($message['trade_state'] == "PAYERROR") {
|
||||
// 支付失败(其他原因,如银行返回失败)
|
||||
$data['detection_pay_status'] = 4;
|
||||
$pay_status = 4;
|
||||
} else {
|
||||
Db::rollBack();
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['detection_pay_status'] = $pay_status;
|
||||
if (isset($detection_status)){
|
||||
$data['detection_status'] = $detection_status;
|
||||
}
|
||||
if (isset($pay_time)){
|
||||
$data['pay_time'] = $pay_time;
|
||||
}
|
||||
|
||||
$data['escrow_trade_no'] = $message['transaction_id'];
|
||||
@ -1215,13 +1201,29 @@ class CallBackController extends AbstractController
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
|
||||
// 修改订单表
|
||||
$data = array();
|
||||
$data['pay_status'] = $pay_status;
|
||||
if (isset($pay_time)){
|
||||
$data['pay_time'] = $pay_time;
|
||||
}
|
||||
$data['escrow_trade_no'] = $message['transaction_id'];
|
||||
$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 (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance()->error("问诊微信支付回调数据处理失败:" . $e->getMessage());
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->error("问诊微信支付回调数据处理失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("检测微信支付回调处理成功");
|
||||
Log::getInstance("CallBack-xPayDetectionSuccess")->info("检测微信支付回调处理成功");
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
@ -1235,8 +1237,6 @@ class CallBackController extends AbstractController
|
||||
*/
|
||||
public function wxPayDetectionRefundCallBack(): ResponseInterface
|
||||
{
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 处理支付结果事件
|
||||
$WechatPay = new WechatPay(1, 1);
|
||||
@ -1250,87 +1250,67 @@ class CallBackController extends AbstractController
|
||||
return $this->response->withStatus(500)->withBody(new SwooleStream(strval(json_encode(['code' => 'ERROR', 'message' => "回调数据为空"], JSON_UNESCAPED_UNICODE))));
|
||||
}
|
||||
|
||||
Log::getInstance()->info("微信退款回调数据:" . json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->info(json_encode($message->toArray(), JSON_UNESCAPED_UNICODE));
|
||||
|
||||
if (empty($message['out_trade_no'])) {
|
||||
Log::getInstance()->info("微信退款回调数据错误");
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->error("缺少外部订单号");
|
||||
return $server->serve();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->error($e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 验证订单数据
|
||||
$params = array();
|
||||
$params['detection_no'] = $message['out_trade_no'];
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)) {
|
||||
Log::getInstance()->info("非法订单");
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->error("非法订单");
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单状态
|
||||
if ($order_detection['detection_status'] == 1) {
|
||||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
Log::getInstance()->info("订单状态错误:当前为" . $order_detection['detection_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->error("订单状态错误:当前为" . $order_detection['detection_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单退款状态
|
||||
if ($order_detection['detection_refund_status'] == 3) {
|
||||
// 检测订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
Log::getInstance()->info("订单退款状态错误:当前为" . $order_detection['detection_refund_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->error("订单退款状态错误:当前为" . $order_detection['detection_refund_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 验证订单支付状态
|
||||
if (in_array($order_detection['detection_pay_status'], [1, 3, 4, 5, 6, 7])) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
Log::getInstance()->info("订单支付状态错误:当前为" . $order_detection['detection_pay_status']);
|
||||
Db::rollBack();
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->error("订单支付状态错误:当前为" . $order_detection['detection_pay_status']);
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
// 退款状态
|
||||
if ($message['refund_status'] == "SUCCESS") {
|
||||
// 退款成功
|
||||
$detection_refund_status = 3;
|
||||
} elseif ($message['refund_status'] == "CLOSED") {
|
||||
// 退款关闭
|
||||
$detection_refund_status = 5;
|
||||
} elseif ($message['refund_status'] == "ABNORMAL") {
|
||||
// 退款异常
|
||||
$detection_refund_status = 6;
|
||||
}
|
||||
|
||||
if (empty($detection_refund_status)) {
|
||||
// 错误,无退款状态
|
||||
Log::getInstance()->error("队列执行失败原因:订单未支付");
|
||||
return $this->wxPayErrorReturn("退款状态错误");
|
||||
}
|
||||
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['detection_refund_status'] = $detection_refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
|
||||
// 修改退款订单
|
||||
$data = array();
|
||||
$data['detection_refund_status'] = $detection_refund_status;
|
||||
$data['success_time'] = $message['success_time'];
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetectionRefund::edit($params, $data);
|
||||
// 处理退款回调结果
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefundResult($order_detection['detection_no'],$message['refund_status'],$message['success_time']);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 验证失败
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->error("微信支付回调数据验证失败:" . $e->getMessage());
|
||||
return $this->wxPayErrorReturn($e->getMessage());
|
||||
}
|
||||
|
||||
Log::getInstance()->info("微信退款回调处理成功");
|
||||
Log::getInstance("CallBack-wxPayDetectionRefund")->info("微信退款回调处理成功");
|
||||
|
||||
return $server->serve();
|
||||
}
|
||||
|
||||
@ -70,8 +70,6 @@ class PatientOrderController extends AbstractController
|
||||
/**
|
||||
* 问诊订单取消支付
|
||||
* @return ResponseInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function putPatientInquiryOrderCancelPay(): ResponseInterface
|
||||
{
|
||||
|
||||
@ -281,22 +281,6 @@ class TestController extends AbstractController
|
||||
dump($result);
|
||||
}
|
||||
|
||||
// 退款
|
||||
public function refund(){
|
||||
$out_trade_no = $this->request->input('out_trade_no');
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $out_trade_no;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)){
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 需退款
|
||||
$inquiryService = new InquiryService();
|
||||
$inquiryService->inquiryRefund($out_trade_no, "取消问诊");
|
||||
return success();
|
||||
}
|
||||
|
||||
// 获取云证书-线上
|
||||
public function test_14(){
|
||||
$CaOnline = new CaOnline();
|
||||
|
||||
81
app/Model/DoctorIncomeRecord.php
Normal file
81
app/Model/DoctorIncomeRecord.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $income_record_id 主键id
|
||||
* @property int $doctor_id 医生id
|
||||
* @property int $order_id 订单id
|
||||
* @property string $start_time 开始时间
|
||||
* @property string $end_time 结束时间
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class DoctorIncomeRecord extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'doctor_income_record';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['income_record_id', 'doctor_id', 'order_id', 'start_time', 'end_time', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "income_record_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params, array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return DoctorIncomeRecord|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public static function addDoctorIncomeRecord(array $data): \Hyperf\Database\Model\Model|DoctorIncomeRecord
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
|
||||
}
|
||||
95
app/Model/Order.php
Normal file
95
app/Model/Order.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $order_id 主键id
|
||||
* @property int $user_id 用户id-患者
|
||||
* @property int $patient_id 患者id
|
||||
* @property int $doctor_id 医生id(存在为null的情况)
|
||||
* @property int $order_type 订单类型(1:问诊订单 2:药品订单 3:检测订单 4:随访包订单 5:健康包订单)
|
||||
* @property int $is_delete 删除状态(0:否 1:是)
|
||||
* @property int $pay_channel 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||||
* @property int $pay_status 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
* @property string $pay_time 支付时间
|
||||
* @property int $refund_status 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
* @property string $order_no 系统订单编号
|
||||
* @property string $escrow_trade_no 第三方支付流水号
|
||||
* @property string $amount_total 订单金额
|
||||
* @property string $coupon_amount_total 优惠卷总金额
|
||||
* @property string $payment_amount_total 实际付款金额
|
||||
* @property int $cancel_status 取消状态(0:否 1:是)
|
||||
* @property string $cancel_time 订单取消时间
|
||||
* @property string $cancel_remarks 取消订单备注
|
||||
* @property string $order_remarks 订单备注
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
*/
|
||||
class Order extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'order';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_id', 'user_id', 'patient_id', 'doctor_id', 'order_type', 'is_delete', 'pay_channel', 'pay_status', 'pay_time', 'refund_status', 'order_no', 'escrow_trade_no', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'cancel_status', 'cancel_time', 'cancel_remarks', 'order_remarks', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params, array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return Order|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public static function addOrder(array $data): \Hyperf\Database\Model\Model|Order
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
|
||||
}
|
||||
80
app/Model/OrderCoupon.php
Normal file
80
app/Model/OrderCoupon.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $order_coupon_id 主键id
|
||||
* @property int $order_id 订单id
|
||||
* @property int $user_coupon_id 用户优惠卷表id
|
||||
* @property string $coupon_name 优惠卷名称
|
||||
* @property string $coupon_use_price 优惠卷使用金额
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class OrderCoupon extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'order_coupon';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_coupon_id', 'order_id', 'user_coupon_id', 'coupon_name', 'coupon_use_price', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_coupon_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params, array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return OrderCoupon|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public static function addOrderCoupon(array $data): \Hyperf\Database\Model\Model|OrderCoupon
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,7 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $order_detection_id 主键id
|
||||
* @property int $order_id 订单id
|
||||
* @property int $user_id 用户id-患者
|
||||
* @property int $patient_id 患者id
|
||||
* @property int $doctor_id 医生id
|
||||
@ -58,7 +59,7 @@ class OrderDetection extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_detection_id', 'user_id', 'patient_id', 'doctor_id', 'family_id', 'detection_project_id', 'purpose_id', 'detection_organ_id', 'order_inquiry_id', 'detection_status', 'is_delete', 'detection_refund_status', 'detection_pay_channel', 'detection_pay_status', 'detection_no', 'escrow_trade_no', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'pay_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'detection_bar_code', 'detection_pic', 'detection_time', 'detection_result_pdf', 'detection_result_date', 'created_at', 'updated_at'];
|
||||
protected array $fillable = ['order_detection_id', 'order_id', 'user_id', 'patient_id', 'doctor_id', 'family_id', 'detection_project_id', 'purpose_id', 'detection_organ_id', 'order_inquiry_id', 'detection_status', 'is_delete', 'detection_refund_status', 'detection_pay_channel', 'detection_pay_status', 'detection_no', 'escrow_trade_no', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'pay_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'detection_bar_code', 'detection_pic', 'detection_time', 'detection_result_pdf', 'detection_result_date', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_detection_id";
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $order_inquiry_id 主键id
|
||||
* @property int $order_id 订单id
|
||||
* @property int $user_id 用户id-患者
|
||||
* @property int $patient_id 患者id
|
||||
* @property int $doctor_id 医生id(未分配时为null)
|
||||
@ -63,7 +64,7 @@ class OrderInquiry extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_inquiry_id', 'user_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', 'coupon_amount_total', 'payment_amount_total', 'pay_time', 'reception_time', 'complete_time', 'finish_time', 'statistics_status', 'statistics_time', 'is_withdrawal', 'withdrawal_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'times_number', 'duration', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'created_at', 'updated_at'];
|
||||
protected array $fillable = ['order_inquiry_id', 'order_id', 'user_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', 'coupon_amount_total', 'payment_amount_total', 'pay_time', 'reception_time', 'complete_time', 'finish_time', 'statistics_status', 'statistics_time', 'is_withdrawal', 'withdrawal_time', 'cancel_time', 'cancel_reason', 'cancel_remarks', 'times_number', 'duration', 'patient_name', 'patient_name_mask', 'patient_sex', 'patient_age', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_inquiry_id";
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property int $order_product_id 主键id
|
||||
* @property int $order_inquiry_id 订单-问诊id
|
||||
* @property int $order_prescription_id 订单-处方id
|
||||
* @property int $order_id 订单id
|
||||
* @property int $doctor_id 医生id
|
||||
* @property int $patient_id 患者id
|
||||
* @property int $family_id 家庭成员id(就诊用户)
|
||||
@ -55,10 +56,10 @@ use Hyperf\Snowflake\Concern\Snowflake;
|
||||
* @property string $consignee_tel_mask 收货人电话(掩码)
|
||||
* @property \Carbon\Carbon $created_at 创建时间
|
||||
* @property \Carbon\Carbon $updated_at 修改时间
|
||||
* @property-read OrderPrescription|null $OrderPrescription
|
||||
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionIcd[]|null $OrderPrescriptionIcd
|
||||
* @property-read \Hyperf\Database\Model\Collection|OrderProductItem[]|null $OrderProductItem
|
||||
* @property-read OrderPrescription|null $OrderPrescription
|
||||
* @property-read PatientFamily|null $PatientFamily
|
||||
* @property-read \Hyperf\Database\Model\Collection|OrderPrescriptionIcd[]|null $OrderPrescriptionIcd
|
||||
*/
|
||||
class OrderProduct extends Model
|
||||
{
|
||||
@ -72,7 +73,7 @@ class OrderProduct extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
|
||||
protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'order_id', 'doctor_id', 'patient_id', 'family_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'is_delete', 'cancel_reason', 'amount_total', 'coupon_amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'logistics_company_code', 'sub_logistics_status', 'delivery_time', 'pay_time', 'remarks', 'refund_status', 'cancel_time', 'cancel_remarks', 'report_pre_status', 'report_pre_time', 'report_pre_fail_reason', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_product_id";
|
||||
|
||||
|
||||
86
app/Model/OrderRefund.php
Normal file
86
app/Model/OrderRefund.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Hyperf\Database\Model\Collection;
|
||||
use Hyperf\Snowflake\Concern\Snowflake;
|
||||
|
||||
/**
|
||||
* @property int $order_refund_id 主键id
|
||||
* @property int $order_id 订单id
|
||||
* @property int $patient_id 患者id
|
||||
* @property string $order_no 系统订单编号
|
||||
* @property string $refund_no 系统退款编号
|
||||
* @property string $refund_id 第三方退款单号
|
||||
* @property int $refund_status 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
* @property string $refund_total 退款金额
|
||||
* @property string $refund_reason 退款原因
|
||||
* @property string $success_time 退款成功时间
|
||||
* @property Carbon $created_at 创建时间
|
||||
* @property Carbon $updated_at 修改时间
|
||||
*/
|
||||
class OrderRefund extends Model
|
||||
{
|
||||
use Snowflake;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
protected ?string $table = 'order_refund';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected array $fillable = ['order_refund_id', 'order_id', 'patient_id', 'order_no', 'refund_no', 'refund_id', 'refund_status', 'refund_total', 'refund_reason', 'success_time', 'created_at', 'updated_at'];
|
||||
|
||||
protected string $primaryKey = "order_refund_id";
|
||||
|
||||
/**
|
||||
* 获取信息-单条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getOne(array $params, array $fields = ['*']): object|null
|
||||
{
|
||||
return self::where($params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条
|
||||
* @param array $params
|
||||
* @param array $fields
|
||||
* @return Collection|array
|
||||
*/
|
||||
public static function getList(array $params, array $fields = ['*']): Collection|array
|
||||
{
|
||||
return self::where($params)->get($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return OrderRefund|\Hyperf\Database\Model\Model
|
||||
*/
|
||||
public static function addOrderRefund(array $data): \Hyperf\Database\Model\Model|OrderRefund
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
|
||||
}
|
||||
@ -13,6 +13,7 @@ use App\Model\BasicNation;
|
||||
use App\Model\DetectionProject;
|
||||
use App\Model\DetectionProjectPurpose;
|
||||
use App\Model\DiseaseClassDetection;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderDetection;
|
||||
use App\Model\OrderDetectionCase;
|
||||
use App\Model\OrderDetectionRefund;
|
||||
@ -40,13 +41,13 @@ class DetectionService extends BaseService
|
||||
*/
|
||||
public function getDetectionProjectList(): array
|
||||
{
|
||||
$company_id = $this->request->input("company_id",1);
|
||||
$company_id = $this->request->input("company_id", 1);
|
||||
|
||||
// 获取合作公司数据
|
||||
$params = array();
|
||||
$params['company_id'] = $company_id;
|
||||
$basic_company = BasicCompany::getOne($params);
|
||||
if (empty($basic_company)){
|
||||
if (empty($basic_company)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -54,11 +55,11 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['company_id'] = $company_id;
|
||||
$detection_projects = DetectionProject::getList($params);
|
||||
if (empty($detection_projects)){
|
||||
if (empty($detection_projects)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
foreach ($detection_projects as &$value){
|
||||
foreach ($detection_projects as &$value) {
|
||||
$value['img_path'] = addAliyunOssWebsite($value['img_path']);
|
||||
}
|
||||
|
||||
@ -71,14 +72,14 @@ class DetectionService extends BaseService
|
||||
*/
|
||||
public function getDetectionProject(): array
|
||||
{
|
||||
$company_id = $this->request->input("company_id",1);
|
||||
$detection_project_id = $this->request->route('detection_project_id',1);
|
||||
$company_id = $this->request->input("company_id", 1);
|
||||
$detection_project_id = $this->request->route('detection_project_id', 1);
|
||||
|
||||
// 获取合作公司数据
|
||||
$params = array();
|
||||
$params['company_id'] = $company_id;
|
||||
$basic_company = BasicCompany::getOne($params);
|
||||
if (empty($basic_company)){
|
||||
if (empty($basic_company)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['detection_project_id'] = $detection_project_id;
|
||||
$detection_project = DetectionProject::getOne($params);
|
||||
if (empty($detection_project)){
|
||||
if (empty($detection_project)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -102,7 +103,7 @@ class DetectionService extends BaseService
|
||||
public function getDetectionDoctorList(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
$company_id = $this->request->input("company_id",1);
|
||||
$company_id = $this->request->input("company_id", 1);
|
||||
$province_id = $this->request->input("province_id");
|
||||
$city_id = $this->request->input("city_id");
|
||||
$county_id = $this->request->input("county_id");
|
||||
@ -111,43 +112,43 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['company_id'] = $company_id;
|
||||
$basic_company = BasicCompany::getOne($params);
|
||||
if (empty($basic_company)){
|
||||
if (empty($basic_company)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 搜索数据
|
||||
$hospital_params = array();
|
||||
|
||||
if (!empty($province_id)){
|
||||
if (!empty($province_id)) {
|
||||
$params = array();
|
||||
$params['area_id'] = $province_id;
|
||||
$params['area_type'] = 2;
|
||||
$area_province = Area::getOne($params);
|
||||
if (!empty($area_province)){
|
||||
if (!empty($area_province)) {
|
||||
// 搜索条件
|
||||
$hospital_params['province_id'] = $area_province['area_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($city_id)){
|
||||
if (!empty($city_id)) {
|
||||
$params = array();
|
||||
$params['area_id'] = $city_id;
|
||||
$params['parent_id'] = $province_id;
|
||||
$params['area_type'] = 3;
|
||||
$area_city = Area::getOne($params);
|
||||
if (!empty($area_city)){
|
||||
if (!empty($area_city)) {
|
||||
// 搜索条件
|
||||
$hospital_params['city_id'] = $area_city['area_id'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($county_id)){
|
||||
if (!empty($county_id)) {
|
||||
$params = array();
|
||||
$params['area_id'] = $county_id;
|
||||
$params['parent_id'] = $city_id;
|
||||
$params['area_type'] = 4;
|
||||
$area_county = Area::getOne($params);
|
||||
if (!empty($area_county)){
|
||||
if (!empty($area_county)) {
|
||||
// 搜索条件
|
||||
$hospital_params['county_id'] = $area_county['area_id'];
|
||||
}
|
||||
@ -168,10 +169,10 @@ class DetectionService extends BaseService
|
||||
"doctor_title",
|
||||
"hospital_id",
|
||||
];
|
||||
$user_doctors = UserDoctor::getDiagnoCoopDoctorList($params,$hospital_params,$fields);
|
||||
if (!empty($user_doctors)){
|
||||
foreach ($user_doctors as &$value){
|
||||
if (!empty($value['Hospital'])){
|
||||
$user_doctors = UserDoctor::getDiagnoCoopDoctorList($params, $hospital_params, $fields);
|
||||
if (!empty($user_doctors)) {
|
||||
foreach ($user_doctors as &$value) {
|
||||
if (!empty($value['Hospital'])) {
|
||||
$value['hospital_name'] = $value['Hospital']['hospital_name'];
|
||||
}
|
||||
|
||||
@ -190,13 +191,13 @@ class DetectionService extends BaseService
|
||||
*/
|
||||
public function getDetectionProjectPurposeList(): array
|
||||
{
|
||||
$detection_project_id = $this->request->input("detection_project_id",1);
|
||||
$detection_project_id = $this->request->input("detection_project_id", 1);
|
||||
|
||||
// 获取项目数据
|
||||
$params = array();
|
||||
$params['detection_project_id'] = $detection_project_id;
|
||||
$detection_project_purpose = DetectionProjectPurpose::getList($params);
|
||||
if (empty($detection_project_purpose)){
|
||||
if (empty($detection_project_purpose)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -238,7 +239,7 @@ class DetectionService extends BaseService
|
||||
$params['family_id'] = $request_params['family_id'];
|
||||
$params['detection_project_id'] = $request_params['detection_project_id'];
|
||||
$order_detection = OrderDetection::getNotFinishedOrderDetectionOne($params);
|
||||
if (!empty($order_detection)){
|
||||
if (!empty($order_detection)) {
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "当前患者存在未完成的检测订单";
|
||||
$result['data']['order_no'] = $order_detection['detection_no'];
|
||||
@ -249,37 +250,37 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['nation_id'] = $request_params['nation_id'];
|
||||
$nation = BasicNation::getOne($params);
|
||||
if (empty($nation)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"民族选择错误");
|
||||
if (empty($nation)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "民族选择错误");
|
||||
}
|
||||
|
||||
// 检测疾病分类
|
||||
$detection_disease_class_ids = explode(',',$request_params['detection_disease_class_ids']);
|
||||
if (count($detection_disease_class_ids) > 3){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"既往病史最多可选三项");
|
||||
$detection_disease_class_ids = explode(',', $request_params['detection_disease_class_ids']);
|
||||
if (count($detection_disease_class_ids) > 3) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "既往病史最多可选三项");
|
||||
}
|
||||
|
||||
$detection_disease_class_names = "";
|
||||
|
||||
foreach ($detection_disease_class_ids as $value){
|
||||
foreach ($detection_disease_class_ids as $value) {
|
||||
$params = array();
|
||||
$params['id'] = $value;
|
||||
$disease_class_detection = DiseaseClassDetection::getOne($params);
|
||||
if (empty($disease_class_detection)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"既往病史错误");
|
||||
if (empty($disease_class_detection)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "既往病史错误");
|
||||
}
|
||||
|
||||
if ($disease_class_detection['status'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"既往病史错误");
|
||||
if ($disease_class_detection['status'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "既往病史错误");
|
||||
}
|
||||
|
||||
if ($disease_class_detection['enable'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"既往病史错误");
|
||||
if ($disease_class_detection['enable'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "既往病史错误");
|
||||
}
|
||||
|
||||
if (empty($detection_disease_class_names)){
|
||||
if (empty($detection_disease_class_names)) {
|
||||
$detection_disease_class_names = $disease_class_detection['name'];
|
||||
}else{
|
||||
} else {
|
||||
$detection_disease_class_names = $detection_disease_class_names . ',' . $disease_class_detection['name'];
|
||||
}
|
||||
}
|
||||
@ -288,12 +289,12 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['detection_project_id'] = $request_params['detection_project_id'];
|
||||
$detection_project = DetectionProject::getOne($params);
|
||||
if (empty($detection_project)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"检测项目错误");
|
||||
if (empty($detection_project)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "检测项目错误");
|
||||
}
|
||||
|
||||
if ($detection_project['detection_project_price'] <= 0){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单金额错误");
|
||||
if ($detection_project['detection_project_price'] <= 0) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单金额错误");
|
||||
}
|
||||
|
||||
// 检测用途
|
||||
@ -301,7 +302,7 @@ class DetectionService extends BaseService
|
||||
$params['purpose_id'] = $request_params['purpose_id'];
|
||||
$params['detection_project_id'] = $request_params['detection_project_id'];
|
||||
$detection_project_purpose = DetectionProjectPurpose::getOne($params);
|
||||
if (empty($detection_project_purpose)){
|
||||
if (empty($detection_project_purpose)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
@ -309,12 +310,12 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['doctor_id'] = $request_params['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"医生错误");
|
||||
if (empty($user_doctor)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "医生错误");
|
||||
}
|
||||
|
||||
if ($user_doctor['is_sys_diagno_cooperation'] != 1){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"医生错误");
|
||||
if ($user_doctor['is_sys_diagno_cooperation'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "医生错误");
|
||||
}
|
||||
|
||||
// 确定支付渠道
|
||||
@ -323,6 +324,8 @@ class DetectionService extends BaseService
|
||||
$detection_pay_channel = 1;
|
||||
} elseif ($request_params['client_type'] == 2) {
|
||||
$detection_pay_channel = 2;
|
||||
} else {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "请选择正确的支付渠道");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
@ -330,26 +333,44 @@ class DetectionService extends BaseService
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
|
||||
try {
|
||||
// 生成订单表
|
||||
$data = array();
|
||||
$data['user_id'] = $user_info['user_id'];
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
$data['doctor_id'] = $user_doctor['doctor_id'];
|
||||
$data['order_type'] = 3; // 订单类型(1:问诊订单 2:药品订单 3:检测订单 4:随访包订单 5:健康包订单)
|
||||
$data['inquiry_pay_channel'] = $detection_pay_channel;// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
$data['pay_status'] = 1;// 1:待支付
|
||||
$data['order_no'] = "D" . $generator->generate();// 订单编号
|
||||
$data['amount_total'] = $detection_project['detection_project_price'];// 订单金额
|
||||
$data['coupon_amount_total'] = 0;// 优惠卷总金额
|
||||
$data['payment_amount_total'] = $detection_project['detection_project_price'];// 实际付款金额
|
||||
$order = Order::addOrder($data);
|
||||
if (empty($order)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
|
||||
// 新增检测订单
|
||||
$data = array();
|
||||
$data['user_id'] = $user_info['user_id'];
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
$data['doctor_id'] = $user_doctor['doctor_id'];
|
||||
$data['family_id'] = $patient_family['family_id'];
|
||||
$data['detection_project_id'] = $detection_project['detection_project_id'];
|
||||
$data['purpose_id'] = $detection_project_purpose['purpose_id'];
|
||||
$data['detection_status'] = 1; // 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
$data['detection_pay_channel'] = $detection_pay_channel; // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||||
$data['detection_no'] = "D" . $generator->generate(); // 系统订单编号
|
||||
$data['amount_total'] = $detection_project['detection_project_price']; // 订单金额
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
$data['doctor_id'] = $user_doctor['doctor_id'];
|
||||
$data['family_id'] = $patient_family['family_id'];
|
||||
$data['detection_project_id'] = $detection_project['detection_project_id'];
|
||||
$data['purpose_id'] = $detection_project_purpose['purpose_id'];
|
||||
$data['detection_status'] = 1; // 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
$data['detection_pay_channel'] = $detection_pay_channel; // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||||
$data['detection_no'] = $order['order_no']; // 系统订单编号
|
||||
$data['amount_total'] = $detection_project['detection_project_price']; // 订单金额
|
||||
$data['coupon_amount_total'] = 0;// 优惠卷总金额
|
||||
$data['payment_amount_total'] = $detection_project['detection_project_price']; // 实际付款金额
|
||||
$data['payment_amount_total'] = $detection_project['detection_project_price']; // 实际付款金额
|
||||
$data['patient_name'] = $patient_family['card_name'];// 患者姓名-就诊人
|
||||
$data['patient_name_mask'] = $patient_family['card_name_mask'];// 患者姓名-就诊人(掩码)
|
||||
$data['patient_sex'] = $patient_family['sex'];// 患者性别-就诊人(0:未知 1:男 2:女)
|
||||
$data['patient_age'] = $patient_family['age'];// 患者年龄-就诊人
|
||||
$order_detection = OrderDetection::addOrderDetection($data);
|
||||
if (empty($order_detection)){
|
||||
if (empty($order_detection)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
@ -368,7 +389,7 @@ class DetectionService extends BaseService
|
||||
$data['detection_disease_class_ids'] = $request_params['detection_disease_class_ids']; // 疾病id-检测-逗号分隔
|
||||
$data['detection_disease_class_names'] = $detection_disease_class_names; // 疾病名称-检测-逗号分隔
|
||||
$order_detection_case = OrderDetectionCase::addOrderDetectionCase($data);
|
||||
if (empty($order_detection_case)){
|
||||
if (empty($order_detection_case)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
@ -388,7 +409,7 @@ class DetectionService extends BaseService
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
}catch (\Exception $e){
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||||
}
|
||||
@ -416,7 +437,7 @@ class DetectionService extends BaseService
|
||||
$params['family_id'] = $family_id;
|
||||
$params['detection_project_id'] = $detection_project_id;
|
||||
$order_detection = OrderDetection::getNotFinishedOrderDetectionOne($params);
|
||||
if (!empty($order_detection)){
|
||||
if (!empty($order_detection)) {
|
||||
return success($order_detection['detection_no']);
|
||||
}
|
||||
|
||||
@ -439,62 +460,61 @@ class DetectionService extends BaseService
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$params['order_detection_id'] = $order_detection_id;
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)){
|
||||
if (empty($order_detection)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_detection['detection_status'] != 2){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单状态错误");
|
||||
if ($order_detection['detection_status'] != 2) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单状态错误");
|
||||
}
|
||||
|
||||
if ($order_detection['detection_pay_status'] != 2){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单未支付");
|
||||
if ($order_detection['detection_pay_status'] != 2) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单未支付");
|
||||
}
|
||||
|
||||
if (!empty($order_detection['detection_bar_code'])){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"请勿重复绑定");
|
||||
if (!empty($order_detection['detection_bar_code'])) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "请勿重复绑定");
|
||||
}
|
||||
|
||||
if (!empty($order_detection['detection_pic']) && !empty($request_params['detection_pic'])){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"请勿重复绑定");
|
||||
if (!empty($order_detection['detection_pic']) && !empty($request_params['detection_pic'])) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "请勿重复绑定");
|
||||
}
|
||||
|
||||
// 处理检测管图片
|
||||
if (!empty($request_params['detection_pic'])){
|
||||
if (!empty($request_params['detection_pic'])) {
|
||||
$detection_pic = implode(',', $request_params['detection_pic']);
|
||||
$detection_pic = PcreMatch::pregRemoveOssWebsite($detection_pic);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 检测检测管编码是否已被使用
|
||||
$params = array();
|
||||
$params['detection_bar_code'] = $request_params['detection_bar_code'];
|
||||
$result = OrderDetection::getOne($params);
|
||||
if (!empty($result)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"检测管已被使用");
|
||||
if (!empty($result)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "检测管已被使用");
|
||||
}
|
||||
|
||||
// 获取检测码对应的检测所
|
||||
$detection_organ_code = substr($request_params['detection_bar_code'], 3, 1);
|
||||
if (!$detection_organ_code){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"检测码错误");
|
||||
if (!$detection_organ_code) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "检测码错误");
|
||||
}
|
||||
|
||||
// 获取检测所数据
|
||||
$params = array();
|
||||
$params['detection_organ_code'] = $detection_organ_code;
|
||||
$basic_detection_organ = BasicDetectionOrgan::getOne($params);
|
||||
if (empty($basic_detection_organ)){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"检测码错误");
|
||||
if (empty($basic_detection_organ)) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "检测码错误");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 修改检测订单
|
||||
$data = array();
|
||||
if (isset($detection_pic)){
|
||||
if (isset($detection_pic)) {
|
||||
$data['detection_pic'] = $detection_pic;
|
||||
}
|
||||
|
||||
@ -505,10 +525,10 @@ class DetectionService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection_id;
|
||||
$res = OrderDetection::editOrderDetection($params,$data);
|
||||
if (!$res){
|
||||
$res = OrderDetection::editOrderDetection($params, $data);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"绑定失败");
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "绑定失败");
|
||||
}
|
||||
|
||||
// 上报数据
|
||||
@ -516,7 +536,7 @@ class DetectionService extends BaseService
|
||||
$wy->report($order_detection_id);
|
||||
|
||||
Db::commit();
|
||||
}catch (\Throwable $e){
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("DetectionService-bindDetectionTube")->error($e->getMessage());
|
||||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||||
@ -552,17 +572,17 @@ class DetectionService extends BaseService
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$params['order_detection_id'] = $order_detection_id;
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)){
|
||||
if (empty($order_detection)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_detection['detection_status'] != 4){
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"订单状态错误");
|
||||
if ($order_detection['detection_status'] != 4) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单状态错误");
|
||||
}
|
||||
|
||||
// 检测是否已经创建问诊订单
|
||||
if (!empty($order_detection['order_inquiry_id'])){
|
||||
if (!empty($order_detection['order_inquiry_id'])) {
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
$result['data'] = (string)$order_detection['order_inquiry_id'];
|
||||
@ -574,9 +594,9 @@ class DetectionService extends BaseService
|
||||
try {
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($order_detection['patient_id'],$order_detection['doctor_id']);
|
||||
if (!empty($order_inquiry)){
|
||||
if ($order_inquiry['inquiry_status'] == 1){
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($order_detection['patient_id'], $order_detection['doctor_id']);
|
||||
if (!empty($order_inquiry)) {
|
||||
if ($order_inquiry['inquiry_status'] == 1) {
|
||||
// 待支付
|
||||
Db::rollBack();
|
||||
|
||||
@ -587,7 +607,7 @@ class DetectionService extends BaseService
|
||||
return success($result);
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_status'] == 3){
|
||||
if ($order_inquiry['inquiry_status'] == 3) {
|
||||
// 待接诊
|
||||
Db::rollBack();
|
||||
|
||||
@ -598,7 +618,7 @@ class DetectionService extends BaseService
|
||||
return success($result);
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_status'] == 4){
|
||||
if ($order_inquiry['inquiry_status'] == 4) {
|
||||
// 已接诊
|
||||
Db::rollBack();
|
||||
|
||||
@ -614,7 +634,7 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['doctor_id'] = $order_detection['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
if (empty($user_doctor)) {
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
}
|
||||
@ -623,7 +643,7 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
$order_detection_case = OrderDetectionCase::getOne($params);
|
||||
if (empty($order_detection_case)){
|
||||
if (empty($order_detection_case)) {
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
}
|
||||
@ -632,7 +652,7 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['detection_project_id'] = $order_detection['detection_project_id'];
|
||||
$detection_project = DetectionProject::getOne($params);
|
||||
if (empty($detection_project)){
|
||||
if (empty($detection_project)) {
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
}
|
||||
@ -649,6 +669,24 @@ class DetectionService extends BaseService
|
||||
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
|
||||
// 生成订单表
|
||||
$data = array();
|
||||
$data['user_id'] = $order_detection['user_id'];
|
||||
$data['patient_id'] = $order_detection['client_user_id'];
|
||||
$data['doctor_id'] = $order_detection['doctor_id'];
|
||||
$data['order_type'] = 1; // 订单类型(1:问诊订单 2:药品订单 3:检测订单 4:随访包订单 5:健康包订单)
|
||||
$data['inquiry_pay_channel'] = 3; // 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
$data['pay_status'] = 2; // 1:待支付
|
||||
$data['order_no'] = "I" . $generator->generate(); // 订单编号
|
||||
$data['amount_total'] = 0; // 订单金额
|
||||
$data['coupon_amount_total'] = 0; // 优惠卷总金额
|
||||
$data['payment_amount_total'] = 0; // 实际付款金额
|
||||
$order = Order::addOrder($data);
|
||||
if (empty($order)) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
|
||||
// 创建问诊订单
|
||||
$data = array();
|
||||
$data['user_id'] = $order_detection['user_id'];
|
||||
@ -660,7 +698,7 @@ class DetectionService extends BaseService
|
||||
$data['inquiry_status'] = 4; // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$data['inquiry_pay_channel'] = 3; // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||||
$data['inquiry_pay_status'] = 2; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$data['inquiry_no'] = $generator->generate();// 订单编号
|
||||
$data['inquiry_no'] = $order['order_no'];// 订单编号
|
||||
$data['escrow_trade_no'] = "GD" . $generator->generate(); // 第三方支付流水号
|
||||
$data['amount_total'] = 0;// 订单金额
|
||||
$data['coupon_amount_total'] = 0;// 优惠卷总金额
|
||||
@ -703,7 +741,7 @@ class DetectionService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params,$data);
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
|
||||
// 添加自动完成队列
|
||||
$time = 1000 * 60 * 60 * 24 * 3;
|
||||
@ -763,7 +801,7 @@ class DetectionService extends BaseService
|
||||
$imService->detectionTestReportStr($data);
|
||||
|
||||
Db::commit();
|
||||
}catch (\Throwable $e){
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("DetectionService-bindDetectionTube")->error($e->getMessage());
|
||||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||||
@ -778,12 +816,12 @@ class DetectionService extends BaseService
|
||||
|
||||
/**
|
||||
* 取消未支付检测订单
|
||||
* @param string|int $order_no 订单编号
|
||||
* @param string|int $order_id
|
||||
* @param string|int $cancel_reason 取消订单原因(1:主动取消 2:客服取消 3:支付超时)
|
||||
* @param string|int $cancel_remarks 取消备注
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayDetectionOrder(string|int $order_no, string|int $cancel_reason, string|int $cancel_remarks): array
|
||||
public function cancelUnpayDetectionOrder(string|int $order_id, string|int $cancel_reason, string|int $cancel_remarks): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
@ -791,26 +829,26 @@ class DetectionService extends BaseService
|
||||
|
||||
// 获取检测订单数据
|
||||
$params = array();
|
||||
$params['detection_no'] = $order_no;
|
||||
$params['order_id'] = $order_id;
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)){
|
||||
if (empty($order_detection)) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的检测订单失败:未查询到对应订单数据";
|
||||
$result['message'] = "未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_detection['detection_status'] == 5) {
|
||||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的检测订单:订单已取消";
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_detection['detection_status'] != 1) {
|
||||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的检测订单:订单状态为" . $order_detection['detection_status'] . "无法执行";
|
||||
$result['message'] = "订单取消失败";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -818,15 +856,15 @@ class DetectionService extends BaseService
|
||||
if (!in_array($order_detection['detection_refund_status'], [0, 4, 5])) {
|
||||
// 检测订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的检测订单:订单正在退款中";
|
||||
$result['message'] = "订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单支付状态
|
||||
if ($order_detection['detection_pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的检测订单:订单已支付";
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -834,14 +872,14 @@ class DetectionService extends BaseService
|
||||
if ($order_detection['is_delete'] == 1) {
|
||||
// 删除状态(0:否 1:是)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的检测订单:订单已被删除";
|
||||
$result['message'] = "订单已被删除";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消检测订单
|
||||
$data = array();
|
||||
$data['detection_status'] = 5; // 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
if ($cancel_reason == 3){
|
||||
if ($cancel_reason == 3) {
|
||||
$data['detection_pay_status'] = 5; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
}
|
||||
|
||||
@ -852,7 +890,7 @@ class DetectionService extends BaseService
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params,$data);
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
|
||||
return $result;
|
||||
}
|
||||
@ -860,7 +898,7 @@ class DetectionService extends BaseService
|
||||
/**
|
||||
* 检测订单退款接口
|
||||
*/
|
||||
public function detectionRefund(string $order_detection_id, string $refund_reason)
|
||||
/*public function detectionRefund(string $order_detection_id, string $refund_reason): void
|
||||
{
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
@ -877,7 +915,7 @@ class DetectionService extends BaseService
|
||||
}
|
||||
|
||||
// 检测订单退款状态
|
||||
if (in_array($order_detection['detection_refund_status'], [2, 3, 5,6])) {
|
||||
if (in_array($order_detection['detection_refund_status'], [2, 3, 5, 6])) {
|
||||
// 检测订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
@ -893,7 +931,7 @@ class DetectionService extends BaseService
|
||||
$detection_refund_no = $generator->generate();
|
||||
|
||||
// 检测订单金额
|
||||
if ($order_detection['payment_amount_total'] > 0){
|
||||
if ($order_detection['payment_amount_total'] > 0) {
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1, 3);
|
||||
|
||||
@ -930,9 +968,9 @@ class DetectionService extends BaseService
|
||||
}
|
||||
|
||||
$refund_id = $result['refund_id'];
|
||||
}else{
|
||||
} else {
|
||||
$detection_refund_status = 3;
|
||||
$success_time = date('Y-m-d H:i:s',time());
|
||||
$success_time = date('Y-m-d H:i:s', time());
|
||||
$refund_id = $generator->generate();
|
||||
}
|
||||
|
||||
@ -963,7 +1001,7 @@ class DetectionService extends BaseService
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 获取患者某一状态下的检测订单数量
|
||||
@ -971,7 +1009,7 @@ class DetectionService extends BaseService
|
||||
* @param int $detection_status 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
* @return int
|
||||
*/
|
||||
public function getPatientDetectionWithStatus(string $patient_id,int $detection_status): int
|
||||
public function getPatientDetectionWithStatus(string $patient_id, int $detection_status): int
|
||||
{
|
||||
$params = array();
|
||||
$params['patient_id'] = $patient_id;
|
||||
|
||||
@ -17,6 +17,8 @@ use App\Model\DoctorInquiryConfigService;
|
||||
use App\Model\Hospital;
|
||||
use App\Model\InquiryCaseProduct;
|
||||
use App\Model\MessageIm;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderCoupon;
|
||||
use App\Model\OrderDetection;
|
||||
use App\Model\OrderEvaluation;
|
||||
use App\Model\OrderInquiry;
|
||||
@ -220,8 +222,31 @@ class InquiryService extends BaseService
|
||||
$payment_amount_total = 0;
|
||||
}
|
||||
|
||||
// 生成订单表
|
||||
$data = array();
|
||||
$data['user_id'] = $user_info['user_id'];
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
if (isset($request_params['doctor_id'])) {
|
||||
if (!empty($request_params['doctor_id'])) {
|
||||
$data['doctor_id'] = $request_params['doctor_id'];
|
||||
}
|
||||
}
|
||||
$data['order_type'] = 1; // 订单类型(1:问诊订单 2:药品订单 3:检测订单 4:随访包订单 5:健康包订单)
|
||||
$data['inquiry_pay_channel'] = $inquiry_pay_channel ?? 0;// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
$data['pay_status'] = 1;// 1:待支付
|
||||
$data['order_no'] = "I" . $generator->generate();// 订单编号
|
||||
$data['amount_total'] = $inquiry_price;// 订单金额
|
||||
$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_id'] = $order['order_id'];
|
||||
$data['user_id'] = $user_info['user_id'];
|
||||
$data['patient_id'] = $user_info['client_user_id'];
|
||||
if (isset($request_params['doctor_id'])) {
|
||||
@ -235,7 +260,7 @@ class InquiryService extends BaseService
|
||||
$data['inquiry_mode'] = $request_params['inquiry_mode'];
|
||||
$data['inquiry_status'] = 1;// 1:待支付
|
||||
$data['inquiry_pay_channel'] = $inquiry_pay_channel ?? 0;// 支付渠道(1:小程序支付 2:微信扫码支付)
|
||||
$data['inquiry_no'] = $generator->generate();// 订单编号
|
||||
$data['inquiry_no'] = $order['order_no'];// 订单编号
|
||||
$data['amount_total'] = $inquiry_price;// 订单金额
|
||||
$data['coupon_amount_total'] = $coupon_amount_total;// 优惠卷总金额
|
||||
$data['payment_amount_total'] = $payment_amount_total;// 实际付款金额
|
||||
@ -383,6 +408,18 @@ class InquiryService extends BaseService
|
||||
// 处理优惠卷数据
|
||||
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_inquiry_id'] = $order_inquiry['order_inquiry_id'];// 订单-问诊id
|
||||
@ -1663,84 +1700,208 @@ class InquiryService extends BaseService
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function inquiryRefund(string $order_inquiry_id, string $refund_reason): void
|
||||
// public function inquiryRefund(string $order_inquiry_id, string $refund_reason): void
|
||||
// {
|
||||
// // 获取订单数据
|
||||
// $params = array();
|
||||
// $params['order_inquiry_id'] = $order_inquiry_id;
|
||||
// $order_inquiry = OrderInquiry::getOne($params);
|
||||
// if (empty($order_inquiry)) {
|
||||
// throw new BusinessException("订单数据为空");
|
||||
// }
|
||||
//
|
||||
// // 检测问诊订单状态
|
||||
// if (!in_array($order_inquiry['inquiry_status'], [2, 3, 4, 5, 7])) {
|
||||
// // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
// throw new BusinessException("订单状态错误");
|
||||
// }
|
||||
//
|
||||
// // 检测订单退款状态
|
||||
// if (in_array($order_inquiry['inquiry_refund_status'], [2, 3, 5])) {
|
||||
// // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
// throw new BusinessException("订单退款状态错误");
|
||||
// }
|
||||
//
|
||||
// // 检测支付状态
|
||||
// if ($order_inquiry['inquiry_pay_status'] != 2) {
|
||||
// // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
// throw new BusinessException("订单支付状态错误");
|
||||
// }
|
||||
//
|
||||
// // 系统退款编号
|
||||
// $generator = $this->container->get(IdGeneratorInterface::class);
|
||||
// $inquiry_refund_no = $generator->generate();
|
||||
//
|
||||
// // 检测订单金额
|
||||
// if ($order_inquiry['payment_amount_total'] > 0) {
|
||||
// // 发起退款
|
||||
// $WechatPay = new WechatPay(1, 1);
|
||||
//
|
||||
// $options = array();
|
||||
// $options['transaction_id'] = $order_inquiry['escrow_trade_no'];
|
||||
// $options['out_refund_no'] = (string)$inquiry_refund_no;
|
||||
// $options['reason'] = $refund_reason;
|
||||
// $options['amount'] = [
|
||||
// 'refund' => (int)round($order_inquiry['payment_amount_total'] * 100),
|
||||
// 'total' => (int)round($order_inquiry['payment_amount_total'] * 100),
|
||||
// 'currency' => "CNY",
|
||||
// ];
|
||||
//
|
||||
// $result = $WechatPay->refund($options);
|
||||
//
|
||||
// // 处理订单退款状态
|
||||
// // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
// $success_time = "";
|
||||
// if ($result['status'] == "SUCCESS") {
|
||||
// // 退款成功
|
||||
// $inquiry_refund_status = 3;
|
||||
// $success_time = $result['success_time'];
|
||||
// } elseif ($result['status'] == "CLOSED") {
|
||||
// // 退款关闭
|
||||
// $inquiry_refund_status = 5;
|
||||
// } elseif ($result['status'] == "PROCESSING") {
|
||||
// // 退款处理中
|
||||
// $inquiry_refund_status = 2;
|
||||
// } elseif ($result['status'] == "ABNORMAL") {
|
||||
// // 退款异常,此情况不处理,进行短信通知
|
||||
// throw new BusinessException("订单退款状态异常");
|
||||
// } else {
|
||||
// throw new BusinessException("订单退款状态错误");
|
||||
// }
|
||||
//
|
||||
// $refund_id = $result['refund_id'];
|
||||
//
|
||||
// } else {
|
||||
// // 模拟退款
|
||||
// $inquiry_refund_status = 3;
|
||||
// $refund_id = "模拟退款:" . $generator->generate();
|
||||
// $success_time = date("Y-m-d H:i:s", time());
|
||||
//
|
||||
// // 模拟退款时手动退还优惠卷
|
||||
// if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0) {
|
||||
// // 获取该订单全部优惠卷数据
|
||||
// $params = array();
|
||||
// $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
// $order_inquiry_coupons = OrderInquiryCoupon::getList($params);
|
||||
// if (!empty($order_inquiry_coupons)) {
|
||||
// $userCouponService = new UserCouponService();
|
||||
// foreach ($order_inquiry_coupons as $order_inquiry_coupon) {
|
||||
// // 退还优惠卷
|
||||
// $userCouponService->returnUserCoupon($order_inquiry_coupon['user_coupon_id']);
|
||||
//
|
||||
// // 发送站内消息-优惠卷退还
|
||||
// $MessagePush = new MessagePush($order_inquiry['user_id']);
|
||||
// $MessagePush->patientRefundCoupon($order_inquiry_coupon['coupon_name']);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 新增退款表
|
||||
// $data = array();
|
||||
// $data['patient_id'] = $order_inquiry['patient_id'];
|
||||
// $data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
// $data['inquiry_no'] = $order_inquiry['inquiry_no'];
|
||||
// $data['inquiry_refund_no'] = $inquiry_refund_no;
|
||||
// $data['refund_id'] = $refund_id;
|
||||
// $data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
// $data['refund_total'] = $order_inquiry['payment_amount_total'];
|
||||
// $data['refund_reason'] = $refund_reason;
|
||||
//
|
||||
// if ($inquiry_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)) {
|
||||
// throw new BusinessException("添加退款表失败");
|
||||
// }
|
||||
//
|
||||
// // 修改问诊订单表状态
|
||||
// $data = array();
|
||||
// $data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
//
|
||||
// $params = array();
|
||||
// $params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
// OrderInquiry::edit($params, $data);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 取消未支付的问诊订单
|
||||
* @param string|int $order_no
|
||||
* @param string|int $cancel_reason 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
* @param string|int $cancel_remarks 取消订单备注
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayInquiryOrder(string|int $order_no, string|int $cancel_reason, string|int $cancel_remarks): array
|
||||
{
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry_id;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
try {
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
|
||||
// 检测问诊订单状态
|
||||
if (!in_array($order_inquiry['inquiry_status'], [2, 3, 4, 5, 7])) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
throw new BusinessException("订单状态错误");
|
||||
}
|
||||
|
||||
// 检测订单退款状态
|
||||
if (in_array($order_inquiry['inquiry_refund_status'], [2, 3, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
// 检测支付状态
|
||||
if ($order_inquiry['inquiry_pay_status'] != 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
throw new BusinessException("订单支付状态错误");
|
||||
}
|
||||
|
||||
// 系统退款编号
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
$inquiry_refund_no = $generator->generate();
|
||||
|
||||
// 检测订单金额
|
||||
if ($order_inquiry['payment_amount_total'] > 0) {
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1, 1);
|
||||
|
||||
$options = array();
|
||||
$options['transaction_id'] = $order_inquiry['escrow_trade_no'];
|
||||
$options['out_refund_no'] = (string)$inquiry_refund_no;
|
||||
$options['reason'] = $refund_reason;
|
||||
$options['amount'] = [
|
||||
'refund' => (int)round($order_inquiry['payment_amount_total'] * 100),
|
||||
'total' => (int)round($order_inquiry['payment_amount_total'] * 100),
|
||||
'currency' => "CNY",
|
||||
];
|
||||
|
||||
$result = $WechatPay->refund($options);
|
||||
|
||||
// 处理订单退款状态
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$success_time = "";
|
||||
if ($result['status'] == "SUCCESS") {
|
||||
// 退款成功
|
||||
$inquiry_refund_status = 3;
|
||||
$success_time = $result['success_time'];
|
||||
} elseif ($result['status'] == "CLOSED") {
|
||||
// 退款关闭
|
||||
$inquiry_refund_status = 5;
|
||||
} elseif ($result['status'] == "PROCESSING") {
|
||||
// 退款处理中
|
||||
$inquiry_refund_status = 2;
|
||||
} elseif ($result['status'] == "ABNORMAL") {
|
||||
// 退款异常,此情况不处理,进行短信通知
|
||||
throw new BusinessException("订单退款状态异常");
|
||||
} else {
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
// 获取问诊订单数据
|
||||
$params = array();
|
||||
$params['order_no'] = $order_no;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
throw new BusinessException("未查询到对应订单数据");
|
||||
}
|
||||
|
||||
$refund_id = $result['refund_id'];
|
||||
// 检测订单状态
|
||||
if ($order_inquiry['inquiry_status'] == 7) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
} else {
|
||||
// 模拟退款
|
||||
$inquiry_refund_status = 3;
|
||||
$refund_id = "模拟退款:" . $generator->generate();
|
||||
$success_time = date("Y-m-d H:i:s", time());
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单取消失败";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 模拟退款时手动退还优惠卷
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单删除状态
|
||||
if ($order_inquiry['is_delete'] == 1) {
|
||||
// 删除状态(0:否 1:是)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已被删除";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消问诊订单
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
if ($cancel_reason == 5) {
|
||||
$data['inquiry_pay_status'] = 5; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
}
|
||||
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = $cancel_reason; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['cancel_remarks'] = $cancel_remarks; // 取消订单备注
|
||||
$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);
|
||||
|
||||
// 处理订单优惠卷
|
||||
if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0) {
|
||||
// 获取该订单全部优惠卷数据
|
||||
$params = array();
|
||||
@ -1758,132 +1919,8 @@ class InquiryService extends BaseService
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
$data = array();
|
||||
$data['patient_id'] = $order_inquiry['patient_id'];
|
||||
$data['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$data['inquiry_no'] = $order_inquiry['inquiry_no'];
|
||||
$data['inquiry_refund_no'] = $inquiry_refund_no;
|
||||
$data['refund_id'] = $refund_id;
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
$data['refund_total'] = $order_inquiry['payment_amount_total'];
|
||||
$data['refund_reason'] = $refund_reason;
|
||||
|
||||
if ($inquiry_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)) {
|
||||
throw new BusinessException("添加退款表失败");
|
||||
}
|
||||
|
||||
// 修改问诊订单表状态
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $inquiry_refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消未支付的问诊订单
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @param string|int $cancel_reason 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
* @param string|int $cancel_remarks 取消订单备注
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function cancelUnpayInquiryOrder(string|int $order_no, string|int $cancel_reason, string|int $cancel_remarks): array
|
||||
{
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_inquiry['inquiry_status'] == 7) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_status'] != 1) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单状态为" . $order_inquiry['inquiry_status'] . "无法执行";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!in_array($order_inquiry['inquiry_refund_status'], [0, 4, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_inquiry['inquiry_pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单删除状态
|
||||
if ($order_inquiry['is_delete'] == 1) {
|
||||
// 删除状态(0:否 1:是)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已被删除";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 取消问诊订单
|
||||
$data = array();
|
||||
$data['inquiry_status'] = 7;
|
||||
if ($cancel_reason == 5) {
|
||||
$data['inquiry_pay_status'] = 5; // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
}
|
||||
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = $cancel_reason; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$data['cancel_remarks'] = $cancel_remarks; // 取消订单备注
|
||||
$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);
|
||||
|
||||
// 处理订单优惠卷
|
||||
if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0) {
|
||||
// 获取该订单全部优惠卷数据
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_coupons = OrderInquiryCoupon::getList($params);
|
||||
if (!empty($order_inquiry_coupons)) {
|
||||
$userCouponService = new UserCouponService();
|
||||
foreach ($order_inquiry_coupons as $order_inquiry_coupon) {
|
||||
// 退还优惠卷
|
||||
$userCouponService->returnUserCoupon($order_inquiry_coupon['user_coupon_id']);
|
||||
|
||||
// 发送站内消息-优惠卷退还
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id']);
|
||||
$MessagePush->patientRefundCoupon($order_inquiry_coupon['coupon_name']);
|
||||
}
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
@ -40,12 +40,10 @@ class OrderProductService extends BaseService
|
||||
/**
|
||||
* 取消未支付的药品订单
|
||||
* 外层需加事物
|
||||
* @param string|int $order_no 系统订单编号
|
||||
* @param string|int $order_no 订单编号
|
||||
* @param string|int $cancel_reason 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时
|
||||
* @param string $cancel_remarks 订单取消原因
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function cancelUnpayProductOrder(string|int $order_no,string|int $cancel_reason,string $cancel_remarks): array
|
||||
{
|
||||
@ -59,36 +57,36 @@ class OrderProductService extends BaseService
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单数据";
|
||||
$result['message'] = "未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order_product['order_product_status'] == 5){
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已取消";
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_product['order_product_status'] != 1){
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单状态为" . $order_product['order_product_status'] . "无法执行";
|
||||
$result['message'] = "订单取消失败";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!in_array($order_product['refund_status'],[0,4,5])) {
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单:订单正在退款中";
|
||||
$result['message'] = "订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order_product['pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 2;
|
||||
$result['message'] = "取消未支付的问诊订单:订单已支付";
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -98,7 +96,7 @@ class OrderProductService extends BaseService
|
||||
$user_patient = UserPatient::getOne($params);
|
||||
if (empty($user_patient)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应用户数据";
|
||||
$result['message'] = "未查询到对应用户数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -125,7 +123,7 @@ class OrderProductService extends BaseService
|
||||
$order_product_item = OrderProductItem::getList($params);
|
||||
if (empty($order_product_item)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单商品订单列表";
|
||||
$result['message'] = "未查询到对应订单商品订单列表";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -136,7 +134,7 @@ class OrderProductService extends BaseService
|
||||
$product = Product::getOne($params);
|
||||
if (empty($product)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单商品订单列表";
|
||||
$result['message'] = "未查询到对应订单商品订单列表";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -145,7 +143,7 @@ class OrderProductService extends BaseService
|
||||
$product_platform_amount = ProductPlatformAmount::getSharedLockOne($params);
|
||||
if (empty($product_platform_amount)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:无商品库存数据";
|
||||
$result['message'] = "无商品库存数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -161,7 +159,7 @@ class OrderProductService extends BaseService
|
||||
$order_prescription = OrderPrescription::getOne($params);
|
||||
if (empty($order_prescription)){
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单处方";
|
||||
$result['message'] = "未查询到对应订单处方";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -181,7 +179,7 @@ class OrderProductService extends BaseService
|
||||
$order_prescription_product = OrderPrescriptionProduct::getList($params);
|
||||
if (empty($order_prescription_product)) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "取消未支付的问诊订单失败:未查询到对应订单处方商品数据";
|
||||
$result['message'] = "未查询到对应订单处方商品数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -225,7 +223,7 @@ class OrderProductService extends BaseService
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function OrderProductRefund(string $order_product_id, string $refund_reason): void
|
||||
/*public function OrderProductRefund(string $order_product_id, string $refund_reason): void
|
||||
{
|
||||
// 获取药品订单数据
|
||||
$params = array();
|
||||
@ -344,6 +342,99 @@ class OrderProductService extends BaseService
|
||||
$data = array();
|
||||
$data['refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
OrderProduct::edit($params,$data);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 药品订单退款
|
||||
* @param string $order_product_id 药品订单id
|
||||
* @param string $refund_reason 退款原因
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function OrderProductRefund(string $order_product_id, string $refund_reason): void
|
||||
{
|
||||
// 获取药品订单数据
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product_id;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
// 系统退款编号
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
$product_refund_no = $generator->generate();
|
||||
|
||||
// 检测订单金额
|
||||
if ($order_product['payment_amount_total'] <= 0){
|
||||
throw new BusinessException("订单金额错误");
|
||||
}
|
||||
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1, 2);
|
||||
|
||||
$options = array();
|
||||
$options['transaction_id'] = $order_product['escrow_trade_no'];
|
||||
$options['out_refund_no'] = (string)$product_refund_no;
|
||||
$options['reason'] = $refund_reason;
|
||||
$options['amount'] = [
|
||||
'refund' => (int)($order_product['payment_amount_total'] * 100),
|
||||
'total' => (int)($order_product['payment_amount_total'] * 100),
|
||||
'currency' => "CNY",
|
||||
];
|
||||
|
||||
$result = $WechatPay->refund($options);
|
||||
|
||||
// 处理订单退款状态
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
$success_time = "";
|
||||
if ($result['status'] == "SUCCESS") {
|
||||
// 退款成功
|
||||
$refund_status = 3;
|
||||
$success_time = $result['success_time'];
|
||||
} elseif ($result['status'] == "CLOSED") {
|
||||
// 退款关闭
|
||||
$refund_status = 5;
|
||||
} elseif ($result['status'] == "PROCESSING") {
|
||||
// 退款处理中
|
||||
$refund_status = 2;
|
||||
} elseif ($result['status'] == "ABNORMAL") {
|
||||
// 退款异常,此情况不处理,进行短信通知
|
||||
throw new BusinessException("订单退款状态异常");
|
||||
} else {
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
$refund_id = $result['refund_id'];
|
||||
|
||||
// 新增退款表
|
||||
$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'] = $product_refund_no;
|
||||
$data['refund_id'] = $refund_id;
|
||||
$data['product_refund_status'] = $refund_status;
|
||||
$data['refund_total'] = $order_product['payment_amount_total'];
|
||||
$data['refund_reason'] = $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)) {
|
||||
throw new BusinessException("添加退款表失败");
|
||||
}
|
||||
|
||||
// 修改药品订单表状态
|
||||
$data = array();
|
||||
$data['refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
OrderProduct::edit($params,$data);
|
||||
|
||||
634
app/Services/OrderService.php
Normal file
634
app/Services/OrderService.php
Normal file
@ -0,0 +1,634 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderCoupon;
|
||||
use App\Model\OrderDetection;
|
||||
use App\Model\OrderDetectionRefund;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCoupon;
|
||||
use App\Model\OrderInquiryRefund;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductRefund;
|
||||
use App\Model\OrderRefund;
|
||||
use App\Utils\Log;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Redis\Redis;
|
||||
use Hyperf\Snowflake\IdGeneratorInterface;
|
||||
|
||||
/**
|
||||
* 订单处理
|
||||
*/
|
||||
class OrderService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 取消未支付的订单
|
||||
* @param string|int $order_no
|
||||
* @param string|int $cancel_reason
|
||||
* @param string|int $cancel_remarks
|
||||
* @return array
|
||||
*/
|
||||
public function cancelUnpayOrder(string|int $order_no, string|int $cancel_reason, string|int $cancel_remarks): array
|
||||
{
|
||||
try {
|
||||
$result = array();
|
||||
$result['status'] = 1;
|
||||
$result['message'] = "成功";
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_no'] = $order_no;
|
||||
$order = Order::getOne($params);
|
||||
if (empty($order)) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "未查询到对应订单数据";
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if ($order['cancel_status'] == 1) {
|
||||
// 取消状态(0:否 1:是)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已取消";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (!in_array($order['refund_status'], [0, 4, 5])) {
|
||||
// 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单正在退款中";
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($order['pay_status'] == 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
$result['status'] = 0;
|
||||
$result['message'] = "订单已支付";
|
||||
return $result;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
if ($cancel_remarks == "支付超时") {
|
||||
$data['pay_status'] = 5;
|
||||
}
|
||||
$data['cancel_status'] = 1;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_remarks'] = $cancel_remarks; // 取消订单备注
|
||||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
|
||||
$params = array();
|
||||
$params['order_id'] = $order['order_id'];
|
||||
Order::edit($params, $data);
|
||||
|
||||
// 取消对应订单
|
||||
if ($order['order_type'] == 1) {
|
||||
// 问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$result = $InquiryService->cancelUnpayInquiryOrder($order['order_id'], $cancel_reason, $cancel_remarks);
|
||||
} elseif ($order['order_type'] == 2) {
|
||||
// 药品订单
|
||||
$OrderProductService = new OrderProductService();
|
||||
$result = $OrderProductService->cancelUnpayProductOrder($order['order_id'], $cancel_reason, $cancel_remarks);
|
||||
} elseif ($order['order_type'] == 3) {
|
||||
// 检测订单
|
||||
$DetectionService = new DetectionService();
|
||||
$result = $DetectionService->cancelUnpayDetectionOrder($order['order_id'], $cancel_reason, $cancel_remarks);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$result['status'] = 0;
|
||||
$result['message'] = $e->getMessage();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起订单退款
|
||||
* @param string $order_no
|
||||
* @param string $refund_reason
|
||||
* @return void
|
||||
*/
|
||||
public function orderRefund(string $order_no, string $refund_reason): void
|
||||
{
|
||||
// 检测参数
|
||||
try {
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_no'] = $order_no;
|
||||
$order = Order::getOne($params);
|
||||
if (empty($order)) {
|
||||
throw new BusinessException("未查询到对应订单数据");
|
||||
}
|
||||
|
||||
// 检测订单退款状态
|
||||
if (in_array($order['refund_status'], [2, 3, 5])) {
|
||||
// 订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
// 检测支付状态
|
||||
if ($order['pay_status'] != 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
throw new BusinessException("订单支付状态错误");
|
||||
}
|
||||
|
||||
// 取消订单
|
||||
$order_data = array();
|
||||
$order_data['cancel_status'] = 1;
|
||||
$order_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$order_data['cancel_remarks'] = "医生未接诊";
|
||||
$order_data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
|
||||
$params = array();
|
||||
$params['order_id'] = $order['order_id'];
|
||||
Order::edit($params, $order_data);
|
||||
|
||||
// 处理对应订单
|
||||
if ($order['order_type'] == 1) {
|
||||
// 检测问诊订单可退款状态
|
||||
$this->checkOrderInquiryStatusForRefund($order['order_no']);
|
||||
} elseif ($order['order_type'] == 2) {
|
||||
// 检测药品订单可退款状态
|
||||
$this->checkOrderProductStatusForRefund($order['order_no']);
|
||||
} elseif ($order['order_type'] == 3) {
|
||||
// 检测检测订单可退款状态
|
||||
$this->checkOrderDetectionStatusForRefund($order['order_no']);
|
||||
} else {
|
||||
throw new BusinessException("订单类型错误");
|
||||
}
|
||||
}catch (\Throwable $e){
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
// 系统退款编号
|
||||
$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'] = $refund_no;
|
||||
$options['reason'] = $refund_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") {
|
||||
// 退款异常,此情况不处理,进行短信通知
|
||||
throw new BusinessException("订单退款状态异常");
|
||||
} else {
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
$refund_id = $refund_result['refund_id'];
|
||||
} else {
|
||||
// 药品订单不存在模拟退款
|
||||
if ($order['order_type'] == 2){
|
||||
throw new BusinessException("订单金额错误");
|
||||
}
|
||||
|
||||
// 模拟退款
|
||||
$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'] = $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)) {
|
||||
throw new BusinessException("添加退款表失败");
|
||||
}
|
||||
|
||||
switch ($order['order_type']) {
|
||||
case 1: // 问诊订单
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
$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'] = $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)) {
|
||||
throw new BusinessException("添加退款表失败");
|
||||
}
|
||||
|
||||
// 修改问诊订单表状态
|
||||
$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)){
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
$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'] = $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)) {
|
||||
throw new BusinessException("添加退款表失败");
|
||||
}
|
||||
|
||||
// 修改药品订单表状态
|
||||
$data = array();
|
||||
$data['refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
OrderProduct::edit($params,$data);
|
||||
|
||||
break;
|
||||
case 3: // 检测订单
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['detection_no'] = $order_no;
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)) {
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
$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'] = $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)) {
|
||||
throw new BusinessException("添加退款表失败");
|
||||
}
|
||||
|
||||
// 修改问诊订单表状态
|
||||
$data = array();
|
||||
$data['detection_refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("订单类型错误");
|
||||
}
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理订单退款回调结果
|
||||
* @param string $order_no
|
||||
* @param string|int $refund_status
|
||||
* @param string $success_time
|
||||
* @return void
|
||||
*/
|
||||
public function orderRefundResult(string $order_no,string|int $refund_status,string $success_time): void
|
||||
{
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_no'] = $order_no;
|
||||
$order = Order::getOne($params);
|
||||
if (empty($order)) {
|
||||
throw new BusinessException("未查询到对应订单数据");
|
||||
}
|
||||
|
||||
// 退款状态
|
||||
if ($refund_status == "SUCCESS") {
|
||||
// 退款成功
|
||||
$refund_status = 3;
|
||||
} elseif ($refund_status == "CLOSED") {
|
||||
// 退款关闭
|
||||
$refund_status = 5;
|
||||
} elseif ($refund_status == "ABNORMAL") {
|
||||
// 退款异常
|
||||
$refund_status = 6;
|
||||
} else{
|
||||
// 错误,无退款状态
|
||||
throw new BusinessException("退款状态错误");
|
||||
}
|
||||
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_no'] = $order['order_no'];
|
||||
Order::edit($params,$data);
|
||||
|
||||
// 修改订单退款表
|
||||
$data = array();
|
||||
$data['refund_status'] = $refund_status;
|
||||
$data['success_time'] = $success_time;
|
||||
|
||||
$params = array();
|
||||
$params['order_no'] = $order['order_no'];
|
||||
OrderRefund::edit($params, $data);
|
||||
|
||||
// 处理对应订单
|
||||
switch ($order['order_type']) {
|
||||
case 1: // 问诊订单
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order['order_no'];
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
// 修改退款订单
|
||||
$data = array();
|
||||
$data['inquiry_refund_status'] = $refund_status;
|
||||
$data['success_time'] = $success_time;
|
||||
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order['order_no'];
|
||||
OrderInquiryRefund::edit($params, $data);
|
||||
|
||||
break;
|
||||
case 2: // 药品订单
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order['order_no'];
|
||||
OrderProduct::edit($params, $data);
|
||||
|
||||
// 修改退款订单
|
||||
$data = array();
|
||||
$data['product_refund_status'] = $refund_status;
|
||||
$data['success_time'] = $success_time;
|
||||
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order['order_no'];
|
||||
OrderProductRefund::edit($params, $data);
|
||||
|
||||
break;
|
||||
case 3: // 检测订单
|
||||
// 修改订单
|
||||
$data = array();
|
||||
$data['detection_refund_status'] = $refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['detection_no'] = $order['order_no'];
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
|
||||
// 修改退款订单
|
||||
$data = array();
|
||||
$data['detection_refund_status'] = $refund_status;
|
||||
$data['success_time'] = $success_time;
|
||||
|
||||
$params = array();
|
||||
$params['detection_no'] = $order['order_no'];
|
||||
OrderDetectionRefund::edit($params, $data);
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("订单类型错误");
|
||||
}
|
||||
|
||||
// 恢复优惠卷
|
||||
if ($refund_status == 3) {
|
||||
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']);
|
||||
|
||||
try {
|
||||
// 发送站内消息-优惠卷退还
|
||||
$MessagePush = new MessagePush($order_coupon['user_id']);
|
||||
$MessagePush->patientRefundCoupon($order_coupon['coupon_name']);
|
||||
}catch (\Throwable $e){
|
||||
// 此处不处理错误
|
||||
Log::getInstance("CallBack-wxPayInquiryRefund")->error("推送消息失败:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检测问诊订单可退款状态
|
||||
* @param string $order_no
|
||||
*/
|
||||
public function checkOrderInquiryStatusForRefund(string $order_no): void
|
||||
{
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['inquiry_no'] = $order_no;
|
||||
$order_inquiry = OrderInquiry::getOne($params);
|
||||
if (empty($order_inquiry)) {
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
// 检测问诊订单状态
|
||||
if (!in_array($order_inquiry['inquiry_status'], [2, 3, 4, 5, 7])) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
throw new BusinessException("订单状态错误");
|
||||
}
|
||||
|
||||
// 检测订单退款状态
|
||||
if (in_array($order_inquiry['inquiry_refund_status'], [2, 3, 5])) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
// 检测支付状态
|
||||
if ($order_inquiry['inquiry_pay_status'] != 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
throw new BusinessException("订单支付状态错误");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测药品订单可退款状态
|
||||
* @param string $order_no
|
||||
*/
|
||||
public function checkOrderProductStatusForRefund(string $order_no): void
|
||||
{
|
||||
// 获取药品订单数据
|
||||
$params = array();
|
||||
$params['order_product_no'] = $order_no;
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
// 检测药品订单数据状态
|
||||
if ($order_product['order_product_status'] == 1){
|
||||
throw new BusinessException("订单未支付");
|
||||
}
|
||||
|
||||
if ($order_product['order_product_status'] == 4){
|
||||
throw new BusinessException("订单已签收");
|
||||
}
|
||||
|
||||
// 检测商品订单退款状态
|
||||
if ($order_product['refund_status'] == 2){
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
throw new BusinessException("订单退款中");
|
||||
}
|
||||
|
||||
if ($order_product['refund_status'] == 3){
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
throw new BusinessException("订单已退款成功");
|
||||
}
|
||||
|
||||
if ($order_product['refund_status'] == 5){
|
||||
// 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
throw new BusinessException("订单退款关闭");
|
||||
}
|
||||
|
||||
// 检测支付状态
|
||||
if ($order_product['pay_status'] != 2){
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
throw new BusinessException("订单支付状态错误,无法退款");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测检测订单可退款状态
|
||||
* @param string $order_no
|
||||
*/
|
||||
public function checkOrderDetectionStatusForRefund(string $order_no): void
|
||||
{
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['detection_no'] = $order_no;
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)) {
|
||||
throw new BusinessException("订单数据为空");
|
||||
}
|
||||
|
||||
// 检测问诊订单状态
|
||||
if (!in_array($order_detection['detection_status'], [2, 5])) {
|
||||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
throw new BusinessException("订单状态错误");
|
||||
}
|
||||
|
||||
// 检测订单退款状态
|
||||
if (in_array($order_detection['detection_refund_status'], [2, 3, 5, 6])) {
|
||||
// 检测订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
// 检测支付状态
|
||||
if ($order_detection['detection_pay_status'] != 2) {
|
||||
// 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
throw new BusinessException("订单支付状态错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,8 @@ use App\Model\BasicLogisticsCompany;
|
||||
use App\Model\DetectionProject;
|
||||
use App\Model\DoctorInquiryConfig;
|
||||
use App\Model\Hospital;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderCoupon;
|
||||
use App\Model\OrderDetection;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Model\OrderInquiryCase;
|
||||
@ -355,11 +357,22 @@ class PatientOrderService extends BaseService
|
||||
$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) {
|
||||
// 需退款
|
||||
$inquiryService = new InquiryService();
|
||||
$inquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "取消问诊");
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefund($order_inquiry['inquiry_no'], "取消问诊");
|
||||
}
|
||||
|
||||
// 删除锁
|
||||
@ -422,14 +435,28 @@ class PatientOrderService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
}
|
||||
|
||||
// 修改订单删除状态
|
||||
$data = array();
|
||||
$data['is_delete'] = 1;
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 修改问诊订单删除状态
|
||||
$data = array();
|
||||
$data['is_delete'] = 1;
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $data);
|
||||
|
||||
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();
|
||||
}
|
||||
@ -437,8 +464,6 @@ class PatientOrderService extends BaseService
|
||||
/**
|
||||
* 问诊订单取消支付
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function putPatientInquiryOrderCancelPay(): array
|
||||
{
|
||||
@ -459,9 +484,8 @@ class PatientOrderService extends BaseService
|
||||
return fail();
|
||||
}
|
||||
|
||||
$InquiryService = new InquiryService();
|
||||
$result = $InquiryService->cancelUnpayInquiryOrder($order_inquiry['inquiry_no'], 2, "主动取消");
|
||||
|
||||
$OrderService = new OrderService();
|
||||
$result = $OrderService->cancelUnpayOrder($order_inquiry['inquiry_no'],2,"主动取消");
|
||||
if ($result['status'] != 1) {
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
@ -634,9 +658,9 @@ class PatientOrderService extends BaseService
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
}
|
||||
$OrderProductService = new OrderProductService();
|
||||
|
||||
$result = $OrderProductService->cancelUnpayProductOrder($order_product['order_product_no'], 1, "主动取消");
|
||||
$OrderService = new OrderService();
|
||||
$result = $OrderService->cancelUnpayOrder($order_product['order_product_no'], 1, "主动取消");
|
||||
if ($result['status'] != 1) {
|
||||
Db::rollBack();
|
||||
return fail();
|
||||
@ -679,14 +703,30 @@ class PatientOrderService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
}
|
||||
|
||||
// 修改订单状态
|
||||
$data = array();
|
||||
$data['is_delete'] = 1;
|
||||
$data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
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);
|
||||
$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();
|
||||
}
|
||||
@ -972,11 +1012,10 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
*模拟支付成功-金额为0时使用
|
||||
*模拟支付成功-金额为0时使用-问诊订单
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function addPatientOrderPay(): array
|
||||
{
|
||||
@ -1019,8 +1058,8 @@ class PatientOrderService extends BaseService
|
||||
}
|
||||
|
||||
$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;
|
||||
@ -1032,13 +1071,25 @@ class PatientOrderService extends BaseService
|
||||
$data['inquiry_status'] = 2;// 2:待分配
|
||||
}
|
||||
|
||||
$data['escrow_trade_no'] = "GD" . $generator->generate(); // 第三方支付流水号
|
||||
$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) {
|
||||
// 快速-购药
|
||||
// 加入分配医生队列
|
||||
@ -1083,8 +1134,6 @@ class PatientOrderService extends BaseService
|
||||
$message->setDelayMs($time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$producer->produce($message);
|
||||
|
||||
Log::getInstance()->info("发送im消息成功");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
@ -1237,6 +1286,8 @@ class PatientOrderService extends BaseService
|
||||
$pay_channel = 1;
|
||||
} elseif ($client_type == 2) {
|
||||
$pay_channel = 2;
|
||||
}else{
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "支付方式错误");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
@ -1244,6 +1295,24 @@ class PatientOrderService extends BaseService
|
||||
$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'];
|
||||
@ -1251,7 +1320,7 @@ class PatientOrderService extends BaseService
|
||||
$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'] = $generator->generate();
|
||||
$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; // 订单金额
|
||||
@ -1347,6 +1416,18 @@ class PatientOrderService extends BaseService
|
||||
// 处理优惠卷数据
|
||||
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
|
||||
@ -1974,14 +2055,29 @@ class PatientOrderService extends BaseService
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法删除");
|
||||
}
|
||||
|
||||
// 修改订单删除状态
|
||||
$data = array();
|
||||
$data['is_delete'] = 1;
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 修改检测订单删除状态
|
||||
$data = array();
|
||||
$data['is_delete'] = 1;
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
|
||||
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();
|
||||
}
|
||||
@ -2041,18 +2137,29 @@ class PatientOrderService extends BaseService
|
||||
$data = array();
|
||||
$data['detection_status'] = 5;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = 2; // 取消订单原因(1:主动取消 2:客服取消 3:支付超时)
|
||||
$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) {
|
||||
// 需退款
|
||||
$detectionService = new DetectionService();
|
||||
$detectionService->detectionRefund($order_detection['order_detection_id'], "取消检测");
|
||||
$OrderService = new OrderService();
|
||||
$OrderService->orderRefund($order_detection['detection_no'],"取消检测");
|
||||
}
|
||||
|
||||
// 删除锁
|
||||
|
||||
48
app/Utils/Utils.php
Normal file
48
app/Utils/Utils.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils;
|
||||
|
||||
use Hyperf\Context\ApplicationContext;
|
||||
use Hyperf\Redis\Redis;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* @property $container
|
||||
*/
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
* 检测执行次数
|
||||
* @param string $redis_key
|
||||
* @return bool
|
||||
*/
|
||||
public function checkHandleNumber(string $redis_key): bool
|
||||
{
|
||||
try {
|
||||
$redis = ApplicationContext::getContainer()->get(Redis::class);
|
||||
|
||||
$redis_value = $redis->get($redis_key);
|
||||
if (empty($redis_value)) {
|
||||
$redis->set($redis_key, 1, 60 * 60 * 24 * 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 问诊订单执行退款次数过多
|
||||
if ($redis_value > 3) {
|
||||
// 加入短信队列,通知管理员
|
||||
|
||||
// 返回false,删除掉缓存
|
||||
$redis->del($redis_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
$redis->incr($redis_key);
|
||||
} catch (\Throwable $e) {
|
||||
Log::getInstance("Utils-checkHandleNumber")->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user