Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
0f90b990
Commit
0f90b990
authored
Oct 09, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完美添加讲师等体验
为上传池表添加迁移
parent
ba273b41
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
168 additions
and
15 deletions
+168
-15
ClassesTeacher.php
src/common/models/ClassesTeacher.php
+28
-0
Teacher.php
src/common/models/Teacher.php
+22
-1
m161009_110732_upload_pools_init.php
src/console/migrations/m161009_110732_upload_pools_init.php
+40
-0
MyCourseController.php
src/frontend/controllers/MyCourseController.php
+1
-1
TeacherManagerController.php
src/frontend/controllers/TeacherManagerController.php
+40
-1
publish.php
src/frontend/views/my-course/publish.php
+3
-3
publish.js
src/frontend/web/js/my-course/publish.js
+34
-9
No files found.
src/common/models/ClassesTeacher.php
View file @
0f90b990
...
...
@@ -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
();
}
}
src/common/models/Teacher.php
View file @
0f90b990
...
...
@@ -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'
,
'm
in'
=>
2
,
'm
ax'
=>
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
;
}
}
}
src/console/migrations/m161009_110732_upload_pools_init.php
0 → 100644
View file @
0f90b990
<?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()
{
}
*/
}
src/frontend/controllers/MyCourseController.php
View file @
0f90b990
...
...
@@ -25,7 +25,7 @@ class MyCourseController extends \yii\web\Controller
//图片上传Token
//$imgName = 'preview/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
$imgPath
=
'preview/'
.
$qiniu
->
generateRandomFilePath
(
'$(min)$(sec)$(ext)'
,
8
);
$thumbToken
=
$qiniu
->
getUploadToken
(
'public'
,
$imgPath
,
3600
);
$thumbToken
=
$qiniu
->
getUploadToken
(
'public'
,
$imgPath
);
//视频上传Token
//$videoName = 'source/'.$qiniu->genRandomDir().'/'.Yii::$app->security->generateRandomString(20);
...
...
src/frontend/controllers/TeacherManagerController.php
View file @
0f90b990
...
...
@@ -3,6 +3,7 @@
namespace
frontend\controllers
;
use
common\models\Teacher
;
use
common\models\ClassesTeacher
;
class
TeacherManagerController
extends
\yii\web\Controller
{
...
...
@@ -12,11 +13,49 @@ class TeacherManagerController extends \yii\web\Controller
{
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
()
{
$model
=
new
Teacher
();
//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
);
}
}
src/frontend/views/my-course/publish.php
View file @
0f90b990
...
...
@@ -26,7 +26,7 @@ $this->registerCss('[v-cloak] {display:none;}');
<div
class=
"tit"
>
讲师
</div>
<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}}"
>
{{item.name}}
<input
name=
"teacher[]"
type=
"checkbox"
value=
"{{item.id}}"
v-model=
"checkedTeachers"
>
{{item.name}}
</label>
<div
class=
"d-i-b"
v-if=
"atState"
>
...
...
@@ -48,13 +48,13 @@ $this->registerCss('[v-cloak] {display:none;}');
<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>
...
...
src/frontend/web/js/my-course/publish.js
View file @
0f90b990
...
...
@@ -6,20 +6,25 @@ 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"
,
data
:
{
vuid
:
""
,
previewKey
:
""
,
teachers
:
[
{
id
:
1
,
name
:
"杨佩佩"
},
{
id
:
2
,
name
:
"马骏"
},
{
id
:
3
,
name
:
"花木兰"
},
{
id
:
4
,
name
:
"张海"
}
],
teachers
:
[],
atState
:
0
,
addTeacherName
:
""
addTeacherName
:
""
,
checkedTeachers
:
[]
},
components
:
{
videoUpload
:
videoUpload
,
...
...
@@ -39,15 +44,30 @@ var vm = new Vue({
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
.
vuid
=
data
.
uuid
;
...
...
@@ -65,7 +85,12 @@ require.ensure("jquery-validation", function() {
$
(
form
).
validate
({
debug
:
true
,
rules
:
{
required
:
true
name
:
{
required
:
true
}
},
submitHandler
:
function
()
{
return
false
;
}
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment