|
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\API\H5;
|
|
|
|
use App\Http\Controllers\API\AspNetZhuanController;
|
|
|
|
use App\Http\Controllers\API\AspNetZhuanController;
|
|
|
|
use App\Http\Controllers\API\XCXApiController;
|
|
|
|
use App\Http\Controllers\API\XCXApiController;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
|
|
|
use App\Services\OrderService;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
|
|
|
|
@ -109,113 +110,11 @@ class PayController extends Controller
|
|
|
|
//判断订单状态是否是已经支付,判断是否到检,
|
|
|
|
//判断订单状态是否是已经支付,判断是否到检,
|
|
|
|
$openid = request('openid');
|
|
|
|
$openid = request('openid');
|
|
|
|
$id = request('id');
|
|
|
|
$id = request('id');
|
|
|
|
$orderInfo = DB::table('orders')->where(['id' => $id])->first();
|
|
|
|
if(!isset($id)) return \Yz::echoError1("id不能为空");
|
|
|
|
if (!$orderInfo) return \Yz::echoError1("未找到有效订单");
|
|
|
|
$service = new OrderService();
|
|
|
|
if ($orderInfo->status !== 2) return \Yz::echoError1("订单状态异常。当前状态:" . $orderInfo->status);
|
|
|
|
$res=$service->Refund($id);
|
|
|
|
if ($orderInfo->check_status == 2) return \Yz::echoError1("已登记体检,禁止退款");
|
|
|
|
if(!$res['status']) return \Yz::echoError1($res['msg']);
|
|
|
|
$person=DB::table('web_user_person')->where(['id' => $orderInfo->person_id])->first();
|
|
|
|
if($res['status']) return \Yz::Return(true, "退款成功", []);
|
|
|
|
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, "退款成功", []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|