Commit 3c56cb0d authored by xiabin's avatar xiabin

提交视频播放页面相关

parent 19ca989b
......@@ -82,4 +82,24 @@ class Comments extends \yii\db\ActiveRecord
$result = self::find()->select('id')->where('id=:id', [':id' => $id])->one();
return $result === NULL ? FALSE : TRUE;
}
public static function getCommentsListsByCoursewareId($coursewareId, $page, $num)
{
$condition = "courseware_id=:courseware_id";
$params = [':courseware_id' => $coursewareId];
//获取总数
$count = self::find()->where($condition, $params)->count();
$start = $page * $num;
$data = [];
if ($count > 0) {
$tableA = self::tableName();
$tableB = User::tableName();
$data = self::find()->select("$tableA.id,$tableA.comment,$tableA.user_id,$tableB.name,$tableB.avatar")->where($condition, $params)->limit($num)->offset($start)->orderBy('created_at DESC')->leftJoin($tableB, "$tableA.user_id = $tableB.id")->asArray()->all();
}
return [
'count' => $count,
'data' => $data
];
}
}
......@@ -83,7 +83,7 @@ class Course extends \yii\db\ActiveRecord
['price', 'integer', 'min' => 0, 'max' => 9999],
['free_time', 'integer', 'min' => 0, 'max' => 15],
['recommend', 'boolean'],
[['recommend', 'comment_count', 'favorit_count', 'support_count', 'play_count'], 'default', 'value' => 0],
[['recommend', 'comment_count', 'favorite_count', 'support_count', 'play_count'], 'default', 'value' => 0],
['status', 'in', 'range' => [0, 1, 2, 3]]
];
}
......@@ -141,7 +141,7 @@ class Course extends \yii\db\ActiveRecord
$count = self::find()->where($condition, $params)->count();
$start = $page * $num;
if ($count > 0) {
$data = self::find()->select('id,user_id,price,name,intro,preview_pic,recommend,play_count,comment_count,favorit_count,support_count,created_at')->where($condition, $params)->limit($num)->offset($start)->with('teachers')->asArray()->all();
$data = self::find()->select('id,user_id,price,name,intro,preview_pic,recommend,play_count,comment_count,favorite_count,support_count,created_at')->where($condition, $params)->limit($num)->offset($start)->with('teachers')->asArray()->all();
}
return [
'count' => $count,
......
......@@ -52,7 +52,7 @@ class Courseware extends ActiveRecord
[['user_id', 'course_id', 'type', 'status', 'size', 'time'], 'integer'],
[['name'], 'string', 'max' => 128],
[['format'], 'string', 'max' => 16],
[['comment_count', 'favorit_count', 'support_count', 'play_count'], 'default', 'value' => 0],
[['comment_count', 'favorite_count', 'support_count', 'play_count'], 'default', 'value' => 0],
];
}
......@@ -103,4 +103,5 @@ class Courseware extends ActiveRecord
$result = self::find()->select('id')->where('id=:id', [':id' => $id])->one();
return $result === NULL ? FALSE : TRUE;
}
}
......@@ -85,7 +85,7 @@ class HomeController extends \yii\web\Controller
*/
public function actionGetCourseLists($classId, $page, $num = 10)
{
if (Yii::$app->request->isAjax or TRUE) {
if (Yii::$app->request->isAjax) {
if ($page >= 0 and $num > 0) {
$result = Course::getCourseListsByClassId($classId, $page, $num);
} else {
......@@ -115,7 +115,7 @@ class HomeController extends \yii\web\Controller
/**
* 视频播放
* 视频播放页面
* @param $courseId
* @return string
*/
......@@ -132,19 +132,39 @@ class HomeController extends \yii\web\Controller
$coursewareInfo['intro'] = $course->intro;
$coursewareInfo['teachers'] = ArrayHelper::toArray($teachers);
$coursewareInfo['videoUrl'] = Yii::$app->qiniu->getUrl('video', $coursewareInfo['name']);
var_dump($coursewareInfo);
$coursewareInfo['isGuest'] = Yii::$app->user->isGuest;
return $this->render('video', [
'coursewareInfo' => $coursewareInfo
]);
}
}
/**
* 获取评论列表
* @param $coursewareId
* @throws ForbiddenHttpException
*/
public function actionGetCommentLists($coursewareId, $page, $num)
{
if (Yii::$app->request->isAjax or TRUE) {
if ($page >= 0 and $num > 0) {
$result = Comments::getCommentsListsByCoursewareId($coursewareId, $page, $num);
} else {
throw new InvalidParamException('参数错误');
}
Utils::ajaxResponse(TRUE, 'ok', $result);
} else {
throw new ForbiddenHttpException('非法请求');
}
}
/**
* 点赞或者取消点赞
* @param $coursewareId
* @throws \yii\web\ForbiddenHttpException
*/
public function actionSupport($coursewareId)
public
function actionSupport($coursewareId)
{
if (Yii::$app->request->isAjax) {
$userId = Yii::$app->user->identity->getId();
......@@ -174,7 +194,8 @@ class HomeController extends \yii\web\Controller
* @param $courseId
* @throws \yii\web\ForbiddenHttpException
*/
public function actionFavorite($courseId)
public
function actionFavorite($courseId)
{
if (Yii::$app->request->isAjax) {
$userId = Yii::$app->user->identity->getId();
......@@ -205,7 +226,8 @@ class HomeController extends \yii\web\Controller
* 评论
* @throws \yii\web\ForbiddenHttpException
*/
public function actionComments()
public
function actionComments()
{
$request = Yii::$app->request;
if ($request->isAjax) {
......@@ -246,7 +268,8 @@ class HomeController extends \yii\web\Controller
* 支付宝支付请求
* @throws InvalidParamException
*/
public function actionPay($courseId)
public
function actionPay($courseId)
{
$courseBaseInfo = Course::findBaseInfoByCourseId($courseId);
if ($courseBaseInfo !== NULL) {
......@@ -294,7 +317,8 @@ class HomeController extends \yii\web\Controller
/**
* 获取微信支付的二维码
*/
public function actionWeixinPayQrcode()
public
function actionWeixinPayQrcode()
{
$userId = Yii::$app->user->identity->getId();
$courseBaseInfo = Course::findBaseInfoByCourseId($courseId);
......@@ -313,7 +337,8 @@ class HomeController extends \yii\web\Controller
/**
* 移动端微信支付
*/
public function actionMobilePay()
public
function actionMobilePay()
{
$weixinpay = \Yii::$app->params['weixinpay'];
$client = new Client(
......@@ -356,7 +381,8 @@ class HomeController extends \yii\web\Controller
* @param $price
* @return false|string
*/
private function generateOrderNumber($userId, $courseId, $price)
private
function generateOrderNumber($userId, $courseId, $price)
{
return md5(date("YmdHis", time()) . "_{$userId}_{$courseId}_{$price}");
}
......
......@@ -19,7 +19,7 @@
<p>{{transcateTime(item.created_at)}}</p>
<div class="v-detail">
<span><i class="icon-comment-full"></i> {{item.comment_count}}</span>
<span><i class="icon-fav-full"></i> {{item.favorit_count}}</span>
<span><i class="icon-fav-full"></i> {{item.favorite_count}}</span>
<span><i class="icon-zan-full"></i> {{item.support_count}}</span>
</div>
</div>
......@@ -67,14 +67,14 @@
var url = __BASE_URL__ + 'home/get-course-lists?classId=' + classId + '&page=' +
page + '&num=' + num;
var self = this;
$.getJSON(url, function (reponse) {
if (reponse.status === true) {
var result = reponse.data;
$.getJSON(url, function (response) {
if (response.status === true) {
var result = response.data;
self.count = result.count;
self.lists = self.lists.concat(result.data);
self.more = (self.count > self.lists.length);
} else {
layer.alert(reponse.message, {'icon': 2, 'title': '提示'})
layer.alert(response.message, {'icon': 2, 'title': '提示'})
}
}).error(function () {
layer.alert('获取推荐课堂列表错误', {'icon': 2, 'title': '提示'})
......
......@@ -4,19 +4,19 @@
<div class="video-description">
<div class="title">视频介绍</div>
<div class="text">
<?= \yii\helpers\Html::encode($coursewareInfo['intro']) ?>
{{coursewareInfo.intro}}
</div>
</div>
<div class="video-comment">
<div class="title">评论
<small>607次</small>
<small>{{coursewareInfo.comment_count}}</small>
</div>
</div>
<div class="comment-login">
<div v-if="coursewareInfo.isGuest" class="comment-login">
需要 <a href="">登录</a> 才能评论
</div>
<div class="comment-box">
<div v-else class="comment-box">
<div class="comment-head">
<img src="">
</div>
......@@ -26,7 +26,7 @@
</div>
</div>
<div class="comment-main-list clearfix">
<div v-for="{item in lists}" class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
......@@ -34,50 +34,46 @@
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
<div class="comment-main-list clearfix">
<div class="user-h pull-left"><img src=""></div>
<div class="user-i">
<span>Frank <small>10分钟前</small></span>
<p>呵呵。。。不知为什么我听了你这么说话特牙疼</p>
</div>
</div>
</div>
</div>
</template>
<script>
export default{
data(){
return {}
return {
lists: [],
page: 0,
num: 10,
more: false
}
},
props: {
coursewareInfo: {
require: true
}
},
components: {}
methods: {
getCommentlists(coursewareId,page,num){
var self = this;
var url = __BASE_URL__ + 'home/get-comment-lists?coursewareId=' + coursewareId + '&page=' +
page + '&num=' + num;
$.getJSON(url, function (response) {
if (response.status === true) {
var result = response.data;
self.more = (result.count > self.lists.length);
self.lists = self.lists.concat(result.data);
}
else {
layer.alert(response.message, {'icon': 2, 'title': '提示'})
}
}).error(function () {
layer.alert('获取评论信息出错', {'icon': 2, 'title': '提示'})
});
}
},
ready(){
this.getCommentlists(this.coursewareInfo.id,this.page,this.num);
}
}
</script>
......@@ -21,14 +21,14 @@
<div class="video-detail-info">
<div class="video-teacher">
<a href="#"><img src=""></a>
<p><a href="#">乔布斯</a></p>
<p><a href="javascript:;">乔布斯</a></p>
<span>2016-10-08</span>
</div>
<div class="video-sm-info">
<a href="#"><i class="icon-comment-empty"></i>543</a>
<a href="#"><i class="icon-fav-empty"></i>31</a>
<a href="#"><i class="icon-zan-empty"></i>97</a>
<a href="javascript:;"><i class="icon-comment-empty"></i>{{coursewareInfo.comment_count}}</a>
<a href="javascript:;"><i class="icon-fav-empty"></i>{{coursewareInfo.favorite_count}}</a>
<a href="javascript:;"><i class="icon-zan-empty"></i>{{coursewareInfo.support_count}}</a>
</div>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment