Files
xk-api-yii/member/models/forms/CommentForm.php
2024-09-19 11:32:39 +08:00

59 lines
1.2 KiB
PHP

<?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]);
}
}