Commit faad91f6 authored by 杨培's avatar 杨培

完成后台的课堂管理

parent da50ffa2
...@@ -18,6 +18,7 @@ class AppAsset extends AssetBundle ...@@ -18,6 +18,7 @@ class AppAsset extends AssetBundle
]; ];
public $js = [ public $js = [
'js/global.js',
'libs/layer/layer.js' 'libs/layer/layer.js'
]; ];
......
...@@ -37,9 +37,16 @@ return [ ...@@ -37,9 +37,16 @@ return [
'errorHandler' => [ 'errorHandler' => [
'errorAction' => 'site/error', 'errorAction' => 'site/error',
], ],
//'assetManager' => [ 'assetManager' => [
// 'appendTimestamp' => true 'appendTimestamp' => false,
//] 'bundles' => [
'yii\web\JqueryAsset' => [
'jsOptions' => [
'position' => 1
]
]
]
]
/* /*
'urlManager' => [ 'urlManager' => [
'enablePrettyUrl' => true, 'enablePrettyUrl' => true,
......
<?php <?php
return [ return [
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
'classes.check.msg.ok' => '恭喜您!您申请的课堂 “{className}” ,已通过审核。',
'classes.check.msg.failed' => '很遗憾,您申请的课堂 “{className}” ,因{reason},未通过审核。',
'classes.check.msg.locked' => '告警,您的课堂 “{className}” ,因{reason},被锁定。'
]; ];
...@@ -8,7 +8,10 @@ ...@@ -8,7 +8,10 @@
namespace backend\controllers; namespace backend\controllers;
use common\libs\Message;
use common\libs\Utils;
use common\models\Classes; use common\models\Classes;
use common\models\User;
use Yii; use Yii;
use yii\web\Controller; use yii\web\Controller;
...@@ -30,7 +33,68 @@ class ClassesController extends Controller ...@@ -30,7 +33,68 @@ class ClassesController extends Controller
public function actionCheck() public function actionCheck()
{ {
$id = (int)Yii::$app->request->post('id');
$check = (int)Yii::$app->request->post('check');
$msg = (int)Yii::$app->request->post('msg');
$class = Classes::findOne(['id'=>$id]);
if (!$class) {
Utils::ajaxResponse(false, '参数错误,目标课堂不存在。');
}
if ($check == $class->status) {
Utils::ajaxResponse(false, '状态没有任何变化。');
}
$user = User::findOne(['id'=>$class->user_id]);
$sms = new Message();
switch ($check) {
case Classes::STATUS_OK:
$class->status = $check;
if ($class->save() && $msg) {
$template = Yii::$app->params['classes.check.msg.ok'];
$sms->send($user->telephone, str_replace('{className}', $class->name, $template));
}
Utils::ajaxResponse(true);
break;
case Classes::STATUS_FAILED:
$reason = Yii::$app->request->post('reason');
if ($msg && $reason == '') {
Utils::ajaxResponse(false, '拒绝审核必须输入理由!');
}
$class->status = $check;
if ($class->save() && $msg) {
$template = Yii::$app->params['classes.check.msg.failed'];
$sms->send($user->telephone, str_replace(['{className}', '{reason}'], [$class->name, $reason], $template));
}
Utils::ajaxResponse(true);
break;
case Classes::STATUS_LOCKED:
$reason = Yii::$app->request->post('reason');
if ($msg && $reason == '') {
Utils::ajaxResponse(false, '锁定课堂必须输入理由!');
}
$class->status = $check;
if ($class->save() && $msg) {
$template = Yii::$app->params['classes.check.msg.locked'];
$sms->send($user->telephone, str_replace(['{className}', '{reason}'], [$class->name, $reason], $template));
}
Utils::ajaxResponse(true);
break;
default:
Utils::ajaxResponse(false, '未知状态');
}
} }
} }
...@@ -13,8 +13,8 @@ use yii\helpers\Url; ...@@ -13,8 +13,8 @@ use yii\helpers\Url;
$this->title = "课堂管理"; $this->title = "课堂管理";
Yii::$app->assetManager->publish('@webroot/back'); //Yii::$app->assetManager->publish('@webroot/back');
AppAsset::addScript($this, 'js/classes/list.js'); //AppAsset::addScript($this, 'js/classes/list.js');
?> ?>
<!-- Content Header (Page header) --> <!-- Content Header (Page header) -->
<section class="content-header"> <section class="content-header">
...@@ -46,7 +46,7 @@ AppAsset::addScript($this, 'js/classes/list.js'); ...@@ -46,7 +46,7 @@ AppAsset::addScript($this, 'js/classes/list.js');
<?php if ($count > 0) { ?> <?php if ($count > 0) { ?>
<div class="row clearfix"> <div class="row clearfix">
<?php foreach ($data as $row) { ?> <?php foreach ($data as $row) { ?>
<div class="col-md-3 CLASS_ROW" data-classId="<?=$row['id']?>"> <div class="col-md-3 CLASS_ROW" data-class-id="<?=$row['id']?>">
<div class="box box-info"> <div class="box box-info">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title"><?=Html::encode($row['name'])?></h3> <h3 class="box-title"><?=Html::encode($row['name'])?></h3>
...@@ -60,29 +60,21 @@ AppAsset::addScript($this, 'js/classes/list.js'); ...@@ -60,29 +60,21 @@ AppAsset::addScript($this, 'js/classes/list.js');
<?=Html::encode($row['desc'])?> <?=Html::encode($row['desc'])?>
<hr> <hr>
<div class="clearfix"> <div class="clearfix">
<?php if ($status == Classes::STATUS_UNCHECK) { ?>
<div class="pull-right"> <div class="pull-right">
<?php if ($status == Classes::STATUS_UNCHECK) { ?>
<button class="btn btn-primary btn-xs CLASS_CHECK"><i class="fa fa-check"></i> 通过</button> <button class="btn btn-primary btn-xs CLASS_CHECK"><i class="fa fa-check"></i> 通过</button>
<button class="btn btn-danger btn-xs CLASS_REFUSE"><i class="fa fa-close"></i> 拒绝</button> <button class="btn btn-danger btn-xs CLASS_REFUSE"><i class="fa fa-close"></i> 拒绝</button>
</div> <?php } elseif ($status == Classes::STATUS_OK) { ?>
<button class="btn btn-default btn-xs CLASS_LOCK"><i class="fa fa-lock"></i> 锁定</button>
<?php } elseif ($status == Classes::STATUS_LOCKED) { ?>
<button class="btn btn-success btn-xs CLASS_UNLOCK"><i class="fa fa-unlock"></i> 解锁</button>
<?php } ?> <?php } ?>
</div>
<div class="clearfix user-lit"> <div class="clearfix user-lit">
<img src="<?=\common\models\User::getAvatarUrl($row['user']['avatar'])?>" class="user-lit-head img-circle"> <img src="<?=\common\models\User::getAvatarUrl($row['user']['avatar'])?>" class="user-lit-head img-circle">
<span><?=$row['user']['username']?></span> <span><?=$row['user']['username']?></span>
</div> </div>
</div> </div>
<?php if ($status == Classes::STATUS_UNCHECK) { ?>
<form class="form-horizontal" style="margin-top:10px;">
<div class="form-group margin-bottom-none">
<div class="col-sm-9">
<input class="form-control input-sm" placeholder="输入拒绝的原因">
</div>
<div class="col-sm-3">
<button type="submit" class="btn btn-danger pull-right btn-block btn-sm">确认</button>
</div>
</div>
</form>
<?php } ?>
</div><!-- /.box-body --> </div><!-- /.box-body -->
</div> </div>
</div> </div>
...@@ -104,3 +96,104 @@ AppAsset::addScript($this, 'js/classes/list.js'); ...@@ -104,3 +96,104 @@ AppAsset::addScript($this, 'js/classes/list.js');
</section> </section>
<!-- /.content --> <!-- /.content -->
<script type="text/javascript">
$(function() {
$("button.CLASS_CHECK").click(function() {
accessAction(this, 1, '确定要通过该课堂申请吗?', true);
});
$("button.CLASS_REFUSE").click(function() {
refuseAction(this, 2, "请输入拒绝原因!", "已拒绝课堂申请!", true);
});
$("button.CLASS_LOCK").click(function() {
refuseAction(this, 3, "请输入锁定原因!", "已锁定指定课堂!", true);
});
$("button.CLASS_UNLOCK").click(function() {
accessAction(this, 1, '确定要解锁该课堂吗?', "该课堂已解锁!", false);
});
});
function refuseAction(element, status, reasonWarn, successMsg, sendMsg) {
var row = $(element).closest(".CLASS_ROW");
var id = row.data("classId");
var form = row.find(".REFUSE_FORM");
if (form.length == 0) {
var refuseForm = generateRefuseForm();
row.find(".box-body").append(refuseForm.html);
form = $("#" + refuseForm.id);
form.submit(function() {
if ($.trim(this.reason.value) == "") {
layer.alert(reasonWarn, {icon:5, title:"提示"});
return false;
}
var idx = layer.msg("正在提交..", {icon:16, shade: [0.2,'#000'], time:0});
$.post("/classes/check", {id:id, check:status, msg:(sendMsg ? 1 : 0), reason: this.reason.value}, function(t) {
if (t.status) {
layer.msg(successMsg, {
time: 1500,
icon: 1,
end: function() {
location.reload();
},
shade: [0.2,'#000']
});
form.remove();
} else {
layer.alert(t.message, {icon:5, title:"提示"});
}
}, "json");
return false;
});
} else {
form.remove();
}
}
function accessAction(element, status, confirmText, successMsg, sendMsg) {
var id = $(element).closest(".CLASS_ROW").data("classId");
layer.confirm(confirmText, {
btn: ['确定','取消']
}, function() {
var idx = layer.msg("正在提交..", {icon:16, shade: [0.2,'#000'], time:0});
$.post("/classes/check", {id:id, check:status, msg:(sendMsg ? 1 : 0)}, function(t) {
layer.close(idx);
if (t.status) {
layer.msg(successMsg, {
time: 1500,
icon: 1,
end: function() {
location.reload();
},
shade: [0.2,'#000']
});
} else {
layer.alert(t.message, {icon:5, title:"提示"});
}
}, "json");
});
}
function generateRefuseForm() {
var x="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",tmp="";
for(var i=0;i<15;i++){tmp+=x.charAt(Math.ceil(Math.random()*100000000)%x.length);}
var randId = 'rf' + tmp;
var html = '<form class="form-horizontal REFUSE_FORM" style="margin-top:10px;" id="' + randId + '" method="post">'
+ '<div class="form-group margin-bottom-none">'
+ '<div class="col-sm-9"><input class="form-control input-sm" name="reason" placeholder="输入原因"></div>'
+ '<div class="col-sm-3"><button type="submit" class="btn btn-danger pull-right btn-block btn-sm">确认</button></div>'
+ '</div>'
+ '</form>';
return {id:randId, html:html};
}
</script>
.box-body hr {margin-top:10px; margin-bottom:10px;} .box-body hr {margin-top:10px; margin-bottom:10px;}
.user-lit .user-lit-head {margin-right:5px;} .user-lit .user-lit-head {margin-right:5px;}
.user-lit span {vertical-align:middle;} .user-lit span {vertical-align:middle;}
.user-lit-head {width:25px; height:25px;} .user-lit-head {width:25px; height:25px;}
sss \ No newline at end of file
\ No newline at end of file
/**
* Created by pader on 2016/10/24.
*/
$("button.CLASS_CHECK").click(function() {
layer.confirm('确定要通过该用户的课堂申请吗?', {
btn: ['确定','取消']
}, function() {
layer.msg('的确很重要', {icon: 1});
});
});
$("button.CLASS_REFUSE").click(function() {
});
\ No newline at end of file
/**
* Created by pader on 2016/10/25.
*/
//yii2框架开启csrf后post请求需要添加
$.ajaxSetup({
beforeSend: function () {
if (this.type == "POST") {
var name = $("meta[name='csrf-param']").attr("content");
var token = $("meta[name='csrf-token']").attr("content");
if (this.data instanceof FormData) {
this.data.append(name, token);
} else {
this.data += (this.data ? "&" : "") + name + "=" + encodeURIComponent(token);
}
}
}
});
\ No newline at end of file
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