调整退款代码结构,下单记录配偶信息

main
yanzai 11 months ago
parent 4cd3fdc775
commit 1bc6ce26a1

@ -75,6 +75,7 @@ class OrderController extends Controller
$type = request('type');//1个检2团检
$group_id = request('group_id');//团检id
$item_ids = request('item_ids');//自选item的ids
$peiou_info = request('peiou_info');//配偶信息
if (count($item_ids) != 0 and $item_ids[0] == "") {
$item_ids = [];
@ -131,8 +132,12 @@ class OrderController extends Controller
'group' => [
'id' => '',
],
'nmr_list' => []
'nmr_list' => [],
'peiou_info' => [],
];
if (!empty($peiou_info)) {
$buy_info['peiou_info'] = $peiou_info ;
}
//如果是套餐
$Nx1_arrInfo = [];
$TJ_Leixing_id = 1;//存储用体检类型

@ -5,6 +5,7 @@ namespace App\Http\Controllers\API\H5;
use App\Http\Controllers\API\AspNetZhuanController;
use App\Http\Controllers\API\XCXApiController;
use App\Http\Controllers\Controller;
use App\Services\OrderService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
@ -109,113 +110,11 @@ class PayController extends Controller
//判断订单状态是否是已经支付,判断是否到检,
$openid = request('openid');
$id = request('id');
$orderInfo = DB::table('orders')->where(['id' => $id])->first();
if (!$orderInfo) return \Yz::echoError1("未找到有效订单");
if ($orderInfo->status !== 2) return \Yz::echoError1("订单状态异常。当前状态:" . $orderInfo->status);
if ($orderInfo->check_status == 2) return \Yz::echoError1("已登记体检,禁止退款");
$person=DB::table('web_user_person')->where(['id' => $orderInfo->person_id])->first();
if(!$person) return \Yz::echoError1("用户不存在");
//调用思信取消,恢复号源
if($orderInfo->appointment_number<>null and $orderInfo->appointment_number<>''){
$ap = new OrderController();
$cancel = $ap->cancel_appointment($orderInfo->hospital_id, [
'type' => $orderInfo->type,
'预约Id' => $orderInfo->appointment_number
]);
if ($cancel['code'] != 0) return \Yz::echoError1("取消预约失败," . $cancel['message']);
}
//如果有二线取消二线
$yyid=6;
if($orderInfo->hospital_id == 1){
$yyid=6;
}
if($orderInfo->hospital_id == 4){
$yyid=2;
}
$AspNet=new AspNetZhuanController();
$erxian_info=json_decode($orderInfo->erxian_appointment_info, true);
if (isset($erxian_info) and !empty($erxian_info)) {
foreach ($erxian_info as $key => $plan_nmr) {
if(isset($plan_nmr['gid'])){
//调用接口取消二线
$erxian_status = $AspNet::ErXian(['id' =>$plan_nmr['gid'], 'yyid' => $yyid, 'action' => 3], uniqid());
$erxian_info[$key]['gid']='';
$ex_u= DB::table('orders')->where(['id' => $orderInfo->id])->update([
'erxian_appointment_info'=>json_encode($erxian_info, JSON_UNESCAPED_UNICODE),
]);
}
}
}
//如果真实支付大于0 则调用小程序退款
if ($orderInfo->true_price > 0) {
$data = [
'orderid' => $orderInfo->order_number,
'refund_order_id' => 'T' . $orderInfo->order_number,
'refund_amount' => (int)($orderInfo->true_price * 100),
'refund_reason' => "体检H5订单退款",
];
$XCX = new XCXApiController();
$res = $XCX::Post('订单退款', $data);
if ($res['data']['refund_state'] != 'SUCCESS') {
return \Yz::echoError1("退款失败" . $res['data']['refund_state']);
}
}
$now_datetime=date('Y-m-d H:i:s');
//调用接口恢复积分和预存款
$env=config('app.globals.Env');
$AspNet=new AspNetZhuanController();
$jifen_huifu_status=true;
$yucunkuan_huifu_status=true;
$r_yyid=$orderInfo->hospital_id;
if($r_yyid==1){
$yyid=6;
}
if($r_yyid==4){
$yyid=2;
}
if($env=='pro') { //如果是正式环境
if($orderInfo->jifen>0 and $orderInfo->is_refund_jifen==0) {
$jifen_huifu_status=false;
$jifen_huifu_status= $AspNet::UseJiFen($person->ghzid,$orderInfo->jifen,$yyid,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime);
if( $jifen_huifu_status===true){
DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_jifen'=>1]);
}
}
if($orderInfo->yucunkuan>0 and $orderInfo->is_refund_yucunkuan==0) {
$yucunkuan_huifu_status=false;
$yucunkuan_huifu_status= $AspNet::UseYuCunKuan($person->ghzid,$orderInfo->yucunkuan,$yyid,0,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime);
if($yucunkuan_huifu_status===true){
DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_yucunkuan'=>1]);
}
}
if(!empty($orderInfo->youhuiquan)){
$youhuiquan=json_decode( $orderInfo->youhuiquan,true);
$data=[
'action'=>4,
'ghzid'=>$person->ghzid,
'dzjid'=>$youhuiquan['id'],
'hxbz'=>"H5撤销核销",
'yyid'=>$yyid
];
$AspNet::YouHuiQuan($data);
}
}
DB::table('orders')->where(['id' => $id])->update([
'status' => 5,
'refund_time'=>$now_datetime
]);
//恢复号源
$up_plan = DB::table('plans')->where(['id' => $orderInfo->plan_id, 'status' => 2])->update([
'status' => 1
]);
return \Yz::Return(true, "退款成功", []);
if(!isset($id)) return \Yz::echoError1("id不能为空");
$service = new OrderService();
$res=$service->Refund($id);
if(!$res['status']) return \Yz::echoError1($res['msg']);
if($res['status']) return \Yz::Return(true, "退款成功", []);
}

