info(json_encode($data, JSON_UNESCAPED_UNICODE)); Db::beginTransaction(); try { // 验证参数 if (!isset($data['order_prescription_id'])){ Db::rollBack(); Log::getInstance("queue-PrescriptionExpired")->error("入参错误"); return Result::DROP; } // 获取处方数据 $params = array(); $params['order_prescription_id'] = $data['order_prescription_id']; $order_prescription = OrderPrescription::getOne($params); if (empty($order_prescription)){ Db::rollBack(); Log::getInstance("queue-PrescriptionExpired")->error("获取处方数据为空"); return Result::DROP; } // 检测处方审核、使用状态 $res = $this->checkPrescriptionStatus($order_prescription); if (!$res){ Db::rollBack(); return Result::ACK; } // 处理处方过期状态 $this->handlePrescription($order_prescription); Db::commit(); Log::getInstance("queue-PrescriptionExpired")->info("成功"); return Result::ACK; } catch (\Exception $e) { Db::rollBack(); Log::getInstance("queue-PrescriptionExpired")->error($e->getMessage()); return Result::ACK; // 重回队列 } } /** * 检测处方审核状态 * @param array|object $order_prescription * @return bool */ protected function checkPrescriptionStatus(array|object $order_prescription): bool { if ($order_prescription['prescription_status'] == 3){ Db::rollBack(); Log::getInstance("queue-PrescriptionExpired")->info("处方已失效,无需处理"); return false; } if ($order_prescription['prescription_status'] == 4){ Db::rollBack(); Log::getInstance("queue-PrescriptionExpired")->info("处方已使用,无需处理"); return false; } return true; } /** * 处理处方过期状态 * @param array|object $order_prescription * @return void */ protected function handlePrescription(array|object $order_prescription): void { $params = array(); $params['order_prescription_id'] = $order_prescription['order_prescription_id']; $data = array(); $data['prescription_status'] = 3; $data['expired_time'] = date('Y-m-d H:i:s',time()); OrderPrescription::edit($params,$data); } }