个检退款,先锁定再退款

main
yanzai 2 years ago
parent 95e7089b3f
commit 6cfbdef589

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

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

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

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

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

Loading…
Cancel
Save