| xqd
@@ -414,4 +414,71 @@ class Order extends BaseModel
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ //后台预约订单取消
|
|
|
+ public static function appiontOrderCancel($order_id, $order_notes = '')
|
|
|
+ {
|
|
|
+ $order = Order::with(['orderPatient'])->where('id', $order_id)->first()->toArray();
|
|
|
+ //判断预约时间是否还剩1小时内
|
|
|
+ $can_refund = true;
|
|
|
+ if (in_array($order['product_type'], [3,4,5])) {
|
|
|
+ if ($order['order_patient']['appoint_start_time'] - 3600 < time()) {
|
|
|
+ $can_refund = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //改变订单状态
|
|
|
+ $updateOrder = ['order_status' => 5, 'order_notes' => $order_notes];
|
|
|
+ if ($order['payment_status'] > 1) {
|
|
|
+ //判断是余额支付还是服务包支付
|
|
|
+ if ($order['payment_type'] == 3) {
|
|
|
+ //退服务包的次数
|
|
|
+ $map = [1 => 'phone_minutes', 2 => 'chat_num', 3 => 'appoint_num', 4 => 'vaccine_limit_amount', 5 => 'nurses_limit_amount'];
|
|
|
+ OrderPack::where('id', $order['pay_order_pack_id'])->increment($map[$order['product_type']]);
|
|
|
+ $updateOrder['cancel_time'] = time();
|
|
|
+ $updateOrder['payment_status'] = 4;
|
|
|
+ if ($order['product_type'] == 3 && !$can_refund) {
|
|
|
+ $updateOrder['payment_status'] = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //申请退款
|
|
|
+ $updateOrder['cancel_time'] = time();
|
|
|
+ //实际付款大于0元才发起退款
|
|
|
+ if ($can_refund && $order['payment_amount'] > 0) {
|
|
|
+ $updateOrder['payment_status'] = 5;
|
|
|
+ $arr = [
|
|
|
+ 'order_id' =>$order_id,
|
|
|
+ 'status' => 1,
|
|
|
+ 'refund_applicant' => \Admin::user()->id,
|
|
|
+ ];
|
|
|
+ RefundApplication::create($arr);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($order['product_type'] == 3 && !$can_refund) {
|
|
|
+ $updateOrder['payment_status'] = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Order::where('id', $order_id)->update($updateOrder);
|
|
|
+
|
|
|
+ //如果是门诊预约且距离预约时间还有1个小时以上,那么预约时间段的订单数减1
|
|
|
+ if ($order['product_type'] == 3 && $can_refund) {
|
|
|
+ $schedule_date = date('Y-m-d', $order['order_patient']['appoint_start_time']);
|
|
|
+ SchedulePeriod::where('docter_id', $order['docter_id'])->where('organization_id', $order['organization_id'])->where('time_period_id', $order['order_patient']['time_period_id'])->where('schedule_date', $schedule_date)->where('order_num', '>', 0)->decrement('order_num');
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果是疫苗儿保预约且距离预约时间还有1个小时以上,那么预约时间段的订单数减1
|
|
|
+ if (in_array($order['product_type'], [4,5]) && $can_refund) {
|
|
|
+ $schedule_type_map = [4 => 2, 5 => 3];
|
|
|
+ $schedule_date = date('Y-m-d', $order['order_patient']['appoint_start_time']);
|
|
|
+ SchedulePeriod::where('organization_id', $order['organization_id'])->where('time_period_id', $order['order_patient']['time_period_id'])->where('schedule_date', $schedule_date)->where('schedule_type', $schedule_type_map[$order['product_type']])->where('order_num', '>', 0)->decrement('order_num');
|
|
|
+ }
|
|
|
+ //如果是疫苗预约那么取消订单就增加疫苗库存
|
|
|
+ if ($order['product_type'] == 4) {
|
|
|
+ $orderVaccine = OrderVaccine::where('order_id', $order_id)->first();
|
|
|
+ Vaccine::where('id', $orderVaccine['vaccine_id'])->increment('stock');
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|