Commit 803c140f authored by 汪波's avatar 汪波

Merge remote-tracking branch 'origin/master'

parents ae2755b3 acabee6f
...@@ -12,6 +12,9 @@ use Yii; ...@@ -12,6 +12,9 @@ use Yii;
*/ */
class ClassesTeacher extends \yii\db\ActiveRecord class ClassesTeacher extends \yii\db\ActiveRecord
{ {
public static $lastErrors;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -41,4 +44,29 @@ class ClassesTeacher extends \yii\db\ActiveRecord ...@@ -41,4 +44,29 @@ class ClassesTeacher extends \yii\db\ActiveRecord
'teacher_id' => 'Teacher ID', '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; ...@@ -17,6 +17,9 @@ use Yii;
*/ */
class Teacher extends \yii\db\ActiveRecord class Teacher extends \yii\db\ActiveRecord
{ {
public static $lastErrors;
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -34,7 +37,7 @@ class Teacher extends \yii\db\ActiveRecord ...@@ -34,7 +37,7 @@ class Teacher extends \yii\db\ActiveRecord
[['user_id', 'name', 'avatar', 'intro', 'created_at', 'updated_at'], 'required'], [['user_id', 'name', 'avatar', 'intro', 'created_at', 'updated_at'], 'required'],
[['user_id', 'created_at', 'updated_at'], 'integer'], [['user_id', 'created_at', 'updated_at'], 'integer'],
[['intro'], 'string'], [['intro'], 'string'],
[['name'], 'string', 'max' => 64], [['name'], 'string', 'min'=>2, 'max' => 64],
[['avatar'], 'string', 'max' => 255], [['avatar'], 'string', 'max' => 255],
]; ];
} }
...@@ -54,4 +57,22 @@ class Teacher extends \yii\db\ActiveRecord ...@@ -54,4 +57,22 @@ class Teacher extends \yii\db\ActiveRecord
'updated_at' => 'Updated At', '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 ...@@ -20,12 +20,12 @@ class MyCourseController extends \yii\web\Controller
$qiniu = Yii::$app->qiniu; $qiniu = Yii::$app->qiniu;
//$auth = Yii::$app->qiniu->getAuthInstance(); //$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 //图片上传Token
//$imgName = 'preview/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20); //$imgName = 'preview/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
$imgPath = 'preview/'.$qiniu->generateRandomFilePath('$(min)$(sec)$(ext)', 8); $imgPath = 'preview/'.$qiniu->generateRandomFilePath('$(min)$(sec)$(ext)', 8);
$thumbToken = $qiniu->getUploadToken('public', $imgPath, 3600, true); $thumbToken = $qiniu->getUploadToken('public', $imgPath);
//视频上传Token //视频上传Token
//$videoName = 'source/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20); //$videoName = 'source/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
......
...@@ -2,11 +2,60 @@ ...@@ -2,11 +2,60 @@
namespace frontend\controllers; namespace frontend\controllers;
use common\models\Teacher;
use common\models\ClassesTeacher;
class TeacherManagerController extends \yii\web\Controller class TeacherManagerController extends \yii\web\Controller
{ {
public $layout = 'user-center';
public function actionIndex() public function actionIndex()
{ {
return $this->render('index'); 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 = '发布课程'; ...@@ -11,9 +11,9 @@ $this->title = '发布课程';
//AppAsset::addScript($this, '@web/assets/single-lib/plupload/plupload.full.min.js'); //AppAsset::addScript($this, '@web/assets/single-lib/plupload/plupload.full.min.js');
AppAsset::addScript($this, '@web/assets/course_publish.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> <div class="tit">发布课程</div>
<form method="post" name="coursePublish"> <form method="post" name="coursePublish">
...@@ -24,25 +24,16 @@ AppAsset::addScript($this, '@web/assets/course_publish.js'); ...@@ -24,25 +24,16 @@ AppAsset::addScript($this, '@web/assets/course_publish.js');
<div class="cls-part teacher-list"> <div class="cls-part teacher-list">
<div class="tit">讲师</div> <div class="tit">讲师</div>
<div class="checkbox" v-cloak>
<div class="checkbox"> <label v-for="(index, item) in teachers" :class="{'m-l-10':index!=0}">
<label> <input name="teacher[]" type="checkbox" value="{{item.id}}" v-model="checkedTeachers">{{item.name}}
<input name="teacher[]" type="checkbox">杨佩佩
</label>
<label class="m-l-10">
<input name="teacher[]" type="checkbox">马骏
</label> </label>
<label class="m-l-10"> <div class="d-i-b" v-if="atState">
<input name="teacher[]" type="checkbox">花木兰 <input type="text" class="input-r-control reset-input" placeholder="请输入讲师名称" v-model="addTeacherName" v-el:tni>
</label> <button type="button" class="btn btn-nobg" @click="addTeacher">保存</button>
</div>
<label class="m-l-10"> <span class="m-l-10" v-if="!atState"><a href="javascript:;" @click="addTeacher">+ 添加讲师</a></span>
<input name="teacher[]" type="checkbox">张海
</label>
<span class="m-l-10"><a href="#">+ 添加讲师</a></span>
</div> </div>
</div> </div>
...@@ -57,20 +48,20 @@ AppAsset::addScript($this, '@web/assets/course_publish.js'); ...@@ -57,20 +48,20 @@ AppAsset::addScript($this, '@web/assets/course_publish.js');
<div class="checkbox rules-set fl"> <div class="checkbox rules-set fl">
<label class="clearfix"> <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> </label>
</div> </div>
<div class="checkbox rules-set m-l-20 fl"> <div class="checkbox rules-set m-l-20 fl">
<label class="clearfix"> <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> </label>
</div> </div>
</div> </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}}" /> <input type="hidden" name="preview_pic" value="{{previewKey}}" />
<div class="cls-part"> <div class="cls-part">
<div class="tit">课程介绍</div> <div class="tit">课程介绍</div>
......
...@@ -15,6 +15,13 @@ html { ...@@ -15,6 +15,13 @@ html {
width: 100%; width: 100%;
} }
.m-t-20 {
margin-top: 20px;
}
.d-i-b {
display: inline-block;
}
/*side bar*/ /*side bar*/
.tp-sidebar { .tp-sidebar {
...@@ -558,6 +565,11 @@ fieldset[disabled] .input-r-control { ...@@ -558,6 +565,11 @@ fieldset[disabled] .input-r-control {
background-color: #eee; background-color: #eee;
opacity: 1; opacity: 1;
} }
.reset-input {
width: 100px;
display: inline-block;
margin-left: 20px;
}
textarea.input-r-control { textarea.input-r-control {
height: auto; height: auto;
} }
...@@ -747,7 +759,7 @@ textarea.input-r-control { ...@@ -747,7 +759,7 @@ textarea.input-r-control {
.cls-list-box .col-md-4 { .cls-list-box .col-md-4 {
} }
.cls-box-main { .cls-box-main {
margin: 0 10px 10px 10px; margin: 0 10px 40px 10px;
background-color: #fff; background-color: #fff;
height: 350px; height: 350px;
} }
...@@ -770,6 +782,10 @@ textarea.input-r-control { ...@@ -770,6 +782,10 @@ textarea.input-r-control {
.video-list-cnt .tit { .video-list-cnt .tit {
font-size: 14px; font-size: 14px;
} }
.video-list-cnt .tit a {
color: #333;
text-decoration: none;
}
.video-list-cnt .description { .video-list-cnt .description {
font-size: 12px; font-size: 12px;
line-height: 1.6; line-height: 1.6;
...@@ -926,4 +942,76 @@ textarea.input-r-control { ...@@ -926,4 +942,76 @@ textarea.input-r-control {
.buy-recode-top .col-md-4 p { .buy-recode-top .col-md-4 p {
font-size: 30px; font-size: 30px;
color: #259e2b; color: #259e2b;
}
/*user center side menu*/
.simple-menu li {
width: 100%;
}
.simple-menu li a {
position: relative;
display: block;
padding-left: 50px;
border-left: 2px solid transparent;
color: #7fa6ad;
height: 50px;
line-height: 50px;
text-decoration: none;
}
.simple-menu li a i {
position: absolute;
left: 10px;
top: 0;
display: inline-block;
width: 50px;
height: 50px;
text-align: center;
line-height: 50px;
padding-right: 12px;
font-size: 18px;
}
.simple-menu li.active a {
background-color: #313a46;
border-left: 2px solid #607ca1;
color: #fff;
}
.apply-class button {
width: 200px;
margin-left: 10px;
}
.sm-box {
height: 320px;
}
.sm-box .price {
height: 40px;
line-height: 40px;
color: #f11300;
}
.play-mask {
position: absolute;
display: inline-block;
top: 0;
left: 0;
width: 100%;
background-color: rgba(0,0,0,.2);
height: 220px;
line-height: 240px;
text-align: center;
z-index: 8;
opacity: 0;
-webkit-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
.play-mask a {
display: block;
}
.play-mask i {
color: #fff;
font-size: 38px;
}
.sm-box:hover .play-mask {
opacity: 1;
} }
\ No newline at end of file
...@@ -2,26 +2,75 @@ ...@@ -2,26 +2,75 @@
* Created by pader on 16/9/28. * Created by pader on 16/9/28.
*/ */
var Vue = require('vue'); var Vue = require('vue');
var videoUpload = require('../components/common/video-upload.vue'); var videoUpload = require('../components/uploader/video-upload.vue');
var thumbUpload = require('../components/common/thumb-upload.vue'); var thumbUpload = require('../components/uploader/thumb-upload.vue');
var form = document.forms["coursePublish"]; 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({ var vm = new Vue({
el: '#publishMain', el: "#publishMain",
data: { data: {
videoKey: "", vuid: "",
previewKey: "" previewKey: "",
teachers: [],
atState: 0,
addTeacherName: "",
checkedTeachers: []
}, },
components: { components: {
videoUpload: videoUpload, videoUpload: videoUpload,
thumbUpload: thumbUpload 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() { ready: function() {
var self = this; var self = this;
this.loadTeacherList();
this.$on("video-uploaded", function(name, data) { this.$on("video-uploaded", function(name, data) {
self.videoKey = data.key; self.vuid = data.uuid;
}); });
this.$on("thumb-uploaded", function(name, data) { this.$on("thumb-uploaded", function(name, data) {
...@@ -36,7 +85,12 @@ require.ensure("jquery-validation", function() { ...@@ -36,7 +85,12 @@ require.ensure("jquery-validation", function() {
$(form).validate({ $(form).validate({
debug: true, debug: true,
rules: { rules: {
required: true name: {
required: true
}
},
submitHandler: function() {
return false;
} }
}); });
}); });
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