患者列表
This commit is contained in:
@@ -49,6 +49,12 @@ class UserPatient extends \common\modelsgii\oldDb\UserPatient
|
||||
{
|
||||
return $this->hasOne(User::class,['user_id'=>'id']);
|
||||
}
|
||||
|
||||
// 用户
|
||||
public function getOneUser()
|
||||
{
|
||||
return $this->hasOne(User::class,['id'=>'user_id']);
|
||||
}
|
||||
// 挂号
|
||||
public function getRegister()
|
||||
{
|
||||
|
||||
@@ -406,70 +406,44 @@ class PatientController extends BaseServiceController
|
||||
*/
|
||||
public function actionPatientList()
|
||||
{
|
||||
|
||||
$post = \Yii::$app->request->post();
|
||||
$this->requestValidate($post, [
|
||||
['status', 'required']
|
||||
]);
|
||||
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,
|
||||
])->andWhere(['r.user_patient_id' => $subQuery])
|
||||
->andWhere(['r.created_at' => $subQuery->select('max_created_at')])
|
||||
->orderBy(['created_at' => SORT_DESC])
|
||||
->with(['patient']);
|
||||
break;
|
||||
case 2:
|
||||
throw new Exception('暂时没写');
|
||||
break;
|
||||
default:
|
||||
throw new Exception('参数错误');
|
||||
}
|
||||
$patientIds = Register::find()->where([
|
||||
'service_user_id' => \Yii::$app->user->id,
|
||||
'store_id' => \Yii::$app->store,
|
||||
'is_delete' => 0,
|
||||
'is_pay' => 1,
|
||||
'is_cancel' => 0,
|
||||
])->select('user_patient_id')->column();
|
||||
$patientIds = array_values(array_unique($patientIds));
|
||||
|
||||
$query = UserPatient::find()->where([
|
||||
'in', 'id', $patientIds
|
||||
])->with(['oneUser']);
|
||||
|
||||
if (!empty($post['name'])) {
|
||||
$name = $post['name'];
|
||||
$query->joinWith(['patient' => function ($model) use ($name) {
|
||||
$model->alias('p');
|
||||
$model->andWhere(['like', 'p.name', $name]);
|
||||
}]);
|
||||
$query->andWhere(['like', 'name', $name]);
|
||||
}
|
||||
if (!empty($post['sex'])) {
|
||||
$sex = $post['sex'];
|
||||
$query->joinWith(['patient' => function ($model) use ($sex) {
|
||||
$model->alias('p');
|
||||
$model->andWhere(['p.sex' => $sex]);
|
||||
}]);
|
||||
$query->andWhere(['sex' => $sex]);
|
||||
}
|
||||
|
||||
$this->field = [
|
||||
Register::class => [
|
||||
UserPatient::class => [
|
||||
'id',
|
||||
'patient_id'=>'patient.id',
|
||||
'user_patient_id'=>'user_patient_id',
|
||||
'patient' => 'patient.name',
|
||||
'avatar' => 'patient.avatar',
|
||||
'user' => 'user',
|
||||
'price', 'pay_time',
|
||||
'patient_id'=>'id',
|
||||
'patient' => 'name',
|
||||
'avatar' => 'avatar',
|
||||
'user' => 'oneUser',
|
||||
'age' => function ($m) {
|
||||
return FuncHelper::getAgeFromIdNo($m->patient->id_card);
|
||||
return FuncHelper::getAgeFromIdNo($m->id_card);
|
||||
},
|
||||
'sex' => 'patient.sex',
|
||||
'sex' => 'sex',
|
||||
'recent_accept' => 'created_at'
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user