个检退款,先锁定再退款

main
yanzai 2 years ago
parent 95e7089b3f
commit 6cfbdef589

@ -99,6 +99,7 @@ class ComboItemController extends Controller
'clinic' => $item['科室Id'],
'clinic_name' => $item['科室名称'],
'choose' => $item['可选'],
'jianjie'=>$item['简介'],
];
}
return $list;

@ -40,6 +40,8 @@ class PEISApiController extends Controller
$api['套餐详情查询'] = "{$url}/PEISCommon/QueryComboDetail/{$code}";
$api['自选项目查询'] = "{$url}/PEISCommon/QueryGroups/{$code}";
$api['套餐查询'] = "{$url}/PEISCommon/QueryCombos/{$code}";
$api['个检预约锁定'] = "{$url}/PEISCommon/LockPersonAppointment/{$code}";
$api['个检预约解锁'] = "{$url}/PEISCommon/UnlockPersonAppointment/{$code}";
return $api["{$url_code}"] ?? $url_code;
}

@ -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]);
}

@ -1,7 +1,7 @@
let url_ = "https://bjrrtj-api.cjy.net.cn";
let report_url_ = "https://bjrrtj-api.cjy.net.cn";
let h5_url_ = "https://bjrrtj-api.cjy.net.cn";
const dev = 0;
const dev = 1;
if (dev === 1) {
url_ = "http://localbeijingrenren";
report_url_ = "http://192.168.31.106:5173";

@ -3,7 +3,7 @@ import {
} from '@/lu/axios.js'
import $api from './api.js'
let url_ = "https://bjrrtj-api.cjy.net.cn";
const dev = 0
const dev = 1
if (dev === 1) {
url_ = "http://localbeijingrenren"
}

Loading…
Cancel
Save