| xqd
@@ -170,25 +170,43 @@ class Order extends BaseModel
|
|
|
public static function orderCancel($order_id, $order_notes = '')
|
|
|
{
|
|
|
$order = Order::with(['orderPatient'])->where('id', $order_id)->first();
|
|
|
+ //判断预约时间是否还剩1小时内
|
|
|
+ $can_refund = true;
|
|
|
+ if (in_array($order['product_type'], [3,4,5])) {
|
|
|
+ $order_notes = '用户取消预约';
|
|
|
+ if ($order['order_patient']['appoint_start_time'] - 3600 < time()) {
|
|
|
+ $order_notes = '用户超时取消';
|
|
|
+ $can_refund = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
//改变订单状态
|
|
|
$updateOrder = ['order_status' => 5, 'order_notes' => $order_notes];
|
|
|
if ($order['payment_status'] > 1) {
|
|
|
//退钱到余额
|
|
|
- if (!empty($order['payment_amount'])) {
|
|
|
+ if (!empty($order['payment_amount']) && $can_refund) {
|
|
|
User::changeBalance($order_id, $order['payment_amount'], 4, $order['id'], '取消订单退款');
|
|
|
}
|
|
|
- $updateOrder['refund_time'] = time();
|
|
|
- $updateOrder['payment_status'] = 4;
|
|
|
+ $updateOrder['cancel_time'] = time();
|
|
|
+ if ($can_refund) {
|
|
|
+ $updateOrder['payment_status'] = 4;
|
|
|
+ }
|
|
|
}
|
|
|
Order::where('id', $order_id)->update($updateOrder);
|
|
|
|
|
|
- //如果是预约类订单且距离预约时间还有半个小时以上,那么预约时间段的订单数减1
|
|
|
- if (in_array($order['product_type'], [3,4,5]) && $order['order_patient']['appoint_start_time'] - 1800 > time()) {
|
|
|
+ //如果是门诊预约且距离预约时间还有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)->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']])->decrement('order_num');
|
|
|
+ }
|
|
|
//更新医生的服务人数
|
|
|
- if ($order['payment_status'] > 1) {
|
|
|
+ if ($order['payment_status'] > 1 && in_array($order['product_type'], [1,2,3])) {
|
|
|
Docter::where('id', $order['docter_id'])->decrement('service_persons');
|
|
|
}
|
|
|
|