request->get(); $res = \Yii::$app->services->validate->validate($get, [ [['course_id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $discuss_data = AddonsCourseDiscuss::allDiscussList($get['course_id'], $this->mall_id); return $this->success('success', $discuss_data); } /** * @name: actionAddDiscuss * @msg: 针对某一课程添加评论 * @param integer cid 课程 id * @param string content 评论内容 * @param integer score 打分(星级) * @param integer is_anonymous 是否匿名评论 * @return {*} */ public function actionAddDiscuss() { $post = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($post, [ [['cid', 'is_anonymous', 'content', 'score'], 'required'], [['cid', 'cpid', 'score', 'is_anonymous'], 'integer'], [['content'], 'string'], ['is_anonymous', 'in', 'range' => [0, 1]], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['cpid'] = is_null($post['cpid']) ? 0 : $post['cpid']; $course_info = AddonsCourse::getOne([['id' => $post['cid']]]); if (0 === (int)$course_info->can_comment) { return $this->error('该课程不允许评论'); } $post['mall_id'] = $this->mall_id; $post['uid'] = $this->user_id; $res = AddonsCourseDiscuss::setData($post); if ($res === false) return $this->error(AddonsCourseOrders::getStaticError()); //设置课评论次数 + 1 if (!$course_info->updateCounters(['comments' => 1])) { return $this->error('保存课程评论次数失败'); } return $this->success('提交成功'); } /** * 课程分享 * @Author: guyu * @DateTime: 2021-03-22 14:53 * @return mixed */ public function actionShare() { $get = \Yii::$app->request->get(); $res = \Yii::$app->services->validate->validate($get, [ [['cid'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $course_info = AddonsCourse::getOne([['id' => $get['cid'], 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]]); if (empty($course_info)) { return $this->error("课程不存在或已下架"); } //设置课程视频分享次数 + 1 $course_res = $course_info->updateCounters(['shares' => 1]); if (true === $course_res) { return $this->success('课程分享成功'); } else { return $this->error("课程分享失败!"); } } /** * @name: actionThumbs * @msg: 对课程点赞 / 取消点赞 * @param $id integer 课程 id * @param $star_status integer 点赞状态,1:点赞;0:取消点赞 * @return {*} */ public function actionThumbs() { $post = \Yii::$app->request->post(); $res = \Yii::$app->services->validate->validate($post, [ [['course_id'], 'required'], ]); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['user_id'] = $this->user_id; $res = AddonsCourseChapterLikes::setData($this->mall_id, $post); if ($res === false) return $this->error(AddonsCourseOrders::getStaticError()); return $this->success('操作成功', $res); } }