取消检测订单,取消订单订阅消息推送
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\Area;
|
||||
use App\Model\BasicCompany;
|
||||
use App\Model\BasicNation;
|
||||
@@ -12,10 +13,12 @@ use App\Model\DetectionProjectPurpose;
|
||||
use App\Model\DiseaseClassDetection;
|
||||
use App\Model\OrderDetection;
|
||||
use App\Model\OrderDetectionCase;
|
||||
use App\Model\OrderDetectionRefund;
|
||||
use App\Model\PatientFamily;
|
||||
use App\Model\UserDoctor;
|
||||
use App\Model\UserLocation;
|
||||
use App\Utils\Log;
|
||||
use Extend\Wechat\WechatPay;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Snowflake\IdGeneratorInterface;
|
||||
@@ -242,7 +245,7 @@ class DetectionService extends BaseService
|
||||
$doctor['hospital_name'] = $value['Hospital']['hospital_name'];
|
||||
}
|
||||
|
||||
// unset($value['Hospital']);
|
||||
unset($value['Hospital']);
|
||||
|
||||
$value['avatar'] = addAliyunOssWebsite($value['avatar']);
|
||||
}
|
||||
@@ -547,4 +550,112 @@ class DetectionService extends BaseService
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测订单退款接口
|
||||
*/
|
||||
public function detectionRefund(string $order_detection_id, string $refund_reason)
|
||||
{
|
||||
// 获取订单数据
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection_id;
|
||||
$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("订单支付状态错误");
|
||||
}
|
||||
|
||||
// 系统退款编号
|
||||
$generator = $this->container->get(IdGeneratorInterface::class);
|
||||
$detection_refund_no = $generator->generate();
|
||||
|
||||
// 检测订单金额
|
||||
if ($order_detection['payment_amount_total'] > 0){
|
||||
// 发起退款
|
||||
$WechatPay = new WechatPay(1, 1);
|
||||
|
||||
$options = array();
|
||||
$options['transaction_id'] = $order_detection['escrow_trade_no'];
|
||||
$options['out_refund_no'] = (string)$detection_refund_no;
|
||||
$options['reason'] = $refund_reason;
|
||||
$options['amount'] = [
|
||||
'refund' => (int)round($order_detection['payment_amount_total'] * 100),
|
||||
'total' => (int)round($order_detection['payment_amount_total'] * 100),
|
||||
'currency' => "CNY",
|
||||
];
|
||||
|
||||
$result = $WechatPay->refund($options);
|
||||
|
||||
// 处理订单退款状态
|
||||
// 检测订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
$success_time = "";
|
||||
if ($result['status'] == "SUCCESS") {
|
||||
// 退款成功
|
||||
$detection_refund_status = 3;
|
||||
$success_time = $result['success_time'];
|
||||
} elseif ($result['status'] == "CLOSED") {
|
||||
// 退款关闭
|
||||
$detection_refund_status = 5;
|
||||
} elseif ($result['status'] == "PROCESSING") {
|
||||
// 退款处理中
|
||||
$detection_refund_status = 2;
|
||||
} elseif ($result['status'] == "ABNORMAL") {
|
||||
// 退款异常,此情况不处理,进行短信通知
|
||||
throw new BusinessException("订单退款状态异常");
|
||||
} else {
|
||||
throw new BusinessException("订单退款状态错误");
|
||||
}
|
||||
|
||||
$refund_id = $result['refund_id'];
|
||||
}else{
|
||||
$detection_refund_status = 3;
|
||||
$success_time = date('Y-m-d H:i:s',time());
|
||||
$refund_id = $generator->generate();
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
$data = array();
|
||||
$data['patient_id'] = $order_detection['patient_id'];
|
||||
$data['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
$data['detection_no'] = $order_detection['detection_no'];
|
||||
$data['detection_refund_no'] = $detection_refund_no;
|
||||
$data['refund_id'] = $refund_id;
|
||||
$data['detection_refund_status'] = $detection_refund_status;
|
||||
$data['refund_total'] = $order_detection['payment_amount_total'];
|
||||
$data['refund_reason'] = $refund_reason;
|
||||
|
||||
if ($detection_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'] = $detection_refund_status;
|
||||
|
||||
$params = array();
|
||||
$params['order_detection_id'] = $order_detection['order_detection_id'];
|
||||
OrderDetection::editOrderDetection($params, $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user