cxfoot/models/common/CommonFeedbackActionForm.php
2023-10-27 14:25:12 +08:00

137 lines
4.3 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2021年6月29日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common;
use app\models\Feedback;
use app\models\User;
use app\models\Model;
class CommonFeedbackActionForm extends Model
{
public $user_id;
public $cx_mch_id;
public $feedback_id;
public $review_comment;
public function rules()
{
return [
[['review_comment'], 'trim'],
[['review_comment'], 'string'],
[['user_id', 'cx_mch_id',], 'integer'],
[['feedback_id'], 'safe'],
[['user_id', 'cx_mch_id', 'feedback_id'], 'required'],
[['review_comment', ], 'required', 'on' => 'review'],
];
}
public function delete()
{
if(!$this->validate()){
return $this->getModelError();
}
if(is_array($this->feedback_id)){
foreach ($this->feedback_id as $feedback_id){
$model = Feedback::find()
->where([
'id' => $feedback_id,
'is_delete' => 0,
'cx_mch_id' => $this->cx_mch_id
])
->andFilterWhere([
'user_id' => $this->user_id,
])->one();
if($model == null)
continue;
$model->is_delete = 1;
if(!$model->save()){
return $this->getModelError($model);
}
}
} else {
$model = Feedback::find()
->where([
'id' => $this->feedback_id,
'is_delete' => 0,
'cx_mch_id' => $this->cx_mch_id
])
->andFilterWhere([
'user_id' => $this->user_id,
])->one();
if($model == null){
return $this->apiReturnError('反馈不存在或已经删除');
}
$model->is_delete = 1;
if(!$model->save()){
return $this->getModelError($model);
}
}
return $this->apiReturnSuccess("删除成功");
}
public function review()
{
if(!$this->validate()){
return $this->getModelError();
}
if(is_array($this->feedback_id)){
foreach ($this->feedback_id as $feedback_id){
$model = Feedback::find()
->where([
'id' => $feedback_id,
'is_delete' => 0,
'cx_mch_id' => $this->cx_mch_id,
'review_status' => Feedback::REVIEW_STATUS_WAITTING
])
->andFilterWhere([
'user_id' => null,
])->one();
if($model == null)
continue;
$model->review_user_id = $this->user_id;
$model->review_status = Feedback::REVIEW_STATUS_DONE;
$model->review_time = time();
$model->review_comment = $this->review_comment;
if(!$model->save()){
return $this->getModelError($model);
}
}
} else {
$model = Feedback::find()
->where([
'id' => $this->feedback_id,
'is_delete' => 0,
'cx_mch_id' => $this->cx_mch_id,
'review_status' => Feedback::REVIEW_STATUS_WAITTING
])
->andFilterWhere([
'user_id' => null,
])->one();
if($model == null){
return $this->apiReturnError('反馈不存在或已经删除');
}
$model->review_user_id = $this->user_id;
$model->review_status = Feedback::REVIEW_STATUS_DONE;
$model->review_time = time();
$model->review_comment = $this->review_comment;
if(!$model->save()){
return $this->getModelError($model);
}
}
return $this->apiReturnSuccess("操作成功");
}
}