初始化仓库
This commit is contained in:
59
member/models/forms/CommentForm.php
Normal file
59
member/models/forms/CommentForm.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace member\models\forms;
|
||||
|
||||
use common\core\BaseModel;
|
||||
use common\models\Order;
|
||||
use common\models\UserComment;
|
||||
use member\models\User;
|
||||
use yii\db\Exception;
|
||||
|
||||
class CommentForm extends BaseModel
|
||||
{
|
||||
public $su_id;
|
||||
public $u_id;
|
||||
public $score;
|
||||
public $order_id;
|
||||
public $comment;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['su_id','u_id','score','comment'],'required']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function del($id)
|
||||
{
|
||||
$userComment=UserComment::find()->where([
|
||||
'id'=>$id,
|
||||
'su_id'=>$this->su_id,
|
||||
'u_id'=>$this->u_id
|
||||
])->one();
|
||||
|
||||
if (!$userComment) throw new Exception('评价不存在');
|
||||
|
||||
$userComment->delete();
|
||||
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
if (!$this->validate()){
|
||||
throw new Exception($this->getErrorMsg($this));
|
||||
}
|
||||
$userComment=UserComment::find()->where([
|
||||
'id'=>$id,
|
||||
'su_id'=>$this->su_id,
|
||||
'u_id'=>$this->u_id
|
||||
])->one();
|
||||
|
||||
if (!$userComment) throw new Exception('评价不存在');
|
||||
|
||||
UserComment::updateAll(['score'=>$this->score,'comment'=>$this->comment],['id'=>$id,'su_id'=>$this->su_id,
|
||||
'u_id'=>$this->u_id]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user