@ -2,7 +2,9 @@
namespace App\Services;
use App\Http\Controllers\API\AspNetZhuanController;
use App\Http\Controllers\API\H5\OrderController;
use App\Http\Controllers\API\PEISApiController;
use App\Http\Controllers\API\XCXApiController;
use Illuminate\Support\Facades\DB;
class OrderService
@ -185,4 +187,114 @@ class OrderService
]);
return true;
}
public function Refund($id)
{
$orderInfo = DB::table('orders')->where(['id' => $id])->first();
if (!$orderInfo) return ['status'=>false,'msg'=>"未找到有效订单"];
if ($orderInfo->status !== 2) return ['status'=>false,'msg'=>"订单状态异常。当前状态:" . $orderInfo->status];
if ($orderInfo->check_status == 2) return ['status'=>false,'msg'=>"已登记体检,禁止退款"];
$person=DB::table('web_user_person')->where(['id' => $orderInfo->person_id])->first();
if(!$person) return ['status'=>false,'msg'=>"用户不存在"];
//调用思信取消,恢复号源
if($orderInfo->appointment_number<>null and $orderInfo->appointment_number<>''){
$ap = new OrderController();
$cancel = $ap->cancel_appointment($orderInfo->hospital_id, [
'type' => $orderInfo->type,
'预约Id' => $orderInfo->appointment_number
]);
if ($cancel['code'] != 0) return ['status'=>false,'msg'=>"取消预约失败," . $cancel['message']];
}
//如果有二线取消二线
$yyid=6;
if($orderInfo->hospital_id == 1){
$yyid=6;
}
if($orderInfo->hospital_id == 4){
$yyid=2;
}
$AspNet=new AspNetZhuanController();
$erxian_info=json_decode($orderInfo->erxian_appointment_info, true);
if (isset($erxian_info) and !empty($erxian_info)) {
foreach ($erxian_info as $key => $plan_nmr) {
if(isset($plan_nmr['gid'])){
//调用接口取消二线
$erxian_status = $AspNet::ErXian(['id' =>$plan_nmr['gid'], 'yyid' => $yyid, 'action' => 3], uniqid());
$erxian_info[$key]['gid']='';
$ex_u= DB::table('orders')->where(['id' => $orderInfo->id])->update([
'erxian_appointment_info'=>json_encode($erxian_info, JSON_UNESCAPED_UNICODE),
]);
}
}
}
//如果真实支付大于0 则调用小程序退款
if ($orderInfo->true_price > 0) {
$data = [
'orderid' => $orderInfo->order_number,
'refund_order_id' => 'T' . $orderInfo->order_number,
'refund_amount' => (int)($orderInfo->true_price * 100),
'refund_reason' => "体检H5订单退款",
];
$XCX = new XCXApiController();
$res = $XCX::Post('订单退款', $data);
if ($res['data']['refund_state'] != 'SUCCESS') {
return ['status'=>false,'msg'=>"退款失败" . $res['data']['refund_state']];
}
}
$now_datetime=date('Y-m-d H:i:s');
//调用接口恢复积分和预存款
$env=config('app.globals.Env');
$AspNet=new AspNetZhuanController();
$jifen_huifu_status=true;
$yucunkuan_huifu_status=true;
$r_yyid=$orderInfo->hospital_id;
if($r_yyid==1){
$yyid=6;
}
if($r_yyid==4){
$yyid=2;
}
if($env=='pro') { //如果是正式环境
if($orderInfo->jifen>0 and $orderInfo->is_refund_jifen==0) {
$jifen_huifu_status=false;
$jifen_huifu_status= $AspNet::UseJiFen($person->ghzid,$orderInfo->jifen,$yyid,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime);
if( $jifen_huifu_status===true){
DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_jifen'=>1]);
}
}
if($orderInfo->yucunkuan>0 and $orderInfo->is_refund_yucunkuan==0) {
$yucunkuan_huifu_status=false;
$yucunkuan_huifu_status= $AspNet::UseYuCunKuan($person->ghzid,$orderInfo->yucunkuan,$yyid,0,$orderInfo->id,'tj_h5','抵扣体检H5订单',$now_datetime);
if($yucunkuan_huifu_status===true){
DB::table('orders')->where('id',$orderInfo->id)->update(['is_refund_yucunkuan'=>1]);
}
}
if(!empty($orderInfo->youhuiquan)){
$youhuiquan=json_decode( $orderInfo->youhuiquan,true);
$data=[
'action'=>4,
'ghzid'=>$person->ghzid,
'dzjid'=>$youhuiquan['id'],
'hxbz'=>"H5撤销核销",
'yyid'=>$yyid
];
$AspNet::YouHuiQuan($data);
}
}
DB::table('orders')->where(['id' => $id])->update([
'status' => 5,
'refund_time'=>$now_datetime
]);
//恢复号源
$up_plan = DB::table('plans')->where(['id' => $orderInfo->plan_id, 'status' => 2])->update([
'status' => 1
]);
return ['status'=>true,'msg'=>"退款成功"];
}
}

Loading…
Cancel
Save