From 1f4ff14f1589589e7837104c3b3bbb523ecd6baf Mon Sep 17 00:00:00 2001 From: liqi Date: Mon, 6 Jan 2025 15:42:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=82=A3=E8=80=85=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/v1/controllers/PatientController.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/service/modules/v1/controllers/PatientController.php b/service/modules/v1/controllers/PatientController.php index 32349dc..e549683 100644 --- a/service/modules/v1/controllers/PatientController.php +++ b/service/modules/v1/controllers/PatientController.php @@ -412,13 +412,25 @@ class PatientController extends BaseServiceController ]); switch ($post['status']) { case 1: + // 子查询:找到每个 user_patient_id 的最大 created_at 时间 + $subQuery = (new \yii\db\Query()) + ->select(['r.user_patient_id', 'MAX(r.created_at) as max_created_at']) + ->from(['r' => Register::tableName()]) + ->where([ + 'r.service_user_id' => \Yii::$app->user->id, + 'r.store_id' => \Yii::$app->store, + 'r.is_delete' => 0, + 'r.is_pay' => 1, + 'r.is_cancel' => 0, + ]) + ->groupBy(['r.user_patient_id']); $query = Register::find()->alias('r')->where([ 'r.service_user_id' => \Yii::$app->user->id, 'r.store_id' => \Yii::$app->store, 'r.is_delete' => 0, 'r.is_pay' => 1, 'r.is_cancel' => 0, - ])->orderBy(['created_at' => SORT_DESC]) + ])->andWhere(['r.user_patient_id' => $subQuery])->orderBy(['created_at' => SORT_DESC]) ->with(['patient']); break; case 2: