diff --git a/app/Services/InquiryService.php b/app/Services/InquiryService.php index a824403..d98b2ec 100644 --- a/app/Services/InquiryService.php +++ b/app/Services/InquiryService.php @@ -1185,20 +1185,34 @@ class InquiryService extends BaseService return true; } - if (!empty($order_inquiry_coupon)) { - // 恢复优惠卷 - $data = array(); + // 获取用户优惠卷数据 + $params = array(); + $params['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id']; + $user_coupon = UserCoupon::getOne($params); + if (empty($user_coupon)){ + // 无该优惠卷数据,无需处理 + return true; + } + + // 恢复优惠卷 + $data = array(); + + // 检测优惠卷过期时间。判断是否需要退还 + if (strtotime($user_coupon['valid_end_time']) <= time()){ + // 超出过期时间,置为已过期 + $data['user_coupon_status'] = 3; + }else{ $data['user_coupon_status'] = 0; $data['coupon_use_date'] = null; - - $params = array(); - $params['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id']; - UserCoupon::edit($params, $data); - - // 发送站内消息-优惠卷退还 - $MessagePush = new MessagePush($patient_user_id,$order_inquiry_id); - $MessagePush->patientRefundCoupon(); } + + $params = array(); + $params['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id']; + UserCoupon::edit($params, $data); + + // 发送站内消息-优惠卷退还 + $MessagePush = new MessagePush($patient_user_id,$order_inquiry_id); + $MessagePush->patientRefundCoupon(); return true; } catch(\Exception $e){ Log::getInstance()->error("退还用户优惠卷失败" . $e->getMessage());