209 lines
8.5 KiB
PHP
209 lines
8.5 KiB
PHP
<?php
|
|
|
|
namespace member\modules\v1\controllers;
|
|
|
|
use common\core\BaseAppController;
|
|
use common\enums\OrderStatusEnum;
|
|
use common\helpers\ArrayHelper;
|
|
use common\helpers\FuncHelper;
|
|
use common\models\oldDb\Order;
|
|
use common\models\oldDb\ServiceUser;
|
|
use common\models\oldDb\UserInquiry;
|
|
use member\models\forms\AskForm;
|
|
use member\models\forms\OrderSubmitResultForm;
|
|
use yii\base\Exception;
|
|
|
|
/**
|
|
* @doc-module 订单管理
|
|
*/
|
|
class OrderController extends BaseAppController
|
|
{
|
|
/**
|
|
* @doc-name 图文问诊
|
|
* @doc-desc 图文问诊后返回订单id,通过订单id去调用订单接口的支付
|
|
* @doc-param int doctor_id 问闻声
|
|
* @doc-param string desc 病情
|
|
* @doc-param json images 检查报告或者患处图片["img1","img2"]
|
|
* @doc-param int patient_id 就诊人id
|
|
* @doc-param int is_visit 是否就诊过0否1是 0 optional
|
|
* @doc-param string visit_desc 就诊描述,is_visit为1必填 / optional
|
|
* @doc-param int liver_function 肝功能0正常1异常 0 optional
|
|
* @doc-param int renal_function 肾功能0正常1异常 0 optional
|
|
* @doc-param string allergic_status 过敏史0无1有 0 optional
|
|
* @doc-param string allergic_history 过敏史选项,选项添加不用保存后台,["选项1","选项2"] [] optional
|
|
* @doc-param string person_status 个人病史0无1有 0 optional
|
|
* @doc-param string person_history 个人病史选项,选项添加不用保存后台,["选项1","选项2"] [] optional
|
|
* @doc-param string family_status 家庭病史0无1有 0 optional
|
|
* @doc-param string family_history 家庭病史选项,选项添加不用保存后台,["选项1","选项2"] [] optional
|
|
* @doc-param int type 1图文2视频
|
|
* @doc-return int order_id 订单id
|
|
*/
|
|
public function actionSubmit()
|
|
{
|
|
$form = new AskForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
return $form->saves();
|
|
}
|
|
|
|
/**
|
|
* @doc-name 订单列表
|
|
* @doc-param int status 0全部1待支付2待接诊3咨询中4待评价
|
|
* @doc-param int page 页码 1 optional
|
|
* @doc-param int page_size 每页条数 20 optional
|
|
* @doc-return mixde @List{Order{id,doctor_avator-string-医生头像,doctor_name-string-医生姓名,doctor_depart-string-医生科室,desc-string-问诊病情,created_at,type,@Order_status{status-int-状态1待支付2待接诊3咨询中4待评价5已完成6已取消,text-string-文字表示}}} 订单列表
|
|
* @doc-return mixed @Pagination{total_count-int-总数量,page_count-int-总页数,current_page-int-当前页,per_page-int-每页条数} 分页数据
|
|
*/
|
|
public function actionList()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
|
|
$query = Order::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
])->with('serviceUser','serviceUser.docInfo','serviceUser.docIdentity','serviceUser.docInfo.depart','inquiry')->orderBy('id desc');
|
|
|
|
$status = ArrayHelper::getValue($post,'status',0);
|
|
switch($status){
|
|
case OrderStatusEnum::WAIT_PAY: //待支付
|
|
$query->andWhere([
|
|
'is_pay' => 0,
|
|
'cancel_status' => 0
|
|
]);
|
|
break;
|
|
case OrderStatusEnum::WAIT_ACCEPT: //待接诊
|
|
$query->andWhere([
|
|
'is_pay' => 1,
|
|
'cancel_status' => 0,
|
|
'accept_status' => OrderStatusEnum::WAIT_ACCEPT,
|
|
]);
|
|
break;
|
|
case OrderStatusEnum::ACCEPTING: //咨询中
|
|
$query->andWhere([
|
|
'is_pay' => 1,
|
|
'cancel_status' => 0,
|
|
'accept_status' => OrderStatusEnum::ACCEPTING,
|
|
]);
|
|
break;
|
|
case OrderStatusEnum::WAIT_COMMENT: //待评价
|
|
$query->andWhere([
|
|
'is_pay' => 1,
|
|
'cancel_status' => 0,
|
|
'accept_status' => OrderStatusEnum::ACCEPTING,
|
|
'is_comment' => 0
|
|
]);
|
|
break;
|
|
}
|
|
|
|
$this->field = [
|
|
Order::class => [
|
|
'id',
|
|
'doctor_avator' => 'serviceUser.docIdentity.work_avator',
|
|
'doctor_name' => 'serviceUser.docInfo.name',
|
|
'doctor_depart' => 'serviceUser.docInfo.depart.name',
|
|
'desc' => function($model){
|
|
if($model->type==1){
|
|
return $model->inquiry->desc;
|
|
}else{
|
|
return null;
|
|
}
|
|
},
|
|
'created_at',
|
|
'type',
|
|
'order_status' => function($model){
|
|
return Order::status_info($model);
|
|
}
|
|
],
|
|
];
|
|
|
|
return $this->create($query,$post);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 订单详情
|
|
* @doc-param int order_id 订单id
|
|
* @doc-return mixed Order{id,su_id,up_id-int-患者id,type,order_no,total_pay_price,is_pay,pay_time,pay_type,cancel_status,cancel_time,auto_cancel_time,auto_refund_time,auto_over_time,accept_status,accept_time,over_time,created_at,cancel_remark,@Order_status{status-int-状态1待支付2待接诊3咨询中4待评价5已完成6已取消,text-string-文字表示},ims_id-int-消息会话id,@ServiceUser{avator-string-头像,name-string-名称,depart-string-科室,hospital-string-医院,yard-string-院区},@Inquiry{UserInquiry{desc,images,is_visit,visit_desc},@Patient_data{name-string-姓名,age-int-年龄,sex-int-1男2女}}} 订单详情
|
|
*/
|
|
public function actionInfo()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
['order_id','required']
|
|
]);
|
|
$info = Order::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->id,
|
|
'id' => $post['order_id'],
|
|
])->with('serviceUser','serviceUser.docInfo','serviceUser.docIdentity','serviceUser.docInfo.depart','serviceUser.docInfo.hospital','inquiry','session')->one();
|
|
if(!$info){
|
|
throw new Exception('订单不存在');
|
|
}
|
|
|
|
return ArrayHelper::toArray($info,[
|
|
Order::class => [
|
|
'id','su_id','up_id','type','order_no','total_pay_price','is_pay','pay_time','pay_type','cancel_status','cancel_time','auto_cancel_time','auto_refund_time','auto_over_time','accept_status','accept_time','over_time','created_at','cancel_remark','order_status'=>function($model){
|
|
return Order::status_info($model);
|
|
},
|
|
'ims_id' => 'session.ims_id',
|
|
'serviceUser','inquiry'
|
|
],
|
|
ServiceUser::class => [
|
|
'avator' => 'docIdentity.work_avator',
|
|
'name' => 'docInfo.name',
|
|
'depart' => 'docInfo.depart.name',
|
|
'hospital' => 'docInfo.hospital.name',
|
|
'yard' => 'docInfo.yard.name',
|
|
'title' => 'docInfo.title.name',
|
|
],
|
|
UserInquiry::class => [
|
|
'desc','images','is_visit','visit_desc',
|
|
'patient_data' => function($model){
|
|
$patient_data = json_decode($model->patient_data,true);
|
|
return [
|
|
'name' => $patient_data['name'],
|
|
'age' => FuncHelper::getAgeFromIdNo($patient_data['id_card']),
|
|
'sex' => $patient_data['sex'],
|
|
];
|
|
},
|
|
]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 获取支付配置
|
|
* @doc-param int order_id 订单id
|
|
* @doc-return int is_paid 1已支付0未支付
|
|
* @doc-return int order_id 订单id
|
|
* @doc-return array config 支付配置参数,在is_paid=0时返回
|
|
*/
|
|
public function actionPay()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
['order_id','required']
|
|
]);
|
|
$form = new OrderSubmitResultForm();
|
|
return $form->getPayData($post['order_id']);
|
|
}
|
|
|
|
/**
|
|
* @doc-name 取消订单
|
|
* @doc-param int order_id 订单id
|
|
*/
|
|
public function actionCancel()
|
|
{
|
|
$post = \Yii::$app->request->post();
|
|
$this->requestValidate($post,[
|
|
['order_id','required']
|
|
]);
|
|
$form = new \common\forms\OrderRefundForm();
|
|
return $form->refund($post['order_id']);
|
|
}
|
|
|
|
/**
|
|
* 去评价
|
|
*/
|
|
public function actionComment()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
} |