Commit 3b82cb02 authored by xiabin's avatar xiabin

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/frontend/web/css/style.css
parents 3e585daa 803c140f
......@@ -12,6 +12,9 @@ use Yii;
*/
class ClassesTeacher extends \yii\db\ActiveRecord
{
public static $lastErrors;
/**
* @inheritdoc
*/
......@@ -41,4 +44,29 @@ class ClassesTeacher extends \yii\db\ActiveRecord
'teacher_id' => 'Teacher ID',
];
}
public static function makeRelation($classId, $teacherId)
{
$model = new self();
$model->teacher_id = $teacherId;
$model->class_id = $classId;
if ($model->save()) {
return true;
} else {
self::$lastErrors = $model->errors;
return false;
}
}
public static function getTeachers($classId)
{
$obj = self::find();
$teacherTable = Teacher::tableName();
return $obj->select('t.id,t.user_id,t.name,t.avatar')->join('LEFT JOIN', $teacherTable.' t', 't.id=c.teacher_id')
->from(self::tableName().' c')->where(['c.class_id'=>$classId])->asArray()->all();
}
}
......@@ -17,6 +17,9 @@ use Yii;
*/
class Teacher extends \yii\db\ActiveRecord
{
public static $lastErrors;
/**
* @inheritdoc
*/
......@@ -34,7 +37,7 @@ class Teacher extends \yii\db\ActiveRecord
[['user_id', 'name', 'avatar', 'intro', 'created_at', 'updated_at'], 'required'],
[['user_id', 'created_at', 'updated_at'], 'integer'],
[['intro'], 'string'],
[['name'], 'string', 'max' => 64],
[['name'], 'string', 'min'=>2, 'max' => 64],
[['avatar'], 'string', 'max' => 255],
];
}
......@@ -54,4 +57,22 @@ class Teacher extends \yii\db\ActiveRecord
'updated_at' => 'Updated At',
];
}
public static function simpleAddTeacher($name)
{
$model = new self();
$model->user_id = 0;
$model->name = $name;
$model->avatar = 'avatar/f6/98/c6/_tjy7DgC0641.jpg';
$model->intro = '这个家伙很懒,什么也没有写。';
$model->created_at = time();
$model->updated_at = time();
if ($model->save()) {
return $model->toArray();
} else {
self::$lastErrors = $model->errors;
return false;
}
}
}
<?php
use yii\db\Migration;
class m161009_110732_upload_pools_init extends Migration
{
public $table = 'upload_pools';
public function up()
{
$this->createTable($this->table, [
'`uuid` char(36) NOT NULL',
'skey' => $this->string(255)->notNull()->comment('文件skey,如"public:avatar/fc/abc.jpg"'),
'filesize' => $this->integer(10)->unsigned()->notNull(),
'w' => $this->smallInteger(5)->unsigned()->defaultValue(0)->comment('图片宽'),
'h' => $this->smallInteger(5)->unsigned()->defaultValue(0)->comment('图片高'),
'`status` tinyint(1) NOT NULL DEFAULT \'0\' COMMENT \'文件状态: 0未认领,1已认领,2已删除(弃用)\'',
'upload_time' => $this->integer(10)->unsigned()->notNull()->comment('上传时间'),
'PRIMARY KEY (`uuid`)',
'KEY `status` (`status`,`upload_time`)',
'KEY `skey` (`skey`)'
], 'ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=\'上传文件状态标记表\'');
}
public function down()
{
$this->dropTable($this->table);
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
......@@ -20,12 +20,12 @@ class MyCourseController extends \yii\web\Controller
$qiniu = Yii::$app->qiniu;
//$auth = Yii::$app->qiniu->getAuthInstance();
$returnBody = '{"uuid":$(uuid), "key": "$(key)", "size": $(fsize), "w":$(imageInfo.width), "h":$(imageInfo.height)}';
//$returnBody = '{"uuid":$(uuid), "key": "$(key)", "size": $(fsize), "w":$(imageInfo.width), "h":$(imageInfo.height)}';
//图片上传Token
//$imgName = 'preview/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
$imgPath = 'preview/'.$qiniu->generateRandomFilePath('$(min)$(sec)$(ext)', 8);
$thumbToken = $qiniu->getUploadToken('public', $imgPath, 3600, true);
$thumbToken = $qiniu->getUploadToken('public', $imgPath);
//视频上传Token
//$videoName = 'source/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
......
......@@ -2,11 +2,60 @@
namespace frontend\controllers;
use common\models\Teacher;
use common\models\ClassesTeacher;
class TeacherManagerController extends \yii\web\Controller
{
public $layout = 'user-center';
public function actionIndex()
{
return $this->render('index');
}
public function actionSimpleTeacherList()
{
//Todo: 假设数据
$classId = 1;
$response = \Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_JSON;
return ClassesTeacher::getTeachers($classId);
}
/**
* 添加讲师
*/
public function actionAddTeacher()
{
//Todo: 假设数据
$uid = 18;
$classId = 1;
$response = \Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_JSON;
$name = strip_tags(\Yii::$app->request->post('name'));
$teacher = Teacher::simpleAddTeacher($name);
if ($teacher) {
ClassesTeacher::makeRelation($classId, $teacher['id']);
return [
'teacher_id' => $teacher['id'],
'name' => $teacher['name']
];
} else {
return ['error'=>join("\\n", Teacher::$lastErrors)];
}
}
public function actionTest()
{
$data = ClassesTeacher::getTeachers(1);
print_r($data);
}
}
......@@ -11,9 +11,9 @@ $this->title = '发布课程';
//AppAsset::addScript($this, '@web/assets/single-lib/plupload/plupload.full.min.js');
AppAsset::addScript($this, '@web/assets/course_publish.js');
$this->registerCss('[v-cloak] {display:none;}');
?>
<div class="send-class" id="publishMain">
<div class="send-class" id="publishMain" xmlns:v-el="http://www.w3.org/1999/xhtml">
<div class="tit">发布课程</div>
<form method="post" name="coursePublish">
......@@ -24,25 +24,16 @@ AppAsset::addScript($this, '@web/assets/course_publish.js');
<div class="cls-part teacher-list">
<div class="tit">讲师</div>
<div class="checkbox">
<label>
<input name="teacher[]" type="checkbox">杨佩佩
</label>
<label class="m-l-10">
<input name="teacher[]" type="checkbox">马骏
<div class="checkbox" v-cloak>
<label v-for="(index, item) in teachers" :class="{'m-l-10':index!=0}">
<input name="teacher[]" type="checkbox" value="{{item.id}}" v-model="checkedTeachers">{{item.name}}
</label>
<label class="m-l-10">
<input name="teacher[]" type="checkbox">花木兰
</label>
<label class="m-l-10">
<input name="teacher[]" type="checkbox">张海
</label>
<span class="m-l-10"><a href="#">+ 添加讲师</a></span>
<div class="d-i-b" v-if="atState">
<input type="text" class="input-r-control reset-input" placeholder="请输入讲师名称" v-model="addTeacherName" v-el:tni>
<button type="button" class="btn btn-nobg" @click="addTeacher">保存</button>
</div>
<span class="m-l-10" v-if="!atState"><a href="javascript:;" @click="addTeacher">+ 添加讲师</a></span>
</div>
</div>
......@@ -57,20 +48,20 @@ AppAsset::addScript($this, '@web/assets/course_publish.js');
<div class="checkbox rules-set fl">
<label class="clearfix">
<input name="vip_price" type="checkbox" class="fl" value="1"><span>会员价</span> <input type="text" value="price" class="input-r-control"> <span>元</span>
<!--<input name="vip_price" type="checkbox" class="fl" value="1">--><span>会员价</span> <input type="text" name="price" class="input-r-control text-center" value="0"> <span>元</span>
</label>
</div>
<div class="checkbox rules-set m-l-20 fl">
<label class="clearfix">
<input name="free_time" type="checkbox" class="fl"><span>免费试看</span> <input type="text" class="input-r-control"> <span>分钟</span>
<!--<input name="free_time" type="checkbox" class="fl">--><span>免费试看</span> <input type="text" name="free_time" class="input-r-control text-center" value="0"> <span>分钟</span>
</label>
</div>
</div>
</div>
<input type="hidden" name="vkey" value="{{videoKey}}" />
<input type="hidden" name="vuid" value="{{vuid}}" />
<input type="hidden" name="preview_pic" value="{{previewKey}}" />
<div class="cls-part">
<div class="tit">课程介绍</div>
......
......@@ -18,9 +18,6 @@ html {
.m-t-20 {
margin-top: 20px;
}
.m-b-20 {
margin-bottom: 20px;
}
.d-i-b {
display: inline-block;
}
......@@ -391,13 +388,11 @@ html {
background-color: #fff;
}
.add-box-main {
position: relative;
padding: 20px 40px;
text-align: center;
}
.add-box-main .tit {
text-align: left;
font-size: 16px;
}
.upload-avatar {
position: relative;
......@@ -432,46 +427,9 @@ html {
cursor: pointer;
}
.upload-avatar img {
position: absolute;
left: 0;
top: 0;
height: 100px;
width: 100px;
border-radius: 100%;
z-index: 2;
}
.upload-avatar span.loading-tip {
position: absolute;
display: inline-block;
width: 100px;
height: 100px;
text-align: center;
line-height: 100px;
color: #fff;
top: 0;
left: 0;
border-radius: 100%;
background-color: rgba(0,0,0,.5);
z-index: 3;
}
.edit-info {
position: absolute;
display: inline-block;
width: 50px;
height: 50px;
border-radius: 100%;
text-align: center;
line-height: 52px;
font-size: 18px;
text-decoration: none;
right: 20px;
top: 20px;
background-color: #f3f3f3;
}
.edit-info:hover {
background-color: #3f7de4;
color: #fff;
text-decoration: none;
}
.type-name {
font-size: 14px;
......
......@@ -2,26 +2,75 @@
* Created by pader on 16/9/28.
*/
var Vue = require('vue');
var videoUpload = require('../components/common/video-upload.vue');
var thumbUpload = require('../components/common/thumb-upload.vue');
var videoUpload = require('../components/uploader/video-upload.vue');
var thumbUpload = require('../components/uploader/thumb-upload.vue');
var form = document.forms["coursePublish"];
var layer = require("layer-js");
//$.ajaxSetup({
// beforeSend: function() {
// if (this.type == "POST") {
// this.data += "&_csrf-frontend=" + encodeURIComponent($("meta[name='csrf-token']").attr("content"));
// }
// }
//});
var vm = new Vue({
el: '#publishMain',
el: "#publishMain",
data: {
videoKey: "",
previewKey: ""
vuid: "",
previewKey: "",
teachers: [],
atState: 0,
addTeacherName: "",
checkedTeachers: []
},
components: {
videoUpload: videoUpload,
thumbUpload: thumbUpload
},
methods: {
addTeacher: function(e) {
if (e.target.tagName.toLowerCase() == "a") {
this.atState = 1;
return;
}
if ($.trim(this.addTeacherName) == "") {
this.$els.tni.focus();
return;
}
var self = this;
//添加讲师
$.post("/teacher-manager/add-teacher", {
name: self.addTeacherName
}, function(t) {
if (!t.error) {
self.loadTeacherList();
self.addTeacherName = "";
self.atState = 0;
self.checkedTeachers.push(t.teacher_id.toString());
} else {
layer.alert("添加讲师失败!\n" + t.error, {icon:5, title:"上传失败"});
}
}, "json");
},
loadTeacherList: function() {
$.getJSON("/teacher-manager/simple-teacher-list", function(t) {
vm.teachers = t;
});
}
},
ready: function() {
var self = this;
this.loadTeacherList();
this.$on("video-uploaded", function(name, data) {
self.videoKey = data.key;
self.vuid = data.uuid;
});
this.$on("thumb-uploaded", function(name, data) {
......@@ -36,7 +85,12 @@ require.ensure("jquery-validation", function() {
$(form).validate({
debug: true,
rules: {
required: true
name: {
required: true
}
},
submitHandler: function() {
return false;
}
});
});
......@@ -24,6 +24,9 @@ html {
.d-i-b {
display: inline-block;
}
.tit {
font-size: 16px;
}
/*side bar*/
......@@ -1056,4 +1059,17 @@ textarea.input-r-control {
}
.sm-box:hover .play-mask {
opacity: 1;
}
.apply-class-box {
max-width: 600px;
margin: 0 auto
}
.empty-data {
height: 300px;
text-align: center;
padding-top: 110px;
background: url("../img/empty.png") center top no-repeat;
color: #999;
}
\ No newline at end of file
......@@ -25,9 +25,14 @@
<li><a href="#"><i class="glyphicon glyphicon-ok"></i>已购课程</a></li>
<li><a href="#"><i class="glyphicon glyphicon-star"></i>收藏纪录</a></li>
<li><a href="#"><i class="glyphicon glyphicon-eye-open"></i>浏览记录</a></li>
<li><a href="#"><i class="glyphicon glyphicon-play-circle"></i>我的课堂</a></li>
<li><a href="#"><i class="glyphicon glyphicon-off"></i>退出登录</a></li>
</ul>
<div class="apply-class">
<button class="btn btn-danger">申请课堂</button>
</div>
</div>
</div>
......
......@@ -23,8 +23,13 @@
<li class="active"><a href="#"><i class="glyphicon glyphicon-ok"></i>已购课程</a></li>
<li><a href="#"><i class="glyphicon glyphicon-star"></i>收藏纪录</a></li>
<li><a href="#"><i class="glyphicon glyphicon-eye-open"></i>浏览记录</a></li>
<li><a href="#"><i class="glyphicon glyphicon-play-circle"></i>我的课堂</a></li>
<li><a href="#"><i class="glyphicon glyphicon-off"></i>退出登录</a></li>
</ul>
<div class="apply-class">
<button class="btn btn-danger">申请课堂</button>
</div>
</div>
</div>
......
......@@ -23,8 +23,13 @@
<li><a href="#"><i class="glyphicon glyphicon-ok"></i>已购课程</a></li>
<li class="active"><a href="#"><i class="glyphicon glyphicon-star"></i>收藏纪录</a></li>
<li><a href="#"><i class="glyphicon glyphicon-eye-open"></i>浏览记录</a></li>
<li><a href="#"><i class="glyphicon glyphicon-play-circle"></i>我的课堂</a></li>
<li><a href="#"><i class="glyphicon glyphicon-off"></i>退出登录</a></li>
</ul>
<div class="apply-class">
<button class="btn btn-danger">申请课堂</button>
</div>
</div>
</div>
......
......@@ -23,6 +23,7 @@
<li><a href="#"><i class="glyphicon glyphicon-ok"></i>已购课程</a></li>
<li><a href="#"><i class="glyphicon glyphicon-star"></i>收藏纪录</a></li>
<li class="active"><a href="#"><i class="glyphicon glyphicon-eye-open"></i>浏览记录</a></li>
<li><a href="#"><i class="glyphicon glyphicon-play-circle"></i>我的课堂</a></li>
<li><a href="#"><i class="glyphicon glyphicon-off"></i>退出登录</a></li>
</ul>
......@@ -40,7 +41,12 @@
<div class="tp-main">
<div class="container">
<div class="cls-list-box">
<!-- 没有内容 -->
<div class="empty-data">
您还没购买任何课程!
</div>
<div class="cls-list-box hide">
<div class="col-md-4">
<div class="cls-box-main sm-box">
<div class="video-img-box">
......
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