57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace member\models\forms;
|
|
|
|
use common\core\BaseModel;
|
|
use common\models\oldDb\UserComment;
|
|
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]);
|
|
|
|
}
|
|
|
|
} |