getUser(); // 订单信息 $order = OrderModel::getUserOrderDetail($order_id, $user['user_id']); // 验证订单是否已完成 $model = new CommentModel; if (!$model->checkOrderAllowComment($order)) { return $this->renderError($model->getError()); } // 待评价商品列表 /* @var \think\Collection $goodsList */ $goodsList = OrderGoodsModel::getNotCommentGoodsList($order_id); if ($goodsList->isEmpty()) { return $this->renderError('该订单没有可评价的商品'); } // 提交商品评价 if ($this->request->isPost()) { $post = $this->request->post('formData'); if ($model->addForOrder($order, $goodsList, $post)) { return $this->renderSuccess([], '评价发表成功'); } return $this->renderError($model->getError() ?: '评价发表失败'); } return $this->renderSuccess(compact('goodsList')); } }