182 lines
6.3 KiB
PHP
182 lines
6.3 KiB
PHP
<?php
|
|
|
|
namespace admin\controllers\base;
|
|
|
|
use admin\components\BaseAdminController;
|
|
use common\enums\UserRoleEnum;
|
|
use common\helpers\FuncHelper;
|
|
use common\models\DoctorService;
|
|
use common\models\Register;
|
|
use common\models\ServiceUser;
|
|
use yii\db\Exception;
|
|
|
|
class RegisterController extends BaseAdminController
|
|
{
|
|
/**
|
|
* @doc-name 挂号列表
|
|
* @doc-param string mobile 电话 / optional
|
|
* @doc-param string name 患者 / optional
|
|
* @doc-param string order_no 订单号 / optional
|
|
* @doc-param string doctor 医生 / optional
|
|
* @doc-return mixed @List{User{id,user_id,doctor-string-医生,user_patient-string-患者,created_at-string-挂号时间,patient_mobile-string-患者点电话,order_no-string-订单号,depart-int-科室} 用户列表
|
|
* @doc-return mixed @Pagination{total-int-总数量,totalPage-int-总页数,pageSize-int-每页条数} 分页数据
|
|
*/
|
|
public function actionList()
|
|
{
|
|
$get = \Yii::$app->request->get();
|
|
|
|
$admin = \Yii::$app->user->identity;
|
|
if (!empty($get['start_time']) && !empty($get['end_time'])) {
|
|
$start_time = strtotime($get['start_time'] . ' ' . '00:00:00');
|
|
$end_time = strtotime($get['end_time'] . ' ' . '23:59:59');
|
|
}
|
|
|
|
if ($admin->role == UserRoleEnum::STORE_ADMIN) {//门店
|
|
$query = Register::find()->alias('r')->where([
|
|
'r.store_id' => $admin->store_id,
|
|
'r.is_delete' => 0,
|
|
])->orderBy(['r.id' => SORT_DESC]);
|
|
} else {
|
|
$query = Register::find()->alias('r')->where([
|
|
'r.is_delete' => 0
|
|
])->orderBy(['r.id' => SORT_DESC]);
|
|
}
|
|
|
|
$patient = $get['patient_name']?? '';
|
|
$mobile = $get['mobile']?? '';
|
|
$doctor = $get['doctor_name']?? '';
|
|
$query->joinWith(['patient' => function ($p) use ($patient, $mobile) {
|
|
$p->alias('p');
|
|
if (!empty($patient)) {//患者
|
|
$p->andWhere(['like', 'p.name', $patient]);
|
|
}
|
|
|
|
if (!empty($mobile)) {//手机号
|
|
$p->andWhere(['p.mobile' => $mobile]);
|
|
}
|
|
}]);
|
|
$query->joinWith(['doctor' => function ($d) use ($doctor) {
|
|
$d->alias('d');
|
|
if (!empty($doctor)) {//医生
|
|
$d->andWhere(['like', 'd.name', $doctor]);
|
|
}
|
|
}]);
|
|
if (!empty($get['order_no'])) {//订单号
|
|
$query->andWhere(['like', 'order_no', $get['order_no']]);
|
|
}
|
|
|
|
if (!empty($start_time) && !empty($end_time)) {
|
|
if ($start_time == $end_time) {//筛选当天
|
|
$time = FuncHelper::getDayBE($get['start_time']);
|
|
|
|
$end_time = $time[1];
|
|
}
|
|
|
|
$query->andWhere(['between', 'r.created_at', $start_time, $end_time]);
|
|
}
|
|
|
|
$this->field = [
|
|
Register::class => [
|
|
'id', 'doctor' => 'doctor.name', 'user_patient' => 'patient.name', 'patient_mobile' => 'patient.mobile', 'user_id', 'order_no', 'depart' => 'depart.name', 'order_number', 'price', 'is_pay', 'status', 'refuse_reason', 'pay_type',
|
|
'pay_time' => function ($p) {
|
|
if (!empty($p->pay_time)) {
|
|
return date('Y-m-d H:i:s', $p->pay_time);
|
|
} else {
|
|
return '无';
|
|
}
|
|
},
|
|
'is_cancel', 'cancel_status', 'cancel_time', 'cancel_remark', 'refund_status', 'refund_time', 'created_at',
|
|
'patient_age' => 'patient.age'
|
|
]
|
|
];
|
|
return $this->create($query, $get);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 挂号设置
|
|
* @doc-param int su_id 医生ID
|
|
* @doc-param int status 1开启0不开启
|
|
* @doc-param float price 价格 /
|
|
*/
|
|
public function actionRegisterSet()
|
|
{
|
|
$get = \Yii::$app->request->get();
|
|
$this->requestValidate($get, [
|
|
[['su_id', 'status'], 'required'],
|
|
]);
|
|
|
|
$ServiceUser = ServiceUser::find()->where(['id' => $get['su_id'], 'is_delete' => 0])->one();
|
|
if (!$ServiceUser) throw new Exception('医生不存在');
|
|
$DoctorService = DoctorService::findOne(['su_id' => $get['su_id']]);
|
|
if (!$DoctorService) {
|
|
throw new Exception('医生基本信息不存在');
|
|
}
|
|
|
|
if ($get['status'] == 1) {
|
|
$DoctorService->register_status = 1;
|
|
$DoctorService->register_price = $get['price'] ?? 0;
|
|
$DoctorService->saveOrFail();
|
|
return ['已开启挂号服务'];
|
|
} else {
|
|
$DoctorService->register_status = 0;
|
|
$DoctorService->register_price = 0;
|
|
$DoctorService->saveOrFail();
|
|
return ['已关闭挂号服务'];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* @doc-name 挂号费汇总
|
|
*/
|
|
public function actionRegisterStatistic()
|
|
{
|
|
$get = \Yii::$app->request->get();
|
|
|
|
if (!empty($get['start_time']) && !empty($get['end_time'])) {
|
|
$start_time = strtotime($get['start_time'] . ' ' . '00:00:00');
|
|
$end_time = strtotime($get['end_time'] . ' ' . '23:59:59');
|
|
}
|
|
|
|
$user = \Yii::$app->user->identity;
|
|
|
|
$register_query = Register::find()->alias('re');
|
|
|
|
$month_start = strtotime(date('Y-m-01 00:00:00'));
|
|
$month_end = strtotime(date('Y-m-t 23:59:59'));
|
|
|
|
|
|
if (!empty($start_time) && !empty($end_time)) {
|
|
$register_data = ['between', 're.created_at', $start_time, $end_time];
|
|
} else {
|
|
$register_data = ['between', 're.created_at', $month_start, $month_end];
|
|
}
|
|
|
|
if ($user->role == UserRoleEnum::STORE_ADMIN) {
|
|
|
|
$register_query->where(['re.store_id' => $user->store_id]);
|
|
}
|
|
|
|
//挂号
|
|
$register_price = $register_query
|
|
->andWhere([
|
|
'and',
|
|
['=', 'is_pay', 1],
|
|
['<>', 'is_cancel', 1],
|
|
['<>', 're.refund_status', 1],
|
|
['=','is_delete' , 0]
|
|
])
|
|
->andWhere([
|
|
'and',
|
|
['<>', 're.status', 0],
|
|
['<>', 're.status', 4],
|
|
['<>', 're.status', 7],
|
|
])
|
|
->andWhere($register_data ?? '')->sum('price');
|
|
|
|
return [
|
|
'register_price' => $register_price ?? 0,
|
|
];
|
|
}
|
|
} |