初始化仓库
This commit is contained in:
124
member/modules/v1/controllers/UserCommentController.php
Normal file
124
member/modules/v1/controllers/UserCommentController.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
namespace member\modules\v1\controllers;
|
||||
|
||||
use common\core\BaseAppController;
|
||||
use common\enums\OrderAcceptEnum;
|
||||
use common\models\Order;
|
||||
use common\models\UserComment;
|
||||
use member\models\forms\CommentForm;
|
||||
use yii\db\Exception;
|
||||
|
||||
/**
|
||||
* @doc-module 用户评价
|
||||
*/
|
||||
class UserCommentController extends BaseAppController
|
||||
{
|
||||
/**
|
||||
* @doc-name 添加评价
|
||||
* @doc-param int su_id 医生id
|
||||
* @doc-param int u_id 患者id
|
||||
* @doc-param int score 评分1很差2较差3好4很好5非常好
|
||||
* @doc-param string comment 内容
|
||||
* @doc-param int order_id 订单id
|
||||
*/
|
||||
public function actionSave()
|
||||
{
|
||||
$post= \Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[['order_id','su_id','u_id','comment','score'],'required']
|
||||
]);
|
||||
$order=Order::find()->where([
|
||||
'id'=>$post['order_id'],
|
||||
'user_id'=>\Yii::$app->user->identity->getId(),
|
||||
'su_id'=>$post['su_id'],
|
||||
'up_id'=>$post['u_id']
|
||||
])->one();
|
||||
|
||||
if (!$order || $order->accept_status != OrderAcceptEnum::OVER) throw new Exception('订单不存在');
|
||||
|
||||
$t=\Yii::$app->db->beginTransaction();
|
||||
try {
|
||||
//评价
|
||||
$UserComment=new UserComment();
|
||||
$UserComment->su_id=$post['su_id'];
|
||||
$UserComment->u_id=$post['u_id'];
|
||||
$UserComment->score=$post['score'];
|
||||
$UserComment->comment=$post['comment'];
|
||||
$UserComment->order_id=$post['order_id'];
|
||||
$UserComment->user_id=\Yii::$app->user->identity->getId();
|
||||
$UserComment->saveOrFail();
|
||||
|
||||
//订单评价状态
|
||||
$order->is_comment=1;
|
||||
$order->comment_time=time();
|
||||
$order->saveOrFail();
|
||||
|
||||
$t->commit();
|
||||
}catch (\Exception $e){
|
||||
$t->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 删除评价
|
||||
* @doc-param int id 评价id
|
||||
* @doc-param int su_id 医生id
|
||||
* @doc-param int u_id 患者id
|
||||
*/
|
||||
public function actionDel()
|
||||
{
|
||||
$post= \Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[ ['id','su_id','u_id'],'required']
|
||||
]);
|
||||
$CommentForm=new CommentForm();
|
||||
$CommentForm->attributes=$post;
|
||||
$CommentForm->del($post['id']);
|
||||
|
||||
return ['删除成功'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 评价列表
|
||||
* @doc-param int su_id 医生id
|
||||
* @doc-return mixed @UserComment{*} 信息
|
||||
*/
|
||||
public function actionList()
|
||||
{
|
||||
$post= \Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[ 'su_id','required']
|
||||
]);
|
||||
$UserComment=UserComment::find()->where([
|
||||
'su_id'=>$post['su_id']
|
||||
])->all();
|
||||
|
||||
if (!$UserComment) throw new Exception('暂时没有任何评价');
|
||||
return $UserComment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @doc-name 编辑评价
|
||||
* @doc-param int id 评价id
|
||||
* @doc-param int su_id 医生id
|
||||
* @doc-param int u_id 患者id
|
||||
* @doc-param int score 评分
|
||||
* @doc-param string comment 内容
|
||||
*/
|
||||
public function actionEditComment()
|
||||
{
|
||||
$post= \Yii::$app->request->post();
|
||||
$this->requestValidate($post,[
|
||||
[ ['id'],'required']
|
||||
]);
|
||||
$CommentForm=new CommentForm();
|
||||
$CommentForm->attributes=$post;
|
||||
|
||||
|
||||
$CommentForm->edit($post['id']);
|
||||
return ['编辑成功'];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user