取消检测订单,取消订单订阅消息推送
This commit is contained in:
@@ -1780,6 +1780,96 @@ class PatientOrderService extends BaseService
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消检测订单
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function putCancelPatientDetectionOrder(): array
|
||||
{
|
||||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||||
|
||||
$order_detection_id = $this->request->route('order_detection_id');
|
||||
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$params['order_detection_id'] = $order_detection_id;
|
||||
$params['is_delete'] = 0;
|
||||
$order_detection = OrderDetection::getOne($params);
|
||||
if (empty($order_detection)) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
$redis = $this->container->get(Redis::class);
|
||||
$redis_key = "order_detection_lock_" . $order_detection_id;
|
||||
$redis_lock = $redis->setnx($redis_key, 1);
|
||||
// 设置过期时间
|
||||
$redis->expire($redis_key, 3);
|
||||
if (!$redis_lock) {
|
||||
// 设置失败,表示已经设置该值
|
||||
return fail(HttpEnumCode::HTTP_SUCCESS, "请您稍后重试");
|
||||
}
|
||||
|
||||
// 检测订单状态
|
||||
if (!in_array($order_detection['detection_status'], [2])) {
|
||||
// 检测订单状态(1:待支付 2:待绑定 3:检测中 4:检测完成 5:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法取消");
|
||||
}
|
||||
|
||||
if ($order_detection['detection_refund_status'] == 1) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单申请退款中,请您稍后取消");
|
||||
}
|
||||
|
||||
if ($order_detection['detection_refund_status'] == 2) {
|
||||
// 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单正在退款中,请您稍后取消");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 退款成功
|
||||
// 修改问诊订单为取消
|
||||
$data = array();
|
||||
$data['detection_status'] = 5;
|
||||
$data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$data['cancel_reason'] = 2; // 取消订单原因(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);
|
||||
|
||||
// 检测支付状态,判断是否需要退款处理
|
||||
if ($order_detection['detection_pay_status'] == 2 && $order_detection['detection_refund_status'] != 3) {
|
||||
// 需退款
|
||||
$detectionService = new DetectionService();
|
||||
$detectionService->detectionRefund($order_detection['order_detection_id'], "取消检测");
|
||||
}
|
||||
|
||||
// 删除锁
|
||||
$redis->del($redis_key);
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
if (!empty($order_inquiry['doctor_id'])) {
|
||||
// 推送患者-订单取消成功通知
|
||||
$MessagePush = new MessagePush($order_detection['user_id'], $order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->patientCancelOrderSuccess($order_detection['order_detection_id']);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return success();
|
||||
}
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取患者未完成订单
|
||||
|
||||
Reference in New Issue
Block a user