217 lines
8.5 KiB
PHP
217 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace service\modules\v1\controllers;
|
|
|
|
use common\core\BaseAppController;
|
|
use common\enums\RegisterEnum;
|
|
use common\helpers\FuncHelper;
|
|
use common\models\newDb\ClinicSalespersonModel;
|
|
use common\models\oldDb\Register;
|
|
use common\models\oldDb\UserPatientCase;
|
|
use common\services\ExportService;
|
|
use yii\db\Exception;
|
|
|
|
/**
|
|
* @doc-module 到店挂号
|
|
*/
|
|
class RegisterController extends BaseAppController
|
|
{
|
|
/**
|
|
* @doc-name 挂号收益统计
|
|
* @doc-return float current_day 当天收益
|
|
* @doc-return float current_month 当月收益
|
|
* @doc-return float total_price 总收益
|
|
*/
|
|
public function actionPrice()
|
|
{
|
|
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
|
|
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
|
|
$current_day= Register::find()->alias('r')->where([
|
|
'r.service_user_id' => \Yii::$app->user->id,
|
|
'r.is_delete' => 0,
|
|
'r.is_pay' => 1,
|
|
'r.is_cancel' => 0,
|
|
])->andWhere(['between', 'created_at', $beginToday, $endToday])->sum('price');
|
|
|
|
$beginThismonth = mktime(0, 0, 0, date('m'), 1, date('Y'));
|
|
$endThismonth = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
|
|
$current_month = Register::find()->alias('r')->where([
|
|
'r.service_user_id' => \Yii::$app->user->id,
|
|
'r.is_delete' => 0,
|
|
'r.is_pay' => 1,
|
|
'r.is_cancel' => 0,
|
|
])->andWhere(['between', 'created_at', $beginThismonth, $endThismonth])->sum('price');
|
|
$total_price = Register::find()->alias('r')->where([
|
|
'r.service_user_id' => \Yii::$app->user->id,
|
|
'r.is_delete' => 0,
|
|
'r.is_pay' => 1,
|
|
'r.is_cancel' => 0,
|
|
])->sum('price');
|
|
return [
|
|
'current_month' => $current_month??0,
|
|
'current_day' => $current_day??0,
|
|
'total_price' => $total_price??0
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @doc-name 挂号人数统计
|
|
* @doc-return int current_month 当月挂号人数
|
|
* @doc-return int current_day 当天挂号人数
|
|
*/
|
|
public function actionRegisterNumber()
|
|
{
|
|
$beginThismonth = mktime(0, 0, 0, date('m'), 1, date('Y'));
|
|
$endThismonth = mktime(23, 59, 59, date('m'), date('t'), date('Y'));
|
|
|
|
$current_month = Register::find()->alias('r')->where([
|
|
'r.service_user_id' => \Yii::$app->user->id,
|
|
'r.is_delete' => 0,
|
|
'r.is_pay' => 1,
|
|
'r.is_cancel' => 0,
|
|
])->andWhere(['between', 'created_at', $beginThismonth, $endThismonth])->count();
|
|
|
|
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
|
|
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
|
|
|
|
$current_day= Register::find()->alias('r')->where([
|
|
'r.service_user_id' => \Yii::$app->user->id,
|
|
'r.is_delete' => 0,
|
|
'r.is_pay' => 1,
|
|
'r.is_cancel' => 0,
|
|
])->andWhere(['between', 'created_at', $beginToday, $endToday])->count();
|
|
return [
|
|
'current_month' => $current_month,
|
|
'current_day' => $current_day
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @doc-name 挂号列表(或到店接诊或挂号患者接口)
|
|
* @doc-param string order_no 挂号单号 / optional
|
|
* @doc-param string name 姓名 / optional
|
|
* @doc-param string start_time 起始时间 / optional
|
|
* @doc-param string end_time 终止时间 / optional
|
|
* @doc-param int status 状态:1已支付待接诊2接诊中3已结束4已取消5待评价6已评价7已拒诊 / optional
|
|
* @doc-return mixed @List{id-int-挂号id,is_case-string-是否有病历0无1有,user_patient_id-int-患者id,store-string-门店,depart-string-科室,order_number-int-挂号序号,price-float-挂号金额,patient-string-患者,idcard-string-身份证,mobile-string-手机号,status-int-状态1待接诊2接诊中3已结束4已取消5待评价6已评价7已拒诊,is_pay-int-是否支付0否1是,created_at-string-挂号时间,sex-int-性别0未知1男2女,order_no-string-订单单号} 挂号信息
|
|
* @doc-return mixed @Pagination{total-int-总数据,totalPage-int-总页数,pageSize-int-每页多少条} 分页信息
|
|
*/
|
|
public function actionList()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$Register = Register::find()->alias('r')->where([
|
|
'r.service_user_id' => \Yii::$app->user->id,
|
|
'r.is_delete' => 0,
|
|
'r.is_pay' => 1,
|
|
'r.type' => 0,
|
|
'r.is_cancel' => 0,
|
|
'r.store_id' => \Yii::$app->store
|
|
])->all();
|
|
if (!$Register) throw new Exception('没有任何挂号');
|
|
|
|
$query = Register::find()->alias('r')->where([
|
|
'r.service_user_id' => \Yii::$app->user->id,
|
|
'r.is_delete' => 0,
|
|
'r.is_pay' => 1,
|
|
'r.type' => 0,
|
|
'r.is_cancel' => 0,
|
|
'r.store_id' => \Yii::$app->store
|
|
])->with(['store', 'depart', 'patient'])->orderBy(['id'=>SORT_DESC]);
|
|
|
|
if (!empty($post['order_no'])){
|
|
$query->andWhere(['order_no'=>$post['order_no']]);
|
|
}
|
|
|
|
if (!empty($post['name'])){
|
|
$name=$post['name'];
|
|
$query->joinWith(['patient' => function ($p) use ($name) {
|
|
$p->alias('p');
|
|
$p->andWhere(['like', 'p.name', $name]);
|
|
}]);
|
|
}
|
|
|
|
if (!empty($post['start_time']) && !empty($post['end_time']) ){
|
|
$query->andWhere(['between','r.created_at',strtotime($post['start_time']),strtotime($post['end_time'])]);
|
|
}
|
|
|
|
if (!empty($post['status'])) {
|
|
switch ($post['status']) {
|
|
case RegisterEnum::WAIT:
|
|
$query->andWhere(['status' => RegisterEnum::WAIT]);
|
|
break;
|
|
case RegisterEnum::ACCEPTING:
|
|
$query->andWhere(['status' => RegisterEnum::ACCEPTING]);
|
|
break;
|
|
case RegisterEnum::OVER:
|
|
$query->andWhere(['in','status', [RegisterEnum::OVER, RegisterEnum::REFUSE]]);
|
|
break;
|
|
case RegisterEnum::CANCEL:
|
|
$query->andWhere(['status' => RegisterEnum::CANCEL]);
|
|
break;
|
|
case RegisterEnum::UNCOMMENT:
|
|
$query->andWhere(['status' => RegisterEnum::UNCOMMENT]);
|
|
break;
|
|
case RegisterEnum::CONMENTED:
|
|
$query->andWhere(['status' => RegisterEnum::CONMENTED]);
|
|
break;
|
|
case RegisterEnum::REFUSE:
|
|
$query->andWhere(['status' => RegisterEnum::REFUSE]);
|
|
break;
|
|
default:
|
|
throw new Exception('参数错误');
|
|
}
|
|
}
|
|
|
|
$this->field = [
|
|
Register::class => [
|
|
'id','doctor_mobile'=>'doctor.mobile',
|
|
'is_case'=>function($m){
|
|
$UserPatientCase= UserPatientCase::find()->where(['register_id'=>$m->id])->one();
|
|
if ($UserPatientCase){
|
|
return 1;
|
|
}
|
|
return 0;
|
|
},
|
|
'user_patient_id','order_no',
|
|
'store' => 'store.name',
|
|
'depart' => 'depart.name',
|
|
'order_number', 'price',
|
|
'patient' => 'patient.name',
|
|
'avatar' => 'patient.avatar',
|
|
'idcard' => 'patient.id_card',
|
|
'mobile' => 'patient.mobile',
|
|
'status', 'is_pay', 'created_at',
|
|
'age' => function ($m) {
|
|
return FuncHelper::getAgeFromIdNo($m->patient->id_card);
|
|
},
|
|
'sex'=>'patient.sex',
|
|
'salesperson_name' => function ($m) {
|
|
if (!$m->hasAttribute('salesperson_id') || (int) $m->salesperson_id <= 0) {
|
|
return '';
|
|
}
|
|
$sp = ClinicSalespersonModel::findOne((int) $m->salesperson_id);
|
|
if (!$sp) {
|
|
return '';
|
|
}
|
|
|
|
return (string) ($sp->nick_name ?? $sp->phone ?? '');
|
|
},
|
|
]
|
|
];
|
|
return $this->create($query, $post);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 挂号导出
|
|
*/
|
|
public function actionInventory()
|
|
{
|
|
$headlist=['就诊人id','诊所id','订单号','挂号序号','挂号金额','是否支付','拒诊原因'];
|
|
$Name='导出挂号';
|
|
$class=new Register();
|
|
(new ExportService())->export($headlist,$Name,$class);
|
|
|
|
}
|
|
|
|
|
|
} |