where('name', 'like', '%' . $searchInfo['name'] . '%'); } if (isset($searchInfo['id_number'])) { $list = $list->where('id_number', $searchInfo['id_number']); } if (isset($searchInfo['order_number'])) { $list = $list->where('order_number', $searchInfo['order_number']); } $count = $list->count(); $list = $list->orderBy('id', 'desc') ->skip(($page - 1) * $pageSize) // 跳过前9999条记录 ->take($pageSize)->get(); return \Yz::Return(true, "查询完成", ['list' => $list, 'count' => $count]); } public function GetDetail() { $id = request('id'); $order = DB::table('orders')->where(['id' => $id])->first(); return \Yz::Return(true, "查询完成", ['info' => $order]); } public function Save() { $info = request('info'); $date = [ 'note' => $info['note'] ]; $u = DB::table('orders')->where(['id' => $info['id']])->update($date); if ($u) { return \Yz::Return(true, "操作完成", []); } else { return \Yz::echoError1("保存失败"); } } public function Refund() { $order_id = request('order_id'); $do_type = request('do_type');//1仅退款 2取消预约并退款 $orderInfo = DB::table('orders')->where(['id' => $order_id])->first(); if (!$orderInfo) return \Yz::echoError1("未找到有效订单"); $person = DB::table('web_user_person')->where(['id' => $orderInfo->person_id])->first(); if (!$person) return \Yz::echoError1("用户不存在"); if ($do_type == 2) { if ($orderInfo->status !== 2) return \Yz::echoError1("订单状态异常。当前状态:" . $orderInfo->status); if ($orderInfo->check_status == 2) return \Yz::echoError1("已登记体检,禁止退款"); //调用思信取消,恢复号源 if ($orderInfo->appointment_number <> null and $orderInfo->appointment_number <> '') { $ap = new \App\Http\Controllers\API\H5\OrderController(); $cancel = $ap->cancel_appointment($orderInfo->hospital_id, [ 'type' => $orderInfo->type, '预约Id' => $orderInfo->appointment_number ]); if ($cancel['code'] != 0) return \Yz::echoError1("取消预约失败," . $cancel['message']); } } if (in_array($do_type, [1, 2])) { //如果有二线取消二线 $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' => $order_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, "退款成功", []); } } }