| xqd
@@ -8,6 +8,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
+use App\Models\Docter;
|
|
|
use App\Models\Nurse;
|
|
|
use App\Models\Order;
|
|
|
use App\Models\OrderNurse;
|
| xqd
@@ -16,6 +17,7 @@ use App\Models\OrderPatient;
|
|
|
use App\Models\OrderVaccine;
|
|
|
use App\Models\Patient;
|
|
|
use App\Models\Payment;
|
|
|
+use App\Models\SchedulePeriod;
|
|
|
use App\Models\ServicePack;
|
|
|
use App\Models\Team;
|
|
|
use App\Models\TimePeriod;
|
| xqd
@@ -626,4 +628,51 @@ class OrderController extends AuthController
|
|
|
|
|
|
return out($config);
|
|
|
}
|
|
|
+
|
|
|
+ public function orderCancel()
|
|
|
+ {
|
|
|
+ $req = request()->post();
|
|
|
+ $this->validate(request(), [
|
|
|
+ 'order_id' => 'required|integer'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $order = Order::with(['orderPatient'])->where('id', $req['order_id'])->first();
|
|
|
+ if ($order['order_status'] == 4) {
|
|
|
+ return out(null, 10001, '订单已完成,不能取消了');
|
|
|
+ }
|
|
|
+ if ($order['order_status'] == 5) {
|
|
|
+ return out(null, 10002, '订单已取消了,请勿重复操作');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($order['product_type'] == 3) {
|
|
|
+ if ($order['order_patient']['appoint_start_time'] + 1800 > time()) {
|
|
|
+ return out(null, 10003, '预约时间临近,不能取消订单了');
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ //改变订单状态
|
|
|
+ Order::where('id', $req['order_id'])->update(['order_status' => 5]);
|
|
|
+ //退钱到余额
|
|
|
+ User::changeBalance($order['user_id'], $order['payment_amount'], 4, $order['id'], '取消订单退款');
|
|
|
+ //预约时间段的订单数减1
|
|
|
+ $orderPatient = OrderPatient::select(['time_period_id', 'appoint_start_time'])->where('order_id', $req['order_id'])->first();
|
|
|
+ $schedule_date = date('Y-m-d', $orderPatient['appoint_start_time']);
|
|
|
+ SchedulePeriod::where('docter_id', $order['docter_id'])->where('organization_id', $order['organization_id'])->where('time_period_id', $orderPatient['time_period_id'])->where('schedule_date', $schedule_date)->decrement('order_num');
|
|
|
+ //更新医生的服务人数
|
|
|
+ Docter::where('id', $order['docter_id'])->decrement('service_persons');
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ } catch (Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+
|
|
|
+ return out(null, 500, '取消订单失败,请稍后重试', $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return out(null, 10001, '暂时只支持取消门诊预约的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ return out();
|
|
|
+ }
|
|
|
}
|