|
|
|
|
@ -367,6 +367,20 @@ class UserOrderController extends Controller
|
|
|
|
|
return Yo::echo(['info' => $order_info]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//锁定预约记录
|
|
|
|
|
public function lock_appointment($hospital,$data){
|
|
|
|
|
$peis = new PEISApiController();
|
|
|
|
|
$url_code ='个检预约锁定';
|
|
|
|
|
$info = $peis::Post($url_code, $hospital, $data);
|
|
|
|
|
return $info;
|
|
|
|
|
}
|
|
|
|
|
//取消锁定预约记录
|
|
|
|
|
public function unlock_appointment($hospital,$data){
|
|
|
|
|
$peis = new PEISApiController();
|
|
|
|
|
$url_code ='个检预约解锁';
|
|
|
|
|
$info = $peis::Post($url_code, $hospital, $data);
|
|
|
|
|
return $info;
|
|
|
|
|
}
|
|
|
|
|
public function refund(Request $request)
|
|
|
|
|
{
|
|
|
|
|
Login::user();
|
|
|
|
|
@ -377,55 +391,119 @@ class UserOrderController extends Controller
|
|
|
|
|
if (!$order_info) Yo::error_echo(100000, ['订单']);
|
|
|
|
|
if ($order_info->status != 2) Yo::error_echo(200051);
|
|
|
|
|
if ($order_info->check_status == 2) Yo::error_echo(200052);
|
|
|
|
|
self::cancel_appointment($order_info->hospital, [
|
|
|
|
|
'type' => $order_info->type,
|
|
|
|
|
'预约Id' => $order_info->appointment_number
|
|
|
|
|
]);
|
|
|
|
|
$appointment = Appointment::where('id', $order_info->appointment)->first();
|
|
|
|
|
if (!!$appointment) {
|
|
|
|
|
$appointment->used_count -= 1;
|
|
|
|
|
$appointment->save();
|
|
|
|
|
}
|
|
|
|
|
$order_info->appointment_number = '';
|
|
|
|
|
switch ($order_info->pay_type) {
|
|
|
|
|
case 1:
|
|
|
|
|
$hospital_extra_content = self::pay_config($order_info->hospital);
|
|
|
|
|
$wcp = new WeChatPayController();
|
|
|
|
|
$wcp->builder([
|
|
|
|
|
'appid' => env('WX_APP_ID'),
|
|
|
|
|
'pem_path' => base_path() . $hospital_extra_content['wxp']['key'],
|
|
|
|
|
'cer_path' => base_path() . $hospital_extra_content['wxp']['crt'],
|
|
|
|
|
'cer_num' => $hospital_extra_content['wxp']['number'],
|
|
|
|
|
'mchid' => $hospital_extra_content['wxp']['id'],
|
|
|
|
|
'v3' => $hospital_extra_content['wxp']['v3'],
|
|
|
|
|
]);
|
|
|
|
|
$out_trade_no = $order_info->show;
|
|
|
|
|
$wcr = new WeChatRefund();
|
|
|
|
|
$post_data = [
|
|
|
|
|
'transaction_id' => $order_info->transaction,
|
|
|
|
|
'out_refund_no' => $out_trade_no,
|
|
|
|
|
'total' => $order_info->true_price * 100,
|
|
|
|
|
];
|
|
|
|
|
$wcr->out_trade_no = $out_trade_no;
|
|
|
|
|
$wcr->post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$pay = $wcp->refund($post_data);
|
|
|
|
|
$wcr->params = json_encode($pay, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$wcr->save();
|
|
|
|
|
if (isset($pay['code'])) Yo::error_echo(200076);
|
|
|
|
|
if ($pay['status'] != 'PROCESSING' && $pay['status'] != 'SUCCESS') Yo::error_echo(200053);
|
|
|
|
|
$order_info->status = 5;
|
|
|
|
|
$order_info->refund = $wcr->id;
|
|
|
|
|
$order_info->refund_time = date('Y-m-d H:i:s');
|
|
|
|
|
$order_info->save();
|
|
|
|
|
return Yo::echo();
|
|
|
|
|
case 2:
|
|
|
|
|
Yo::error_echo(200047);
|
|
|
|
|
case 3:
|
|
|
|
|
$order_info->status = 5;
|
|
|
|
|
$order_info->refund_time = date('Y-m-d H:i:s');
|
|
|
|
|
$order_info->save();
|
|
|
|
|
return Yo::echo();
|
|
|
|
|
$appointment_id=$order_info->appointment_number;
|
|
|
|
|
//如果是个检预约,先进行锁定,再退款,再取消预约
|
|
|
|
|
if($order_info->type==1){
|
|
|
|
|
//锁定
|
|
|
|
|
self::lock_appointment($order_info->hospital, [
|
|
|
|
|
'预约Id' => $order_info->appointment_number
|
|
|
|
|
]);
|
|
|
|
|
$order_info->appointment_number = '';
|
|
|
|
|
switch ($order_info->pay_type) {
|
|
|
|
|
case 1:
|
|
|
|
|
$hospital_extra_content = self::pay_config($order_info->hospital);
|
|
|
|
|
$wcp = new WeChatPayController();
|
|
|
|
|
$wcp->builder([
|
|
|
|
|
'appid' => env('WX_APP_ID'),
|
|
|
|
|
'pem_path' => base_path() . $hospital_extra_content['wxp']['key'],
|
|
|
|
|
'cer_path' => base_path() . $hospital_extra_content['wxp']['crt'],
|
|
|
|
|
'cer_num' => $hospital_extra_content['wxp']['number'],
|
|
|
|
|
'mchid' => $hospital_extra_content['wxp']['id'],
|
|
|
|
|
'v3' => $hospital_extra_content['wxp']['v3'],
|
|
|
|
|
]);
|
|
|
|
|
$out_trade_no = $order_info->show;
|
|
|
|
|
$wcr = new WeChatRefund();
|
|
|
|
|
$post_data = [
|
|
|
|
|
'transaction_id' => $order_info->transaction,
|
|
|
|
|
'out_refund_no' => $out_trade_no,
|
|
|
|
|
'total' => $order_info->true_price * 100,
|
|
|
|
|
];
|
|
|
|
|
$wcr->out_trade_no = $out_trade_no;
|
|
|
|
|
$wcr->post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$pay = $wcp->refund($post_data);
|
|
|
|
|
$wcr->params = json_encode($pay, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$wcr->save();
|
|
|
|
|
if (isset($pay['code'])) Yo::error_echo(200076);
|
|
|
|
|
if ($pay['status'] != 'PROCESSING' && $pay['status'] != 'SUCCESS'){ //如果退款失败,则解除锁定
|
|
|
|
|
self::unlock_appointment($order_info->hospital, [
|
|
|
|
|
'预约Id' =>$appointment_id
|
|
|
|
|
]);
|
|
|
|
|
Yo::error_echo(200053);
|
|
|
|
|
}
|
|
|
|
|
$order_info->status = 5;
|
|
|
|
|
$order_info->refund = $wcr->id;
|
|
|
|
|
$order_info->refund_time = date('Y-m-d H:i:s');
|
|
|
|
|
$order_info->save();
|
|
|
|
|
// return Yo::echo();
|
|
|
|
|
case 2:
|
|
|
|
|
// Yo::error_echo(200048);
|
|
|
|
|
case 3:
|
|
|
|
|
$order_info->status = 5;
|
|
|
|
|
$order_info->refund_time = date('Y-m-d H:i:s');
|
|
|
|
|
$order_info->save();
|
|
|
|
|
// return Yo::echo();
|
|
|
|
|
}
|
|
|
|
|
self::cancel_appointment($order_info->hospital, [
|
|
|
|
|
'type' => $order_info->type,
|
|
|
|
|
'预约Id' => $appointment_id
|
|
|
|
|
]);
|
|
|
|
|
$appointment = Appointment::where('id', $order_info->appointment)->first();
|
|
|
|
|
if (!!$appointment) {
|
|
|
|
|
$appointment->used_count -= 1;
|
|
|
|
|
$appointment->save();
|
|
|
|
|
}
|
|
|
|
|
}else{ //如果不是个检预约,则先取消,再退款
|
|
|
|
|
self::cancel_appointment($order_info->hospital, [
|
|
|
|
|
'type' => $order_info->type,
|
|
|
|
|
'预约Id' => $order_info->appointment_number
|
|
|
|
|
]);
|
|
|
|
|
$appointment = Appointment::where('id', $order_info->appointment)->first();
|
|
|
|
|
if (!!$appointment) {
|
|
|
|
|
$appointment->used_count -= 1;
|
|
|
|
|
$appointment->save();
|
|
|
|
|
}
|
|
|
|
|
$order_info->appointment_number = '';
|
|
|
|
|
switch ($order_info->pay_type) {
|
|
|
|
|
case 1:
|
|
|
|
|
$hospital_extra_content = self::pay_config($order_info->hospital);
|
|
|
|
|
$wcp = new WeChatPayController();
|
|
|
|
|
$wcp->builder([
|
|
|
|
|
'appid' => env('WX_APP_ID'),
|
|
|
|
|
'pem_path' => base_path() . $hospital_extra_content['wxp']['key'],
|
|
|
|
|
'cer_path' => base_path() . $hospital_extra_content['wxp']['crt'],
|
|
|
|
|
'cer_num' => $hospital_extra_content['wxp']['number'],
|
|
|
|
|
'mchid' => $hospital_extra_content['wxp']['id'],
|
|
|
|
|
'v3' => $hospital_extra_content['wxp']['v3'],
|
|
|
|
|
]);
|
|
|
|
|
$out_trade_no = $order_info->show;
|
|
|
|
|
$wcr = new WeChatRefund();
|
|
|
|
|
$post_data = [
|
|
|
|
|
'transaction_id' => $order_info->transaction,
|
|
|
|
|
'out_refund_no' => $out_trade_no,
|
|
|
|
|
'total' => $order_info->true_price * 100,
|
|
|
|
|
];
|
|
|
|
|
$wcr->out_trade_no = $out_trade_no;
|
|
|
|
|
$wcr->post_data = json_encode($post_data, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$pay = $wcp->refund($post_data);
|
|
|
|
|
$wcr->params = json_encode($pay, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
$wcr->save();
|
|
|
|
|
if (isset($pay['code'])) Yo::error_echo(200076);
|
|
|
|
|
if ($pay['status'] != 'PROCESSING' && $pay['status'] != 'SUCCESS') Yo::error_echo(200053);
|
|
|
|
|
$order_info->status = 5;
|
|
|
|
|
$order_info->refund = $wcr->id;
|
|
|
|
|
$order_info->refund_time = date('Y-m-d H:i:s');
|
|
|
|
|
$order_info->save();
|
|
|
|
|
return Yo::echo();
|
|
|
|
|
case 2:
|
|
|
|
|
Yo::error_echo(200048);
|
|
|
|
|
case 3:
|
|
|
|
|
$order_info->status = 5;
|
|
|
|
|
$order_info->refund_time = date('Y-m-d H:i:s');
|
|
|
|
|
$order_info->save();
|
|
|
|
|
return Yo::echo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Yo::echo(['info' => $order_info]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|