Files
xk-api-yii/member/models/forms/CommentForm.php

57 lines
1.2 KiB
PHP
Raw Normal View History

2024-09-19 11:32:39 +08:00
<?php
namespace member\models\forms;
use common\core\BaseModel;
2024-12-19 19:20:27 +08:00
use common\models\oldDb\UserComment;
2024-09-19 11:32:39 +08:00
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]);
}
}