Commit d45b99b6 authored by 汪波's avatar 汪波
parents c39a1ff7 875c8343
......@@ -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
];
}
}
......@@ -4,8 +4,8 @@ namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\data\Pagination;
use yii\helpers\HtmlPurifier;
use yii\redis\ActiveQuery;
use yii\redis\ActiveRecord;
/**
......@@ -127,26 +127,37 @@ class Course extends \yii\db\ActiveRecord
/**
* 获取课程列表
* @param $classId
* @param $page 从0开始
* @param $num
*
* @param int $classId
* @param int $page 从0开始,如果传入null则使用系统分页机制,并返回 pagination 对象
* @param int $num
* @param int $status 要获取的状态,null代表获取全部,默认为只获取审核通过的课程
* @return array
*/
public static function getCourseListsByClassId($classId, $page, $num)
public static function getCourseListsByClassId($classId, $page=0, $num=10, $status=self::STATUS_OK)
{
$status = self::STATUS_OK;
$condition = "class_id=:class_id and status=$status";
$params = [':class_id' => $classId];
$cond = ['class_id'=>$classId];
$status !== null && $cond['status'] = $status;
//获取总数
$count = self::find()->where($condition, $params)->count();
$start = $page * $num;
$count = self::find()->where($cond)->count();
$return = ['count'=>$count, 'data' =>[]];
if ($page === null) {
$pagination = new Pagination(['totalCount' => $count, 'pageSize'=>$num, 'forcePageParam'=>false]);
$offset = $pagination->offset;
$return['pagination'] = $pagination;
} else {
$offset = $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();
$return['data'] = self::find()
->select('id,user_id,price,name,intro,preview_pic,recommend,play_count,comment_count,favorite_count,created_at')
->where($cond)->limit($num)->offset($offset)->with('teachers')->asArray()->all();
}
return [
'count' => $count,
'data' => $data
];
return $return;
}
/**
......
......@@ -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;
}
}
......@@ -21,6 +21,7 @@ class m160927_115114_classes_init extends Migration
'id_name' => $this->string(64)->notNull(),
'name' => $this->string(64)->notNull(),
'intro' => $this->text()->notNull(),
'desc' => $this->text()->notNull()->comment('案例资源'),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未审核 1 审核通过 2 审核不通过 3 锁定 '),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
......
......@@ -17,16 +17,20 @@ class m160927_121107_course_init extends Migration
$this->createTable($this->table, [
'id' => $this->primaryKey()->unsigned(),
'user_id' => $this->integer()->notNull()->unsigned(),
'classed_id' => $this->integer()->notNull()->unsigned(),
'class_id' => $this->integer(10)->notNull()->unsigned(),
'name' => $this->string(32)->notNull(),
'price' => $this->integer()->notNull(),
'free_time' => $this->integer()->notNull(),
'price' => $this->integer(10)->notNull()->defaultValue(0),
'free_time' => $this->integer(10)->notNull()->defaultValue(0),
'intro' => $this->text()->notNull(),
'preview_pic' => $this->string(255)->notNull(),
'recommend' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 表示推荐 1推荐'),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未审核 1 审核通过 2 审核不通过 3 锁定 '),
'play_count' => $this->integer(10)->unsigned()->notNull()->defaultValue(0)->comment('播放次数'),
'comment_count' => $this->integer(8)->unsigned()->notNull()->defaultValue(0)->comment('评论次数'),
'favorite_count' => $this->integer(8)->unsigned()->notNull()->defaultValue(0)->comment('收藏次数'),
'support_count' => $this->integer(8)->unsigned()->notNull()->defaultValue(0)->comment('点赞次数'),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull()
], $tableOptions);
$this->createIndex(
'index-user_id-status',
......
......@@ -20,12 +20,16 @@ class m160927_121625_courseware_init extends Migration
'course_id' => $this->integer()->notNull()->unsigned(),
'type' => $this->smallInteger()->notNull()->defaultValue(0)->unsigned()->comment('课件类型 默认0'),
'name' => $this->string(128)->notNull(),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未审核 1 审核通过 2 审核不通过 3 锁定 '),
'size' => $this->string(32)->notNull()->comment('文件大小 kb'),
'time' => $this->string(32)->notNull()->comment('视频时间 秒'),
'status' => $this->smallInteger()->notNull()->defaultValue(0)->comment('0 未审核, 1 审核通过, 2 审核不通过, 3 锁定'),
'size' => $this->integer(10)->notNull()->unsigned()->comment('文件大小/bytes'),
'time' => $this->smallInteger(8)->unsigned()->notNull()->comment('视频时间/秒'),
'format' => $this->string(16)->notNull()->comment('格式'),
'play_count' => $this->integer(10)->unsigned()->notNull()->defaultValue(0)->comment('播放次数'),
'comment_count' => $this->integer(8)->unsigned()->notNull()->defaultValue(0)->comment('评论次数'),
'favorite_count' => $this->integer(8)->unsigned()->notNull()->defaultValue(0)->comment('收藏次数'),
'support_count' => $this->integer(8)->unsigned()->notNull()->defaultValue(0)->comment('点赞次数'),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull()
], $tableOptions);
$this->addCommentOnTable($this->table, '用户课件表');
$this->createIndex('index-course_id', $this->table, 'course_id');
......
......@@ -9,7 +9,9 @@ use yii\filters\AccessControl;
class ClassesInfoController extends \yii\web\Controller
{
public $layout = 'classCenter';
public $classStatus;
/**
* @inheritdoc
......@@ -36,7 +38,8 @@ class ClassesInfoController extends \yii\web\Controller
public function actionIndex()
{
return $this->render('index');
$model = Classes::findOne($this->classStatus['id']);
return $this->render('index', compact('model'));
}
/**
......
......@@ -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,40 @@ 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 +195,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 +227,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 +269,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 +318,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 +338,8 @@ class HomeController extends \yii\web\Controller
/**
* 移动端微信支付
*/
public function actionMobilePay()
public
function actionMobilePay()
{
$weixinpay = \Yii::$app->params['weixinpay'];
$client = new Client(
......@@ -356,7 +382,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}");
}
......
......@@ -44,23 +44,27 @@ class MyCourseController extends \yii\web\Controller
];
}
/**
* 课程列表
*
* @return string
*/
public function actionIndex()
{
//return $this->render('index');
$list = Course::getCourseListsByClassId($this->classStatus['id'], null, 6, null);
return $this->render('index', ['list'=>$list['data'], 'pagination'=>$list['pagination']]);
}
/**
* 发布课程
*
*
* @param int $id
* @return string
*/
public function actionPublish()
public function actionPublish($id=0)
{
/* @var \common\components\Qiniu $qiniu */
$qiniu = Yii::$app->qiniu;
//$auth = Yii::$app->qiniu->getAuthInstance();
//$returnBody = '{"uuid":$(uuid), "key": "$(key)", "size": $(fsize), "w":$(imageInfo.width), "h":$(imageInfo.height)}';
//图片上传Token
//$imgName = 'preview/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
......@@ -219,7 +223,14 @@ class MyCourseController extends \yii\web\Controller
Utils::ajaxResponse(true, '', ['course_id'=>$course->id]);
}
/**
* 显示课程状态
*
* @return string|Response
* @throws \yii\web\ForbiddenHttpException
* @throws \yii\web\NotFoundHttpException
*/
public function actionResult()
{
$id = Yii::$app->request->get('id');
......
......@@ -317,6 +317,21 @@ class SiteController extends Controller
}
}
/**
* 设置登录后回调url
* @param $url
* @throws \yii\web\ForbiddenHttpException
*/
public function actionSetReturnUrl($url)
{
if (Yii::$app->request->isAjax) {
Yii::$app->user->setReturnUrl($url);
Utils::ajaxResponse(TRUE);
} else {
throw new \yii\web\ForbiddenHttpException('非法请求');
}
}
/**
* 发送注册短信
* ajax
......@@ -324,7 +339,7 @@ class SiteController extends Controller
*/
public function actionSendSignupMsg()
{
if (TRUE || Yii::$app->request->isAjax) {
if (Yii::$app->request->isAjax) {
$telephone = trim(Yii::$app->request->get('telephone'));
if (Utils::isTelephone($telephone)) {
$key = self::REDIS_SIGNUP_MSG_PREFIX . '::' . Utils::getRealIP();
......
......@@ -42,8 +42,7 @@ class TeacherManagerController extends \yii\web\Controller
*/
public function actionIndex()
{
$data = Teacher::fetchTeachers($this->classStatus['id']);
$data = Teacher::fetchTeachers($this->classStatus['id'], 0, 100);
return $this->render('index', compact('data'));
}
......@@ -100,8 +99,13 @@ class TeacherManagerController extends \yii\web\Controller
}
$oldAvatar = $model->avatar;
}
$data = [];
foreach (['name', 'intro', 'avatar'] as $k) {
$data[$k] = Yii::$app->request->post($k);
}
$model->load(Yii::$app->request->post());
$model->load($data);
$model->class_id = $this->classStatus['id'];
//认领头像文件
......
......@@ -2,11 +2,10 @@
/**
* @var $this yii\web\View
* @var \common\models\Classes $model
* @var int $agreement
*/
$this->title = '我的课堂';
?>
<div class="class-name">为课堂起个响亮的名字吧</div>
<div class="class-name"><?=$model->name?></div>
<div class="class-intro">
<div class="col-md-4">
<h3>课程总数</h3>
......
......@@ -19,7 +19,7 @@ $this->beginContent('@app/views/layouts/center.php');
<li>
<div class="link"><i class="icon-palette"></i>我的课堂<i class="icon-navigate_next"></i></div>
<ul class="submenu">
<li class="active"><a href="#">课堂概况</a></li>
<li class="active"><a href="/classes-info">课堂概况</a></li>
<li><a href="/teacher-manager">讲师管理</a></li>
</ul>
</li>
......@@ -27,7 +27,7 @@ $this->beginContent('@app/views/layouts/center.php');
<div class="link"><i class="icon-ondemand_video"></i>我的课程<i class="icon-navigate_next"></i></div>
<ul class="submenu">
<li><a href="/my-course/publish">发布课程</a></li>
<li><a href="#">课程列表</a></li>
<li><a href="/my-course">课程列表</a></li>
</ul>
</li>
<li>
......
<?php
/* @var $this yii\web\View */
?>
<h1>my-course/index</h1>
/**
* @var $this yii\web\View
* @var $list array
* @var $pagination yii\data\Pagination
*/
use yii\helpers\Url;
use yii\widgets\LinkPager;
$this->title = '课程列表';
<p>
You may change the content of this page by modifying
the file <code><?= __FILE__; ?></code>.
</p>
/**
* @var $qiniu common\components\Qiniu;
*/
$qiniu = \Yii::$app->qiniu;
?>
<div class="cls-list-box clearfix">
<?php foreach ($list as $course) { ?>
<div class="col-md-4">
<div class="cls-box-main">
<div class="video-img-box">
<a href="<?=Url::to(['video/index', 'id'=>$course['id']])?>" target="_blank"><img src="<?=$qiniu->getUrl('public', $course['preview_pic'])?>-m.preview"></a>
<div class="video-list-cnt">
<div class="tit"><a href="<?=Url::to(['video/index', 'id'=>$course['id']])?>" target="_blank"><?=$course['name']?></a></div>
<?php if ($course['teachers']) { ?>
<div class="teacher">讲师:<?=join(', ', array_column($course['teachers'], 'name'))?></div>
<?php } ?>
<div class="description"><?=mb_substr(strip_tags($course['intro']), 0, 250)?></div>
</div>
<div class="outline">
<span><?=$course['play_count']?> 次播放</span> · <span><?=$course['comment_count']?> 次评论</span> · <span><?=$course['favorite_count']?> 收藏</span>
</div>
<!--<div class="edit"><a href="<?=Url::to(['my-course/publish', 'id'=>$course['id']])?>"><i class="icon-mode_edit"></i></a></div>-->
</div>
</div>
</div>
<?php } ?>
</div>
<?=LinkPager::widget(['pagination'=>$pagination])?>
\ No newline at end of file
......@@ -806,7 +806,7 @@ textarea.input-r-control {
.cls-box-main {
margin: 0 10px 40px 10px;
background-color: #fff;
height: 350px;
height: 370px;
}
.video-img-box {
position: relative;
......@@ -837,6 +837,11 @@ textarea.input-r-control {
color: #999;
margin-top: 5px;
}
.video-list-cnt .teacher {
font-size: 12px;
margin-top: 5px;
color: #666;
}
.video-img-box .outline {
position: absolute;
bottom: 10px;
......
......@@ -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">
需要 <a href="">登录</a> 才能评论
<div v-if="coursewareInfo.isGuest" class="comment-login">
需要 <a @click="login" href="javascript:;">登录</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,55 @@
</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: {
login(){
var returnUrl = __BASE_URL__ + 'home/video?courseId=5';
var url = __BASE_URL__ + 'site/set-return-url?url=' + returnUrl;
$.getJSON(url, function () {
window.location.href = __BASE_URL__ + 'site/login';
}).error(function () {
layer.alert('设置登录回调url错误', {'icon': 2, 'title': '提示'})
});
},
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