diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/OrderController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/OrderController.php index e089382..63aae10 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/OrderController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/OrderController.php @@ -2,50 +2,173 @@ namespace App\Http\Controllers\API\Admin\YeWu; +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; class OrderController extends Controller { - public function GetList() - { - $page = request('page'); - $pageSize = request('pageSize'); - $searchInfo = request('searchInfo'); - $list=DB::table('orders'); - if(isset($searchInfo['name'])){ - $list = $list->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 GetList() + { + $page = request('page'); + $pageSize = request('pageSize'); + $searchInfo = request('searchInfo'); + $list = DB::table('orders'); + if (isset($searchInfo['name'])) { + $list = $list->where('name', 'like', '%' . $searchInfo['name'] . '%'); } - public function GetDetail() - { - $id = request('id'); - $order=DB::table('orders')->where(['id'=>$id])->first(); - return \Yz::Return(true,"查询完成",['info'=>$order]); + if (isset($searchInfo['id_number'])) { + $list = $list->where('id_number', $searchInfo['id_number']); } - 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("保存失败"); + 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, "退款成功", []); + } + + } } diff --git a/Laravel/app/Http/Controllers/API/H5/PayController.php b/Laravel/app/Http/Controllers/API/H5/PayController.php index b05bb66..aa6d93f 100644 --- a/Laravel/app/Http/Controllers/API/H5/PayController.php +++ b/Laravel/app/Http/Controllers/API/H5/PayController.php @@ -138,7 +138,7 @@ class PayController extends Controller 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([ @@ -208,7 +208,8 @@ class PayController extends Controller } DB::table('orders')->where(['id' => $id])->update([ - 'status' => 5 + 'status' => 5, + 'refund_time'=>$now_datetime ]); //恢复号源 $up_plan = DB::table('plans')->where(['id' => $orderInfo->plan_id, 'status' => 2])->update([ diff --git a/Laravel/routes/api.php b/Laravel/routes/api.php index 908f75b..66b4703 100644 --- a/Laravel/routes/api.php +++ b/Laravel/routes/api.php @@ -115,6 +115,7 @@ Route::group(['middleware' => ['checktoken', 'log'], 'prefix' => 'v1'], function Route::post('admin/OrderGetList', 'App\Http\Controllers\API\Admin\YeWu\OrderController@GetList');//订单列表 Route::post('admin/OrderGetDetail', 'App\Http\Controllers\API\Admin\YeWu\OrderController@GetDetail');//订单详情 Route::post('admin/OrderSave', 'App\Http\Controllers\API\Admin\YeWu\OrderController@Save');//订单保存 + Route::post('admin/OrderRefund', 'App\Http\Controllers\API\Admin\YeWu\OrderController@Refund');//订单退款 Route::post('admin/QuestionGetList', 'App\Http\Controllers\API\Admin\YeWu\QuestionController@GetList');//问答列表 Route::post('admin/QuestionSave', 'App\Http\Controllers\API\Admin\YeWu\QuestionController@Save');//保存题目 Route::post('admin/QuestionGetDetail', 'App\Http\Controllers\API\Admin\YeWu\QuestionController@GetDetail');//题目详情 diff --git a/admin/src/api/api.js b/admin/src/api/api.js index 7dad294..fda94c0 100644 --- a/admin/src/api/api.js +++ b/admin/src/api/api.js @@ -263,7 +263,10 @@ export const YuYueOrderGetDetail = (data = {}) => { export const YuYueOrderSave = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/YuYueOrderSave', data: data }) } - +//订单退款 +export const OrderRefund = (data = {}) => { + return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/OrderRefund', data: data }) +} //获取问答列表 export const QuestionGetList = (data = {}) => { return axios({ url: import.meta.env.VITE_APP_API + 'v1/admin/QuestionGetList', data: data }) diff --git a/admin/src/views/OrderMngr/Order.vue b/admin/src/views/OrderMngr/Order.vue index 39797d8..4a1396d 100644 --- a/admin/src/views/OrderMngr/Order.vue +++ b/admin/src/views/OrderMngr/Order.vue @@ -85,12 +85,24 @@ {{Info.yucunkuan}} + +
预约成功:{{Info.appointment_number}}
+
预约失败
+
待支付 - 已预约 +
+ 已付款 +
交易关闭 - 已完成 +
+ 已完成 +
已退款 +
+ 仅退款 + 取消预约、退款 +
待检 @@ -124,13 +136,11 @@ ref, onMounted } from 'vue' - import { - ElMessage - } from 'element-plus' +import {ElMessage, ElMessageBox} from 'element-plus' import { OrderGetList, OrderGetDetail, - OrderSave + OrderSave,OrderRefund } from '@/api/api.js' import { Edit @@ -199,6 +209,32 @@ } }) } + const Refund=(do_type)=>{ + ElMessageBox.confirm( + '是否确认为此订单退款?', + '提示', + { + confirmButtonText: '确认', + cancelButtonText: '取消', + type: 'warning', + } + ).then(() => { + loading.value = true + OrderRefund({ + order_id: Info.value.id, + do_type: do_type, + }).then(res => { + loading.value = false + if (res.status) { + GetDetailFunc(Info.value.id) + } else { + ElMessage.error(res.msg) + } + }) + }).catch(() => { + }) + + } onMounted(() => { GetList() })